Skip to content

Commit e7ad82c

Browse files
committed
feat: electron v6.x support
1 parent 24acd20 commit e7ad82c

31 files changed

+331
-153
lines changed

.travis.yml

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
matrix:
22
allow_failures:
3-
- name: "Test Suite - Nightly build"
3+
- name: "Test Suite - Node.js Nightly build"
44
- name: "Linter"
55
include:
6-
- name: Linter
7-
language: node_js
8-
node_js: stable
9-
script: npm run lint
106
- name: "Test Suite + coverage - 12.0.0" #min
117
language: node_js
128
node_js: 12.0.0
@@ -22,10 +18,18 @@ matrix:
2218
os: windows
2319
script: npm test
2420
node_js: node
25-
- name: "Test Suite - Nightly build"
21+
- name: "Test Suite - Electron build"
22+
language: node_js
23+
node_js: stable
24+
script: xvfb-run npx electron@beta ./test/electron
25+
- name: "Test Suite - Node.js Nightly build"
2626
language: minimal
2727
env: NVM_NODEJS_ORG_MIRROR=https://nodejs.org/download/nightly/
2828
install:
2929
- nvm i node
3030
- npm i
3131
script: npm test
32+
- name: Linter
33+
language: node_js
34+
node_js: stable
35+
script: npm run lint

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,18 @@ key = jose.JWK.asKey(fs.readFileSync('path/to/key/file'))
311311
key.crv === 'P-256K'
312312
```
313313

314+
#### Electron Support
315+
316+
Electron v6.x runtime is supported to the extent of the crypto engine BoringSSL feature parity with
317+
standard Node.js OpenSSL. The following is disabled in Electron runtime because of its lack of
318+
[support](https://github.com/panva/jose/blob/master/test/electron/electron.test.js).
319+
320+
- JWE `A128KW`, `A192KW` and `A256KW` algs are not available, this also means that other JWAs
321+
depending on those are not working, those are `ECDH-ES+A128KW`, `ECDH-ES+A192KW`,
322+
`ECDH-ES+A256KW`, `PBES2-HS256+A128KW`, `PBES2-HS384+A192KW`, `PBES2-HS512+A256KW`)
323+
- OKP curves `Ed448`, `X25519` and `X448` are not supported
324+
- EC curve `secp256k1` is not supported
325+
314326
## FAQ
315327

316328
#### Semver?

lib/help/consts.js

+9
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,12 @@ module.exports.KEYLENGTHS = {
3131
A192GCM: 192,
3232
A256GCM: 256
3333
}
34+
35+
/* c8 ignore next 7 */
36+
if ('electron' in process.versions) {
37+
module.exports.OKP_CURVES.delete('Ed448')
38+
module.exports.OKP_CURVES.delete('X25519')
39+
module.exports.OKP_CURVES.delete('X448')
40+
module.exports.EC_CURVES.delete(secp256k1)
41+
module.exports.ECDH_ALGS.splice(1, module.exports.ECDH_ALGS.length - 1)
42+
}

lib/jwk/key/oct.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class OctKey extends Key {
9191

9292
switch (operation) {
9393
case 'deriveKey':
94-
if (use === 'sig') {
94+
if (use === 'sig' || 'electron' in process.versions) {
9595
return new Set()
9696
}
9797

@@ -116,6 +116,11 @@ class OctKey extends Key {
116116
return new Set()
117117
}
118118

119+
/* c8 ignore next 3 */
120+
if ('electron' in process.versions) {
121+
return new Set([`A${this.length}GCMKW`])
122+
}
123+
119124
return new Set([`A${this.length}KW`, `A${this.length}GCMKW`])
120125
case undefined:
121126
return new Set([

lib/jwk/key/rsa.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class RSAKey extends Key {
139139
}
140140

141141
static async generate (len = 2048, privat = true) {
142-
if (!Number.isSafeInteger(len) || len < 512 || len % 8 !== 0) {
142+
if (!Number.isSafeInteger(len) || len < 512 || len % 8 !== 0 || (('electron' in process.versions) && len % 128 !== 0)) {
143143
throw new TypeError('invalid bit length')
144144
}
145145

@@ -149,7 +149,7 @@ class RSAKey extends Key {
149149
}
150150

151151
static generateSync (len = 2048, privat = true) {
152-
if (!Number.isSafeInteger(len) || len < 512 || len % 8 !== 0) {
152+
if (!Number.isSafeInteger(len) || len < 512 || len % 8 !== 0 || (('electron' in process.versions) && len % 128 !== 0)) {
153153
throw new TypeError('invalid bit length')
154154
}
155155

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"decode",
88
"decrypt",
99
"eddsa",
10+
"electron",
1011
"encrypt",
1112
"flattened",
1213
"general",

test/cookbook/5_10.including_additional_authentication_data.test.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const test = require('ava')
22

3+
if ('electron' in process.versions) return
4+
35
const recipe = require('./recipes').get('5.10')
46
const { enc: verifiers } = require('./verifiers')
57

test/cookbook/5_11.protecting_specific_header_fields.test.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const test = require('ava')
22

3+
if ('electron' in process.versions) return
4+
35
const recipe = require('./recipes').get('5.11')
46
const { enc: verifiers } = require('./verifiers')
57

test/cookbook/5_12.protecting_content_only.test.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const test = require('ava')
22

3+
if ('electron' in process.versions) return
4+
35
const recipe = require('./recipes').get('5.12')
46
const { enc: verifiers } = require('./verifiers')
57

test/cookbook/5_13.encrypting_to_multiple_recipients.test.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const test = require('ava')
22

3+
if ('electron' in process.versions) return
4+
35
const recipe = require('./recipes').get('5.13')
46
const { enc: verifiers } = require('./verifiers')
57

test/cookbook/5_3.key_wrap_using_pbes2-aes-keywrap_with-aes-cbc-hmac-sha2.test.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const test = require('ava')
22

3+
if ('electron' in process.versions) return
4+
35
const recipe = require('./recipes').get('5.3')
46
const { enc: verifiers } = require('./verifiers')
57

test/cookbook/5_4.key_agreement_with_key_wrapping_using_ecdh-es_and_aes-keywrap_with_aes-gcm.test.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const test = require('ava')
22

3+
if ('electron' in process.versions) return
4+
35
const recipe = require('./recipes').get('5.4')
46
const { enc: verifiers } = require('./verifiers')
57

test/cookbook/5_8.key_wrap_using_aes-keywrap_with_aes-gcm.test.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const test = require('ava')
22

3+
if ('electron' in process.versions) return
4+
35
const recipe = require('./recipes').get('5.8')
46
const { enc: verifiers } = require('./verifiers')
57

test/cookbook/5_9.compressed_content.test.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const test = require('ava')
22

3+
if ('electron' in process.versions) return
4+
35
const recipe = require('./recipes').get('5.9')
46
const { enc: verifiers } = require('./verifiers')
57

test/electron/electron.test.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const test = require('ava')
2+
3+
if (!('electron' in process.versions)) return
4+
5+
const crypto = require('crypto')
6+
7+
const fixtures = require('../fixtures')
8+
9+
;['aes128', 'aes192', 'aes256'].forEach((cipher) => {
10+
test(`${cipher} is not supported`, t => {
11+
t.false(crypto.getCiphers().includes(cipher))
12+
})
13+
})
14+
15+
test('secp256k1 is not supported', t => {
16+
t.false(crypto.getCurves().includes('secp256k1'))
17+
})
18+
19+
;['Ed448', 'X25519', 'X448'].forEach((okp) => {
20+
test(`${okp} is not supported`, t => {
21+
t.throws(() => {
22+
crypto.createPrivateKey(fixtures.PEM[okp].private)
23+
}, { instanceOf: Error, code: 'ERR_OSSL_EVP_UNSUPPORTED_ALGORITHM' })
24+
})
25+
})

test/electron/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const exit = () => process.exit(process.exitCode)
2+
require('ava/lib/cli').run().then(exit, exit)

test/help/P-256K.key_utils.test.js

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
require('../../P-256K')
33

44
const test = require('ava')
5+
6+
if ('electron' in process.versions) return
7+
58
const { createPublicKey, createPrivateKey } = require('crypto')
69

710
const { keyObjectToJWK, jwkToPem } = require('../../lib/help/key_utils')

test/help/key_utils.test.js

+52-50
Original file line numberDiff line numberDiff line change
@@ -57,56 +57,58 @@ test('Ed25519 Private key', t => {
5757
t.deepEqual(actual, expected)
5858
})
5959

60-
test('Ed448 Public key', t => {
61-
const expected = clone(fixtures.Ed448)
62-
delete expected.d
63-
const pem = createPublicKey(jwkToPem(expected))
64-
const actual = keyObjectToJWK(pem)
65-
66-
t.deepEqual(actual, expected)
67-
})
68-
69-
test('Ed448 Private key', t => {
70-
const expected = fixtures.Ed448
71-
const pem = createPrivateKey(jwkToPem(expected))
72-
const actual = keyObjectToJWK(pem)
73-
74-
t.deepEqual(actual, expected)
75-
})
76-
77-
test('X25519 Public key', t => {
78-
const expected = clone(fixtures.X25519)
79-
delete expected.d
80-
const pem = createPublicKey(jwkToPem(expected))
81-
const actual = keyObjectToJWK(pem)
82-
83-
t.deepEqual(actual, expected)
84-
})
85-
86-
test('X25519 Private key', t => {
87-
const expected = fixtures.X25519
88-
const pem = createPrivateKey(jwkToPem(expected))
89-
const actual = keyObjectToJWK(pem)
90-
91-
t.deepEqual(actual, expected)
92-
})
93-
94-
test('X448 Public key', t => {
95-
const expected = clone(fixtures.X448)
96-
delete expected.d
97-
const pem = createPublicKey(jwkToPem(expected))
98-
const actual = keyObjectToJWK(pem)
99-
100-
t.deepEqual(actual, expected)
101-
})
102-
103-
test('X448 Private key', t => {
104-
const expected = fixtures.X448
105-
const pem = createPrivateKey(jwkToPem(expected))
106-
const actual = keyObjectToJWK(pem)
107-
108-
t.deepEqual(actual, expected)
109-
})
60+
if (!('electron' in process.versions)) {
61+
test('Ed448 Public key', t => {
62+
const expected = clone(fixtures.Ed448)
63+
delete expected.d
64+
const pem = createPublicKey(jwkToPem(expected))
65+
const actual = keyObjectToJWK(pem)
66+
67+
t.deepEqual(actual, expected)
68+
})
69+
70+
test('Ed448 Private key', t => {
71+
const expected = fixtures.Ed448
72+
const pem = createPrivateKey(jwkToPem(expected))
73+
const actual = keyObjectToJWK(pem)
74+
75+
t.deepEqual(actual, expected)
76+
})
77+
78+
test('X25519 Public key', t => {
79+
const expected = clone(fixtures.X25519)
80+
delete expected.d
81+
const pem = createPublicKey(jwkToPem(expected))
82+
const actual = keyObjectToJWK(pem)
83+
84+
t.deepEqual(actual, expected)
85+
})
86+
87+
test('X25519 Private key', t => {
88+
const expected = fixtures.X25519
89+
const pem = createPrivateKey(jwkToPem(expected))
90+
const actual = keyObjectToJWK(pem)
91+
92+
t.deepEqual(actual, expected)
93+
})
94+
95+
test('X448 Public key', t => {
96+
const expected = clone(fixtures.X448)
97+
delete expected.d
98+
const pem = createPublicKey(jwkToPem(expected))
99+
const actual = keyObjectToJWK(pem)
100+
101+
t.deepEqual(actual, expected)
102+
})
103+
104+
test('X448 Private key', t => {
105+
const expected = fixtures.X448
106+
const pem = createPrivateKey(jwkToPem(expected))
107+
const actual = keyObjectToJWK(pem)
108+
109+
t.deepEqual(actual, expected)
110+
})
111+
}
110112

111113
test('EC P-256 Public key', t => {
112114
const expected = clone(fixtures['P-256'])

0 commit comments

Comments
 (0)