Back to project page hello-pinnedcerts.
The source code is released under:
Copyright (c) 2014 Ivan Ku?t Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Softwar...
If you think the Android project hello-pinnedcerts listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package co.infinum.https; /*w ww. j av a 2s . c o m*/ import android.content.res.Resources; import org.apache.http.client.CookieStore; import org.apache.http.conn.scheme.SocketFactory; import java.io.IOException; import java.io.InputStream; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import retrofit.client.ApacheClient; import retrofit.client.Client; /** * Builder for creating Apache HttpClient with pinned certificate that can be used with Retrofit. */ public class RetrofitApacheClientBuilder { protected HttpClientBuilder httpClientBuilder = new HttpClientBuilder(); public RetrofitApacheClientBuilder setConnectionTimeout(int connectionTimeout) { httpClientBuilder.setConnectionTimeout(connectionTimeout); return this; } public RetrofitApacheClientBuilder setSocketTimeout(int socketTimeout) { httpClientBuilder.setSocketTimeout(socketTimeout); return this; } public RetrofitApacheClientBuilder setCookieStore(CookieStore cookieStore) { httpClientBuilder.setCookieStore(cookieStore); return this; } public RetrofitApacheClientBuilder pinCertificates(InputStream resourceStream, char[] password) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException { httpClientBuilder.pinCertificates(resourceStream, password); return this; } public RetrofitApacheClientBuilder pinCertificates(Resources resources, int certificateRawResource, char[] password) throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException { httpClientBuilder.pinCertificates(resources, certificateRawResource, password); return this; } public RetrofitApacheClientBuilder ignoreCertificates() { httpClientBuilder.ignoreCertificates(); return this; } public RetrofitApacheClientBuilder registerScheme(String name, SocketFactory factory, int port) { httpClientBuilder.registerScheme(name, factory, port); return this; } public RetrofitApacheClientBuilder setHttpPort(int port) { httpClientBuilder.setHttpPort(port); return this; } public RetrofitApacheClientBuilder setHttpsPort(int port) { httpClientBuilder.setHttpsPort(port); return this; } public Client.Provider build() { return new Client.Provider() { public Client get() { return new ApacheClient(httpClientBuilder.build()); } }; } }