From 76833eaa8d7e55594d63b955b65897d5a054e3a2 Mon Sep 17 00:00:00 2001 From: "gyeongseok.seo" Date: Fri, 5 Apr 2013 16:06:54 +0900 Subject: [PATCH] [Title] Refactoring signing password validation check logic [Desc.] [Issue] #8967 Change-Id: I499c6f55ef4ad4a64e820e8835c5b2abf05ec53d --- .../command/ReadSigningProfileFileCommand.java | 92 +++++++++------------- 1 file changed, 38 insertions(+), 54 deletions(-) diff --git a/org.tizen.common.sign/src/org/tizen/common/sign/command/ReadSigningProfileFileCommand.java b/org.tizen.common.sign/src/org/tizen/common/sign/command/ReadSigningProfileFileCommand.java index 518e688..24e4d11 100755 --- a/org.tizen.common.sign/src/org/tizen/common/sign/command/ReadSigningProfileFileCommand.java +++ b/org.tizen.common.sign/src/org/tizen/common/sign/command/ReadSigningProfileFileCommand.java @@ -105,14 +105,44 @@ extends AbstractCommand } } - /* - * validate password, if inputed wrong password then throw CertificationException + /** + * checking password
+ * if wrong password or wrong certificate then throw exception + * + * @param item - SigningProfileItem - item have certificate path and password + * @throws CertificationException - throw exception when invalid time */ - protected void validateSigningInfo() throws CertificationException { + protected void checkPkcs12Password(SigningProfileItem item) throws CertificationException { boolean isCorrectPassword = false; String message = StringUtil.EMPTY_STRING; - String password = StringUtil.EMPTY_STRING; + try { + String password = new String( item.getPassword() ); + String path = item.getKeyLocation(); + isCorrectPassword = HashingSigning.CheckPkcs12Password( path, password ); + } catch ( UnrecoverableKeyException e ) { + message = "Invaild password"; + } catch ( FileNotFoundException e ) { + message = "Certificate file not found"; + } catch ( IOException e ) { + message = "Invaild certificate"; + } catch ( IllegalArgumentException e ) { + message = "Invaild password"; + } catch ( IllegalStateException e ) { + message = "Not supported certificate file format"; + } catch ( Exception e ) { + message = "Invaild profile"; + } finally { + if ( !isCorrectPassword ) { + throw new CertificationException( message ); + } + } + } + + /* + * validate password, if inputed wrong password then throw CertificationException + */ + protected void validateSigningInfo() throws CertificationException { SigningProfileItem authorItem = getItem( true ); SigningProfileItem distributorItem = getItem( false ); @@ -121,59 +151,13 @@ extends AbstractCommand if ( hasAuthor ) { // author password validating - try { - password = new String( authorItem.getPassword() ); - isCorrectPassword = HashingSigning.CheckPkcs12Password( authorItem.getKeyLocation(), - password ); - } catch ( UnrecoverableKeyException e ) { - message = "Wrong author password"; - isCorrectPassword = false; - } catch ( FileNotFoundException e ) { - message = "Certificate file not found"; - isCorrectPassword = false; - } catch ( IOException e ) { - message = "Wrong certificate file"; - isCorrectPassword = false; - } catch ( IllegalArgumentException e ) { - message = "Wrong author password"; - isCorrectPassword = false; - } catch ( IllegalStateException e ) { - message = "Can't support type certificate file"; - isCorrectPassword = false; - } finally { - if ( !isCorrectPassword ) { - throw new CertificationException( message ); - } - } - } // author password validating + checkPkcs12Password( authorItem ); + } if ( hasDistributor ) { // distributor password validating - try { - password = new String( distributorItem.getPassword() ); - isCorrectPassword = HashingSigning.CheckPkcs12Password( distributorItem.getKeyLocation(), - password ); - } catch ( UnrecoverableKeyException e ) { - message = "Wrong author password"; - isCorrectPassword = false; - } catch ( FileNotFoundException e ) { - message = "Certificate file not found"; - isCorrectPassword = false; - } catch ( IOException e ) { - message = "Wrong certificate file"; - isCorrectPassword = false; - } catch ( IllegalArgumentException e ) { - message = "Wrong author password"; - isCorrectPassword = false; - } catch ( IllegalStateException e ) { - message = "Can't support type certificate file"; - isCorrectPassword = false; - } finally { - if ( !isCorrectPassword ) { - throw new CertificationException( message ); - } - } - } // distributor password validating + checkPkcs12Password( distributorItem ); + } } protected void interactForPassword(final Executor executor, final ExecutionContext context) -- 2.7.4