@expo/pkcs12 0.0.7 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -4
- package/build/index.js +12 -8
- package/build/index.js.map +1 -1
- package/package.json +26 -19
package/README.md
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
<!-- Title -->
|
|
2
|
+
<h1 align="center">
|
|
3
|
+
👋 Welcome to <br><code>@expo/pkcs12</code>
|
|
4
|
+
</h1>
|
|
2
5
|
|
|
3
|
-
PKCS#12 utility functions to extract certificates from conventional and keystore PKCS#12 files
|
|
6
|
+
<p align="center">PKCS#12 utility functions to extract certificates from conventional and keystore PKCS#12 files.</p>
|
|
4
7
|
|
|
5
8
|
# Examples
|
|
6
9
|
|
|
7
10
|
## Extracting a certificate from a conventional PKCS#12 file
|
|
8
11
|
|
|
9
|
-
```
|
|
12
|
+
```js
|
|
10
13
|
const p12 = parsePKCS12(base64EncodedP12, password); // deserializes encodedP12
|
|
11
14
|
const certificate = getX509Certificate(p12); // extracts single certificate from p12
|
|
12
15
|
const sha1Fingerprint = getCertificateFingerprint(certificate, {
|
|
@@ -16,7 +19,7 @@ const sha1Fingerprint = getCertificateFingerprint(certificate, {
|
|
|
16
19
|
|
|
17
20
|
## Extracting a certificate from a keystore in a PKCS#12 file
|
|
18
21
|
|
|
19
|
-
```
|
|
22
|
+
```js
|
|
20
23
|
const p12 = parsePKCS12(base64EncodedP12, password); // deserializes encodedP12
|
|
21
24
|
const certificate = getX509CertificateByFriendlyName(p12, alias); // extracts single certificate stored under alias in p12
|
|
22
25
|
const sha1Fingerprint = getCertificateFingerprint(certificate, {
|
package/build/index.js
CHANGED
|
@@ -36,8 +36,10 @@ exports.getX509Certificate = getX509Certificate;
|
|
|
36
36
|
function getX509CertificateByFriendlyName(p12, friendlyName) {
|
|
37
37
|
const certBagType = node_forge_1.default.pki.oids.certBag;
|
|
38
38
|
// node-forge converts friendly names to lowercase, so we search by lowercase
|
|
39
|
-
const bags = p12.getBags({
|
|
40
|
-
.
|
|
39
|
+
const bags = p12.getBags({
|
|
40
|
+
friendlyName: friendlyName.toLowerCase(),
|
|
41
|
+
bagType: certBagType,
|
|
42
|
+
}).friendlyName;
|
|
41
43
|
if (!bags || bags.length === 0) {
|
|
42
44
|
return null;
|
|
43
45
|
}
|
|
@@ -59,8 +61,10 @@ function getX509CertificateFromBag(bag) {
|
|
|
59
61
|
function getX509Asn1ByFriendlyName(p12, friendlyName) {
|
|
60
62
|
const certBagType = node_forge_1.default.pki.oids.certBag;
|
|
61
63
|
// node-forge converts friendly names to lowercase, so we search by lowercase
|
|
62
|
-
const bags = p12.getBags({
|
|
63
|
-
.
|
|
64
|
+
const bags = p12.getBags({
|
|
65
|
+
friendlyName: friendlyName.toLowerCase(),
|
|
66
|
+
bagType: certBagType,
|
|
67
|
+
}).friendlyName;
|
|
64
68
|
if (!bags || bags.length === 0) {
|
|
65
69
|
return null;
|
|
66
70
|
}
|
|
@@ -70,28 +74,28 @@ function getX509Asn1ByFriendlyName(p12, friendlyName) {
|
|
|
70
74
|
}
|
|
71
75
|
// if asn1 is present but certificate isnt, the certificate type was unknown
|
|
72
76
|
// github.com/digitalbazaar/forge/blob/1887cfce43a8f5ca9cb5c256168cf12ce1715ecf/lib/pkcs12.js#L703
|
|
73
|
-
return asn1
|
|
77
|
+
return asn1 ?? null;
|
|
74
78
|
}
|
|
75
79
|
exports.getX509Asn1ByFriendlyName = getX509Asn1ByFriendlyName;
|
|
76
80
|
function parsePKCS12(p12BufferOrBase64String, maybePassword) {
|
|
77
81
|
const base64EncodedP12 = Buffer.isBuffer(p12BufferOrBase64String)
|
|
78
82
|
? p12BufferOrBase64String.toString('base64')
|
|
79
83
|
: p12BufferOrBase64String;
|
|
80
|
-
const password = String(maybePassword
|
|
84
|
+
const password = String(maybePassword ?? '');
|
|
81
85
|
const p12Der = node_forge_1.default.util.decode64(base64EncodedP12);
|
|
82
86
|
const p12Asn1 = node_forge_1.default.asn1.fromDer(p12Der);
|
|
83
87
|
return node_forge_1.default.pkcs12.pkcs12FromAsn1(p12Asn1, password);
|
|
84
88
|
}
|
|
85
89
|
exports.parsePKCS12 = parsePKCS12;
|
|
86
90
|
function getHash(data, { hashAlgorithm, hashEncoding, inputEncoding, }) {
|
|
87
|
-
const hash = crypto_1.default.createHash(hashAlgorithm
|
|
91
|
+
const hash = crypto_1.default.createHash(hashAlgorithm ?? 'sha1');
|
|
88
92
|
if (inputEncoding) {
|
|
89
93
|
hash.update(data, inputEncoding);
|
|
90
94
|
}
|
|
91
95
|
else {
|
|
92
96
|
hash.update(data); // use Node's default inputEncoding
|
|
93
97
|
}
|
|
94
|
-
return hash.digest(hashEncoding
|
|
98
|
+
return hash.digest(hashEncoding ?? 'hex');
|
|
95
99
|
}
|
|
96
100
|
function getAsn1Hash(asn1, { hashAlgorithm, }) {
|
|
97
101
|
const certDer = node_forge_1.default.asn1.toDer(asn1).getBytes(); // binary encoded string
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAgE;AAChE,4DAA+B;AAE/B;;GAEG;AACH,SAAgB,wBAAwB,CAAC,WAAkC;IACzE,MAAM,EAAE,YAAY,EAAE,GAAG,WAAW,CAAC;IACrC,OAAO,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7E,CAAC;AAHD,4DAGC;AAED;;;GAGG;AACH,SAAgB,kBAAkB,CAAC,GAA2B;IAC5D,MAAM,WAAW,GAAG,oBAAK,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC;IAC3C,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IAAI,MAAM,CAAC,CAAC;IACxD,IAAI,aAAa,EAAE;QACjB,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;KAClC;SAAM;QACL,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,mCAAmC;KACvD;IACD,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,IAAI,KAAK,CAAC,CAAC;AAC5C,CAAC;AAED,SAAgB,WAAW,CACzB,IAAqB,EACrB,EACE,aAAa,GAGd;IAED,MAAM,OAAO,GAAG,oBAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,wBAAwB;IAC3E,OAAO,OAAO,CAAC,OAAO,EAAE;QACtB,aAAa;QACb,YAAY,EAAE,KAAK;QACnB,aAAa,EAAE,QAAQ,EAAE,gCAAgC;KAC1D,CAAC,CAAC;AACL,CAAC;AAdD,kCAcC;AAED,SAAgB,yBAAyB,CACvC,WAAkC,EAClC,EACE,aAAa,GAGd;IAED,MAAM,QAAQ,GAAG,oBAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAC1D,OAAO,WAAW,CAAC,QAAQ,EAAE;QAC3B,aAAa;KACd,CAAC,CAAC;AACL,CAAC;AAZD,8DAYC"}
|
package/package.json
CHANGED
|
@@ -1,35 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expo/pkcs12",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "PKCS#12 Utilities for Node.js",
|
|
5
|
-
"main": "build/index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"watch": "tsc --watch --preserveWatchOutput",
|
|
8
|
-
"build": "tsc",
|
|
9
|
-
"prepare": "yarn build",
|
|
10
|
-
"lint": "eslint .",
|
|
11
|
-
"test": "jest"
|
|
12
|
-
},
|
|
13
|
-
"repository": {
|
|
14
|
-
"type": "git",
|
|
15
|
-
"url": "https://github.com/expo/expo-cli.git",
|
|
16
|
-
"directory": "packages/pkcs12"
|
|
17
|
-
},
|
|
18
5
|
"keywords": [
|
|
19
6
|
"pkcs12"
|
|
20
7
|
],
|
|
21
8
|
"license": "MIT",
|
|
22
|
-
"
|
|
23
|
-
"url": "https://github.com/expo/expo-cli/issues"
|
|
24
|
-
},
|
|
25
|
-
"homepage": "https://github.com/expo/expo-cli/tree/main/packages/pkcs12#readme",
|
|
9
|
+
"main": "build/index.js",
|
|
26
10
|
"files": [
|
|
27
11
|
"build"
|
|
28
12
|
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "expo-module tsc",
|
|
15
|
+
"clean": "expo-module clean",
|
|
16
|
+
"lint": "expo-module lint",
|
|
17
|
+
"prepare": "yarn run clean && yarn run build",
|
|
18
|
+
"prepublishOnly": "expo-module prepublishOnly",
|
|
19
|
+
"test": "expo-module test",
|
|
20
|
+
"typecheck": "expo-module typecheck",
|
|
21
|
+
"watch": "yarn run build --watch --preserveWatchOutput"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://github.com/expo/expo/tree/main/packages/%40expo/pkcs12#readme",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/expo/expo/issues"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/expo/expo.git",
|
|
30
|
+
"directory": "packages/@expo/pkcs12"
|
|
31
|
+
},
|
|
29
32
|
"dependencies": {
|
|
30
33
|
"node-forge": "^1.2.1"
|
|
31
34
|
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"expo-module-scripts": "^3.3.0"
|
|
37
|
+
},
|
|
32
38
|
"publishConfig": {
|
|
33
39
|
"access": "public"
|
|
34
|
-
}
|
|
40
|
+
},
|
|
41
|
+
"gitHead": "6aca7ce098ddc667776a3d7cf612adbb985e264a"
|
|
35
42
|
}
|