Skip to content

Instantly share code, notes, and snippets.

@maplerise
Last active June 2, 2017 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maplerise/0416a4a122cc15abf80f44d8cf8aa8aa to your computer and use it in GitHub Desktop.
Save maplerise/0416a4a122cc15abf80f44d8cf8aa8aa to your computer and use it in GitHub Desktop.
Builds client with interceptor, pinner, and verifier
public class App extends Application {
// ...
@Override
public void onCreate (){
super.onCreate();
mPlatformSpecifics = new AndroidPlatformSpecifics(this);
mAttestation = new ApproovAttestation(mPlatformSpecifics);
try {
SSLContextPinner pinner = new SSLContextPinner("cert.pem");
mClient = new OkHttpClient.Builder()
.sslSocketFactory(pinner.getSSLContext().getSocketFactory(), pinner.getX509TrustManager())
.hostnameVerifier(new NoHostnameVerifier())
.addInterceptor(new ApproovInterceptor(mAttestation))
.build();
} catch (Exception e) {
Log.e("App", e.toString());
Log.e("App", "Failed to pin connection");
throw new IllegalStateException("Failed to pin connection:");
}
mDownloader = new Picasso.Builder(this)
.downloader(new OkHttp3Downloader(mClient))
.build();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment