Skip to content
This repository was archived by the owner on Jan 25, 2024. It is now read-only.

Update fully-validate-ssl-tls.md #78

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions en/sensitive-data/fully-validate-ssl-tls.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,26 @@ Pinning certificates to a default Apache HTTP client shipped with Android consis

The following sample code demonstrates how a BKS keystore can be loaded:

` InputStream in = resources.openRawResource(certificateRawResource);
```
InputStream in = resources.openRawResource(certificateRawResource);

keyStore = KeyStore.getInstance("BKS");
keyStore.load(resourceStream, password);`
keyStore = KeyStore.getInstance("BKS");
keyStore.load(resourceStream, password);
```

The constructed httpClient instance can be configured to only allow requests to host that present certificates that have been signed with certificates stored inside the application.

The following sample code illustrates this approach:
` HttpParams httpParams = new BasicHttpParams();

SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("https", new SSLSocketFactory(keyStore), 443));
```
HttpParams httpParams = new BasicHttpParams();

ThreadSafeClientConnManager clientMan = new ThreadSafeClientConnManager(httpParams, schemeRegistry);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("https", new SSLSocketFactory(keyStore), 443));
ThreadSafeClientConnManager clientMan = new ThreadSafeClientConnManager(httpParams, schemeRegistry);

httpClient = new DefaultHttpClient(clientMan, httpParams);`
httpClient = new DefaultHttpClient(clientMan, httpParams);
```

For more information on implementing certificate pinning in Android, refer to the OWASP [Certificate and Public Key Pinning guide](https://www.owasp.org/index.php/Certificate_and_Public_Key_Pinning#Android) - https://www.owasp.org/index.php/Certificate_and_Public_Key_Pinning#Android.

Expand Down