Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80645 views
1
try {
2
var asn1 = require('asn1.js');
3
} catch (e) {
4
var asn1 = require('../' + '..');
5
}
6
7
var CRLReason = asn1.define('CRLReason', function() {
8
this.enum({
9
0: 'unspecified',
10
1: 'keyCompromise',
11
2: 'CACompromise',
12
3: 'affiliationChanged',
13
4: 'superseded',
14
5: 'cessationOfOperation',
15
6: 'certificateHold',
16
8: 'removeFromCRL',
17
9: 'privilegeWithdrawn',
18
10: 'AACompromise'
19
});
20
});
21
exports.CRLReason = CRLReason;
22
23
var AlgorithmIdentifier = asn1.define('AlgorithmIdentifier', function() {
24
this.seq().obj(
25
this.key('algorithm').objid(),
26
this.key('parameters').optional().any()
27
);
28
});
29
exports.AlgorithmIdentifier = AlgorithmIdentifier;
30
31
var Certificate = asn1.define('Certificate', function() {
32
this.seq().obj(
33
this.key('tbsCertificate').use(TBSCertificate),
34
this.key('signatureAlgorithm').use(AlgorithmIdentifier),
35
this.key('signature').bitstr()
36
);
37
});
38
exports.Certificate = Certificate;
39
40
var TBSCertificate = asn1.define('TBSCertificate', function() {
41
this.seq().obj(
42
this.key('version').def('v1').explicit(0).use(Version),
43
this.key('serialNumber').use(CertificateSerialNumber),
44
this.key('signature').use(AlgorithmIdentifier),
45
this.key('issuer').use(Name),
46
this.key('validity').use(Validity),
47
this.key('subject').use(Name),
48
this.key('subjectPublicKeyInfo').use(SubjectPublicKeyInfo),
49
50
// TODO(indutny): validate that version is v2 or v3
51
this.key('issuerUniqueID').optional().explicit(1).use(UniqueIdentifier),
52
this.key('subjectUniqueID').optional().explicit(2).use(UniqueIdentifier),
53
54
// TODO(indutny): validate that version is v3
55
this.key('extensions').optional().explicit(3).use(Extensions)
56
);
57
});
58
exports.TBSCertificate = TBSCertificate;
59
60
var Version = asn1.define('Version', function() {
61
this.int({
62
0: 'v1',
63
1: 'v2',
64
2: 'v3'
65
});
66
});
67
exports.Version = Version;
68
69
var CertificateSerialNumber = asn1.define('CertificateSerialNumber',
70
function() {
71
this.int();
72
});
73
exports.CertificateSerialNumber = CertificateSerialNumber;
74
75
var Validity = asn1.define('Validity', function() {
76
this.seq().obj(
77
this.key('notBefore').use(Time),
78
this.key('notAfter').use(Time)
79
);
80
});
81
exports.Validity = Validity;
82
83
var Time = asn1.define('Time', function() {
84
this.choice({
85
utcTime: this.utctime(),
86
genTime: this.gentime()
87
});
88
});
89
exports.Time = Time;
90
91
var UniqueIdentifier = asn1.define('UniqueIdentifier', function() {
92
this.bitstr();
93
});
94
exports.UniqueIdentifier = UniqueIdentifier;
95
96
var SubjectPublicKeyInfo = asn1.define('SubjectPublicKeyInfo', function() {
97
this.seq().obj(
98
this.key('algorithm').use(AlgorithmIdentifier),
99
this.key('subjectPublicKey').bitstr()
100
);
101
});
102
exports.SubjectPublicKeyInfo = SubjectPublicKeyInfo;
103
104
var Extensions = asn1.define('Extensions', function() {
105
this.seqof(Extension);
106
});
107
exports.Extensions = Extensions;
108
109
var Extension = asn1.define('Extension', function() {
110
this.seq().obj(
111
this.key('extnID').objid(),
112
this.key('critical').bool().def(false),
113
this.key('extnValue').octstr()
114
);
115
});
116
exports.Extension = Extension;
117
118
var Name = asn1.define('Name', function() {
119
this.choice({
120
rdn: this.use(RDNSequence)
121
});
122
});
123
exports.Name = Name;
124
125
var RDNSequence = asn1.define('RDNSequence', function() {
126
this.seqof(RelativeDistinguishedName);
127
});
128
exports.RDNSequence = RDNSequence;
129
130
var RelativeDistinguishedName = asn1.define('RelativeDistinguishedName',
131
function() {
132
this.setof(AttributeTypeAndValue);
133
});
134
exports.RelativeDistinguishedName = RelativeDistinguishedName;
135
136
var AttributeTypeAndValue = asn1.define('AttributeTypeAndValue', function() {
137
this.seq().obj(
138
this.key('type').use(AttributeType),
139
this.key('value').use(AttributeValue)
140
);
141
});
142
exports.AttributeTypeAndValue = AttributeTypeAndValue;
143
144
var AttributeType = asn1.define('AttributeType', function() {
145
this.objid();
146
});
147
exports.AttributeType = AttributeType;
148
149
var AttributeValue = asn1.define('AttributeValue', function() {
150
this.any();
151
});
152
exports.AttributeValue = AttributeValue;
153
154
var GeneralNames = asn1.define('GeneralNames', function() {
155
this.seqof(GeneralName);
156
});
157
exports.GeneralNames = GeneralNames;
158
159
var GeneralName = asn1.define('GeneralName', function() {
160
return this.choice({
161
otherName: this.implicit(0).use(AnotherName),
162
rfc822Name: this.implicit(1).ia5str(),
163
dNSName: this.implicit(2).ia5str(),
164
directoryName: this.implicit(4).use(Name),
165
166
// TODO(indutny): requires DirectoryString, ORAddress
167
// ediPartyName: this.implicit(5).use(EDIPartyName),
168
// x400Address: this.implicit(3).use(ORAddress),
169
170
uniformResourceIdentifier: this.implicit(6).ia5str(),
171
iPAddress: this.implicit(7).octstr(),
172
registeredID: this.implicit(8).objid()
173
});
174
});
175
exports.GeneralName = GeneralName;
176
177
var AnotherName = asn1.define('AnotherName', function() {
178
return this.seq().obj(
179
this.key('type-id').objid(),
180
this.key('value').explicit(0).any()
181
);
182
});
183
exports.AnotherName = AnotherName;
184
185
exports['id-pe-authorityInfoAccess'] = [ 1, 3, 6, 1, 5, 5, 7, 1, 1];
186
187
var AuthorityInfoAccessSyntax = asn1.define('AuthorityInfoAccessSyntax',
188
function() {
189
this.seqof(AccessDescription);
190
});
191
exports.AuthorityInfoAccessSyntax = AuthorityInfoAccessSyntax;
192
193
var AccessDescription = asn1.define('AccessDescription', function() {
194
this.seq().obj(
195
this.key('accessMethod').objid(),
196
this.key('accessLocation').use(GeneralName)
197
);
198
});
199
exports.AccessDescription = AccessDescription;
200
201