jose 4.1.4 → 4.1.5
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 +3 -0
- package/dist/browser/key/import.js +2 -1
- package/dist/node/cjs/key/import.js +2 -1
- package/dist/node/cjs/runtime/decrypt.js +8 -6
- package/dist/node/cjs/runtime/encrypt.js +2 -1
- package/dist/node/esm/key/import.js +2 -1
- package/dist/node/esm/runtime/decrypt.js +8 -6
- package/dist/node/esm/runtime/encrypt.js +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -65,6 +65,7 @@ If you or your business use `jose`, please consider becoming a [sponsor][support
|
|
|
65
65
|
- [Cloudflare Workers Support][]
|
|
66
66
|
- [Deno Support][]
|
|
67
67
|
- [Electron Support][]
|
|
68
|
+
- [Next.js Middleware / Vercel Edge Functions Support][]
|
|
68
69
|
- [Node.js Support][]
|
|
69
70
|
|
|
70
71
|
## FAQ
|
|
@@ -133,8 +134,10 @@ install size should not be a cause for concern.
|
|
|
133
134
|
[webcrypto]: https://www.w3.org/TR/WebCryptoAPI/
|
|
134
135
|
[nodewebcrypto]: https://nodejs.org/docs/latest-v15.x/api/webcrypto.html
|
|
135
136
|
[deno.land/x/jose]: https://deno.land/x/jose
|
|
137
|
+
|
|
136
138
|
[Browser Support]: https://github.com/panva/jose/issues/263
|
|
137
139
|
[Cloudflare Workers Support]: https://github.com/panva/jose/issues/265
|
|
138
140
|
[Deno Support]: https://github.com/panva/jose/issues/266
|
|
139
141
|
[Electron Support]: https://github.com/panva/jose/issues/264
|
|
142
|
+
[Next.js Middleware / Vercel Edge Functions Support]: https://github.com/panva/jose/issues/301
|
|
140
143
|
[Node.js Support]: https://github.com/panva/jose/issues/262
|
|
@@ -62,7 +62,8 @@ function parseElement(bytes) {
|
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
64
|
function spkiFromX509(buf) {
|
|
65
|
-
|
|
65
|
+
const tbsCertificate = getElement(getElement(parseElement(buf).contents)[0].contents);
|
|
66
|
+
return encodeBase64(tbsCertificate[tbsCertificate[0].raw[0] === 0xa0 ? 6 : 5].raw);
|
|
66
67
|
}
|
|
67
68
|
function getSPKI(x509) {
|
|
68
69
|
const pem = x509.replace(/(?:-----(?:BEGIN|END) CERTIFICATE-----|\s)/g, '');
|
|
@@ -65,7 +65,8 @@ function parseElement(bytes) {
|
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
67
|
function spkiFromX509(buf) {
|
|
68
|
-
|
|
68
|
+
const tbsCertificate = getElement(getElement(parseElement(buf).contents)[0].contents);
|
|
69
|
+
return (0, base64url_js_1.encodeBase64)(tbsCertificate[tbsCertificate[0].raw[0] === 0xa0 ? 6 : 5].raw);
|
|
69
70
|
}
|
|
70
71
|
function getSPKI(x509) {
|
|
71
72
|
const pem = x509.replace(/(?:-----(?:BEGIN|END) CERTIFICATE-----|\s)/g, '');
|
|
@@ -36,8 +36,8 @@ async function cbcDecrypt(enc, cek, ciphertext, iv, tag, aad) {
|
|
|
36
36
|
}
|
|
37
37
|
let plaintext;
|
|
38
38
|
try {
|
|
39
|
-
const
|
|
40
|
-
plaintext = (0, buffer_utils_js_1.concat)(
|
|
39
|
+
const decipher = (0, crypto_1.createDecipheriv)(algorithm, encKey, iv);
|
|
40
|
+
plaintext = (0, buffer_utils_js_1.concat)(decipher.update(ciphertext), decipher.final());
|
|
41
41
|
}
|
|
42
42
|
catch {
|
|
43
43
|
}
|
|
@@ -53,12 +53,14 @@ async function gcmDecrypt(enc, cek, ciphertext, iv, tag, aad) {
|
|
|
53
53
|
throw new errors_js_1.JOSENotSupported(`alg ${enc} is not supported by your javascript runtime`);
|
|
54
54
|
}
|
|
55
55
|
try {
|
|
56
|
-
const
|
|
57
|
-
|
|
56
|
+
const decipher = (0, crypto_1.createDecipheriv)(algorithm, cek, iv, { authTagLength: 16 });
|
|
57
|
+
decipher.setAuthTag(tag);
|
|
58
58
|
if (aad.byteLength) {
|
|
59
|
-
|
|
59
|
+
decipher.setAAD(aad, { plaintextLength: ciphertext.length });
|
|
60
60
|
}
|
|
61
|
-
|
|
61
|
+
const plaintext = decipher.update(ciphertext);
|
|
62
|
+
decipher.final();
|
|
63
|
+
return plaintext;
|
|
62
64
|
}
|
|
63
65
|
catch {
|
|
64
66
|
throw new errors_js_1.JWEDecryptionFailed();
|
|
@@ -38,7 +38,8 @@ async function gcmEncrypt(enc, plaintext, cek, iv, aad) {
|
|
|
38
38
|
if (aad.byteLength) {
|
|
39
39
|
cipher.setAAD(aad, { plaintextLength: plaintext.length });
|
|
40
40
|
}
|
|
41
|
-
const ciphertext =
|
|
41
|
+
const ciphertext = cipher.update(plaintext);
|
|
42
|
+
cipher.final();
|
|
42
43
|
const tag = cipher.getAuthTag();
|
|
43
44
|
return { ciphertext, tag };
|
|
44
45
|
}
|
|
@@ -62,7 +62,8 @@ function parseElement(bytes) {
|
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
64
|
function spkiFromX509(buf) {
|
|
65
|
-
|
|
65
|
+
const tbsCertificate = getElement(getElement(parseElement(buf).contents)[0].contents);
|
|
66
|
+
return encodeBase64(tbsCertificate[tbsCertificate[0].raw[0] === 0xa0 ? 6 : 5].raw);
|
|
66
67
|
}
|
|
67
68
|
function getSPKI(x509) {
|
|
68
69
|
const pem = x509.replace(/(?:-----(?:BEGIN|END) CERTIFICATE-----|\s)/g, '');
|
|
@@ -34,8 +34,8 @@ async function cbcDecrypt(enc, cek, ciphertext, iv, tag, aad) {
|
|
|
34
34
|
}
|
|
35
35
|
let plaintext;
|
|
36
36
|
try {
|
|
37
|
-
const
|
|
38
|
-
plaintext = concat(
|
|
37
|
+
const decipher = createDecipheriv(algorithm, encKey, iv);
|
|
38
|
+
plaintext = concat(decipher.update(ciphertext), decipher.final());
|
|
39
39
|
}
|
|
40
40
|
catch {
|
|
41
41
|
}
|
|
@@ -51,12 +51,14 @@ async function gcmDecrypt(enc, cek, ciphertext, iv, tag, aad) {
|
|
|
51
51
|
throw new JOSENotSupported(`alg ${enc} is not supported by your javascript runtime`);
|
|
52
52
|
}
|
|
53
53
|
try {
|
|
54
|
-
const
|
|
55
|
-
|
|
54
|
+
const decipher = createDecipheriv(algorithm, cek, iv, { authTagLength: 16 });
|
|
55
|
+
decipher.setAuthTag(tag);
|
|
56
56
|
if (aad.byteLength) {
|
|
57
|
-
|
|
57
|
+
decipher.setAAD(aad, { plaintextLength: ciphertext.length });
|
|
58
58
|
}
|
|
59
|
-
|
|
59
|
+
const plaintext = decipher.update(ciphertext);
|
|
60
|
+
decipher.final();
|
|
61
|
+
return plaintext;
|
|
60
62
|
}
|
|
61
63
|
catch {
|
|
62
64
|
throw new JWEDecryptionFailed();
|
|
@@ -36,7 +36,8 @@ async function gcmEncrypt(enc, plaintext, cek, iv, aad) {
|
|
|
36
36
|
if (aad.byteLength) {
|
|
37
37
|
cipher.setAAD(aad, { plaintextLength: plaintext.length });
|
|
38
38
|
}
|
|
39
|
-
const ciphertext =
|
|
39
|
+
const ciphertext = cipher.update(plaintext);
|
|
40
|
+
cipher.final();
|
|
40
41
|
const tag = cipher.getAuthTag();
|
|
41
42
|
return { ciphertext, tag };
|
|
42
43
|
}
|