我对iOS的课程了解不多。我正在构建需要SSL固定的iOS应用(离子3)。大部分google示例均基于swift。我可以知道步骤吗,或者有人可以提供有关iOS SSL固定的链接吗?
PS:我的服务器中已经有一个证书。另外,我已经完成了Android网络安全配置的SSL固定。参考https://developer.android.com/training/articles/security-config。工作正常。
谢谢。
答案 0 :(得分:0)
离子5.4.15版本解决方案。
要在ionic中启用SSL固定,请在根文件夹中创建一个目录,例如“证书”,并将所有证书放入此文件夹。 重要说明:此文件夹中的所有证书都必须带有后缀.cer !!!
然后在根项目目录中修改angular.json 将这部分附加到“资产”数组的所有出现处。
{
"glob": "**/*",
"input": "certificates",
"output": "certificates"
}
然后在根项目中删除www目录并运行“ ionic build”, 它将在您的www文件夹中生成新的子目录“证书”
使用打字稿中的证书:
我正在使用离子本机的http和cordova-advanced-http-plugin
安装:
ionic cordova plugin add cordova-plugin-advanced-http
npm install @ionic-native/http
导入您的根xyz.module.ts文件:
import { HTTP } from '@ionic-native/http/ngx';
将其附加到提供者:
providers: [
StatusBar,
SplashScreen,
**HTTP**,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
],
导入您的页面/组件xyz.ts文件:
import { HTTP } from '@ionic-native/http/ngx';
在构造函数中声明:
constructor(private http: HTTP) {}
在提出任何请求之前固定证书:
async ngOnInit() {
await this.platform.ready();
this.advHttp.setServerTrustMode('pinned').then((res: any) => {
}, (error) => {
this.helpers.showError(error);
});
this.advHttp.setRequestTimeout(5);
}
现在全部设置好了,可以使用https请求! 文件: https://ionicframework.com/docs/native/http