Search in sources :

Example 1 with SEKeyDetails

use of com.biglybt.core.security.SEKeyDetails in project BiglyBT by BiglySoftware.

the class AEJarBuilder method buildFromResources2.

private static long buildFromResources2(OutputStream os, ClassLoader class_loader, String resource_prefix, String[] resource_names, String sign_alias) throws IOException {
    if (sign_alias != null) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream(65536);
        long tim = buildFromResourcesSupport(new JarOutputStream(baos), class_loader, resource_prefix, resource_names);
        try {
            // leave this check in here as we might as well check for the alias
            SEKeyDetails kd = SESecurityManager.getKeyDetails(sign_alias);
            if (kd == null) {
                Logger.log(new LogAlert(LogAlert.UNREPEATABLE, LogAlert.AT_ERROR, "Certificate alias '" + sign_alias + "' not found, jar signing fails"));
                throw (new Exception("Certificate alias '" + sign_alias + "' not found "));
            }
            // WUJarSigner signer = new WUJarSigner(sign_alias, (PrivateKey)kd.getKey(), kd.getCertificateChain());
            AEJarSigner2 signer = new AEJarSigner2(sign_alias, SESecurityManager.getKeystoreName(), SESecurityManager.getKeystorePassword());
            signer.signJarStream(new ByteArrayInputStream(baos.toByteArray()), os);
            return (tim);
        } catch (Throwable e) {
            Debug.printStackTrace(e);
            throw (new IOException(e.getMessage()));
        }
    } else {
        JarOutputStream jos;
        if (os instanceof JarOutputStream) {
            jos = (JarOutputStream) os;
        } else {
            jos = new JarOutputStream(os);
        }
        return (buildFromResourcesSupport(jos, class_loader, resource_prefix, resource_names));
    }
}
Also used : SEKeyDetails(com.biglybt.core.security.SEKeyDetails) JarOutputStream(java.util.jar.JarOutputStream) LogAlert(com.biglybt.core.logging.LogAlert)

Example 2 with SEKeyDetails

use of com.biglybt.core.security.SEKeyDetails in project BiglyBT by BiglySoftware.

the class SESecurityManagerImpl method getKeyDetails.

public SEKeyDetails getKeyDetails(String alias) throws Exception {
    // Create the key manager factory used to extract the server key
    KeyStore key_store = loadKeyStore();
    final Key key = key_store.getKey(alias, SESecurityManager.SSL_PASSWORD.toCharArray());
    if (key == null) {
        return (null);
    }
    java.security.cert.Certificate[] chain = key_store.getCertificateChain(alias);
    final X509Certificate[] res = new X509Certificate[chain.length];
    for (int i = 0; i < chain.length; i++) {
        if (!(chain[i] instanceof X509Certificate)) {
            throw (new Exception("Certificate chain must be comprised of X509Certificate entries"));
        }
        res[i] = (X509Certificate) chain[i];
    }
    return (new SEKeyDetails() {

        @Override
        public Key getKey() {
            return (key);
        }

        @Override
        public X509Certificate[] getCertificateChain() {
            return (res);
        }
    });
}
Also used : SEKeyDetails(com.biglybt.core.security.SEKeyDetails) KeyStore(java.security.KeyStore) Key(java.security.Key) X509Certificate(java.security.cert.X509Certificate) CertificateException(java.security.cert.CertificateException) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Aggregations

SEKeyDetails (com.biglybt.core.security.SEKeyDetails)2 LogAlert (com.biglybt.core.logging.LogAlert)1 Key (java.security.Key)1 KeyStore (java.security.KeyStore)1 Certificate (java.security.cert.Certificate)1 CertificateException (java.security.cert.CertificateException)1 X509Certificate (java.security.cert.X509Certificate)1 JarOutputStream (java.util.jar.JarOutputStream)1