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 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
- return encodeBase64(getElement(getElement(parseElement(buf).contents)[0].contents)[6].raw);
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
- return (0, base64url_js_1.encodeBase64)(getElement(getElement(parseElement(buf).contents)[0].contents)[6].raw);
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 cipher = (0, crypto_1.createDecipheriv)(algorithm, encKey, iv);
40
- plaintext = (0, buffer_utils_js_1.concat)(cipher.update(ciphertext), cipher.final());
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 cipher = (0, crypto_1.createDecipheriv)(algorithm, cek, iv, { authTagLength: 16 });
57
- cipher.setAuthTag(tag);
56
+ const decipher = (0, crypto_1.createDecipheriv)(algorithm, cek, iv, { authTagLength: 16 });
57
+ decipher.setAuthTag(tag);
58
58
  if (aad.byteLength) {
59
- cipher.setAAD(aad, { plaintextLength: ciphertext.length });
59
+ decipher.setAAD(aad, { plaintextLength: ciphertext.length });
60
60
  }
61
- return (0, buffer_utils_js_1.concat)(cipher.update(ciphertext), cipher.final());
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 = (0, buffer_utils_js_1.concat)(cipher.update(plaintext), cipher.final());
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
- return encodeBase64(getElement(getElement(parseElement(buf).contents)[0].contents)[6].raw);
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 cipher = createDecipheriv(algorithm, encKey, iv);
38
- plaintext = concat(cipher.update(ciphertext), cipher.final());
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 cipher = createDecipheriv(algorithm, cek, iv, { authTagLength: 16 });
55
- cipher.setAuthTag(tag);
54
+ const decipher = createDecipheriv(algorithm, cek, iv, { authTagLength: 16 });
55
+ decipher.setAuthTag(tag);
56
56
  if (aad.byteLength) {
57
- cipher.setAAD(aad, { plaintextLength: ciphertext.length });
57
+ decipher.setAAD(aad, { plaintextLength: ciphertext.length });
58
58
  }
59
- return concat(cipher.update(ciphertext), cipher.final());
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 = concat(cipher.update(plaintext), cipher.final());
39
+ const ciphertext = cipher.update(plaintext);
40
+ cipher.final();
40
41
  const tag = cipher.getAuthTag();
41
42
  return { ciphertext, tag };
42
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jose",
3
- "version": "4.1.4",
3
+ "version": "4.1.5",
4
4
  "description": "'JSON Web Almost Everything' - JWA, JWS, JWE, JWT, JWK, JWKS with no dependencies using runtime's native crypto",
5
5
  "keywords": [
6
6
  "browser",