npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@aalzehla/capacitor-ssl-pinning

v0.0.7

Published

Check/pin SSL certificates

Downloads

18

Readme

Capacitor SSL Pinning

Ionic Capacitor Plugin to perform SSL checking/pinning. Checks the SSL certificate SHA256 fingerprint of a server and compares it to a provided fingerprint. On Android, the plugin also returns some additional information about the certificate.

Note:

  • On Fingerprints: There are different ways of expressing the fingerprint, some may use colons and others may not. This plugin normalizes the fingerprint to lowercase and removes colons for comparison. While it expects uppercase, it should not make a difference if you use colons or not. However it is recommended to use the format from the docs.
  • On Subject: The subject is the hostname of the certificate. On Android, the plugin returns the hostname of the certificate. On iOS, the plugin returns URL it was given.
  • On Issuer: The issuer is the issuer of the certificate. There are different formats on iOS and Android, their results are not guaranteed to be the same.

HitCount

https://nodei.co/npm/capacitor-ssl-pinning.png?downloads=true&downloadRank=true&stars=true

Install

npm install capacitor-ssl-pinning
npx cap sync

Obtain fingerprint

via website

  • get cert via browser: https://superuser.com/questions/1833063/how-to-get-a-certificate-out-of-chrome-now-the-padlock-has-gone
  • open cert in text editor, copy public key to clipboard
  • go to https://www.samltool.com/fingerprint.php
  • paste public key into textarea
  • select SHA-256 as Algorithm
  • copy fingerprint (with colons)

via command line

  • get cert via browser: https://superuser.com/questions/1833063/how-to-get-a-certificate-out-of-chrome-now-the-padlock-has-gone
  • get fingerprint: openssl x509 -noout -fingerprint -sha256 -inform pem -in /path/to/cert.pem

API

checkCertificate(...)

checkCertificate(options: SSLCertificateCheckerOptions) => Promise<SSLCertificateCheckerResult>

SSLCertificateCheckerResult

export type SSLCertificateCheckerResult = {
  /**
   * The subject of the certificate
   * @platform Android
   */
  subject?: string;
  /**
   * The issuer of the certificate
   * @platform Android
   */
  issuer?: string;
  /**
   * The valid from date of the certificate
   * @platform Android
   */
  validFrom?: string;
  /**
   * The valid to date of the certificate
   * @platform Android
   */
  validTo?: string;
  /**
   * The fingerprint of the certificate
   * @platform Android
   */
  fingerprint?: string;
  /**
   * Whether the fingerprint matches the expected fingerprint
   */
  fingerprintMatched?: boolean;
  /**
   * The error that occurred while checking the certificate
   */
  error?: string;
};

SSLCertificateCheckerOptions

export type SSLCertificateCheckerOptions = {
  url: string;
  fingerprint: string;
};

Usage

Note:

SSLCertificateChecker.checkCertificate({
  url: 'https://example.com', // replace with your server url
  fingerprint:
    '50:4B:A1:B5:48:96:71:F3:9F:87:7E:0A:09:FD:3E:1B:C0:4F:AA:9F:FC:83:3E:A9:3A:00:78:88:F8:BA:60:26', // replace with your server fingerprint
}).then(res => {
  console.log(res.fingerprintMatched);
});

Example Interceptor:

// src/app/interceptors/ssl-pinning.interceptor.ts

import { Injectable } from '@angular/core';
import {
  HttpRequest,
  HttpHandler,
  HttpEvent,
  HttpInterceptor,
} from '@angular/common/http';
import { from, Observable, switchMap, throwError } from 'rxjs';
import { SSLCertificateChecker } from 'capacitor-ssl-pinning';
import { environment } from 'src/environments/environment';
import { Capacitor } from '@capacitor/core';

@Injectable()
export class SslPinningInterceptor implements HttpInterceptor {
  intercept(
    request: HttpRequest<any>,
    next: HttpHandler
  ): Observable<HttpEvent<any>> {
    // only available on android/ios
    if (Capacitor.getPlatform() === 'web') {
      return next.handle(request);
    }
    return from(
      SSLCertificateChecker.checkCertificate({
        url: environment.baseUrlBase,
        fingerprint: environment.fingerprint,
      })
    ).pipe(
      switchMap((res) => {
        if (res.fingerprintMatched) {
          return next.handle(request);
        }
        return throwError(() => new Error('Fingerprint not matched'));
      })
    );
  }
}