简体   繁体   English

如何在 Ionic 3 的 iOS 中实现 SSL Key Pinning?

[英]How to implement SSL Key Pinning in iOS in Ionic 3?

I did not have much knowledge in iOS classes.我对 iOS 课程的了解不多。 I am building an iOS app(Ionic 3) which required the SSL pinning.我正在构建一个需要 SSL 固定的 iOS 应用程序(Ionic 3)。 Most of the google example based on swift.大多数基于 swift 的 google 示例。 May I know the steps or could anybody provide some links regarding iOS SSL pinning?我可以知道这些步骤吗,或者有人可以提供一些有关 iOS SSL 固定的链接吗?

PS: I already have a certificate in my server. PS:我的服务器中已经有一个证书。 Also, I have done the SSL pinning with Network security configuration for Android.另外,我已经使用 Android 的网络安全配置完成了 SSL 固定。 Refhttps://developer.android.com/training/articles/security-config .参考https://developer.android.com/training/articles/security-config Its working fine.它的工作正常。

Thanks in advance.提前致谢。

Ionic 5.4.15 version solution. Ionic 5.4.15 版本解决方案。

To enable SSL pinning in ionic create a directory inside your root folder eg "certificates" and put all your certificates inside this folder.要在 ionic 中启用 SSL 固定,请在根文件夹中创建一个目录,例如“证书”,并将所有证书放在此文件夹中。 IMPORTANT: all certificates inside this folder must have suffix .cer!!!重要提示:此文件夹中的所有证书都必须有后缀 .cer!!!

After that modify angular.json in root project directory append this part to all occurencies of "assets" array.之后修改根项目目录中的 angular.json 将此部分附加到“assets”数组的所有出现处。

{   
"glob": "**/*", 
"input": "certificates",    
"output": "certificates"
}

then delete your www directory in root project and run "ionic build", it will generate new subdirectory "certificates" in your www folder然后在根项目中删除您的 www 目录并运行“ionic build”,它将在您的 www 文件夹中生成新的子目录“certificates”

USE of certificates in Typescript:在 Typescript 中使用证书:

I am using ionic-native http and cordova-advanced-http-plugin我正在使用 ionic-native http 和 cordova-advanced-http-plugin

Install:安装:

ionic cordova plugin add cordova-plugin-advanced-http
npm install @ionic-native/http

Import in your root, xyz.module.ts file:在您的根目录中导入 xyz.module.ts 文件:

import { HTTP } from '@ionic-native/http/ngx';

Append it to providers:将其附加到提供者:

 providers: [
    StatusBar,
    SplashScreen,
    **HTTP**,
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
  ],

Import in your page/component, xyz.ts file:在您的页面/组件中导入 xyz.ts 文件:

import { HTTP } from '@ionic-native/http/ngx';

Declare in constructor:在构造函数中声明:

constructor(private http: HTTP) {}

Pinning the certificates before any request made:在提出任何请求之前固定证书:

  async ngOnInit() {
    await this.platform.ready();
    this.advHttp.setServerTrustMode('pinned').then((res: any) => {
    }, (error) => {
      this.helpers.showError(error);
    });
    this.advHttp.setRequestTimeout(5);
  }

Now youre all set and may use https requests!现在您已准备就绪,可以使用 https 请求了! Docs: https://ionicframework.com/docs/native/http文档: https : //ionicframework.com/docs/native/http

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM