React-Native axios https

北城以北 提交于 2021-02-11 13:46:34

问题


How does react-native use self-signed certificates for HTTPS requests?

axios({
        method: 'POST',
        url: url,
        headers: headers,
        data: params,
        timeout: timeout,
        // httpsAgent: new https.Agent({ rejectUnauthorized: false }),
    })

回答1:


You may try below :

NPM : react-native-ssl-pinning

for more info : npmjs.com/package/react-native-ssl-pinning




回答2:


I was able to enable SSL pinning on the iOS part for my React Native Application using TrustKit. I am also using Axios to make server interactions. There are two ways to implement TrustKit, by code or by using Info.plist. I have done using the Info.plist and you can find the implementation for the same below:

  1. Add and install TrustKit in your podfile. (pod 'TrustKit')
  2. Open your Info.plist as Source Code add the below code to it.
<key>TSKConfiguration</key>
<dict>
    <key>TSKSwizzleNetworkDelegates</key>
    <true/>
    <key>TSKPinnedDomains</key>
    <dict>
        <key>yourDomain.com</key>
        <dict>
            <key>TSKPublicKeyHashes</key>
            <array>
                <string>public key 1</string>
                <string>public key 2</string>
            </array>
            <key>TSKPublicKeyAlgorithms</key>
            <array>
                <string>TSKAlgorithmRsa2048</string>
            </array>
            <key>TSKIncludeSubdomains</key>
            <true/>
            <key>TSKEnforcePinning</key>
            <true/>
        </dict>
    </dict>
</dict>

Important things to note:

  1. TSKSwizzleNetworkDelegates needs to be set to true.
  2. yourDomain.com is the base URL for your API.
  3. public Key 1 and public Key 2 are the public keys for your API. You can get the pubic keys for any public domain here
  4. TSKEnforcePinning can be used to enable / disable SSL pinning by setting it to true / false respectively. (Incase you wish to enable/disable it temporarily)
  5. For more details, please check out TrustKit Documentation


来源:https://stackoverflow.com/questions/59762520/react-native-axios-https

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!