feedback
This commit is contained in:
parent
1afc25aa70
commit
3b116ac1e1
|
|
@ -81,7 +81,6 @@ class DER {
|
||||||
static encodeDate(date: Date): Buffer {
|
static encodeDate(date: Date): Buffer {
|
||||||
const year = date.getUTCFullYear();
|
const year = date.getUTCFullYear();
|
||||||
const isGeneralizedTime = year >= 2050;
|
const isGeneralizedTime = year >= 2050;
|
||||||
|
|
||||||
const parts = [
|
const parts = [
|
||||||
isGeneralizedTime ? year.toString() : year.toString().slice(-2),
|
isGeneralizedTime ? year.toString() : year.toString().slice(-2),
|
||||||
(date.getUTCMonth() + 1).toString().padStart(2, '0'),
|
(date.getUTCMonth() + 1).toString().padStart(2, '0'),
|
||||||
|
|
@ -90,10 +89,8 @@ class DER {
|
||||||
date.getUTCMinutes().toString().padStart(2, '0'),
|
date.getUTCMinutes().toString().padStart(2, '0'),
|
||||||
date.getUTCSeconds().toString().padStart(2, '0')
|
date.getUTCSeconds().toString().padStart(2, '0')
|
||||||
];
|
];
|
||||||
|
|
||||||
const encodedDate = parts.join('') + 'Z';
|
const encodedDate = parts.join('') + 'Z';
|
||||||
const tag = isGeneralizedTime ? 0x18 : 0x17; // 0x18 for GeneralizedTime, 0x17 for UTCTime
|
const tag = isGeneralizedTime ? 0x18 : 0x17; // 0x18 for GeneralizedTime, 0x17 for UTCTime
|
||||||
|
|
||||||
return this._encode(tag, Buffer.from(encodedDate));
|
return this._encode(tag, Buffer.from(encodedDate));
|
||||||
}
|
}
|
||||||
private static _encode(tag: number, data: Buffer): Buffer {
|
private static _encode(tag: number, data: Buffer): Buffer {
|
||||||
|
|
@ -133,6 +130,8 @@ export function generateSelfSignedCertificate() {
|
||||||
DER.encodeObjectIdentifier('2.5.4.3'), // commonName X.520 DN component
|
DER.encodeObjectIdentifier('2.5.4.3'), // commonName X.520 DN component
|
||||||
DER.encodePrintableString('localhost')
|
DER.encodePrintableString('localhost')
|
||||||
]),
|
]),
|
||||||
|
]),
|
||||||
|
DER.encodeSet([
|
||||||
DER.encodeSequence([
|
DER.encodeSequence([
|
||||||
DER.encodeObjectIdentifier('2.5.4.10'), // organizationName X.520 DN component
|
DER.encodeObjectIdentifier('2.5.4.10'), // organizationName X.520 DN component
|
||||||
DER.encodePrintableString('Client Certificate Demo')
|
DER.encodePrintableString('Client Certificate Demo')
|
||||||
|
|
@ -149,6 +148,8 @@ export function generateSelfSignedCertificate() {
|
||||||
DER.encodeObjectIdentifier('2.5.4.3'), // commonName X.520 DN component
|
DER.encodeObjectIdentifier('2.5.4.3'), // commonName X.520 DN component
|
||||||
DER.encodePrintableString('localhost')
|
DER.encodePrintableString('localhost')
|
||||||
]),
|
]),
|
||||||
|
]),
|
||||||
|
DER.encodeSet([
|
||||||
DER.encodeSequence([
|
DER.encodeSequence([
|
||||||
DER.encodeObjectIdentifier('2.5.4.10'), // organizationName X.520 DN component
|
DER.encodeObjectIdentifier('2.5.4.10'), // organizationName X.520 DN component
|
||||||
DER.encodePrintableString('Client Certificate Demo')
|
DER.encodePrintableString('Client Certificate Demo')
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue