Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

[pkcs12] new package for PKCS#12 utilities #2773

Merged
merged 20 commits into from Oct 13, 2020
Merged

[pkcs12] new package for PKCS#12 utilities #2773

merged 20 commits into from Oct 13, 2020

Conversation

quinlanj
Copy link
Member

@quinlanj quinlanj commented Oct 9, 2020

Why

Creates a new pkcs12 utility package meant to replace PKCS12Utils.ts in xdl. This is because:

  • www depends on xdl, but only uses this file
  • eas-cli has a duplicated PKCS12Utils file, and we can refactor it out to a common package
  • xdl and expo-cli can eventually be refactored to use this common package

Integration Plan

  1. 🚨 🚨🚨 Replace in www. This is the most urgent usecase because we need keystore pkcs12 support ASAP. This is also a good place to start because if there are any bugs, it will be the easiest to detect in Google Cloud Logs and the easiest to rollback. 🚨🚨🚨
  2. Replace in eas-cli, xdl and expo-cli

How

  • provides ways to extract conventional pkcs#12 files as well as keystore formatted pkcs#12 files (generated by the java keytool binary)
  • more comprehensive tests

Notable Changes

Functions have been changed to be more modular to account for the different p12 formats

  • getPKCS deserializes encoded p12 file
  • getx509Certificate and getx509CertificateByFriendlyName extract the certificate from a p12 object. For use by conventional p12 and keystore formatted p12 formats, respectively.
  • getCertificateFingerprint calculates the various hashes for a certificate object
  • getFormattedSerialNumber calculates the serial number for a certificate object

packages/pkcs12/tsconfig.json Outdated Show resolved Hide resolved
packages/pkcs12/README.md Outdated Show resolved Hide resolved
packages/pkcs12/README.md Outdated Show resolved Hide resolved
packages/pkcs12/README.md Outdated Show resolved Hide resolved
packages/pkcs12/src/__tests__/pkcs12-test.ts Outdated Show resolved Hide resolved
packages/pkcs12/src/index.ts Outdated Show resolved Hide resolved
packages/pkcs12/src/index.ts Outdated Show resolved Hide resolved
packages/pkcs12/src/index.ts Outdated Show resolved Hide resolved
packages/pkcs12/src/index.ts Outdated Show resolved Hide resolved
packages/pkcs12/src/index.ts Outdated Show resolved Hide resolved
return certificate;
}

export function getPKCS12(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe parse or decode would be better here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decrypt?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure pkcs12FromAsn1 returns decrypted values, but if that is the case then yes decrypt would be a better name.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think parse would be better here -- it definitely parse/decodes the base64 p12 to an object. It also optionally uses the password to decrypt the p12 if the content type is marked as 'encryptedData' https://github.com/digitalbazaar/forge/blob/588c41062d9a13f8dc91be3723b159c6cc434b15/lib/pkcs12.js#L554

? p12BufferOrBase64String.toString('base64')
: p12BufferOrBase64String;
const password = String(maybePassword || '');
const p12Der = forge.util.decode64(base64EncodedP12);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the format of p12Der? just want to make sure we're not doing extra work converting a buffer to base64 and then converting it back to some buffer-like data type.

Copy link
Member Author

@quinlanj quinlanj Oct 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p12Der is a binary encoded string. The way we are getting the p12 file is how node-forge recommends in their docs for pkcs12 files. The methods they expose are basically to get the base64 p12 -> decode it into a binary encoded string (p12Der) -> convert it to an asn1 object -> convert it to a pkcs12 object.

quinlanj and others added 15 commits October 11, 2020 17:51
Co-authored-by: James Ide <ide@users.noreply.github.com>
Co-authored-by: James Ide <ide@users.noreply.github.com>
Co-authored-by: James Ide <ide@users.noreply.github.com>
Co-authored-by: James Ide <ide@users.noreply.github.com>
Co-authored-by: James Ide <ide@users.noreply.github.com>
Co-authored-by: James Ide <ide@users.noreply.github.com>
Co-authored-by: James Ide <ide@users.noreply.github.com>
Co-authored-by: James Ide <ide@users.noreply.github.com>
Co-authored-by: James Ide <ide@users.noreply.github.com>
Co-authored-by: James Ide <ide@users.noreply.github.com>
Co-authored-by: James Ide <ide@users.noreply.github.com>
Co-authored-by: James Ide <ide@users.noreply.github.com>
@quinlanj quinlanj requested a review from ide October 12, 2020 06:03
packages/pkcs12/README.md Outdated Show resolved Hide resolved
Co-authored-by: James Ide <ide@users.noreply.github.com>
@quinlanj quinlanj merged commit 635275e into master Oct 13, 2020
@quinlanj quinlanj deleted the @quin/pkcs12 branch October 13, 2020 00:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants