Skip to content

Instantly share code, notes, and snippets.

@MediumOne
Created May 31, 2017 14:41
Show Gist options
  • Save MediumOne/6887a8679c3c937b9ae0ae8fe6d16865 to your computer and use it in GitHub Desktop.
Save MediumOne/6887a8679c3c937b9ae0ae8fe6d16865 to your computer and use it in GitHub Desktop.
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