react-native-ssl-pinning-guard
Version:
SSL pinning module for React Native using TurboModules
89 lines (60 loc) โข 1.89 kB
Markdown
# react-native-ssl-pinning-guard
A robust SSL Pinning plugin for React Native, supporting New Architecture (TurboModules) for Android and iOS. Pass domains and public key hashes from TypeScript โ no hardcoding in native code.
## ๐ฆ Installation
```sh
yarn add react-native-ssl-pinning-guard
cd ios && pod install
```
## โ๏ธ Configuration (New Architecture)
Ensure TurboModules are enabled in your React Native project.
## ๐ Usage
```ts
import SslPinningGuard from 'react-native-ssl-pinning-guard';
SslPinningGuard.configure({
domains: ['api.example.com'],
hashes: ['base64_encoded_sha256_pubkey']
});
```
- `domains`: List of domains to pin
- `hashes`: SHA256 public key hashes in Base64 format (use tools like OpenSSL to get it)
## โ
How to Get Public Key Hash
1. Get the certificate:
```sh
openssl s_client -connect api.example.com:443 | openssl x509 > cert.pem
```
2. Extract public key:
```sh
openssl x509 -in cert.pem -pubkey -noout > pubkey.pem
```
3. Convert to DER:
```sh
openssl pkey -pubin -in pubkey.pem -outform DER | openssl dgst -sha256 -binary | openssl base64
```
Use that base64 string in the `hashes` array.
## ๐ฑ Platform Support
- โ
Android (Kotlin + OkHttp)
- โ
iOS (NSURLSession + SecTrust)
## ๐ฎ Security
- Public Key Hash Pinning (preferred over certificate pinning)
- Prevents MITM by rejecting untrusted certs
- Works with custom API clients (OkHttpClient on Android, NSURLSessionDelegate on iOS)
## ๐ก๏ธ Next Steps
- Add Jailbreak / Root / Debugger detection
- Obfuscate strings and hashes
## ๐ Structure
```
react-native-ssl-pinning-guard/
โโโ android/
โโโ ios/
โโโ src/
โโโ babel.config.js
โโโ README.md
โโโ ...
```
## ๐งช Example
```ts
SslPinningGuard.configure({
domains: ['secure.myapi.com'],
hashes: ['yRtD48DUeF29ZUdOn8LqLqfydnVGckLtb+5KMcMlEZg=']
});
```