@@ -39,30 +39,44 @@ export async function fetchWrappedKey(
39
39
) ;
40
40
}
41
41
42
- export type KasPublicKeyAlgorithm = 'ec:secp256r1' | 'rsa:2048' ;
42
+ export type KasPublicKeyAlgorithm =
43
+ | 'ec:secp256r1'
44
+ | 'ec:secp384r1'
45
+ | 'ec:secp521r1'
46
+ | 'rsa:2048'
47
+ | 'rsa:4096' ;
43
48
44
49
export const isPublicKeyAlgorithm = ( a : string ) : a is KasPublicKeyAlgorithm => {
45
50
return a === 'ec:secp256r1' || a === 'rsa:2048' ;
46
51
} ;
47
52
48
- export const keyAlgorithmToPublicKeyAlgorithm = ( a : KeyAlgorithm ) : KasPublicKeyAlgorithm => {
53
+ export const keyAlgorithmToPublicKeyAlgorithm = ( k : CryptoKey ) : KasPublicKeyAlgorithm => {
54
+ const a = k . algorithm ;
49
55
if ( a . name === 'ECDSA' || a . name === 'ECDH' ) {
50
56
const eca = a as EcKeyAlgorithm ;
51
- if ( eca . namedCurve === 'P-256' ) {
52
- return 'ec:secp256r1' ;
57
+ switch ( eca . namedCurve ) {
58
+ case 'P-256' :
59
+ return 'ec:secp256r1' ;
60
+ case 'P-384' :
61
+ return 'ec:secp384r1' ;
62
+ case 'P-521' :
63
+ return 'ec:secp521r1' ;
64
+ default :
65
+ throw new Error ( `unsupported EC curve: ${ eca . namedCurve } ` ) ;
53
66
}
54
- throw new Error ( `unsupported EC curve: ${ eca . namedCurve } ` ) ;
55
67
}
56
- if ( a . name === 'RSA-OAEP' ) {
68
+ if ( a . name === 'RSA-OAEP' || a . name === 'RSASSA-PKCS1-v1_5' ) {
57
69
const rsaa = a as RsaHashedKeyAlgorithm ;
58
- if ( rsaa . modulusLength === 2048 ) {
59
- // if (rsaa.hash.name !== 'RSASSA-PKCS1-v1_5') {
60
- // throw new Error(`unsupported RSA hash: ${rsaa.hash.name}`);
61
- // }
62
- if ( rsaa . publicExponent . toString ( ) !== '1,0,1' ) {
63
- throw new Error ( `unsupported RSA public exponent: ${ rsaa . publicExponent } ` ) ;
64
- }
65
- return 'rsa:2048' ;
70
+ if ( rsaa . publicExponent . toString ( ) !== '1,0,1' ) {
71
+ throw new Error ( `unsupported RSA public exponent: ${ rsaa . publicExponent } ` ) ;
72
+ }
73
+ switch ( rsaa . modulusLength ) {
74
+ case 2048 :
75
+ return 'rsa:2048' ;
76
+ case 4096 :
77
+ return 'rsa:4096' ;
78
+ default :
79
+ throw new Error ( `unsupported RSA modulus length: ${ rsaa . modulusLength } ` ) ;
66
80
}
67
81
}
68
82
throw new Error ( `unsupported key algorithm: ${ a . name } ` ) ;
@@ -74,6 +88,14 @@ export const publicKeyAlgorithmToJwa = (a: KasPublicKeyAlgorithm): string => {
74
88
return 'ES256' ;
75
89
case 'rsa:2048' :
76
90
return 'RS256' ;
91
+ case 'rsa:4096' :
92
+ return 'RS512' ;
93
+ case 'ec:secp384r1' :
94
+ return 'ES384' ;
95
+ case 'ec:secp521r1' :
96
+ return 'ES512' ;
97
+ default :
98
+ throw new Error ( `unsupported public key algorithm: ${ a } ` ) ;
77
99
}
78
100
} ;
79
101
0 commit comments