cloudstack-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From koushik-das <...@git.apache.org>
Subject [GitHub] cloudstack pull request: 4.9/master bountycastle changes
Date Fri, 20 May 2016 09:46:30 GMT
Github user koushik-das commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1511#discussion_r64015658
  
    --- 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 --
    
    @DaanHoogland Thanks


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message