Created
May 31, 2017 14:41
-
-
Save MediumOne/6887a8679c3c937b9ae0ae8fe6d16865 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package org.littleshoot.proxy.extras; | |
import io.netty.handler.codec.http.HttpRequest; | |
import org.littleshoot.proxy.MitmManager; | |
import java.security.cert.Certificate; | |
import javax.net.ssl.SSLEngine; | |
import javax.net.ssl.SSLSession; | |
/** | |
* {@link MitmManager} that uses self-signed certs for everything. | |
*/ | |
public class ClientCertLoggingMitmManager implements MitmManager { | |
SelfSignedSslEngineSource selfSignedSslEngineSource = | |
new SelfSignedSslEngineSource(true); | |
private SSLEngine clientToProxySSLEngine; | |
@Override | |
public SSLEngine serverSslEngine(String peerHost, int peerPort) { | |
logClientCerts(); | |
return selfSignedSslEngineSource.newSslEngine(peerHost, peerPort); | |
} | |
@Override | |
public SSLEngine serverSslEngine() { | |
logClientCerts(); | |
return selfSignedSslEngineSource.newSslEngine(); | |
} | |
private void logClientCerts() { | |
Certificate[] clientCertificates = clientToProxySSLEngine.getSession().getPeerCertificates(); //or getSession().getLocalCertificates(), not sure. | |
logCerts(clientCertificates); | |
} | |
@Override | |
public SSLEngine clientSslEngineFor(HttpRequest httpRequest, SSLSession serverSslSession) { | |
clientToProxySSLEngine = selfSignedSslEngineSource.newSslEngine(); | |
return clientToProxySSLEngine; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment