Skip to content

Commit

Permalink
fix: log ssl init fail
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyWie committed May 14, 2021
1 parent 1d02b6d commit 4b7a35c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Proxyee is a JAVA written HTTP proxy server library that supports HTTP, HTTPS, W
<dependency>
<groupId>com.github.monkeywie</groupId>
<artifactId>proxyee</artifactId>
<version>1.4.4</version>
<version>1.4.5</version>
</dependency>
```

Expand Down Expand Up @@ -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"
```
Expand Down
4 changes: 2 additions & 2 deletions README_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Proxyee 是一个 JAVA 编写的 HTTP 代理服务器类库,支持 HTTP、HTTP
<dependency>
<groupId>com.github.monkeywie</groupId>
<artifactId>proxyee</artifactId>
<version>1.4.4</version>
<version>1.4.5</version>
</dependency>
```

Expand Down Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.github.monkeywie</groupId>
<artifactId>proxyee</artifactId>
<version>1.4.4</version>
<version>1.4.5</version>
<build>
<plugins>
<plugin>
Expand Down
24 changes: 14 additions & 10 deletions src/main/java/com/github/monkeywie/proxyee/crt/CertUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)));
Expand All @@ -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 {
Expand All @@ -89,30 +89,34 @@ 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);
return getKeyFactory().generatePublic(publicKeySpec);
}

/**
* 从文件加载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)));
return getKeyFactory().generatePublic(publicKeySpec);
}

/**
* 从文件加载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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 4b7a35c

Please sign in to comment.