EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
x509.js
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014-2015 Sylvain Peyrefitte
3 *
4 * This file is part of node-rdpjs.
5 *
6 * node-rdpjs is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20// https://tools.ietf.org/html/rfc5280
21
22var asn1 = require('../asn1');
23
24/**
25 * @see https://tools.ietf.org/html/rfc5280 page 20
26 * @returns {asn1.univ.Choice}
27 */
28function DirectoryString() {
29 return new asn1.univ.Choice({
30 teletexString : new asn1.univ.T61String(),
31 printableString : new asn1.univ.PrintableString(),
32 universalString : new asn1.univ.UniversalString(),
33 utf8String : new asn1.univ.UTF8String(),
34 bmpString : new asn1.univ.BMPString(),
35 ia5String : new asn1.univ.IA5String()
36 });
37}
38
39/**
40 * https://tools.ietf.org/html/rfc5280 page 20
41 * @returns {asn1.univ.Choice}
42 */
43function AttributeValue() {
44 return DirectoryString();
45}
46
47/**
48 * @see https://tools.ietf.org/html/rfc5280 page 20
49 * @returns {asn1.univ.ObjectIdentifier}
50 */
51function AttributeType() {
52 return new asn1.univ.ObjectIdentifier();
53}
54
55/**
56 * @see https://tools.ietf.org/html/rfc5280 page 20
57 * @returns {asn1.univ.Sequence}
58 */
59function AttributeTypeAndValue() {
60 return new asn1.univ.Sequence({
61 type : AttributeType(),
62 value : AttributeValue()
63 });
64}
65
66/**
67 * https://tools.ietf.org/html/rfc5280 page 116
68 * @returns {asn1.univ.SetOf}
69 */
70function RelativeDistinguishedName() {
71 return new asn1.univ.SetOf(AttributeTypeAndValue);
72}
73
74/**
75 * https://tools.ietf.org/html/rfc5280 page 116
76 * @returns {asn1.univ.SequenceOf}
77 */
78function RDNSequence() {
79 return new asn1.univ.SequenceOf(RelativeDistinguishedName);
80}
81
82/**
83 * @see https://tools.ietf.org/html/rfc5280 page 116
84 * @returns {asn1.univ.Choice}
85 */
86function Name() {
87 return new asn1.univ.Choice({
88 rdnSequence : RDNSequence()
89 });
90}
91
92/**
93 * @see https://tools.ietf.org/html/rfc5280 page 18
94 * @returns {asn1.univ.Sequence}
95 */
96function AlgorithmIdentifier() {
97 return new asn1.univ.Sequence({
98 algorithm : new asn1.univ.ObjectIdentifier(),
99 parameters : new asn1.univ.Null()
100 });
101}
102
103/**
104 * @see https://tools.ietf.org/html/rfc5280 page 117
105 * @returns {asn1.univ.Sequence}
106 */
107function Extension() {
108 return new asn1.univ.Sequence({
109 extnID : new asn1.univ.ObjectIdentifier(),
110 critical : new asn1.univ.Boolean(),
111 extnValue : new asn1.univ.OctetString()
112 });
113}
114
115/**
116 * @see https://tools.ietf.org/html/rfc5280 page 117
117 * @returns {asn1.univ.SequenceOf}
118 */
119function Extensions() {
120 return new asn1.univ.SequenceOf(Extension);
121}
122
123/**
124 * @see https://tools.ietf.org/html/rfc5280 page 117
125 * @returns {asn1.univ.Choice}
126 */
127function Time() {
128 return new asn1.univ.Choice({
129 utcTime : new asn1.univ.UTCTime(),
130 generalTime : new asn1.univ.GeneralizedTime()
131 });
132}
133
134/**
135 * @see https://tools.ietf.org/html/rfc5280 page 117
136 * @returns {asn1.univ.Sequence}
137 */
138function Validity() {
139 return new asn1.univ.Sequence({
140 notBefore : Time(),
141 notAfter : Time()
142 });
143}
144
145/**
146 * @see https://tools.ietf.org/html/rfc5280 page 117
147 * @returns {asn1.univ.Integer}
148 */
149function CertificateSerialNumber() {
150 return new asn1.univ.Integer();
151}
152
153/**
154 * @see https://tools.ietf.org/html/rfc5280 page 117
155 * @returns {asn1.univ.Sequence}
156 */
157function SubjectPublicKeyInfo() {
158 return new asn1.univ.Sequence({
159 algorithm : AlgorithmIdentifier(),
160 subjectPublicKey : new asn1.univ.BitString()
161 });
162}
163
164/**
165 * @see https://tools.ietf.org/html/rfc5280 page 117
166 * @returns {asn1.univ.BitString}
167 */
168function UniqueIdentifier() {
169 return new asn1.univ.BitString();
170}
171
172/**
173 * @see https://tools.ietf.org/html/rfc5280 page 117
174 * @returns {asn1.univ.Sequence}
175 */
176function TbsCertificate() {
177 return new asn1.univ.Sequence({
178 version : CertificateSerialNumber().explicitTag(new asn1.spec.Asn1Tag(asn1.spec.TagClass.Context, asn1.spec.TagFormat.Constructed, 0)),
179 serialNumber : new asn1.univ.Integer(),
180 signature : AlgorithmIdentifier(),
181 issuer : Name(),
182 validity : Validity(),
183 subject : Name(),
184 subjectPublicKeyInfo : SubjectPublicKeyInfo(),
185 issuerUniqueID : UniqueIdentifier().implicitTag(asn1.spec.TagClass.Context, asn1.spec.TagFormat.Primitive, 1).optional(),
186 subjectUniqueID : UniqueIdentifier().implicitTag(asn1.spec.TagClass.Context, asn1.spec.TagFormat.Primitive, 2).optional(),
187 extensions : Extensions().implicitTag(asn1.spec.TagClass.Context, asn1.spec.TagFormat.Primitive, 3).optional()
188 });
189}
190
191/**
192 * @see https://tools.ietf.org/html/rfc5280 page 117
193 * @returns {asn1.univ.Sequence}
194 */
195function X509Certificate() {
196 return new asn1.univ.Sequence({
197 tbsCertificate : TbsCertificate(),
198 signatureAlgorithm : AlgorithmIdentifier(),
199 signatureValue : new asn1.univ.BitString()
200 });
201}
202
203function RSAPublicKey() {
204 return new asn1.univ.Sequence({
205 modulus : new asn1.univ.Integer(),
206 publicExponent : new asn1.univ.Integer()
207 });
208}
209
210/**
211 * Module Export
212 */
213module.exports = {
214 X509Certificate : X509Certificate,
215 RSAPublicKey : RSAPublicKey
216};