com.browserup.bup.mitm.manager.ImpersonatingMitmManager Java Examples

The following examples show how to use com.browserup.bup.mitm.manager.ImpersonatingMitmManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MitmManagerFactory.java    From vividus with Apache License 2.0 6 votes vote down vote up
@Override
public MitmManager createMitmManager(MitmManagerOptions options)
{
    KeyStoreOptions keyStoreOptions = options.getKeyStoreOptions();
    checkNotNull(keyStoreOptions.getPath(), "key store path");
    checkNotNull(keyStoreOptions.getType(), "key store type");
    checkNotNull(keyStoreOptions.getPassword(), "key store password");
    checkNotNull(options.getAlias(), "alias");

    File keyStore = ResourceUtils.loadFile(getClass(), keyStoreOptions.getPath());
    KeyStoreFileCertificateSource certificateSource = new KeyStoreFileCertificateSource(keyStoreOptions.getType(),
            keyStore, options.getAlias(), keyStoreOptions.getPassword());

    return ImpersonatingMitmManager
            .builder()
            .rootCertificateSource(certificateSource)
            .trustAllServers(options.isTrustAllServers())
            .build();
}
 
Example #2
Source File: LittleProxyDefaultConfigExample.java    From browserup-proxy with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    // initialize an MitmManager with default settings
    ImpersonatingMitmManager mitmManager = ImpersonatingMitmManager.builder().build();

    // to save the generated CA certificate for installation in a browser, see SaveGeneratedCAExample.java

    // tell the HttpProxyServerBootstrap to use the new MitmManager
    HttpProxyServer proxyServer = DefaultHttpProxyServer.bootstrap()
            .withManInTheMiddle(mitmManager)
            .start();

    // make your requests to the proxy server
    //...

    proxyServer.abort();
}
 
Example #3
Source File: CustomCAKeyStoreExample.java    From browserup-proxy with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    // load the root certificate and private key from an existing KeyStore
    KeyStoreFileCertificateSource fileCertificateSource = new KeyStoreFileCertificateSource(
            "PKCS12",                               // KeyStore type. for .jks files (Java KeyStore), use "JKS"
            new File("/path/to/my/keystore.p12"),
            "keyAlias",                             // alias of the private key in the KeyStore; if you did not specify an alias when creating it, use "1"
            "keystorePassword");


    // tell the MitmManager to use the custom certificate and private key
    ImpersonatingMitmManager mitmManager = ImpersonatingMitmManager.builder()
            .rootCertificateSource(fileCertificateSource)
            .build();

    // tell the HttpProxyServerBootstrap to use the new MitmManager
    HttpProxyServer proxyServer = DefaultHttpProxyServer.bootstrap()
            .withManInTheMiddle(mitmManager)
            .start();

    // make your requests to the proxy server
    //...

    proxyServer.abort();
}
 
Example #4
Source File: SaveGeneratedCAExample.java    From browserup-proxy with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    // create a dynamic CA root certificate generator using default settings (2048-bit RSA keys)
    RootCertificateGenerator rootCertificateGenerator = RootCertificateGenerator.builder().build();

    // save the dynamically-generated CA root certificate for installation in a browser
    rootCertificateGenerator.saveRootCertificateAsPemFile(new File("/tmp/my-dynamic-ca.cer"));

    // tell the MitmManager to use the root certificate we just generated
    ImpersonatingMitmManager mitmManager = ImpersonatingMitmManager.builder()
            .rootCertificateSource(rootCertificateGenerator)
            .build();

    // tell the HttpProxyServerBootstrap to use the new MitmManager
    HttpProxyServer proxyServer = DefaultHttpProxyServer.bootstrap()
            .withManInTheMiddle(mitmManager)
            .start();

    // make your requests to the proxy server
    //...

    proxyServer.abort();
}
 
Example #5
Source File: CustomCAPemFileExample.java    From browserup-proxy with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    // load the root certificate and private key from existing PEM-encoded certificate and private key files
    PemFileCertificateSource fileCertificateSource = new PemFileCertificateSource(
            new File("/path/to/my/certificate.cer"),    // the PEM-encoded certificate file
            new File("/path/to/my/private-key.pem"),    // the PEM-encoded private key file
            "privateKeyPassword");                      // the password for the private key -- can be null if the private key is not encrypted


    // tell the MitmManager to use the custom certificate and private key
    ImpersonatingMitmManager mitmManager = ImpersonatingMitmManager.builder()
            .rootCertificateSource(fileCertificateSource)
            .build();

    // tell the HttpProxyServerBootstrap to use the new MitmManager
    HttpProxyServer proxyServer = DefaultHttpProxyServer.bootstrap()
            .withManInTheMiddle(mitmManager)
            .start();

    // make your requests to the proxy server
    //...

    proxyServer.abort();
}
 
Example #6
Source File: MitmManagerFactoryTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@Test
void testCreateMitmManager()
{
    IMitmManagerFactory factory = new MitmManagerFactory();
    MitmManagerOptions options = new MitmManagerOptions("alias", true,
            new KeyStoreOptions("bundle.p12", "password", "PKCS12"));
    MitmManager mitmManager = factory.createMitmManager(options);
    assertThat(mitmManager, instanceOf(ImpersonatingMitmManager.class));
}
 
Example #7
Source File: EllipticCurveCAandServerExample.java    From browserup-proxy with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    // create a dyamic CA root certificate generator using Elliptic Curve keys
    RootCertificateGenerator ecRootCertificateGenerator = RootCertificateGenerator.builder()
            .keyGenerator(new ECKeyGenerator())     // use EC keys, instead of the default RSA
            .build();

    // save the dynamically-generated CA root certificate for installation in a browser
    ecRootCertificateGenerator.saveRootCertificateAsPemFile(new File("/tmp/my-dynamic-ca.cer"));

    // save the dynamically-generated CA private key for use in future LittleProxy executions
    // (see CustomCAPemFileExample.java for an example loading a previously-generated CA cert + key from a PEM file)
    ecRootCertificateGenerator.savePrivateKeyAsPemFile(new File("/tmp/my-ec-private-key.pem"), "secretPassword");

    // tell the MitmManager to use the root certificate we just generated, and to use EC keys when
    // creating impersonated server certs
    ImpersonatingMitmManager mitmManager = ImpersonatingMitmManager.builder()
            .rootCertificateSource(ecRootCertificateGenerator)
            .serverKeyGenerator(new ECKeyGenerator())
            .build();

    // tell the HttpProxyServerBootstrap to use the new MitmManager
    HttpProxyServer proxyServer = DefaultHttpProxyServer.bootstrap()
            .withManInTheMiddle(mitmManager)
            .start();

    // make your requests to the proxy server
    //...

    proxyServer.abort();
}