-
Notifications
You must be signed in to change notification settings - Fork 576
/
certificate.js
91 lines (78 loc) · 2.57 KB
/
certificate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
// Copyright 2017 crypto-browserify. All rights reserved. MIT license.
// from https://github.com/crypto-browserify/parse-asn1/blob/fbd70dca8670d17955893e083ca69118908570be/certificate.js
import * as asn from "../asn1.js/mod.js";
const Time = asn.define("Time", function () {
this.choice({
utcTime: this.utctime(),
generalTime: this.gentime(),
});
});
const AttributeTypeValue = asn.define("AttributeTypeValue", function () {
this.seq().obj(
this.key("type").objid(),
this.key("value").any(),
);
});
const AlgorithmIdentifier = asn.define("AlgorithmIdentifier", function () {
this.seq().obj(
this.key("algorithm").objid(),
this.key("parameters").optional(),
this.key("curve").objid().optional(),
);
});
const SubjectPublicKeyInfo = asn.define("SubjectPublicKeyInfo", function () {
this.seq().obj(
this.key("algorithm").use(AlgorithmIdentifier),
this.key("subjectPublicKey").bitstr(),
);
});
const RelativeDistinguishedName = asn.define(
"RelativeDistinguishedName",
function () {
this.setof(AttributeTypeValue);
},
);
const RDNSequence = asn.define("RDNSequence", function () {
this.seqof(RelativeDistinguishedName);
});
const Name = asn.define("Name", function () {
this.choice({
rdnSequence: this.use(RDNSequence),
});
});
const Validity = asn.define("Validity", function () {
this.seq().obj(
this.key("notBefore").use(Time),
this.key("notAfter").use(Time),
);
});
const Extension = asn.define("Extension", function () {
this.seq().obj(
this.key("extnID").objid(),
this.key("critical").bool().def(false),
this.key("extnValue").octstr(),
);
});
const TBSCertificate = asn.define("TBSCertificate", function () {
this.seq().obj(
this.key("version").explicit(0).int().optional(),
this.key("serialNumber").int(),
this.key("signature").use(AlgorithmIdentifier),
this.key("issuer").use(Name),
this.key("validity").use(Validity),
this.key("subject").use(Name),
this.key("subjectPublicKeyInfo").use(SubjectPublicKeyInfo),
this.key("issuerUniqueID").implicit(1).bitstr().optional(),
this.key("subjectUniqueID").implicit(2).bitstr().optional(),
this.key("extensions").explicit(3).seqof(Extension).optional(),
);
});
export const X509Certificate = asn.define("X509Certificate", function () {
this.seq().obj(
this.key("tbsCertificate").use(TBSCertificate),
this.key("signatureAlgorithm").use(AlgorithmIdentifier),
this.key("signatureValue").bitstr(),
);
});
export default X509Certificate;