Skip to content

Commit

Permalink
feat: enable RSA-OAEP-256 when node runtime supports it
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Aug 20, 2019
1 parent a019fc9 commit cfada87
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 33 deletions.
20 changes: 10 additions & 10 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2879,8 +2879,8 @@ _**default value**_:

```js
[
// asymmetric RSAES based
'RSA-OAEP', 'RSA1_5',
// asymmetric RSAES based (note: RSA-OAEP-256 is only supported in node runtime >= 12.9.0)
'RSA-OAEP', 'RSA-OAEP-256', 'RSA1_5',
// asymmetric ECDH-ES based
'ECDH-ES', 'ECDH-ES+A128KW', 'ECDH-ES+A192KW', 'ECDH-ES+A256KW',
// symmetric AES key wrapping
Expand Down Expand Up @@ -3006,8 +3006,8 @@ _**default value**_:

```js
[
// asymmetric RSAES based
'RSA-OAEP', 'RSA1_5',
// asymmetric RSAES based (note: RSA-OAEP-256 is only supported in node runtime >= 12.9.0)
'RSA-OAEP', 'RSA-OAEP-256', 'RSA1_5',
// asymmetric ECDH-ES based
'ECDH-ES', 'ECDH-ES+A128KW', 'ECDH-ES+A192KW', 'ECDH-ES+A256KW',
// symmetric AES key wrapping
Expand Down Expand Up @@ -3104,8 +3104,8 @@ _**default value**_:

```js
[
// asymmetric RSAES based
'RSA-OAEP', 'RSA1_5',
// asymmetric RSAES based (note: RSA-OAEP-256 is only supported in node runtime >= 12.9.0)
'RSA-OAEP', 'RSA-OAEP-256', 'RSA1_5',
// asymmetric ECDH-ES based
'ECDH-ES', 'ECDH-ES+A128KW', 'ECDH-ES+A192KW', 'ECDH-ES+A256KW',
// symmetric AES key wrapping
Expand Down Expand Up @@ -3234,8 +3234,8 @@ _**default value**_:

```js
[
// asymmetric RSAES based
'RSA-OAEP', 'RSA1_5',
// asymmetric RSAES based (note: RSA-OAEP-256 is only supported in node runtime >= 12.9.0)
'RSA-OAEP', 'RSA-OAEP-256', 'RSA1_5',
// asymmetric ECDH-ES based
'ECDH-ES', 'ECDH-ES+A128KW', 'ECDH-ES+A192KW', 'ECDH-ES+A256KW',
// symmetric AES key wrapping
Expand Down Expand Up @@ -3396,8 +3396,8 @@ _**default value**_:

```js
[
// asymmetric RSAES based
'RSA-OAEP', 'RSA1_5',
// asymmetric RSAES based (note: RSA-OAEP-256 is only supported in node runtime >= 12.9.0)
'RSA-OAEP', 'RSA-OAEP-256', 'RSA1_5',
// asymmetric ECDH-ES based
'ECDH-ES', 'ECDH-ES+A128KW', 'ECDH-ES+A192KW', 'ECDH-ES+A256KW',
// symmetric AES key wrapping
Expand Down
8 changes: 6 additions & 2 deletions lib/consts/jwa.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
const [major, minor] = process.version.substr(1).split('.').map((x) => parseInt(x, 10));

const OAEP256 = major > 12 || (major === 12 && minor >= 9);

const signingAlgValues = [
'HS256', 'HS384', 'HS512',
'RS256', 'RS384', 'RS512',
Expand All @@ -8,14 +12,14 @@ const signingAlgValues = [

const encryptionAlgValues = [
// asymmetric kw
'RSA-OAEP', 'RSA1_5',
'RSA-OAEP', OAEP256 ? 'RSA-OAEP-256' : false, 'RSA1_5',
'ECDH-ES', 'ECDH-ES+A128KW', 'ECDH-ES+A192KW', 'ECDH-ES+A256KW',
// symmetric kw
'A128GCMKW', 'A192GCMKW', 'A256GCMKW', 'A128KW', 'A192KW', 'A256KW',
'PBES2-HS256+A128KW', 'PBES2-HS384+A192KW', 'PBES2-HS512+A256KW',
// no kw
'dir',
];
].filter(Boolean);

const encryptionEncValues = [
'A128CBC-HS256', 'A128GCM', 'A192CBC-HS384', 'A192GCM', 'A256CBC-HS512', 'A256GCM',
Expand Down
20 changes: 10 additions & 10 deletions lib/helpers/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -2131,8 +2131,8 @@ const DEFAULTS = {
* example: Supported values list
* ```js
* [
* // asymmetric RSAES based
* 'RSA-OAEP', 'RSA1_5',
* // asymmetric RSAES based (note: RSA-OAEP-256 is only supported in node runtime >= 12.9.0)
* 'RSA-OAEP', 'RSA-OAEP-256', 'RSA1_5',
* // asymmetric ECDH-ES based
* 'ECDH-ES', 'ECDH-ES+A128KW', 'ECDH-ES+A192KW', 'ECDH-ES+A256KW',
* // symmetric AES key wrapping
Expand All @@ -2158,8 +2158,8 @@ const DEFAULTS = {
* example: Supported values list
* ```js
* [
* // asymmetric RSAES based
* 'RSA-OAEP', 'RSA1_5',
* // asymmetric RSAES based (note: RSA-OAEP-256 is only supported in node runtime >= 12.9.0)
* 'RSA-OAEP', 'RSA-OAEP-256', 'RSA1_5',
* // asymmetric ECDH-ES based
* 'ECDH-ES', 'ECDH-ES+A128KW', 'ECDH-ES+A192KW', 'ECDH-ES+A256KW',
* // symmetric AES key wrapping
Expand All @@ -2184,8 +2184,8 @@ const DEFAULTS = {
* example: Supported values list
* ```js
* [
* // asymmetric RSAES based
* 'RSA-OAEP', 'RSA1_5',
* // asymmetric RSAES based (note: RSA-OAEP-256 is only supported in node runtime >= 12.9.0)
* 'RSA-OAEP', 'RSA-OAEP-256', 'RSA1_5',
* // asymmetric ECDH-ES based
* 'ECDH-ES', 'ECDH-ES+A128KW', 'ECDH-ES+A192KW', 'ECDH-ES+A256KW',
* // symmetric AES key wrapping
Expand All @@ -2211,8 +2211,8 @@ const DEFAULTS = {
* example: Supported values list
* ```js
* [
* // asymmetric RSAES based
* 'RSA-OAEP', 'RSA1_5',
* // asymmetric RSAES based (note: RSA-OAEP-256 is only supported in node runtime >= 12.9.0)
* 'RSA-OAEP', 'RSA-OAEP-256', 'RSA1_5',
* // asymmetric ECDH-ES based
* 'ECDH-ES', 'ECDH-ES+A128KW', 'ECDH-ES+A192KW', 'ECDH-ES+A256KW',
* // symmetric AES key wrapping
Expand All @@ -2238,8 +2238,8 @@ const DEFAULTS = {
* example: Supported values list
* ```js
* [
* // asymmetric RSAES based
* 'RSA-OAEP', 'RSA1_5',
* // asymmetric RSAES based (note: RSA-OAEP-256 is only supported in node runtime >= 12.9.0)
* 'RSA-OAEP', 'RSA-OAEP-256', 'RSA1_5',
* // asymmetric ECDH-ES based
* 'ECDH-ES', 'ECDH-ES+A128KW', 'ECDH-ES+A192KW', 'ECDH-ES+A256KW',
* // symmetric AES key wrapping
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},
"dependencies": {
"@koa/cors": "^3.0.0",
"@panva/jose": "^1.5.0",
"@panva/jose": "^1.7.0",
"debug": "^4.1.1",
"ejs": "^2.6.2",
"got": "^9.6.0",
Expand Down
24 changes: 14 additions & 10 deletions test/configuration/client_metadata.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const Provider = require('../../lib');
const { whitelistedJWA } = require('../default.config');
const mtlsKeys = require('../jwks/jwks.json');

const [major, minor] = process.version.substr(1).split('.').map((x) => parseInt(x, 10));

const OAEP256 = major > 12 || (major === 12 && minor >= 9);

const sigKey = global.keystore.get().toJWK();
const privateKey = global.keystore.get().toJWK(true);
const { DYNAMIC_SCOPE_LABEL, errors: { InvalidClientMetadata } } = Provider;
Expand Down Expand Up @@ -607,10 +611,10 @@ describe('Client metadata validation', () => {
}));
allows(this.title, 'dir', undefined, configuration);
[
'RSA-OAEP', 'RSA1_5', 'ECDH-ES', 'ECDH-ES+A128KW', 'ECDH-ES+A192KW',
'RSA-OAEP', OAEP256 ? 'RSA-OAEP-256' : false, 'RSA1_5', 'ECDH-ES', 'ECDH-ES+A128KW', 'ECDH-ES+A192KW',
'ECDH-ES+A256KW', 'A128GCMKW', 'A192GCMKW', 'A256GCMKW', 'A128KW', 'A192KW', 'A256KW',
'PBES2-HS256+A128KW', 'PBES2-HS384+A192KW', 'PBES2-HS512+A256KW',
].forEach((value) => {
].filter(Boolean).forEach((value) => {
allows(this.title, value, {
jwks: { keys: [sigKey] },
}, configuration);
Expand Down Expand Up @@ -669,10 +673,10 @@ describe('Client metadata validation', () => {
}));
allows(this.title, 'dir', undefined, configuration);
[
'RSA-OAEP', 'RSA1_5', 'ECDH-ES', 'ECDH-ES+A128KW', 'ECDH-ES+A192KW',
'RSA-OAEP', OAEP256 ? 'RSA-OAEP-256' : false, 'RSA1_5', 'ECDH-ES', 'ECDH-ES+A128KW', 'ECDH-ES+A192KW',
'ECDH-ES+A256KW', 'A128GCMKW', 'A192GCMKW', 'A256GCMKW', 'A128KW', 'A192KW', 'A256KW',
'PBES2-HS256+A128KW', 'PBES2-HS384+A192KW', 'PBES2-HS512+A256KW',
].forEach((value) => {
].filter(Boolean).forEach((value) => {
allows(this.title, value, {
jwks: { keys: [sigKey] },
}, configuration);
Expand Down Expand Up @@ -732,10 +736,10 @@ describe('Client metadata validation', () => {
}));
allows(this.title, 'dir', undefined, configuration);
[
'RSA-OAEP', 'RSA1_5', 'ECDH-ES', 'ECDH-ES+A128KW', 'ECDH-ES+A192KW',
'RSA-OAEP', OAEP256 ? 'RSA-OAEP-256' : false, 'RSA1_5', 'ECDH-ES', 'ECDH-ES+A128KW', 'ECDH-ES+A192KW',
'ECDH-ES+A256KW', 'A128GCMKW', 'A192GCMKW', 'A256GCMKW', 'A128KW', 'A192KW', 'A256KW',
'PBES2-HS256+A128KW', 'PBES2-HS384+A192KW', 'PBES2-HS512+A256KW',
].forEach((value) => {
].filter(Boolean).forEach((value) => {
allows(this.title, value, {
jwks: { keys: [sigKey] },
}, configuration);
Expand Down Expand Up @@ -795,10 +799,10 @@ describe('Client metadata validation', () => {
}));
allows(this.title, 'dir', undefined, configuration);
[
'RSA-OAEP', 'RSA1_5', 'ECDH-ES', 'ECDH-ES+A128KW', 'ECDH-ES+A192KW',
'RSA-OAEP', OAEP256 ? 'RSA-OAEP-256' : false, 'RSA1_5', 'ECDH-ES', 'ECDH-ES+A128KW', 'ECDH-ES+A192KW',
'ECDH-ES+A256KW', 'A128GCMKW', 'A192GCMKW', 'A256GCMKW', 'A128KW', 'A192KW', 'A256KW',
'PBES2-HS256+A128KW', 'PBES2-HS384+A192KW', 'PBES2-HS512+A256KW',
].forEach((value) => {
].filter(Boolean).forEach((value) => {
allows(this.title, value, {
jwks: { keys: [sigKey] },
}, configuration);
Expand Down Expand Up @@ -864,10 +868,10 @@ describe('Client metadata validation', () => {
}));
allows(this.title, 'dir', undefined, configuration);
[
'RSA-OAEP', 'RSA1_5', 'ECDH-ES', 'ECDH-ES+A128KW', 'ECDH-ES+A192KW',
'RSA-OAEP', OAEP256 ? 'RSA-OAEP-256' : false, 'RSA1_5', 'ECDH-ES', 'ECDH-ES+A128KW', 'ECDH-ES+A192KW',
'ECDH-ES+A256KW', 'A128GCMKW', 'A192GCMKW', 'A256GCMKW', 'A128KW', 'A192KW', 'A256KW',
'PBES2-HS256+A128KW', 'PBES2-HS384+A192KW', 'PBES2-HS512+A256KW',
].forEach((value) => {
].filter(Boolean).forEach((value) => {
allows(this.title, value, undefined, configuration);
if (value === 'ECDH-ES') {
rejects(this.title, value, 'A192CBC-HS384 is not possible with ECDH-ES', {
Expand Down

0 comments on commit cfada87

Please sign in to comment.