this.container = new SigningProfileContainer();
this.container.readProfileXML( profileInputStream );
+ for ( SigningProfile profile : this.container.getProfiles() ) {
+ logger.info( "profile : {}", profile.getProfileName() );
+ logger.info( " author : {}", profile.getAuthorProfileItem() );
+ for ( SigningProfileItem item : profile.getDistributorProfileItems() ) {
+ logger.info( "dist : {}", item );
+ }
+ }
+
interactForPassword( executor, context );
validateSigningInfo();
boolean isCorrectPassword = false;
try {
- String password = new String( item.getPassword() );
+ char[] pass = item.getPassword();
+ String password = pass == null ? StringUtil.EMPTY_STRING : new String( pass );
String path = item.getKeyLocation();
isCorrectPassword = HashingSigning.CheckPkcs12Password( path, password );
} catch (FileNotFoundException e) {
if ( ! hasAuthor || ! hasDist1 ) {
// If don't have author certificate, no interact.
- return;
+ String msg = "Both an author and a first distributor must be required. Please check your profile infomation.";
+ context.getPrompter().notify( msg );
+ throw new CertificationException( msg );
}
// get an optional profile item
// generate fields
List<UserField> fieldList = new ArrayList<UserField>();
+
Object[][] fields = new Object[][] {
- new Object[] { SignatureConstants.AUTHOR, "Author password: ", true, authorItem.getPassword(), "Input author password.", "authorPwdSavable", "Save author password" },
- new Object[] { SignatureConstants.DISTRIBUTOR_1ST, "Distributor1 password: ", true, dist1Item.getPassword(), "Input distributor1 password.", "dist1PwdSavable", "Save distributor1 password" },
- new Object[] { SignatureConstants.DISTRIBUTOR_2ND, "Distributor2 password: ", hasDist2, dist2Item.getPassword(), "Input distributor2 password.", "dist2PwdSavable", "Save distributor2 password" },
+ new Object[] { SignatureConstants.AUTHOR, "Author password: ", isModifiable( authorItem ), authorItem.getPassword(), "Input author password.", "authorPwdSavable", "Save author password" },
+ new Object[] { SignatureConstants.DISTRIBUTOR_1ST, "Distributor1 password: ", isModifiable( dist1Item ), dist1Item.getPassword(), "Input distributor1 password.", "dist1PwdSavable", "Save distributor1 password" },
+ new Object[] { SignatureConstants.DISTRIBUTOR_2ND, "Distributor2 password: ", isModifiable( dist2Item ), hasDist2 ? dist2Item.getPassword() : new char[0], "Input distributor2 password.", "dist2PwdSavable", "Save distributor2 password" },
};
for (Object[] field : fields ) {
final String textId = (String) field[0];
context.getPrompter().batch( fieldList, options );
// write savable profile items
- boolean[] updateFlags = { true, true, hasDist2 };
+ boolean[] updateFlags = { (Boolean) fields[0][2], (Boolean) fields[1][2], (Boolean) fields[2][2] };
for ( int i = SigningProfile.AUTHOR_ORDINAL; i <= SigningProfile.MAX_DISTRIBUTOR; i++ ) {
updateProfileItem( profile, i, fieldList.get( i * 2 ), fieldList.get( i * 2 + 1), updateFlags[ i ], true );
}
if ( modifiable && saveValue ) {
SigningProfileItem profileItem = profile.removeProfileItem( ordinal );
- profileItem.setPassword( (char[]) text.getValue() );
- profile.setProfileItem( ordinal, profileItem );
+ if ( profileItem != null ) {
+ profileItem.setPassword( (char[]) text.getValue() );
+ profile.setProfileItem( ordinal, profileItem );
+ }
}
}
return item == null ? false : item.hasKeyLocation();
}
+ protected boolean isModifiable(SigningProfileItem item) {
+ if ( ! isValidItem( item ) ) {
+ return false;
+ }
+
+ char[] password = item.getPassword();
+ if ( password != null && ! StringUtil.isEmpty( new String( password ) ) ) {
+ return false;
+ }
+
+ return true;
+ }
+
protected boolean getBoolean(Object obj) {
return ( obj == null ) ? true : Boolean.parseBoolean( String.valueOf( obj ) );
}
return null;
}
- logger.trace( "item - key :{}, ordinal :{}, ca :{}, rootca :{}, pass {}", new Object[] { key, ordinal, ca, rootca, pass } );
+ logger.trace( "item - key :{}, ordinal :{}, ca :{}, rootca :{}, pass : {}", new Object[] { key, ordinal, ca, rootca, pass } );
return createProfileItem( ordinal, key, pass, ca, rootca );
}
XMLUtil.setElementAttribute( doc, SignatureConstants.PROFILEITEM_ATTR_ROOTCA, item.getRootCAPath(), element );
// encrypt password. if failed, write an original password.
- String pass = new String( item.getPassword() );
+ char[] password = item.getPassword();
+ String pass = password == null ? StringUtil.EMPTY_STRING : new String( item.getPassword() );
try {
pass = CipherUtil.getEncryptedString( pass );
// TODO: Organize exceptions