2 * Copyright (c) 2014-2015 Sylvain Peyrefitte
4 * This file is part of node-rdpjs.
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.
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.
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/>.
20// https://tools.ietf.org/html/rfc5280
22var asn1 = require('../asn1');
25 * @see https://tools.ietf.org/html/rfc5280 page 20
26 * @returns {asn1.univ.Choice}
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()
40 * https://tools.ietf.org/html/rfc5280 page 20
41 * @returns {asn1.univ.Choice}
43function AttributeValue() {
44 return DirectoryString();
48 * @see https://tools.ietf.org/html/rfc5280 page 20
49 * @returns {asn1.univ.ObjectIdentifier}
51function AttributeType() {
52 return new asn1.univ.ObjectIdentifier();
56 * @see https://tools.ietf.org/html/rfc5280 page 20
57 * @returns {asn1.univ.Sequence}
59function AttributeTypeAndValue() {
60 return new asn1.univ.Sequence({
61 type : AttributeType(),
62 value : AttributeValue()
67 * https://tools.ietf.org/html/rfc5280 page 116
68 * @returns {asn1.univ.SetOf}
70function RelativeDistinguishedName() {
71 return new asn1.univ.SetOf(AttributeTypeAndValue);
75 * https://tools.ietf.org/html/rfc5280 page 116
76 * @returns {asn1.univ.SequenceOf}
78function RDNSequence() {
79 return new asn1.univ.SequenceOf(RelativeDistinguishedName);
83 * @see https://tools.ietf.org/html/rfc5280 page 116
84 * @returns {asn1.univ.Choice}
87 return new asn1.univ.Choice({
88 rdnSequence : RDNSequence()
93 * @see https://tools.ietf.org/html/rfc5280 page 18
94 * @returns {asn1.univ.Sequence}
96function AlgorithmIdentifier() {
97 return new asn1.univ.Sequence({
98 algorithm : new asn1.univ.ObjectIdentifier(),
99 parameters : new asn1.univ.Null()
104 * @see https://tools.ietf.org/html/rfc5280 page 117
105 * @returns {asn1.univ.Sequence}
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()
116 * @see https://tools.ietf.org/html/rfc5280 page 117
117 * @returns {asn1.univ.SequenceOf}
119function Extensions() {
120 return new asn1.univ.SequenceOf(Extension);
124 * @see https://tools.ietf.org/html/rfc5280 page 117
125 * @returns {asn1.univ.Choice}
128 return new asn1.univ.Choice({
129 utcTime : new asn1.univ.UTCTime(),
130 generalTime : new asn1.univ.GeneralizedTime()
135 * @see https://tools.ietf.org/html/rfc5280 page 117
136 * @returns {asn1.univ.Sequence}
139 return new asn1.univ.Sequence({
146 * @see https://tools.ietf.org/html/rfc5280 page 117
147 * @returns {asn1.univ.Integer}
149function CertificateSerialNumber() {
150 return new asn1.univ.Integer();
154 * @see https://tools.ietf.org/html/rfc5280 page 117
155 * @returns {asn1.univ.Sequence}
157function SubjectPublicKeyInfo() {
158 return new asn1.univ.Sequence({
159 algorithm : AlgorithmIdentifier(),
160 subjectPublicKey : new asn1.univ.BitString()
165 * @see https://tools.ietf.org/html/rfc5280 page 117
166 * @returns {asn1.univ.BitString}
168function UniqueIdentifier() {
169 return new asn1.univ.BitString();
173 * @see https://tools.ietf.org/html/rfc5280 page 117
174 * @returns {asn1.univ.Sequence}
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(),
182 validity : Validity(),
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()
192 * @see https://tools.ietf.org/html/rfc5280 page 117
193 * @returns {asn1.univ.Sequence}
195function X509Certificate() {
196 return new asn1.univ.Sequence({
197 tbsCertificate : TbsCertificate(),
198 signatureAlgorithm : AlgorithmIdentifier(),
199 signatureValue : new asn1.univ.BitString()
203function RSAPublicKey() {
204 return new asn1.univ.Sequence({
205 modulus : new asn1.univ.Integer(),
206 publicExponent : new asn1.univ.Integer()
214 X509Certificate : X509Certificate,
215 RSAPublicKey : RSAPublicKey