client-certificate-auth 2.0.1 → 2.0.2
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.
|
@@ -85,8 +85,8 @@ function clientCertificateAuth(callback, options = {}) {
|
|
|
85
85
|
queueMicrotask(() => {
|
|
86
86
|
try {
|
|
87
87
|
const result = hook(...args);
|
|
88
|
-
if (result
|
|
89
|
-
result.catch(err => console.error('client-certificate-auth: hook error:', err));
|
|
88
|
+
if (isThenable(result)) {
|
|
89
|
+
Promise.resolve(result).catch(err => console.error('client-certificate-auth: hook error:', err));
|
|
90
90
|
}
|
|
91
91
|
} catch (err) {
|
|
92
92
|
console.error('client-certificate-auth: hook error:', err);
|
|
@@ -118,8 +118,8 @@ export default function clientCertificateAuth(callback, options = {}) {
|
|
|
118
118
|
queueMicrotask(() => {
|
|
119
119
|
try {
|
|
120
120
|
const result = hook(...args);
|
|
121
|
-
if (result
|
|
122
|
-
result.catch(err => console.error('client-certificate-auth: hook error:', err));
|
|
121
|
+
if (isThenable(result)) {
|
|
122
|
+
Promise.resolve(result).catch(err => console.error('client-certificate-auth: hook error:', err));
|
|
123
123
|
}
|
|
124
124
|
} catch (err) {
|
|
125
125
|
console.error('client-certificate-auth: hook error:', err);
|
package/lib/helpers.js
CHANGED
|
@@ -38,7 +38,8 @@ export function allowCN(names) {
|
|
|
38
38
|
* Create a validation callback that allows certificates with matching fingerprints.
|
|
39
39
|
* Supports SHA-1 fingerprints (compared against cert.fingerprint) and SHA-256
|
|
40
40
|
* fingerprints with "SHA256:" prefix (compared against cert.fingerprint256).
|
|
41
|
-
* Fingerprints without a prefix are treated as SHA-1.
|
|
41
|
+
* Fingerprints without a prefix are treated as SHA-1. Hex inputs are
|
|
42
|
+
* normalized: case and colon delimiters are ignored on both sides.
|
|
42
43
|
*
|
|
43
44
|
* @param {string[]} fingerprints - Allowed fingerprints
|
|
44
45
|
* @returns {ValidationCallback}
|
|
@@ -46,28 +47,30 @@ export function allowCN(names) {
|
|
|
46
47
|
* @example
|
|
47
48
|
* app.use(clientCertificateAuth(allowFingerprints([
|
|
48
49
|
* 'SHA256:AB:CD:EF:...', // matched against cert.fingerprint256
|
|
49
|
-
* 'AB:CD:EF:...'
|
|
50
|
+
* 'AB:CD:EF:...', // colon-delimited, matched against cert.fingerprint
|
|
51
|
+
* 'ABCDEF...' // contiguous hex also matches cert.fingerprint
|
|
50
52
|
* ])));
|
|
51
53
|
*/
|
|
52
54
|
export function allowFingerprints(fingerprints) {
|
|
55
|
+
const normalize = (fp) => fp.toUpperCase().replace(/:/g, '');
|
|
53
56
|
const sha256Allowed = new Set();
|
|
54
57
|
const sha1Allowed = new Set();
|
|
55
58
|
|
|
56
59
|
for (const fp of fingerprints) {
|
|
57
60
|
const upper = fp.toUpperCase();
|
|
58
61
|
if (upper.startsWith('SHA256:')) {
|
|
59
|
-
sha256Allowed.add(upper.slice(7));
|
|
62
|
+
sha256Allowed.add(normalize(upper.slice(7)));
|
|
60
63
|
} else {
|
|
61
|
-
sha1Allowed.add(upper);
|
|
64
|
+
sha1Allowed.add(normalize(upper));
|
|
62
65
|
}
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
return (cert) => {
|
|
66
69
|
if (sha1Allowed.size > 0 && cert.fingerprint) {
|
|
67
|
-
if (sha1Allowed.has(cert.fingerprint
|
|
70
|
+
if (sha1Allowed.has(normalize(cert.fingerprint))) {return true;}
|
|
68
71
|
}
|
|
69
72
|
if (sha256Allowed.size > 0 && cert.fingerprint256) {
|
|
70
|
-
if (sha256Allowed.has(cert.fingerprint256
|
|
73
|
+
if (sha256Allowed.has(normalize(cert.fingerprint256))) {return true;}
|
|
71
74
|
}
|
|
72
75
|
return false;
|
|
73
76
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "client-certificate-auth",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Express/Connect middleware for mTLS client certificate authentication with reverse proxy support (AWS ALB, Envoy, Cloudflare, Traefik)",
|
|
5
5
|
"homepage": "https://github.com/tgies/client-certificate-auth",
|
|
6
6
|
"bugs": {
|