Skip to content

Commit c805487

Browse files
committed
fix: add RSA SHA1 support
1 parent f604d32 commit c805487

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ As all the cryptography is handled by either "webcrypto" or a "pure-js" implemen
3434
- RSA-PKCS1-SHA256
3535
- RSA-PKCS1-SHA384
3636
- RSA-PKCS1-SHA512
37+
- RSA-PKCS1-SHA1
3738

3839
### Cipher Suites (TLS 1.3)
3940
- AES-128-GCM-SHA256

src/crypto/webcrypto.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,22 @@ export const webcryptoCrypto: Crypto<WebCrypto.CryptoKey> = {
111111
case 'RSA-PKCS1-SHA512':
112112
case 'RSA-PKCS1-SHA256':
113113
case 'RSA-PKCS1-SHA384':
114+
case 'RSA-PKCS1-SHA1':
114115
keyType = 'spki'
115116
keyUsages = ['verify']
116117
subtleArgs = {
117118
name: 'RSASSA-PKCS1-v1_5',
118119
hash: alg === 'RSA-PKCS1-SHA256'
119120
? 'SHA-256'
120-
: (alg === 'RSA-PKCS1-SHA384' ? 'SHA-384' : 'SHA-512')
121+
: (
122+
alg === 'RSA-PKCS1-SHA384'
123+
? 'SHA-384'
124+
: (
125+
alg === 'RSA-PKCS1-SHA1'
126+
? 'SHA-1'
127+
: 'SHA-512'
128+
)
129+
)
121130
}
122131
break
123132
case 'RSA-PCKS1_5':
@@ -296,11 +305,16 @@ export const webcryptoCrypto: Crypto<WebCrypto.CryptoKey> = {
296305
case 'RSA-PKCS1-SHA512':
297306
case 'RSA-PKCS1-SHA256':
298307
case 'RSA-PKCS1-SHA384':
308+
case 'RSA-PKCS1-SHA1':
299309
verifyArgs = {
300310
name: 'RSASSA-PKCS1-v1_5',
301-
hash: alg === 'RSA-PKCS1-SHA256'
302-
? 'SHA-256'
303-
: (alg === 'RSA-PKCS1-SHA384' ? 'SHA-384' : 'SHA-512')
311+
hash: alg === 'RSA-PKCS1-SHA384'
312+
? 'SHA-384'
313+
: (
314+
alg === 'RSA-PKCS1-SHA1'
315+
? 'SHA-1'
316+
: 'SHA-512'
317+
)
304318
}
305319
break
306320
case 'ECDSA-SECP256R1-SHA256':

src/types/crypto.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export type SignatureAlgorithm = 'RSA-PSS-SHA256'
1717
| 'RSA-PKCS1-SHA512'
1818
| 'RSA-PKCS1-SHA384'
1919
| 'RSA-PKCS1-SHA256'
20+
| 'RSA-PKCS1-SHA1'
2021

2122
export type HashAlgorithm = 'SHA-256' | 'SHA-384' | 'SHA-1'
2223

src/utils/x509.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function getSigAlgorithm(
8989
)
9090
}
9191

92-
let hashName: 'SHA256' | 'SHA384' | 'SHA512'
92+
let hashName: 'SHA256' | 'SHA384' | 'SHA512' | 'SHA1'
9393
switch (hash.name) {
9494
case 'SHA-256':
9595
hashName = 'SHA256'
@@ -100,15 +100,19 @@ function getSigAlgorithm(
100100
case 'SHA-512':
101101
hashName = 'SHA512'
102102
break
103+
case 'SHA-1':
104+
hashName = 'SHA1'
105+
break
103106
default:
104107
throw new Error(`Unsupported hash algorithm: ${hash.name}`)
105108
}
106109

107110
switch (name) {
108111
case 'RSASSA-PKCS1-v1_5':
112+
case 'RSA-PKCS1-SHA1':
109113
return `RSA-PKCS1-${hashName}`
110114
case 'ECDSA':
111-
if(hashName === 'SHA512') {
115+
if(hashName === 'SHA512' || hashName === 'SHA1') {
112116
throw new Error(`Unsupported hash algorithm for ECDSA: ${hashName}`)
113117
}
114118

0 commit comments

Comments
 (0)