【问题标题】:There is any way to validate app signature in ionic?有什么方法可以在 ionic 中验证应用程序签名?
【发布时间】:2021-02-22 02:48:28
【问题描述】:

已经2天了。我正在寻找有关 ionic 中的应用程序证书验证库/函数的一些线索。就像在 android 中我发现 SignatureCheck.java enter link description here 那么我们是否也可以在 TypeScript 中实现类似的东西来检查应用程序证书是否相同? 任何建议都会有帮助谢谢

【问题讨论】:

    标签: javascript typescript ionic-framework ionic3 cordova-plugins


    【解决方案1】:

    我刚才也在想同样的问题,经过一番搜索后,我发现了这个帖子:https://medium.com/@atifhussain.nu21/ssl-pinning-in-ionic-cordova-based-applications-ce993adcc07

    这看起来是一个非常可行的解决方案,使用了一个 cordova 插件/库“cordova-plugin-sslcertificatechecker”。

    示例代码:

    import { Injectable, Injector } from '@angular/core';
    import {
     HttpEvent,
     HttpHandler,
     HttpInterceptor,
     HttpRequest
    } from '@angular/common/http';
    import { Network } from '@ionic-native/network';
    import { Observable } from 'rxjs/Rx';
    import { CONFIG_CONSTANTS } from '../../common/constant/app-config';
    import { MESSAGE_CONSTANTS } from '../../common/constant/message';
    declare var window: any;
    @Injectable()
    export class RequestInterceptor implements HttpInterceptor {
     helperFunction: HelperFunctions;
    constructor(private network: Network, private injector: Injector) { }
    intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    this.helperFunction = this.injector.get(HelperFunctions);
    let setHeader = {
       'ContentType': 'application/json',
       'Accept': 'application/json',
       'DEVICETYPE': 'MOBILE',
       'X-Requested-With': 'XMLHttpRequest',
       'Content-Type': 'application/json',
       'dataType': 'json'
      };
    let Host = CONFIG_CONSTANTS.BASE_URL;
    if (this.network.type === 'none') {
       this.helperFunction.showAlert(MESSAGE_CONSTANTS.CONNECTION_NOT_WORKING);
       return next.handle(request);
      }
    return this.checkSecurity(`${Host}${request.url}`, request).flatMap((modifiedReq) => {
       let newReq = null;
       if (modifiedReq['message'] === 'CONNECTION_SECURE') {
        newReq = request.clone({
         url: `${Host}${request.url}`,
         setHeaders: setHeader
        });
       }
       return next.handle(newReq);
      });
     }
    checkSecurity(URL, request) {
      return new Observable((observer) => {
       window.plugins.sslCertificateChecker.check(
        (message) => {
         return observer.next({req: request, message: message});
        },
        (message) => {
         return observer.error({req: request, message: message});
        },
        URL,
        CONFIG_CONSTANTS.FINGERPRINT);
      });
     }
    }
    

    我还没有亲自为我自己的项目尝试过这个。我希望这会有所帮助,让我们知道。 :)

    【讨论】:

      猜你喜欢
      • 2011-04-16
      • 2015-11-26
      • 2017-10-03
      • 2022-12-18
      • 2011-07-13
      • 1970-01-01
      • 1970-01-01
      • 2020-06-25
      • 2019-05-13
      相关资源
      最近更新 更多