Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ECC support #43

Open
wuhongzhi opened this issue Jun 24, 2018 · 2 comments
Open

add ECC support #43

wuhongzhi opened this issue Jun 24, 2018 · 2 comments

Comments

@wuhongzhi
Copy link

https://github.com/wuhongzhi/wildfly-openssl/blob/master/java/src/main/java/org/wildfly/openssl/OpenSSLContextSPI.java

/**
 * Setup the SSL_CTX
 *
 * @param kms Must contain a KeyManager of the type
 *            {@code OpenSSLKeyManager}
 * @param tms
 */
private synchronized void init(KeyManager[] kms, TrustManager[] tms) throws KeyManagementException {
    if (initialized) {
        LOG.warning(Messages.MESSAGES.ignoringSecondInit());
        return;
    }
    SSL_INSTANCE = SSL.getInstance();
    try {
        // Load Server key and certificate
        X509KeyManager keyManager = chooseKeyManager(kms);
        if (keyManager != null) {
            for (String algorithm : ALGORITHMS) {
                final String[] aliases = keyManager.getServerAliases(algorithm, null);
                if (aliases != null && aliases.length != 0) {
                    for(String alias: aliases) {
                        X509Certificate[] certificates = keyManager.getCertificateChain(alias);
                        if (certificates == null || certificates.length == 0) continue;
                        byte[][] certs = new byte[certificates.length][];
                        int idx = 0;
                        for (X509Certificate c: certificates) {
                        	certs[idx++] = c.getEncoded();
                        }
                        PrivateKey key = keyManager.getPrivateKey(alias);
                        if(key == null || key.getEncoded() == null) {
                            continue;
                        }
                        if (LOG.isLoggable(Level.FINE)) {
                            LOG.fine("Using alias " + alias + " for " + algorithm);
                        }
                        StringBuilder sb = new StringBuilder(String.format(BEGIN_CERT, algorithm));
                        sb.append(Base64.getMimeEncoder(64, new byte[]{'\n'}).encodeToString(key.getEncoded()));
                        sb.append(String.format(END_CERT, algorithm));
                        switch (algorithm) {
						case "RSA":
							idx = SSL.SSL_AIDX_RSA;
							break;
						case "DSA":
							idx = SSL.SSL_AIDX_DSA;
							break;
						case "EC":
							idx = SSL.SSL_AIDX_ECC;
							break;
						}
                        SSL_INSTANCE.setCertificate(ctx, certs[0], 
                        		Arrays.copyOfRange(certs, 1, certs.length), 
                        		sb.toString().getBytes(StandardCharsets.US_ASCII), idx);
                        break;
                    }
                }
            }
        }

https://github.com/wuhongzhi/wildfly-openssl/blob/master/java/src/main/java/org/wildfly/openssl/SSL.java

static final int SSL_AIDX_ECC = 3;
@sophokles73
Copy link

Hi @wuhongzhi I would also like to see support for ECC. Could you turn this issue into a PR so that it can be merged?

@wuhongzhi
Copy link
Author

I saw you had merged the c parts code, but java code yet, as my fork on 1.0.x, see my major modify on https://github.com/wuhongzhi/wildfly-openssl/blob/master/java/src/main/java/org/wildfly/openssl/OpenSSLContextSPI.java, as comment above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants