Add getRandomCandidate() and defaults for keyFormat

This commit is contained in:
Christoph Diehl 2018-01-30 17:49:59 +01:00
parent 7af5e072fd
commit 96e9210407
No known key found for this signature in database
GPG key ID: 799CE5B68FEF404A

View file

@ -194,6 +194,7 @@ make.crypto = {
return this.alg() return this.alg()
}, },
presets: { presets: {
raw: null,
jwk: [ jwk: [
{ {
kty: 'RSA', kty: 'RSA',
@ -255,6 +256,7 @@ make.crypto = {
return this.alg() return this.alg()
}, },
presets: { presets: {
raw: null,
jwk: [ jwk: [
{ {
kty: 'RSA', kty: 'RSA',
@ -327,6 +329,7 @@ make.crypto = {
return this.alg() return this.alg()
}, },
presets: { presets: {
raw: null,
jkw: [ jkw: [
{ {
kty: 'RSA', kty: 'RSA',
@ -387,6 +390,7 @@ make.crypto = {
return this.alg() return this.alg()
}, },
presets: { presets: {
raw: null,
jwk: [ jwk: [
{ {
kty: 'EC', kty: 'EC',
@ -506,6 +510,7 @@ make.crypto = {
return this.encrypt() return this.encrypt()
}, },
presets: { presets: {
raw: new Uint8Array([122, 94, 39, 230, 46, 23, 151, 80, 131, 230, 3, 101, 80, 234, 143, 9, 251, 152, 229, 228, 89, 222, 31, 135, 214, 104, 55, 68, 67, 59, 5, 51]),
jwk: [ jwk: [
{ {
kty: 'oct', kty: 'oct',
@ -514,7 +519,8 @@ make.crypto = {
ext: true ext: true
} }
], ],
raw: new Uint8Array([122, 94, 39, 230, 46, 23, 151, 80, 131, 230, 3, 101, 80, 234, 143, 9, 251, 152, 229, 228, 89, 222, 31, 135, 214, 104, 55, 68, 67, 59, 5, 51]) spki: null,
pkcs8: null
} }
}, },
'AES-CBC': { 'AES-CBC': {
@ -566,6 +572,7 @@ make.crypto = {
} }
}, },
presets: { presets: {
raw: new Uint8Array([122, 94, 39, 230, 46, 23, 151, 80, 131, 230, 3, 101, 80, 234, 143, 9, 251, 152, 229, 228, 89, 222, 31, 135, 214, 104, 55, 68, 67, 59, 5, 51]),
jwk: [ jwk: [
{ {
kty: 'oct', kty: 'oct',
@ -574,7 +581,8 @@ make.crypto = {
ext: true ext: true
} }
], ],
raw: new Uint8Array([122, 94, 39, 230, 46, 23, 151, 80, 131, 230, 3, 101, 80, 234, 143, 9, 251, 152, 229, 228, 89, 222, 31, 135, 214, 104, 55, 68, 67, 59, 5, 51]) spki: null,
pkcs8: null
} }
}, },
'AES-GCM': { 'AES-GCM': {
@ -629,6 +637,7 @@ make.crypto = {
} }
}, },
presets: { presets: {
raw: new Uint8Array([122, 94, 39, 230, 46, 23, 151, 80, 131, 230, 3, 101, 80, 234, 143, 9, 251, 152, 229, 228, 89, 222, 31, 135, 214, 104, 55, 68, 67, 59, 5, 51]),
jwk: [ jwk: [
{ {
kty: 'oct', kty: 'oct',
@ -637,7 +646,8 @@ make.crypto = {
ext: true ext: true
} }
], ],
raw: new Uint8Array([122, 94, 39, 230, 46, 23, 151, 80, 131, 230, 3, 101, 80, 234, 143, 9, 251, 152, 229, 228, 89, 222, 31, 135, 214, 104, 55, 68, 67, 59, 5, 51]) spki: null,
pkcs8: null
} }
}, },
'AES-KW': { 'AES-KW': {
@ -675,6 +685,7 @@ make.crypto = {
} }
}, },
presets: { presets: {
raw: new Uint8Array([122, 94, 39, 230, 46, 23, 151, 80, 131, 230, 3, 101, 80, 234, 143, 9, 251, 152, 229, 228, 89, 222, 31, 135, 214, 104, 55, 68, 67, 59, 5, 51]),
jwk: [ jwk: [
{ {
kty: 'oct', kty: 'oct',
@ -683,7 +694,8 @@ make.crypto = {
ext: true ext: true
} }
], ],
raw: new Uint8Array([122, 94, 39, 230, 46, 23, 151, 80, 131, 230, 3, 101, 80, 234, 143, 9, 251, 152, 229, 228, 89, 222, 31, 135, 214, 104, 55, 68, 67, 59, 5, 51]) spki: null,
pkcs8: null
} }
}, },
'HMAC': { 'HMAC': {
@ -719,13 +731,15 @@ make.crypto = {
return this.alg() return this.alg()
}, },
presets: { presets: {
raw: new Uint8Array([122, 94, 39, 230, 46, 23, 151, 80, 131, 230, 3, 101, 80, 234, 143, 9, 251, 152, 229, 228, 89, 222, 31, 135, 214, 104, 55, 68, 67, 59, 5, 51]),
jwk: { jwk: {
kty: 'oct', kty: 'oct',
k: 'KfKY5nueRX7eBrOddn9IerHLv1r-T7qpggaCF3MfSR4', k: 'KfKY5nueRX7eBrOddn9IerHLv1r-T7qpggaCF3MfSR4',
alg: 'HS256', alg: 'HS256',
ext: true ext: true
}, },
raw: new Uint8Array([122, 94, 39, 230, 46, 23, 151, 80, 131, 230, 3, 101, 80, 234, 143, 9, 251, 152, 229, 228, 89, 222, 31, 135, 214, 104, 55, 68, 67, 59, 5, 51]) spki: null,
pkcs8: null
} }
}, },
'HKDF': { 'HKDF': {
@ -773,6 +787,9 @@ make.crypto = {
return { return {
} }
}, },
generateKey: () => {
return this.alg()
},
deriveBits: function () { deriveBits: function () {
return Object.assign( return Object.assign(
this.alg(), this.alg(),
@ -789,7 +806,10 @@ make.crypto = {
return this.deriveBits() return this.deriveBits()
}, },
presets: { presets: {
raw: crypto.getRandomValues(new Uint8Array(16)) raw: crypto.getRandomValues(new Uint8Array(16)),
jwk: null,
spki: null,
pkcs8: null
} }
}, },
'DH': { 'DH': {
@ -825,10 +845,19 @@ make.crypto = {
this.generateKey(), this.generateKey(),
key key
) )
},
presets: {
raw: null,
jwk: null,
spki: null,
pkcs8: null
} }
} }
}, },
randomAlgorithm: () => { randomAlgorithm: () => {
return make.crypto.algorithms[random.item(Object.keys(make.crypto.algorithms))] return make.crypto.algorithms[random.item(Object.keys(make.crypto.algorithms))]
},
getRandomCandidate: (alg) => {
return make.crypto.randomAlgorithm(make.crypto.algorithmNames[random.item(alg.keyUsages)])
} }
} }