From 4b7a35cf06d2b84342bee50cd73df219404f590d Mon Sep 17 00:00:00 2001 From: liwei Date: Fri, 14 May 2021 15:30:16 +0800 Subject: [PATCH] fix: log ssl init fail --- README.md | 4 ++-- README_zh-CN.md | 4 ++-- pom.xml | 2 +- .../monkeywie/proxyee/crt/CertUtil.java | 24 +++++++++++-------- .../proxyee/server/HttpProxyServer.java | 5 ++++ 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 4df21ea..c6eb113 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Proxyee is a JAVA written HTTP proxy server library that supports HTTP, HTTPS, W com.github.monkeywie proxyee - 1.4.4 + 1.4.5 ``` @@ -108,7 +108,7 @@ Since the root certificate and private key attached to the project are public, t ```sh openssl genrsa -out ca.key 2048 -openssl rsa -in ca.key -out ca_private.der -outform der +openssl pkcs8 -topk8 -nocrypt -inform PEM -outform DER -in ca.key -out ca_private.der openssl req -sha256 -new -x509 -days 365 -key ca.key -out ca.crt \ -subj "/C=CN/ST=GD/L=SZ/O=lee/OU=study/CN=testRoot" ``` diff --git a/README_zh-CN.md b/README_zh-CN.md index 322927f..f2d3f00 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -25,7 +25,7 @@ Proxyee 是一个 JAVA 编写的 HTTP 代理服务器类库,支持 HTTP、HTTP com.github.monkeywie proxyee - 1.4.4 + 1.4.5 ``` @@ -111,7 +111,7 @@ new HttpProxyServer() openssl genrsa -out ca.key 2048 #key的转换,转换成netty支持私钥编码格式 -openssl rsa -in ca.key -out ca_private.der -outform der +openssl pkcs8 -topk8 -nocrypt -inform PEM -outform DER -in ca.key -out ca_private.der #crt的生成,通过-subj选项可以自定义证书的相关信息 openssl req -sha256 -new -x509 -days 365 -key ca.key -out ca.crt \ diff --git a/pom.xml b/pom.xml index ca86b40..cbf8ef5 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.github.monkeywie proxyee - 1.4.4 + 1.4.5 diff --git a/src/main/java/com/github/monkeywie/proxyee/crt/CertUtil.java b/src/main/java/com/github/monkeywie/proxyee/crt/CertUtil.java index 095923e..d36187f 100644 --- a/src/main/java/com/github/monkeywie/proxyee/crt/CertUtil.java +++ b/src/main/java/com/github/monkeywie/proxyee/crt/CertUtil.java @@ -46,8 +46,8 @@ public static KeyPair genKeyPair() throws Exception { } /** - * 从文件加载RSA私钥 openssl pkcs8 -topk8 -nocrypt -inform PEM -outform DER -in ca.key -out - * ca_private.der + * 从文件加载RSA私钥 + * openssl pkcs8 -topk8 -nocrypt -inform PEM -outform DER -in ca.key -out ca_private.der */ public static PrivateKey loadPriKey(byte[] bts) throws NoSuchAlgorithmException, InvalidKeySpecException { @@ -56,8 +56,8 @@ public static PrivateKey loadPriKey(byte[] bts) } /** - * 从文件加载RSA私钥 openssl pkcs8 -topk8 -nocrypt -inform PEM -outform DER -in ca.key -out - * ca_private.der + * 从文件加载RSA私钥 + * openssl pkcs8 -topk8 -nocrypt -inform PEM -outform DER -in ca.key -out ca_private.der */ public static PrivateKey loadPriKey(String path) throws Exception { return loadPriKey(Files.readAllBytes(Paths.get(path))); @@ -72,8 +72,8 @@ public static PrivateKey loadPriKey(URI uri) throws Exception { } /** - * 从文件加载RSA私钥 openssl pkcs8 -topk8 -nocrypt -inform PEM -outform DER -in ca.key -out - * ca_private.der + * 从文件加载RSA私钥 + * openssl pkcs8 -topk8 -nocrypt -inform PEM -outform DER -in ca.key -out ca_private.der */ public static PrivateKey loadPriKey(InputStream inputStream) throws IOException, InvalidKeySpecException, NoSuchAlgorithmException { @@ -89,7 +89,8 @@ public static PrivateKey loadPriKey(InputStream inputStream) } /** - * 从文件加载RSA公钥 openssl rsa -in ca.key -pubout -outform DER -out ca_pub.der + * 从文件加载RSA公钥 + * openssl rsa -in ca.key -pubout -outform DER -out ca_pub.der */ public static PublicKey loadPubKey(byte[] bts) throws Exception { EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(bts); @@ -97,7 +98,8 @@ public static PublicKey loadPubKey(byte[] bts) throws Exception { } /** - * 从文件加载RSA公钥 openssl rsa -in ca.key -pubout -outform DER -out ca_pub.der + * 从文件加载RSA公钥 + * openssl rsa -in ca.key -pubout -outform DER -out ca_pub.der */ public static PublicKey loadPubKey(String path) throws Exception { EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(Files.readAllBytes(Paths.get(path))); @@ -105,14 +107,16 @@ public static PublicKey loadPubKey(String path) throws Exception { } /** - * 从文件加载RSA公钥 openssl rsa -in ca.key -pubout -outform DER -out ca_pub.der + * 从文件加载RSA公钥 + * openssl rsa -in ca.key -pubout -outform DER -out ca_pub.der */ public static PublicKey loadPubKey(URI uri) throws Exception { return loadPubKey(Paths.get(uri).toString()); } /** - * 从文件加载RSA公钥 openssl rsa -in ca.key -pubout -outform DER -out ca_pub.der + * 从文件加载RSA公钥 + * openssl rsa -in ca.key -pubout -outform DER -out ca_pub.der */ public static PublicKey loadPubKey(InputStream inputStream) throws Exception { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); diff --git a/src/main/java/com/github/monkeywie/proxyee/server/HttpProxyServer.java b/src/main/java/com/github/monkeywie/proxyee/server/HttpProxyServer.java index 6548354..ce33472 100644 --- a/src/main/java/com/github/monkeywie/proxyee/server/HttpProxyServer.java +++ b/src/main/java/com/github/monkeywie/proxyee/server/HttpProxyServer.java @@ -20,6 +20,8 @@ import io.netty.handler.logging.LoggingHandler; import io.netty.handler.ssl.SslContextBuilder; import io.netty.handler.ssl.util.InsecureTrustManagerFactory; +import io.netty.util.internal.logging.InternalLogger; +import io.netty.util.internal.logging.InternalLoggerFactory; import java.security.KeyPair; import java.security.PrivateKey; @@ -30,6 +32,8 @@ public class HttpProxyServer { + private final static InternalLogger log = InternalLoggerFactory.getInstance(HttpProxyServer.class); + //http代理隧道握手成功 public final static HttpResponseStatus SUCCESS = new HttpResponseStatus(200, "Connection established"); @@ -80,6 +84,7 @@ private void init() { serverConfig.setServerPubKey(keyPair.getPublic()); } catch (Exception e) { serverConfig.setHandleSsl(false); + log.warn("SSL init fail,cause:" + e.getMessage()); } } if (proxyInterceptInitializer == null) {