"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.PBES2ESParams = exports.PBKDF2Params = exports.PBES2Params = exports.PBEParameter = exports.EncryptedPrivateKeyInfo = exports.OneAsymmetricKey = exports.SubjectPublicKeyInfo = exports.KeyStructure = void 0; var _asn = _interopRequireDefault(require("asn1.js")); /** * asn1def.js */ /////////////////////////////////////////////////////////////////////////////////////////// /** * This is either one of subjectPublicKeyInfo, oneAsymmetricKey or encryptedPrivateKeyInfo in ASN.1 format. * @type {AsnObject} */ var KeyStructure = _asn.default.define('KeyStructure', function () { this.choice({ subjectPublicKeyInfo: this.use(SubjectPublicKeyInfo), oneAsymmetricKey: this.use(OneAsymmetricKey), encryptedPrivateKeyInfo: this.use(EncryptedPrivateKeyInfo) }); }); /** * SubjectPublicKeyInfo specified in RFC 5280 {@link https://tools.ietf.org/html/rfc5280}. * @type {AsnObject} */ exports.KeyStructure = KeyStructure; var SubjectPublicKeyInfo = _asn.default.define('SubjectPublicKeyInfo', function () { this.seq().obj(this.key('algorithm').use(AlgorithmIdentifier), this.key('subjectPublicKey').bitstr()); }); /////////////////////////////////////////////////////////////////////////////////////////// /** * OneAsymmetricKey specified in RFC5958 {@link https://tools.ietf.org/html/rfc5958}. * (old version PrivateKeyInfo {@link https://tools.ietf.org/html/rfc5208}.) * @type {AsnObject} */ exports.SubjectPublicKeyInfo = SubjectPublicKeyInfo; var OneAsymmetricKey = _asn.default.define('OneAsymmetricKey', function () { this.seq().obj(this.key('version').use(Version), this.key('privateKeyAlgorithm').use(AlgorithmIdentifier), this.key('privateKey').octstr(), this.key('attributes').implicit(0).optional().any(), this.key('publicKey').implicit(1).optional().bitstr()); }); /** * EncryptedPrivateKeyInfo specified in RFC5958 {@link https://tools.ietf.org/html/rfc5958}. * @type {AsnObject} */ exports.OneAsymmetricKey = OneAsymmetricKey; var EncryptedPrivateKeyInfo = _asn.default.define('EncryptedPrivateKeyInfo', function () { this.seq().obj(this.key('encryptionAlgorithm').use(AlgorithmIdentifier), this.key('encryptedData').octstr()); }); /////////////////////////////////////////////////////////////////////////////////////////// /** * PBEParameter, parameter for password-based encryption, specified in RFC 8018 {@link https://tools.ietf.org/html/rfc8018}. * @type {AsnObject} */ exports.EncryptedPrivateKeyInfo = EncryptedPrivateKeyInfo; var PBEParameter = _asn.default.define('PBEParameter', function () { this.seq().obj(this.key('salt').octstr(8), this.key('iterationCount').int()); }); /** * PBES2Params, parameter for password-based encryption scheme 2, specified in RFC 8018 {@link https://tools.ietf.org/html/rfc8018}. * @type {AsnObject} */ exports.PBEParameter = PBEParameter; var PBES2Params = _asn.default.define('PBES2Params', function () { this.seq().obj(this.key('keyDerivationFunc').use(AlgorithmIdentifier), this.key('encryptionScheme').use(AlgorithmIdentifier)); }); /////////////////////////////////////////////////////////////////////////////////////////// // PBKDF2-params ::= SEQUENCE { // salt CHOICE { // specified OCTET STRING, // otherSource AlgorithmIdentifier {{PBKDF2-SaltSources}} // }, // iterationCount INTEGER (1..MAX), // keyLength INTEGER (1..MAX) OPTIONAL, // prf AlgorithmIdentifier {{PBKDF2-PRFs}} DEFAULT // algid-hmacWithSHA1 // } /** * PBKDF2Params, parameter for PBKDF2, specified in RFC 8018 {@link https://tools.ietf.org/html/rfc8018}. * @type {AsnObject} */ exports.PBES2Params = PBES2Params; var PBKDF2Params = _asn.default.define('PBKDF2Params', function () { this.seq().obj(this.key('salt').choice({ 'specified': this.octstr(), 'otherSource': this.use(AlgorithmIdentifier) }), this.key('iterationCount').int(), this.key('keyLength').int().optional(), this.key('prf').use(AlgorithmIdentifier).def({ algorithm: [1, 2, 840, 113549, 2, 7], // hmacWithSHA1 parameters: Buffer.from([0x05, 0x00]) })); }); /////////////////////////////////////////////////////////////////////////////////////////// /** * PBES2ESParams specified in RFC 8018 {@link https://tools.ietf.org/html/rfc8018}. * @type {{'aes192-cbc': AsnObject, 'aes128-cbc': AsnObject, 'des-ede3-cbc': Object, 'aes256-cbc': AsnObject}} */ exports.PBKDF2Params = PBKDF2Params; var PBES2ESParams = { 'des-ede3-cbc': _asn.default.define('DesEde3CbcParams', function () { this.octstr(); }), 'aes128-cbc': _asn.default.define('Aes128CbcParams', function () { this.octstr(); }), 'aes192-cbc': _asn.default.define('Aes192CbcParams', function () { this.octstr(); }), 'aes256-cbc': _asn.default.define('Aes256CbcParams', function () { this.octstr(); }) }; //////////////////////////////////////////////////////////////////////////////////// /** * AlgorithmIdentifier given in RFC 5280 {@link https://tools.ietf.org/html/rfc5280} * @type AsnObject */ exports.PBES2ESParams = PBES2ESParams; var AlgorithmIdentifier = _asn.default.define('AlgorithmIdentifier', function () { this.seq().obj(this.key('algorithm').objid(), this.key('parameters').optional().any()); }); /** * Version * @type {AsnObject} */ var Version = _asn.default.define('Version', function () { this.int(); });