首页 > 解决方案 > 如何绕过 Angular2-Nativescript 上的 SSL 错误?

问题描述

我是 NativeScript 的新手,所以我需要帮助绕过 iOS 和 Android。我试着在谷歌上寻找,但我已经筋疲力尽地试图找到一个足以满足 Angular2+ 的解决方案。

我有一个来自 GoDaddy 的通配符 SSL 证书,所以我不能使用 nativescript-https(根据他们的 github 问题 https://github.com/gethuman/nativescript-https/issues/14)

一个真实的例子,我可以阅读代码并了解一切发生的地方会很棒,我的意思是,我尝试查看https://discourse.nativescript.org/t/how-to-ignore-invalid-ssl-certificate -in-nativescript/1924,但这对我来说没有任何意义,因为我不知道在使用这个例子时从哪里开始。

编辑:我尝试使用 nativescript-https disableSSLPining,没有成功。在我的app.module.ts

import * as application from 'application';
import * as platform from 'platform';
import * as HTTPS from 'nativescript-https';

var disabledSSLError = () => {
    if(platform.isAndroid){
        application.android.startActivity = () => {
            HTTPS.disableSSLPinning();
        }
    }
};

disabledSSLError();

但是,当我发送 POST

    "message": "Http failure response for (unknown url): 0 Unknown Error",
JS:   "error": {
JS:     "originalStack": "Error: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.\n    at new ZoneAwareError (file:///data/data/org.nativescript.myapp/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:1298:33)\n    at onRequestComplete (file:///data/data/org.nativescript.myapp/files/app/tns_modules/tns-core-modules/http/http-request/http-request.js:45:34)\n    at Object.onComplete (file:///data/data/org.nativescript.myapp/files/app/tns_modules/tns-core-modules/http/http-request/http-request.js:37:13)",

标签: sslangular2-nativescript

解决方案


您可以使用 https。我认为你误解了这个问题。这个问题只是说如果您使用固定,那么您不能使用通配符 https(但您不需要使用它)。

SSL pinning 增加了额外的安全层,但如果您刚刚开始,则不需要它。参考

只需使用 HttpClient 库继续执行标准 https 请求,就可以了。


推荐阅读