generated from Lenni0451/GradleTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added option to ignore invalid SSL certificates
- Loading branch information
Showing
7 changed files
with
170 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...httpclient/src/main/java/net/lenni0451/commons/httpclient/utils/IgnoringTrustManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package net.lenni0451.commons.httpclient.utils; | ||
|
||
import javax.net.ssl.SSLContext; | ||
import javax.net.ssl.SSLEngine; | ||
import javax.net.ssl.TrustManager; | ||
import javax.net.ssl.X509ExtendedTrustManager; | ||
import java.io.IOException; | ||
import java.net.Socket; | ||
import java.security.SecureRandom; | ||
import java.security.cert.X509Certificate; | ||
|
||
public class IgnoringTrustManager extends X509ExtendedTrustManager { | ||
|
||
public static SSLContext makeIgnoringSSLContext() throws IOException { | ||
try { | ||
SSLContext sslContext = SSLContext.getInstance("TLS"); | ||
sslContext.init(null, new TrustManager[]{new IgnoringTrustManager()}, new SecureRandom()); | ||
return sslContext; | ||
} catch (Throwable t) { | ||
throw new IOException("Failed to create ignoring SSL socket factory", t); | ||
} | ||
} | ||
|
||
|
||
@Override | ||
public void checkClientTrusted(X509Certificate[] chain, String authType, Socket socket) { | ||
} | ||
|
||
@Override | ||
public void checkServerTrusted(X509Certificate[] chain, String authType, Socket socket) { | ||
} | ||
|
||
@Override | ||
public void checkClientTrusted(X509Certificate[] chain, String authType, SSLEngine engine) { | ||
} | ||
|
||
@Override | ||
public void checkServerTrusted(X509Certificate[] chain, String authType, SSLEngine engine) { | ||
} | ||
|
||
@Override | ||
public void checkClientTrusted(X509Certificate[] chain, String authType) { | ||
} | ||
|
||
@Override | ||
public void checkServerTrusted(X509Certificate[] chain, String authType) { | ||
} | ||
|
||
@Override | ||
public X509Certificate[] getAcceptedIssuers() { | ||
return null; | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
...ns-httpclient/src/main/java/net/lenni0451/commons/httpclient/utils/ResettableStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package net.lenni0451.commons.httpclient.utils; | ||
|
||
public class ResettableStorage<T> { | ||
|
||
private boolean set = false; | ||
private T value; | ||
|
||
public ResettableStorage() { | ||
} | ||
|
||
public ResettableStorage(final T defaultValue) { | ||
this.set(defaultValue); | ||
} | ||
|
||
public boolean isSet() { | ||
return this.set; | ||
} | ||
|
||
public void unset() { | ||
this.set = false; | ||
this.value = null; | ||
} | ||
|
||
public T get() { | ||
if (!this.set) throw new IllegalStateException("Value is not set"); | ||
return this.value; | ||
} | ||
|
||
public void set(final T value) { | ||
this.value = value; | ||
this.set = true; | ||
} | ||
|
||
} |