001: /*
002: * PasswordContextImpl.java
003: *
004: */
005:
006: /**
007: *
008: * @author ss133690
009: * @version
010: */package com.sun.portal.cli.cert;
011:
012: import org.mozilla.jss.crypto.*;
013: import com.sun.portal.log.common.PortalLogger;
014: import org.mozilla.jss.*;
015:
016: public class PasswordContextImpl implements PasswordContext {
017: public String generatePassphrase(JSSContext cntx) {
018: /**
019: * If the .jsspass file exists and returns the .jsspass password.
020: *If not it will create the .jsspass file with the new password.
021: *
022: */
023: String passphrase = "";
024: boolean flag = true;
025: if (!cntx.isDBFileExist() || !cntx.isPassFileExist()) {
026:
027: while (flag) {
028: CertAdminUtil.println(CertAdminHelpText
029: .getPassphraseHelpText());
030: //passphrase = CertAdminUtil.questionMasked("Enter passphrase []");
031: passphrase = CertAdminUtil
032: .questionMasked(CertAdminLocale.getPFString(
033: "q20", CertAdminConstants.q20));
034: while (passphrase.trim().equals("")) {
035: //println("Passphrase cannot be blank.");
036: CertAdminUtil.println(CertAdminLocale.getPFString(
037: "m40", CertAdminConstants.m40));
038: passphrase = CertAdminUtil
039: .questionMasked(CertAdminLocale
040: .getPFString("q20",
041: CertAdminConstants.q20));
042: }
043: //String confirmPassphrase = CertAdminUtil.questionMasked("Verify (re-enter) passphrase []");
044: String confirmPassphrase = CertAdminUtil
045: .questionMasked(CertAdminLocale.getPFString(
046: "q21", CertAdminConstants.q21));
047: CertAdminUtil.println(CertAdminConstants.newline);
048: if (passphrase.equals(confirmPassphrase)) {
049: //println("Passphrase accepted.");
050: CertAdminUtil.println(CertAdminLocale.getPFString(
051: "m41", CertAdminConstants.m41));
052: boolean stored = false;
053: if (cntx.isPasswordEcrypted()) {
054: try {
055: stored = CertAdminUtil.writeLine(JSSUtil
056: .encryptPassword(passphrase), cntx
057: .getCertdir()
058: + CertAdminConstants.SEPERATOR
059: + CertAdminConstants.JSSPASSFILE);
060: } catch (SRADecoderException ex) {
061: CertAdminUtil.println(CertAdminLocale
062: .getPFString("m55",
063: CertAdminConstants.m55)
064: + CertAdminConstants.newline + ex);
065: return null;
066: }
067: } else {
068: stored = CertAdminUtil
069: .writeLine(
070: passphrase,
071: cntx.getCertdir()
072: + CertAdminConstants.SEPERATOR
073: + CertAdminConstants.JSSPASSFILE);
074: }
075: //if(!CertAdminUtil.writeLine(passphrase, cntx.getCertdir()+CertAdminConstants.SEPERATOR+CertAdminConstants.JSSPASSFILE)){
076: if (!stored) {
077: //println("Could not store the password");
078: CertAdminUtil.println(CertAdminLocale
079: .getPFString("m42",
080: CertAdminConstants.m42));
081: }
082: flag = false;
083: } else {
084: //println("Passwords do not match.");
085: CertAdminUtil.println(CertAdminLocale.getPFString(
086: "m43", CertAdminConstants.m43));
087: }
088: }
089: } else {
090: passphrase = CertAdminUtil.readLine(cntx.getCertdir()
091: + CertAdminConstants.SEPERATOR
092: + CertAdminConstants.JSSPASSFILE);
093: if (cntx.isPasswordEcrypted()) {
094: try {
095: com.sun.portal.cli.cert.Password pass = JSSUtil
096: .decryptPassword(passphrase);
097: passphrase = pass.getPassword();
098: } catch (SRADecoderException ex) {
099: CertAdminUtil.println(CertAdminLocale.getPFString(
100: "m55", CertAdminConstants.m55)
101: + CertAdminConstants.newline + ex);
102: return null;
103: }
104: }
105: }
106: return passphrase;
107:
108: }
109:
110: }
|