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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
|
import * as asn1js from "asn1js";
import * as pvutils from "pvutils";
import { GeneralNames, GeneralNamesJson } from "../GeneralNames";
import { AlgorithmIdentifier, AlgorithmIdentifierJson, AlgorithmIdentifierSchema } from "../AlgorithmIdentifier";
import { Attribute, AttributeJson } from "../Attribute";
import { Extensions, ExtensionsJson, ExtensionsSchema } from "../Extensions";
import { AttCertValidityPeriod, AttCertValidityPeriodJson, AttCertValidityPeriodSchema } from "./AttCertValidityPeriod";
import { IssuerSerial, IssuerSerialJson } from "./IssuerSerial";
import * as Schema from "../Schema";
import { PkiObject, PkiObjectParameters } from "../PkiObject";
import { AsnError } from "../errors";
import { EMPTY_STRING } from "../constants";
const VERSION = "version";
const BASE_CERTIFICATE_ID = "baseCertificateID";
const SUBJECT_NAME = "subjectName";
const ISSUER = "issuer";
const SIGNATURE = "signature";
const SERIAL_NUMBER = "serialNumber";
const ATTR_CERT_VALIDITY_PERIOD = "attrCertValidityPeriod";
const ATTRIBUTES = "attributes";
const ISSUER_UNIQUE_ID = "issuerUniqueID";
const EXTENSIONS = "extensions";
const CLEAR_PROPS = [
VERSION,
BASE_CERTIFICATE_ID,
SUBJECT_NAME,
ISSUER,
SIGNATURE,
SERIAL_NUMBER,
ATTR_CERT_VALIDITY_PERIOD,
ATTRIBUTES,
ISSUER_UNIQUE_ID,
EXTENSIONS,
];
export interface IAttributeCertificateInfoV1 {
/**
* The version field MUST have the value of v2
*/
version: number;
baseCertificateID?: IssuerSerial;
subjectName?: GeneralNames;
issuer: GeneralNames;
/**
* Contains the algorithm identifier used to validate the AC signature
*/
signature: AlgorithmIdentifier;
serialNumber: asn1js.Integer;
/**
* Specifies the period for which the AC issuer certifies that the binding between
* the holder and the attributes fields will be valid
*/
attrCertValidityPeriod: AttCertValidityPeriod;
/**
* The attributes field gives information about the AC holder
*/
attributes: Attribute[];
/**
* Issuer unique identifier
*/
issuerUniqueID?: asn1js.BitString;
/**
* The extensions field generally gives information about the AC as opposed
* to information about the AC holder
*/
extensions?: Extensions;
}
export interface AttributeCertificateInfoV1Json {
version: number;
baseCertificateID?: IssuerSerialJson;
subjectName?: GeneralNamesJson;
issuer: GeneralNamesJson;
signature: AlgorithmIdentifierJson;
serialNumber: asn1js.IntegerJson;
attrCertValidityPeriod: AttCertValidityPeriodJson;
attributes: AttributeJson[];
issuerUniqueID: asn1js.BitStringJson;
extensions: ExtensionsJson;
}
export type AttributeCertificateInfoV1Parameters = PkiObjectParameters & Partial<IAttributeCertificateInfoV1>;
export type AttributeCertificateInfoV1Schema = Schema.SchemaParameters<{
version?: string;
baseCertificateID?: string;
subjectName?: string;
signature?: AlgorithmIdentifierSchema;
issuer?: string;
attrCertValidityPeriod?: AttCertValidityPeriodSchema;
serialNumber?: string;
attributes?: string;
issuerUniqueID?: string;
extensions?: ExtensionsSchema;
}>;
/**
* Represents the AttributeCertificateInfoV1 structure described in [RFC5755](https://datatracker.ietf.org/doc/html/rfc5755)
*/
export class AttributeCertificateInfoV1 extends PkiObject implements IAttributeCertificateInfoV1 {
public static override CLASS_NAME = "AttributeCertificateInfoV1";
version!: number;
baseCertificateID?: IssuerSerial;
subjectName?: GeneralNames;
issuer!: GeneralNames;
signature!: AlgorithmIdentifier;
serialNumber!: asn1js.Integer;
attrCertValidityPeriod!: AttCertValidityPeriod;
attributes!: Attribute[];
issuerUniqueID?: asn1js.BitString;
extensions?: Extensions;
/**
* Initializes a new instance of the {@link AttributeCertificateInfoV1} class
* @param parameters Initialization parameters
*/
constructor(parameters: AttributeCertificateInfoV1Parameters = {}) {
super();
this.version = pvutils.getParametersValue(parameters, VERSION, AttributeCertificateInfoV1.defaultValues(VERSION));
if (BASE_CERTIFICATE_ID in parameters) {
this.baseCertificateID = pvutils.getParametersValue(parameters, BASE_CERTIFICATE_ID, AttributeCertificateInfoV1.defaultValues(BASE_CERTIFICATE_ID));
}
if (SUBJECT_NAME in parameters) {
this.subjectName = pvutils.getParametersValue(parameters, SUBJECT_NAME, AttributeCertificateInfoV1.defaultValues(SUBJECT_NAME));
}
this.issuer = pvutils.getParametersValue(parameters, ISSUER, AttributeCertificateInfoV1.defaultValues(ISSUER));
this.signature = pvutils.getParametersValue(parameters, SIGNATURE, AttributeCertificateInfoV1.defaultValues(SIGNATURE));
this.serialNumber = pvutils.getParametersValue(parameters, SERIAL_NUMBER, AttributeCertificateInfoV1.defaultValues(SERIAL_NUMBER));
this.attrCertValidityPeriod = pvutils.getParametersValue(parameters, ATTR_CERT_VALIDITY_PERIOD, AttributeCertificateInfoV1.defaultValues(ATTR_CERT_VALIDITY_PERIOD));
this.attributes = pvutils.getParametersValue(parameters, ATTRIBUTES, AttributeCertificateInfoV1.defaultValues(ATTRIBUTES));
if (ISSUER_UNIQUE_ID in parameters)
this.issuerUniqueID = pvutils.getParametersValue(parameters, ISSUER_UNIQUE_ID, AttributeCertificateInfoV1.defaultValues(ISSUER_UNIQUE_ID));
if (EXTENSIONS in parameters) {
this.extensions = pvutils.getParametersValue(parameters, EXTENSIONS, AttributeCertificateInfoV1.defaultValues(EXTENSIONS));
}
if (parameters.schema) {
this.fromSchema(parameters.schema);
}
}
/**
* Returns default values for all class members
* @param memberName String name for a class member
* @returns Default value
*/
public static override defaultValues(memberName: typeof VERSION): number;
public static override defaultValues(memberName: typeof BASE_CERTIFICATE_ID): IssuerSerial;
public static override defaultValues(memberName: typeof SUBJECT_NAME): GeneralNames;
public static override defaultValues(memberName: typeof ISSUER): GeneralNames;
public static override defaultValues(memberName: typeof SIGNATURE): AlgorithmIdentifier;
public static override defaultValues(memberName: typeof SERIAL_NUMBER): asn1js.Integer;
public static override defaultValues(memberName: typeof ATTR_CERT_VALIDITY_PERIOD): AttCertValidityPeriod;
public static override defaultValues(memberName: typeof ATTRIBUTES): Attribute[];
public static override defaultValues(memberName: typeof ISSUER_UNIQUE_ID): asn1js.BitString;
public static override defaultValues(memberName: typeof EXTENSIONS): Extensions;
public static override defaultValues(memberName: string): any {
switch (memberName) {
case VERSION:
return 0;
case BASE_CERTIFICATE_ID:
return new IssuerSerial();
case SUBJECT_NAME:
return new GeneralNames();
case ISSUER:
return new GeneralNames();
case SIGNATURE:
return new AlgorithmIdentifier();
case SERIAL_NUMBER:
return new asn1js.Integer();
case ATTR_CERT_VALIDITY_PERIOD:
return new AttCertValidityPeriod();
case ATTRIBUTES:
return [];
case ISSUER_UNIQUE_ID:
return new asn1js.BitString();
case EXTENSIONS:
return new Extensions();
default:
return super.defaultValues(memberName);
}
}
/**
* @inheritdoc
* @asn ASN.1 schema
* ```asn
* AttributeCertificateInfo ::= SEQUENCE {
* version Version DEFAULT v1,
* subject CHOICE {
* baseCertificateID [0] IssuerSerial, -- associated with a Public Key Certificate
* subjectName [1] GeneralNames }, -- associated with a name
* issuer GeneralNames, -- CA issuing the attribute certificate
* signature AlgorithmIdentifier,
* serialNumber CertificateSerialNumber,
* attrCertValidityPeriod AttCertValidityPeriod,
* attributes SEQUENCE OF Attribute,
* issuerUniqueID UniqueIdentifier OPTIONAL,
* extensions Extensions OPTIONAL
* }
*```
*/
public static override schema(parameters: AttributeCertificateInfoV1Schema = {}): Schema.SchemaType {
const names = pvutils.getParametersValue<NonNullable<typeof parameters.names>>(parameters, "names", {});
return (new asn1js.Sequence({
name: (names.blockName || EMPTY_STRING),
value: [
new asn1js.Integer({ name: (names.version || EMPTY_STRING) }),
new asn1js.Choice({
value: [
new asn1js.Constructed({
name: (names.baseCertificateID || EMPTY_STRING),
idBlock: {
tagClass: 3,
tagNumber: 0 // [0]
},
value: IssuerSerial.schema().valueBlock.value
}),
new asn1js.Constructed({
name: (names.subjectName || EMPTY_STRING),
idBlock: {
tagClass: 3,
tagNumber: 1 // [2]
},
value: GeneralNames.schema().valueBlock.value
}),
]
}),
GeneralNames.schema({
names: {
blockName: (names.issuer || EMPTY_STRING)
}
}),
AlgorithmIdentifier.schema(names.signature || {}),
new asn1js.Integer({ name: (names.serialNumber || EMPTY_STRING) }),
AttCertValidityPeriod.schema(names.attrCertValidityPeriod || {}),
new asn1js.Sequence({
name: (names.attributes || EMPTY_STRING),
value: [
new asn1js.Repeated({
value: Attribute.schema()
})
]
}),
new asn1js.BitString({
optional: true,
name: (names.issuerUniqueID || EMPTY_STRING)
}),
Extensions.schema(names.extensions || {}, true)
]
}));
}
public fromSchema(schema: Schema.SchemaType): void {
// Clear input data first
pvutils.clearProps(schema, CLEAR_PROPS);
//#region Check the schema is valid
const asn1 = asn1js.compareSchema(schema,
schema,
AttributeCertificateInfoV1.schema({
names: {
version: VERSION,
baseCertificateID: BASE_CERTIFICATE_ID,
subjectName: SUBJECT_NAME,
issuer: ISSUER,
signature: {
names: {
blockName: SIGNATURE
}
},
serialNumber: SERIAL_NUMBER,
attrCertValidityPeriod: {
names: {
blockName: ATTR_CERT_VALIDITY_PERIOD
}
},
attributes: ATTRIBUTES,
issuerUniqueID: ISSUER_UNIQUE_ID,
extensions: {
names: {
blockName: EXTENSIONS
}
}
}
})
);
AsnError.assertSchema(asn1, this.className);
//#endregion
//#region Get internal properties from parsed schema
this.version = asn1.result.version.valueBlock.valueDec;
if (BASE_CERTIFICATE_ID in asn1.result) {
this.baseCertificateID = new IssuerSerial({
schema: new asn1js.Sequence({
value: asn1.result.baseCertificateID.valueBlock.value
})
});
}
if (SUBJECT_NAME in asn1.result) {
this.subjectName = new GeneralNames({
schema: new asn1js.Sequence({
value: asn1.result.subjectName.valueBlock.value
})
});
}
this.issuer = asn1.result.issuer;
this.signature = new AlgorithmIdentifier({ schema: asn1.result.signature });
this.serialNumber = asn1.result.serialNumber;
this.attrCertValidityPeriod = new AttCertValidityPeriod({ schema: asn1.result.attrCertValidityPeriod });
this.attributes = Array.from(asn1.result.attributes.valueBlock.value, element => new Attribute({ schema: element }));
if (ISSUER_UNIQUE_ID in asn1.result) {
this.issuerUniqueID = asn1.result.issuerUniqueID;
}
if (EXTENSIONS in asn1.result) {
this.extensions = new Extensions({ schema: asn1.result.extensions });
}
//#endregion
}
public toSchema(): asn1js.Sequence {
const result = new asn1js.Sequence({
value: [new asn1js.Integer({ value: this.version })]
});
if (this.baseCertificateID) {
result.valueBlock.value.push(new asn1js.Constructed({
idBlock: {
tagClass: 3,
tagNumber: 0 // [0]
},
value: this.baseCertificateID.toSchema().valueBlock.value
}));
}
if (this.subjectName) {
result.valueBlock.value.push(new asn1js.Constructed({
idBlock: {
tagClass: 3,
tagNumber: 1 // [1]
},
value: this.subjectName.toSchema().valueBlock.value
}));
}
result.valueBlock.value.push(this.issuer.toSchema());
result.valueBlock.value.push(this.signature.toSchema());
result.valueBlock.value.push(this.serialNumber);
result.valueBlock.value.push(this.attrCertValidityPeriod.toSchema());
result.valueBlock.value.push(new asn1js.Sequence({
value: Array.from(this.attributes, o => o.toSchema())
}));
if (this.issuerUniqueID) {
result.valueBlock.value.push(this.issuerUniqueID);
}
if (this.extensions) {
result.valueBlock.value.push(this.extensions.toSchema());
}
return result;
}
public toJSON(): AttributeCertificateInfoV1Json {
const result = {
version: this.version
} as AttributeCertificateInfoV1Json;
if (this.baseCertificateID) {
result.baseCertificateID = this.baseCertificateID.toJSON();
}
if (this.subjectName) {
result.subjectName = this.subjectName.toJSON();
}
result.issuer = this.issuer.toJSON();
result.signature = this.signature.toJSON();
result.serialNumber = this.serialNumber.toJSON();
result.attrCertValidityPeriod = this.attrCertValidityPeriod.toJSON();
result.attributes = Array.from(this.attributes, o => o.toJSON());
if (this.issuerUniqueID) {
result.issuerUniqueID = this.issuerUniqueID.toJSON();
}
if (this.extensions) {
result.extensions = this.extensions.toJSON();
}
return result;
}
}
|