-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle ssl on the assumption that server certificate is always valid.
- Loading branch information
chongyuan
committed
Dec 2, 2019
1 parent
46515da
commit a8c7f01
Showing
5 changed files
with
156 additions
and
67 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
mqtt_jmeter/src/main/java/net/xmeter/AcceptAllTrustManager.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,25 @@ | ||
package net.xmeter; | ||
|
||
import java.security.cert.CertificateException; | ||
import java.security.cert.X509Certificate; | ||
|
||
import javax.net.ssl.X509TrustManager; | ||
|
||
public class AcceptAllTrustManager implements X509TrustManager { | ||
|
||
@Override | ||
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { | ||
|
||
} | ||
|
||
@Override | ||
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { | ||
|
||
} | ||
|
||
@Override | ||
public X509Certificate[] getAcceptedIssuers() { | ||
return null; | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
mqtt_jmeter/src/main/java/net/xmeter/AcceptAllTrustManagerFactory.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,61 @@ | ||
package net.xmeter; | ||
|
||
import java.security.InvalidAlgorithmParameterException; | ||
import java.security.KeyStore; | ||
import java.security.KeyStoreException; | ||
import java.security.Provider; | ||
import java.security.cert.X509Certificate; | ||
|
||
import javax.net.ssl.ManagerFactoryParameters; | ||
import javax.net.ssl.TrustManager; | ||
import javax.net.ssl.TrustManagerFactory; | ||
import javax.net.ssl.TrustManagerFactorySpi; | ||
import javax.net.ssl.X509TrustManager; | ||
|
||
public class AcceptAllTrustManagerFactory extends TrustManagerFactory { | ||
|
||
private static final Provider PROVIDER = new Provider("", 0.0, "") { | ||
private static final long serialVersionUID = -2226165055935321223L; | ||
}; | ||
|
||
private AcceptAllTrustManagerFactory() { | ||
super(AcceptAllTrustManagerFactorySpi.getInstance(), PROVIDER, ""); | ||
} | ||
|
||
public static final TrustManagerFactory getInstance() { | ||
return new AcceptAllTrustManagerFactory(); | ||
} | ||
|
||
static final class AcceptAllTrustManagerFactorySpi extends TrustManagerFactorySpi { | ||
|
||
public static final AcceptAllTrustManagerFactorySpi getInstance() { | ||
return new AcceptAllTrustManagerFactorySpi(); | ||
} | ||
|
||
@Override | ||
protected TrustManager[] engineGetTrustManagers() { | ||
System.out.println("!! get trust managers (X509)"); | ||
return new TrustManager[] { new X509TrustManager() { | ||
public X509Certificate[] getAcceptedIssuers() { | ||
return null; | ||
} | ||
|
||
public void checkClientTrusted(X509Certificate[] certs, String authType) { | ||
} | ||
|
||
public void checkServerTrusted(X509Certificate[] certs, String authType) { | ||
} | ||
} }; | ||
} | ||
|
||
@Override | ||
protected void engineInit(KeyStore ks) throws KeyStoreException { | ||
} | ||
|
||
@Override | ||
protected void engineInit(ManagerFactoryParameters spec) throws InvalidAlgorithmParameterException { | ||
} | ||
|
||
} | ||
|
||
} |
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