Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/**
http://tools.ietf.org/html/rfc2315#section-9.1
SignedData ::= SEQUENCE {
version Version,
digestAlgorithms DigestAlgorithmIdentifiers,
contentInfo ContentInfo,
certificates
[0] IMPLICIT ExtendedCertificatesAndCertificates
OPTIONAL,
crls
[1] IMPLICIT CertificateRevocationLists OPTIONAL,
signerInfos SignerInfos }
*/
var SignedData = asn1.define('SignedData', function() {
this.seq().obj(
this.key('version').int(),
this.key('digestAlgorithms').use(DigestAlgorithmIdentifiers),
this.key('contentInfo').use(ContentInfo),
this.key('certificate').optional().implicit(0).use(Certificates),
this.key('crls').optional().implicit(1).set(), // NOT PARSED
this.key('signerInfos').use(SignerInfos)
);
});
var RecipientKeyIdentifier = asn1.define('RecipientKeyIdentifier', function() {
this.seq().obj(
this.key('subjectKeyIdentifier').octstr(),
this.key('date').use(rfc3280.Time).optional(),
this.key('other').optional().any()
import { ec as EC } from 'elliptic'
// @ts-ignore
import * as asn1 from 'asn1.js'
const BN = require('bn.js')
/**
* Use types for the `bn.js` lib, e.g. `@types/bn.js`
*/
type BNjs = any
const ECPrivateKeyASN = asn1.define('ECPrivateKey', function () {
// @ts-ignore
const self = this as any
self.seq().obj(
self.key('version').int(),
self.key('privateKey').octstr(),
self.key('parameters').explicit(0).objid().optional(),
self.key('publicKey').explicit(1).bitstr().optional()
)
})
const SubjectPublicKeyInfoASN = asn1.define('SubjectPublicKeyInfo', function () {
// @ts-ignore
const self = this as any
self.seq().obj(
self.key('algorithm').seq().obj(
self.key("id").objid(),
// TODO(indutny): validate that version is v3
this.key('extensions').optional().explicit(3).use(Extensions)
);
});
exports.TBSCertificate = TBSCertificate;
var Version = asn1.define('Version', function() {
this.int({
0: 'v1',
1: 'v2',
2: 'v3'
});
});
exports.Version = Version;
var CertificateSerialNumber = asn1.define('CertificateSerialNumber',
function() {
this.int();
});
exports.CertificateSerialNumber = CertificateSerialNumber;
var Validity = asn1.define('Validity', function() {
this.seq().obj(
this.key('notBefore').use(Time),
this.key('notAfter').use(Time)
);
});
exports.Validity = Validity;
var Time = asn1.define('Time', function() {
this.choice({
utcTime: this.utctime(),
});
text = text.slice(1, -1).join('');
return new Buffer(text.replace(/[^\w\d\+\/=]+/g, ''), 'base64');
}
var ECDSAPublicKey = asn.define('ECDSAPublicKey', function () {
this.seq().obj(
/*this.key('ECpoint').octstr()
/*
// TODO Figure out this format/sequence
this.key('x').int(),
this.key('y').int()*/
)
})
var AlgorithmIdentifier = asn.define('AlgorithmIdentifier', function () {
this.seq().obj(
this.key('algorithm').objid(),
this.key('parameters').optional().any()
)
})
var PublicKeyInfo = asn.define('PublicKeyInfo', function () {
this.seq().obj(
this.key('algorithm').use(AlgorithmIdentifier),
this.key('subjectPublicKey').bitstr()
)
})
var Version = asn.define('Version', function () {
this.int({
0: 'two-prime',
this.seqof(RelativeDistinguishedName);
});
var RelativeDistinguishedName = asn1.define('RelativeDistinguishedName',
function() {
this.setof(AttributeTypeAndValue);
});
var AttributeTypeAndValue = asn1.define('AttributeTypeAndValue', function() {
this.seq().obj(
this.key('type').use(AttributeType),
this.key('value').use(AttributeValue)
);
});
var AttributeType = asn1.define('AttributeType', function() {
this.objid();
});
var AttributeValue = asn1.define('AttributeValue', function() {
this.any();
});
//-----END copied from https://github.com/indutny/asn1.js/blob/master/rfc/3280/index.js
function pem2der(certpem){
var lines = certpem.split('\n');
var stripped = ''; //strip ascii armor and newlines
for(var i = 1; i < lines.length-2; i++){
stripped += lines[i];
}
stripped = stripped.replace(/\n/g, '');
this.key('responses').seqof(SingleResponse),
this.key('responseExtensions').optional().explicit(0)
.use(rfc5280.Extensions)
);
});
exports.ResponseData = ResponseData;
var ResponderID = asn1.define('ResponderId', function() {
this.choice({
byName: this.explicit(1).use(rfc5280.Name),
byKey: this.explicit(2).use(KeyHash)
});
});
exports.ResponderID = ResponderID;
var KeyHash = asn1.define('KeyHash', function() {
this.octstr();
});
exports.KeyHash = KeyHash;
var SingleResponse = asn1.define('SingleResponse', function() {
this.seq().obj(
this.key('certId').use(CertID),
this.key('certStatus').use(CertStatus),
this.key('thisUpdate').gentime(),
this.key('nextUpdate').optional().explicit(0).gentime(),
this.key('singleExtensions').optional().explicit(1).use(rfc5280.Extensions)
);
});
exports.SingleResponse = SingleResponse;
var CertStatus = asn1.define('CertStatus', function() {
'use strict';
var asn1 = require('asn1.js');
var Buffer = require('buffer').Buffer;
var origcerts = certs;
//--------BEGIN copied from https://github.com/indutny/asn1.js/blob/master/rfc/3280/index.js
var AlgorithmIdentifier = asn1.define('AlgorithmIdentifier', function() {
this.seq().obj(
this.key('algorithm').objid(),
this.key('parameters').optional().any()
);
});
var Certificate = asn1.define('Certificate', function() {
this.seq().obj(
this.key('tbsCertificate').use(TBSCertificate),
this.key('signatureAlgorithm').use(AlgorithmIdentifier),
this.key('signature').bitstr()
);
});
const BasicConstraints = asn1.define('BasicConstraints', function() {
this.seq().obj(
var Version = asn.define('Version', function () {
this.int({
0: 'two-prime',
1: 'multi'
})
})
var OtherPrimeInfos = asn.define('OtherPrimeInfos', function () {
this.seq().obj(
this.key('ri').int(),
this.key('di').int(),
this.key('ti').int()
)
})
let RSAPublicKey = asn.define('RSAPublicKey', function () {
this.seq().obj(
this.key('n').int(),
this.key('e').int()
)
})
var AlgorithmIdentifier = asn.define('AlgorithmIdentifier', function () {
this.seq().obj(
this.key('algorithm').objid(),
this.key('parameters').optional().any()
)
})
var RSAPrivateKey = asn.define('RSAPrivateKey', function () {
this.key('p').int(),
this.key('q').int(),
this.key('g').int()
).optional()
)
})
var PrivateKeyInfo = asn1.define('PrivateKeyInfo', function () {
this.seq().obj(
this.key('version').int(),
this.key('algorithm').use(AlgorithmIdentifier),
this.key('subjectPrivateKey').octstr()
)
})
exports.PrivateKey = PrivateKeyInfo
var EncryptedPrivateKeyInfo = asn1.define('EncryptedPrivateKeyInfo', function () {
this.seq().obj(
this.key('algorithm').seq().obj(
this.key('id').objid(),
this.key('decrypt').seq().obj(
this.key('kde').seq().obj(
this.key('id').objid(),
this.key('kdeparams').seq().obj(
this.key('salt').octstr(),
this.key('iters').int()
)
),
this.key('cipher').seq().obj(
this.key('algo').objid(),
this.key('iv').octstr()
)
)
exports.UniqueIdentifier = UniqueIdentifier;
var SubjectPublicKeyInfo = asn1.define('SubjectPublicKeyInfo', function() {
this.seq().obj(
this.key('algorithm').use(AlgorithmIdentifier),
this.key('subjectPublicKey').bitstr()
);
});
exports.SubjectPublicKeyInfo = SubjectPublicKeyInfo;
var Extensions = asn1.define('Extensions', function() {
this.seqof(Extension);
});
exports.Extensions = Extensions;
var Extension = asn1.define('Extension', function() {
this.seq().obj(
this.key('extnID').objid(),
this.key('critical').bool().def(false),
this.key('extnValue').octstr()
);
});
exports.Extension = Extension;
var Name = asn1.define('Name', function() {
this.choice({
rdn: this.use(RDNSequence)
});
});
exports.Name = Name;
var RDNSequence = asn1.define('RDNSequence', function() {