@expo/pkcs12 0.0.8 → 0.1.1
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 +1 -12
- package/build/index.d.ts +0 -1
- package/build/index.js +19 -16
- package/build/index.js.map +1 -1
- package/package.json +26 -19
package/README.md
CHANGED
|
@@ -3,18 +3,7 @@
|
|
|
3
3
|
👋 Welcome to <br><code>@expo/pkcs12</code>
|
|
4
4
|
</h1>
|
|
5
5
|
|
|
6
|
-
<p align="center">PKCS#12 utility functions to extract certificates from conventional and keystore PKCS#12 files
|
|
7
|
-
.</p>
|
|
8
|
-
|
|
9
|
-
<p align="center">
|
|
10
|
-
<img src="https://flat.badgen.net/packagephobia/install/@expo/pkcs12">
|
|
11
|
-
|
|
12
|
-
<a href="https://www.npmjs.com/package/@expo/pkcs12">
|
|
13
|
-
<img src="https://flat.badgen.net/npm/dw/@expo/pkcs12" target="_blank" />
|
|
14
|
-
</a>
|
|
15
|
-
</p>
|
|
16
|
-
|
|
17
|
-
<!-- Body -->
|
|
6
|
+
<p align="center">PKCS#12 utility functions to extract certificates from conventional and keystore PKCS#12 files.</p>
|
|
18
7
|
|
|
19
8
|
# Examples
|
|
20
9
|
|
package/build/index.d.ts
CHANGED
package/build/index.js
CHANGED
|
@@ -3,7 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.getFormattedSerialNumber = getFormattedSerialNumber;
|
|
7
|
+
exports.getX509Certificate = getX509Certificate;
|
|
8
|
+
exports.getX509CertificateByFriendlyName = getX509CertificateByFriendlyName;
|
|
9
|
+
exports.getX509Asn1ByFriendlyName = getX509Asn1ByFriendlyName;
|
|
10
|
+
exports.parsePKCS12 = parsePKCS12;
|
|
11
|
+
exports.getAsn1Hash = getAsn1Hash;
|
|
12
|
+
exports.getCertificateFingerprint = getCertificateFingerprint;
|
|
7
13
|
const crypto_1 = __importDefault(require("crypto"));
|
|
8
14
|
const node_forge_1 = __importDefault(require("node-forge"));
|
|
9
15
|
/**
|
|
@@ -13,7 +19,6 @@ function getFormattedSerialNumber(certificate) {
|
|
|
13
19
|
const { serialNumber } = certificate;
|
|
14
20
|
return serialNumber ? serialNumber.replace(/^0+/, '').toUpperCase() : null;
|
|
15
21
|
}
|
|
16
|
-
exports.getFormattedSerialNumber = getFormattedSerialNumber;
|
|
17
22
|
/**
|
|
18
23
|
* Extracts a certificate from PKCS#12
|
|
19
24
|
* This is assumed to be a conventional PKCS#12 where there is exactly one certificate and one key
|
|
@@ -26,7 +31,6 @@ function getX509Certificate(p12) {
|
|
|
26
31
|
}
|
|
27
32
|
return getX509CertificateFromBag(bags[0]);
|
|
28
33
|
}
|
|
29
|
-
exports.getX509Certificate = getX509Certificate;
|
|
30
34
|
/**
|
|
31
35
|
* Extracts a certificate from PKCS#12
|
|
32
36
|
* This is assumed to be a PKCS#12 containing a keystore where the friendlyName (alias) contains a PrivateKeyEntry
|
|
@@ -36,14 +40,15 @@ exports.getX509Certificate = getX509Certificate;
|
|
|
36
40
|
function getX509CertificateByFriendlyName(p12, friendlyName) {
|
|
37
41
|
const certBagType = node_forge_1.default.pki.oids.certBag;
|
|
38
42
|
// node-forge converts friendly names to lowercase, so we search by lowercase
|
|
39
|
-
const bags = p12.getBags({
|
|
40
|
-
.
|
|
43
|
+
const bags = p12.getBags({
|
|
44
|
+
friendlyName: friendlyName.toLowerCase(),
|
|
45
|
+
bagType: certBagType,
|
|
46
|
+
}).friendlyName;
|
|
41
47
|
if (!bags || bags.length === 0) {
|
|
42
48
|
return null;
|
|
43
49
|
}
|
|
44
50
|
return getX509CertificateFromBag(bags[0]);
|
|
45
51
|
}
|
|
46
|
-
exports.getX509CertificateByFriendlyName = getX509CertificateByFriendlyName;
|
|
47
52
|
function getX509CertificateFromBag(bag) {
|
|
48
53
|
const { cert, asn1 } = bag;
|
|
49
54
|
if (!cert && asn1) {
|
|
@@ -59,8 +64,10 @@ function getX509CertificateFromBag(bag) {
|
|
|
59
64
|
function getX509Asn1ByFriendlyName(p12, friendlyName) {
|
|
60
65
|
const certBagType = node_forge_1.default.pki.oids.certBag;
|
|
61
66
|
// node-forge converts friendly names to lowercase, so we search by lowercase
|
|
62
|
-
const bags = p12.getBags({
|
|
63
|
-
.
|
|
67
|
+
const bags = p12.getBags({
|
|
68
|
+
friendlyName: friendlyName.toLowerCase(),
|
|
69
|
+
bagType: certBagType,
|
|
70
|
+
}).friendlyName;
|
|
64
71
|
if (!bags || bags.length === 0) {
|
|
65
72
|
return null;
|
|
66
73
|
}
|
|
@@ -70,28 +77,26 @@ function getX509Asn1ByFriendlyName(p12, friendlyName) {
|
|
|
70
77
|
}
|
|
71
78
|
// if asn1 is present but certificate isnt, the certificate type was unknown
|
|
72
79
|
// github.com/digitalbazaar/forge/blob/1887cfce43a8f5ca9cb5c256168cf12ce1715ecf/lib/pkcs12.js#L703
|
|
73
|
-
return asn1
|
|
80
|
+
return asn1 ?? null;
|
|
74
81
|
}
|
|
75
|
-
exports.getX509Asn1ByFriendlyName = getX509Asn1ByFriendlyName;
|
|
76
82
|
function parsePKCS12(p12BufferOrBase64String, maybePassword) {
|
|
77
83
|
const base64EncodedP12 = Buffer.isBuffer(p12BufferOrBase64String)
|
|
78
84
|
? p12BufferOrBase64String.toString('base64')
|
|
79
85
|
: p12BufferOrBase64String;
|
|
80
|
-
const password = String(maybePassword
|
|
86
|
+
const password = String(maybePassword ?? '');
|
|
81
87
|
const p12Der = node_forge_1.default.util.decode64(base64EncodedP12);
|
|
82
88
|
const p12Asn1 = node_forge_1.default.asn1.fromDer(p12Der);
|
|
83
89
|
return node_forge_1.default.pkcs12.pkcs12FromAsn1(p12Asn1, password);
|
|
84
90
|
}
|
|
85
|
-
exports.parsePKCS12 = parsePKCS12;
|
|
86
91
|
function getHash(data, { hashAlgorithm, hashEncoding, inputEncoding, }) {
|
|
87
|
-
const hash = crypto_1.default.createHash(hashAlgorithm
|
|
92
|
+
const hash = crypto_1.default.createHash(hashAlgorithm ?? 'sha1');
|
|
88
93
|
if (inputEncoding) {
|
|
89
94
|
hash.update(data, inputEncoding);
|
|
90
95
|
}
|
|
91
96
|
else {
|
|
92
97
|
hash.update(data); // use Node's default inputEncoding
|
|
93
98
|
}
|
|
94
|
-
return hash.digest(hashEncoding
|
|
99
|
+
return hash.digest(hashEncoding ?? 'hex');
|
|
95
100
|
}
|
|
96
101
|
function getAsn1Hash(asn1, { hashAlgorithm, }) {
|
|
97
102
|
const certDer = node_forge_1.default.asn1.toDer(asn1).getBytes(); // binary encoded string
|
|
@@ -101,12 +106,10 @@ function getAsn1Hash(asn1, { hashAlgorithm, }) {
|
|
|
101
106
|
inputEncoding: 'latin1', // latin1 is an alias for binary
|
|
102
107
|
});
|
|
103
108
|
}
|
|
104
|
-
exports.getAsn1Hash = getAsn1Hash;
|
|
105
109
|
function getCertificateFingerprint(certificate, { hashAlgorithm, }) {
|
|
106
110
|
const certAsn1 = node_forge_1.default.pki.certificateToAsn1(certificate);
|
|
107
111
|
return getAsn1Hash(certAsn1, {
|
|
108
112
|
hashAlgorithm,
|
|
109
113
|
});
|
|
110
114
|
}
|
|
111
|
-
exports.getCertificateFingerprint = getCertificateFingerprint;
|
|
112
115
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAMA,4DAGC;AAMD,gDAOC;AAQD,4EAcC;AAeD,8DAoBC;AAED,kCAWC;AAuBD,kCAcC;AAED,8DAYC;AA/ID,oDAAgE;AAChE,4DAA+B;AAE/B;;GAEG;AACH,SAAgB,wBAAwB,CAAC,WA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name": "@expo/pkcs12",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
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": "4165b8d72e1b9a1889c2767534cc619e21468110"
|
|
35
42
|
}
|