brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aledsage <...@git.apache.org>
Subject [GitHub] incubator-brooklyn pull request: Jclouds tidy
Date Mon, 26 Jan 2015 11:59:21 GMT
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/465#discussion_r23525418
  
    --- Diff: core/src/main/java/brooklyn/util/crypto/SecureKeys.java ---
    @@ -19,182 +19,149 @@
     package brooklyn.util.crypto;
     
     import java.io.ByteArrayInputStream;
    -import java.io.ByteArrayOutputStream;
    -import java.io.FileWriter;
     import java.io.IOException;
     import java.io.InputStream;
     import java.io.InputStreamReader;
     import java.io.StringWriter;
     import java.security.KeyPair;
    -import java.security.KeyPairGenerator;
    -import java.security.KeyStore;
    -import java.security.KeyStoreException;
    -import java.security.NoSuchAlgorithmException;
    +import java.security.PrivateKey;
    +import java.security.PublicKey;
     import java.security.Security;
    -import java.security.cert.CertificateException;
    -import java.security.cert.X509Certificate;
    -import java.util.NoSuchElementException;
    -
    -import javax.net.ssl.TrustManager;
    -import javax.net.ssl.TrustManagerFactory;
    -import javax.net.ssl.X509TrustManager;
    -import javax.security.auth.x500.X500Principal;
     
    +import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
     import org.bouncycastle.jce.X509Principal;
     import org.bouncycastle.jce.provider.BouncyCastleProvider;
    +import org.bouncycastle.openssl.PEMDecryptorProvider;
    +import org.bouncycastle.openssl.PEMEncryptedKeyPair;
    +import org.bouncycastle.openssl.PEMKeyPair;
    +import org.bouncycastle.openssl.PEMParser;
     import org.bouncycastle.openssl.PEMReader;
     import org.bouncycastle.openssl.PEMWriter;
     import org.bouncycastle.openssl.PasswordFinder;
    +import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter;
    +import org.bouncycastle.openssl.jcajce.JcePEMDecryptorProviderBuilder;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
     
     import brooklyn.util.exceptions.Exceptions;
    +import brooklyn.util.stream.Streams;
     
    +import com.google.common.base.Objects;
     import com.google.common.base.Throwables;
     
     /**
      * Utility methods for generating and working with keys
      */
    -public class SecureKeys {
    +public class SecureKeys extends SecureKeysWithoutBouncyCastle {
     
    +    private static final Logger log = LoggerFactory.getLogger(SecureKeys.class);
    +    
         static { Security.addProvider(new BouncyCastleProvider()); }
         
    -    private static KeyPairGenerator defaultKeyPairGenerator = newKeyPairGenerator("RSA",
1024);  
    -
    -    private SecureKeys() {}
    -
    -    public static KeyPairGenerator newKeyPairGenerator(String algorithm, int bits) {
    -        KeyPairGenerator keyPairGenerator;
    -        try {
    -            keyPairGenerator = KeyPairGenerator.getInstance(algorithm);
    -        } catch (NoSuchAlgorithmException e) {
    -            throw Exceptions.propagate(e);
    -        }
    -        keyPairGenerator.initialize(bits);
    -        return keyPairGenerator;
    +    public static class PassphraseProblem extends IllegalStateException {
    +        private static final long serialVersionUID = -3382824813899223447L;
    +        public PassphraseProblem() { super("Passphrase problem with this key"); }
    --- End diff --
    
    True that most/all exceptions that come from java 1.0 have a no-arg constructor. It was
a great relief when they stopped using those in situations like `ClassCastException`, to actually
tell you something about the exception.
    
    For new exception classes that folk are writing, the (vast?) majority of cases it deserves
forcing the caller to pass a message, rather than allowing the absence of useful info to the
end-user.


---
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