Github user koushik-das commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1511#discussion_r63829633
  
    --- Diff: server/src/org/apache/cloudstack/network/lb/CertServiceImpl.java 
---
    @@ -429,60 +434,42 @@ private void validateChain(List<Certificate> chain, 
Certificate cert) {
     
         }
     
    -    public PrivateKey parsePrivateKey(String key, String password) throws 
IOException {
    -
    -        PasswordFinder pGet = null;
    -
    -        if (password != null)
    -            pGet = new KeyPassword(password.toCharArray());
    -
    -        PEMReader privateKey = new PEMReader(new StringReader(key), pGet);
    -        Object obj = null;
    -        try {
    -            obj = privateKey.readObject();
    -        } finally {
    -            IOUtils.closeQuietly(privateKey);
    -        }
    -
    -        try {
    -
    -            if (obj instanceof KeyPair)
    -                return ((KeyPair)obj).getPrivate();
    -
    -            return (PrivateKey)obj;
    -
    -        } catch (Exception e) {
    +    public PrivateKey parsePrivateKey(final String key) throws IOException 
{
    +        try (final PemReader pemReader = new PemReader(new 
StringReader(key));) {
    +            final PemObject pemObject = pemReader.readPemObject();
    +            final byte[] content = pemObject.getContent();
    +            final PKCS8EncodedKeySpec privKeySpec = new 
PKCS8EncodedKeySpec(content);
    +            final KeyFactory factory = KeyFactory.getInstance("RSA", "BC");
    +            return factory.generatePrivate(privKeySpec);
    +        } catch (NoSuchAlgorithmException | NoSuchProviderException e) {
    +            throw new IOException("No encryption provider available.", e);
    +        } catch (final InvalidKeySpecException e) {
                 throw new IOException("Invalid Key format or invalid 
password.", e);
    --- End diff --
    
    Since password is now removed, the exception message also needs to be 
updated.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to