Example usage for com.squareup.okhttp OkHttpClient setCertificatePinner

List of usage examples for com.squareup.okhttp OkHttpClient setCertificatePinner

Introduction

In this page you can find the example usage for com.squareup.okhttp OkHttpClient setCertificatePinner.

Prototype

public OkHttpClient setCertificatePinner(CertificatePinner certificatePinner) 

Source Link

Document

Sets the certificate pinner that constrains which certificates are trusted.

Usage

From source file:com.mycelium.wallet.external.cashila.api.CashilaService.java

License:Microsoft Reference Source License

public CashilaService(String baseUrl, String apiVersion, Bus eventBus) {
    this.baseUrl = baseUrl;
    this.eventBus = eventBus;

    OkHttpClient client = new OkHttpClient();
    client.setConnectTimeout(5000, TimeUnit.MILLISECONDS);
    client.setReadTimeout(5000, TimeUnit.MILLISECONDS);
    client.networkInterceptors().add(hmacInterceptor);
    CertificatePinner certPinner = new CertificatePinner.Builder().add("cashila.com", CASHILA_CERT)
            .add("cashila-staging.com", CASHILA_CERT).build();
    client.setCertificatePinner(certPinner);

    // use jackson as json mapper, as we already use it in the rest of the project
    objectMapper = new ObjectMapper();
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
    objectMapper.registerModule(new WapiJsonModule());

    RestAdapter adapter = new RestAdapter.Builder().setEndpoint(baseUrl + apiVersion + "/")
            .setLogLevel(RestAdapter.LogLevel.BASIC)
            //.setLogLevel(RestAdapter.LogLevel.FULL)
            .setConverter(new JacksonConverter(objectMapper)).setClient(new OkClient(client))
            .setRequestInterceptor(apiIdInterceptor).build();

    cashila = adapter.create(Cashila.class);

    // initialise nonce with current time and increase by one on each call
    lastNonce = System.currentTimeMillis();
}

From source file:io.apiman.gateway.platforms.servlet.connectors.HttpConnectorFactory.java

License:Apache License

/**
 * @return a new http client//from w  w  w  .  j a v a 2  s  .co  m
 */
private OkHttpClient createHttpClient() {
    OkHttpClient client = new OkHttpClient();
    client.setReadTimeout(connectorOptions.getReadTimeout(), TimeUnit.SECONDS);
    client.setWriteTimeout(connectorOptions.getWriteTimeout(), TimeUnit.SECONDS);
    client.setConnectTimeout(connectorOptions.getConnectTimeout(), TimeUnit.SECONDS);
    client.setFollowRedirects(connectorOptions.isFollowRedirects());
    client.setFollowSslRedirects(connectorOptions.isFollowRedirects());
    client.setProxySelector(ProxySelector.getDefault());
    client.setCookieHandler(CookieHandler.getDefault());
    client.setCertificatePinner(CertificatePinner.DEFAULT);
    client.setAuthenticator(AuthenticatorAdapter.INSTANCE);
    client.setConnectionPool(ConnectionPool.getDefault());
    client.setProtocols(Util.immutableList(Protocol.HTTP_1_1));
    client.setConnectionSpecs(DEFAULT_CONNECTION_SPECS);
    client.setSocketFactory(SocketFactory.getDefault());
    Internal.instance.setNetwork(client, Network.DEFAULT);

    return client;
}