From 79f2f332ece3954c0d3c463e59362510ac67ccb6 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Sun, 18 May 2014 03:45:58 +0900 Subject: [PATCH] Fix JDK 8 compatibility issue with OpenJdkSelfSignedCertGenerator - X509CertInfo.setSubject/setIssuer() requires X500Name instead of CertificateSubjectName/CertificateIssuerName. --- .../ssl/util/OpenJdkSelfSignedCertGenerator.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/handler/src/main/java/io/netty/handler/ssl/util/OpenJdkSelfSignedCertGenerator.java b/handler/src/main/java/io/netty/handler/ssl/util/OpenJdkSelfSignedCertGenerator.java index 691f50b0cd..d1559eb70d 100644 --- a/handler/src/main/java/io/netty/handler/ssl/util/OpenJdkSelfSignedCertGenerator.java +++ b/handler/src/main/java/io/netty/handler/ssl/util/OpenJdkSelfSignedCertGenerator.java @@ -32,6 +32,7 @@ import java.math.BigInteger; import java.security.KeyPair; import java.security.PrivateKey; import java.security.SecureRandom; +import java.security.cert.CertificateException; import static io.netty.handler.ssl.util.SelfSignedCertificate.*; @@ -48,8 +49,16 @@ final class OpenJdkSelfSignedCertGenerator { X500Name owner = new X500Name("CN=" + fqdn); info.set(X509CertInfo.VERSION, new CertificateVersion(CertificateVersion.V3)); info.set(X509CertInfo.SERIAL_NUMBER, new CertificateSerialNumber(new BigInteger(64, random))); - info.set(X509CertInfo.SUBJECT, new CertificateSubjectName(owner)); - info.set(X509CertInfo.ISSUER, new CertificateIssuerName(owner)); + try { + info.set(X509CertInfo.SUBJECT, new CertificateSubjectName(owner)); + } catch (CertificateException ignore) { + info.set(X509CertInfo.SUBJECT, owner); + } + try { + info.set(X509CertInfo.ISSUER, new CertificateIssuerName(owner)); + } catch (CertificateException ignore) { + info.set(X509CertInfo.ISSUER, owner); + } info.set(X509CertInfo.VALIDITY, new CertificateValidity(NOT_BEFORE, NOT_AFTER)); info.set(X509CertInfo.KEY, new CertificateX509Key(keypair.getPublic())); info.set(X509CertInfo.ALGORITHM_ID,