Commit b71f46c
committed
fix(subtle): tighten WebCrypto JWK import validation across all importers
Address review feedback on PQC JWK import/export PR (#996):
- Centralize JWK structural validation in `validateJwkStructure`:
- `ext`: existing
- `use`: new — must match algorithm's expected use ('sig' or 'enc')
when usages are non-empty (mirrors Node's `validateJwk`)
- `key_ops`: new duplicate detection per Node's `validateKeyOps`
- Reorder validation in all 8 importers (kmac, rsa, hmac, aes, ec, ed,
mldsa, mlkem) so JWK structure (kty/use/key_ops/ext/alg) is checked
before key-usage validation — matches Node and the WebCrypto spec.
- Wrap every `handle.initJwk()` call site in try/catch so C++ errors
surface as `DataError` DOMExceptions, not generic `Error`s.
- Add type guard in `pqcIsPublicImport` so a non-object passed at
`format === 'jwk'` is not silently treated as a public key.
- Fix `lazyDOMException` to format the object-form domName correctly
(was producing `[object Object]` in the message).1 parent 33c19e6 commit b71f46c
5 files changed
Lines changed: 260 additions & 170 deletions
File tree
- packages/react-native-quick-crypto
- cpp/keys
- src
- utils
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
365 | 365 | | |
366 | 366 | | |
367 | 367 | | |
368 | | - | |
| 368 | + | |
369 | 369 | | |
370 | 370 | | |
371 | 371 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
93 | 94 | | |
94 | 95 | | |
95 | 96 | | |
96 | | - | |
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
101 | 103 | | |
102 | 104 | | |
103 | 105 | | |
104 | | - | |
105 | 106 | | |
106 | 107 | | |
107 | 108 | | |
108 | 109 | | |
109 | 110 | | |
110 | 111 | | |
| 112 | + | |
| 113 | + | |
111 | 114 | | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | 115 | | |
122 | 116 | | |
123 | | - | |
124 | 117 | | |
125 | | - | |
126 | 118 | | |
127 | 119 | | |
128 | 120 | | |
| |||
132 | 124 | | |
133 | 125 | | |
134 | 126 | | |
135 | | - | |
136 | 127 | | |
137 | 128 | | |
138 | | - | |
139 | | - | |
| 129 | + | |
140 | 130 | | |
141 | 131 | | |
142 | 132 | | |
143 | 133 | | |
144 | 134 | | |
145 | 135 | | |
146 | 136 | | |
147 | | - | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
148 | 153 | | |
149 | 154 | | |
150 | | - | |
151 | | - | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
152 | 164 | | |
153 | | - | |
| 165 | + | |
154 | 166 | | |
155 | 167 | | |
156 | | - | |
157 | 168 | | |
158 | 169 | | |
159 | 170 | | |
160 | 171 | | |
161 | 172 | | |
162 | 173 | | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
| 174 | + | |
167 | 175 | | |
168 | 176 | | |
169 | 177 | | |
170 | 178 | | |
171 | 179 | | |
172 | | - | |
173 | 180 | | |
174 | 181 | | |
175 | 182 | | |
176 | 183 | | |
177 | 184 | | |
178 | 185 | | |
179 | 186 | | |
180 | | - | |
181 | 187 | | |
182 | 188 | | |
183 | 189 | | |
184 | | - | |
185 | 190 | | |
186 | 191 | | |
187 | 192 | | |
| |||
0 commit comments