MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / _verify

Method _verify

modules/crypt/ssl/ssl_cert.js:210–268  ·  view source on GitHub ↗
(spki, x509)

Source from the content-addressed store, hash-verified

208 }
209
210 _verify(spki, x509) {
211 let pk, hash;
212 let sig = x509.sig;
213
214 switch (x509.algo.toString()) {
215 case "1,2,840,113549,1,1,4": // PKCS-1 MD5 with RSA encryption
216 hash = "MD5";
217 pk = PKCS1_5;
218 break;
219 case "1,2,840,113549,1,1,5": // PKCS-1 SHA1 with RSA encryption
220 hash = "SHA1";
221 pk = PKCS1_5;
222 break;
223 case "1,2,840,113549,1,1,11": // PKCS-1 SHA256 with RSA encryption
224 hash = "SHA256";
225 pk = PKCS1_5;
226 break;
227 case "1,2,840,113549,1,1,12": // PKCS-1 SHA384 with RSA encryption
228 hash = "SHA384";
229 pk = PKCS1_5;
230 break;
231 case "1,2,840,113549,1,1,13": // PKCS-1 SHA512 with RSA encryption
232 hash = "SHA512";
233 pk = PKCS1_5;
234 break;
235 case "1,2,840,113549,1,1,14": // PKCS-1 SHA224 with RSA encryption
236 hash = "SHA224";
237 pk = PKCS1_5;
238 break;
239 case "1,2,840,10040,4,3":
240 case "1,3,14,3,2,27": {
241 hash = "SHA1";
242 pk = DSA;
243 // need to decode the sig value into <r, s>
244 const ber = new BER(x509.sig);
245 if (ber.getTag() !== 0x30)
246 throw new Error;
247 ber.getLength();
248 sig = (ArrayBuffer.fromBigInt(ber.getInteger())).concat(ArrayBuffer.fromBigInt(ber.getInteger()));
249 } break;
250 case "1,2,840,10045,4,3,1":
251 case "1,2,840,10045,4,3,2":
252 case "1,2,840,10045,4,3,3":
253 case "1,2,840,10045,4,3,4": { // ECDSA with SHA224, SHA256, SHA384, SHA512
254 hash = ["SHA224", "SHA256", "SHA384", "SHA512"][x509.algo[6] - 1];
255 pk = ECDSA;
256 // need to decode the sig value into <r, s>
257 const ber = new BER(sig);
258 if (ber.getTag() !== 0x30)
259 throw new Error;
260 ber.getLength();
261 sig = (ArrayBuffer.fromBigInt(ber.getInteger())).concat(ArrayBuffer.fromBigInt(ber.getInteger()));
262 return (new pk(spki.pub, spki.curve, false, [] /* any oid */)).verify((new Crypt.Digest(hash)).process(x509.tbs), sig);
263 } break;
264 default:
265 throw new Error("Cert: unsupported algorithm: " + x509.algo.toString());
266 }
267 return (new pk(spki, false, [] /* any oid */)).verify((new Crypt.Digest(hash)).process(x509.tbs), sig);

Callers 1

verifyMethod · 0.95

Calls 8

getTagMethod · 0.95
getLengthMethod · 0.95
getIntegerMethod · 0.95
fromBigIntMethod · 0.80
concatMethod · 0.65
toStringMethod · 0.45
verifyMethod · 0.45
processMethod · 0.45

Tested by

no test coverage detected