[Title] common-eplugin: fixed NPE for profile convering
authorJihoon Song <jihoon80.song@samsung.com>
Mon, 1 Jul 2013 03:08:41 +0000 (12:08 +0900)
committerJihoon Song <jihoon80.song@samsung.com>
Mon, 1 Jul 2013 07:14:32 +0000 (16:14 +0900)
[Desc.]
[Issue]

Change-Id: I6d96e01477954ff83ded6b484a01ffd67d722a4b

org.tizen.common.sign/src/org/tizen/common/sign/command/ReadSigningProfileFileCommand.java
org.tizen.common.sign/src/org/tizen/common/sign/preferences/SigningProfile.java

index 4ecefcd..188cc01 100755 (executable)
@@ -101,6 +101,14 @@ extends AbstractCommand<Object>
             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();
             
@@ -120,7 +128,8 @@ extends AbstractCommand<Object>
         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) {
@@ -173,7 +182,9 @@ extends AbstractCommand<Object>
         
         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
@@ -188,10 +199,11 @@ extends AbstractCommand<Object>
         
         // 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];
@@ -217,7 +229,7 @@ extends AbstractCommand<Object>
         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 );
         }
@@ -237,8 +249,10 @@ extends AbstractCommand<Object>
         
         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 );
+            }
         }
     }
     
@@ -316,6 +330,19 @@ extends AbstractCommand<Object>
         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 ) );
     }
index 8aedeb9..3e943bd 100644 (file)
@@ -262,7 +262,7 @@ public class SigningProfile {
             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 );
     }
@@ -283,7 +283,8 @@ public class SigningProfile {
         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