11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst {
41cb0ef41Sopenharmony_ci  ObjectSetPrototypeOf,
51cb0ef41Sopenharmony_ci  SafeMap,
61cb0ef41Sopenharmony_ci  Symbol,
71cb0ef41Sopenharmony_ci} = primordials;
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst {
101cb0ef41Sopenharmony_ci  parseX509,
111cb0ef41Sopenharmony_ci  X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT,
121cb0ef41Sopenharmony_ci  X509_CHECK_FLAG_NEVER_CHECK_SUBJECT,
131cb0ef41Sopenharmony_ci  X509_CHECK_FLAG_NO_WILDCARDS,
141cb0ef41Sopenharmony_ci  X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS,
151cb0ef41Sopenharmony_ci  X509_CHECK_FLAG_MULTI_LABEL_WILDCARDS,
161cb0ef41Sopenharmony_ci  X509_CHECK_FLAG_SINGLE_LABEL_SUBDOMAINS,
171cb0ef41Sopenharmony_ci} = internalBinding('crypto');
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ciconst {
201cb0ef41Sopenharmony_ci  PublicKeyObject,
211cb0ef41Sopenharmony_ci  isKeyObject,
221cb0ef41Sopenharmony_ci} = require('internal/crypto/keys');
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ciconst {
251cb0ef41Sopenharmony_ci  customInspectSymbol: kInspect,
261cb0ef41Sopenharmony_ci  kEmptyObject,
271cb0ef41Sopenharmony_ci} = require('internal/util');
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ciconst {
301cb0ef41Sopenharmony_ci  validateBoolean,
311cb0ef41Sopenharmony_ci  validateObject,
321cb0ef41Sopenharmony_ci  validateString,
331cb0ef41Sopenharmony_ci} = require('internal/validators');
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ciconst { inspect } = require('internal/util/inspect');
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ciconst { Buffer } = require('buffer');
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ciconst {
401cb0ef41Sopenharmony_ci  isArrayBufferView,
411cb0ef41Sopenharmony_ci} = require('internal/util/types');
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ciconst {
441cb0ef41Sopenharmony_ci  codes: {
451cb0ef41Sopenharmony_ci    ERR_INVALID_ARG_TYPE,
461cb0ef41Sopenharmony_ci    ERR_INVALID_ARG_VALUE,
471cb0ef41Sopenharmony_ci  },
481cb0ef41Sopenharmony_ci} = require('internal/errors');
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ciconst {
511cb0ef41Sopenharmony_ci  JSTransferable,
521cb0ef41Sopenharmony_ci  kClone,
531cb0ef41Sopenharmony_ci  kDeserialize,
541cb0ef41Sopenharmony_ci} = require('internal/worker/js_transferable');
551cb0ef41Sopenharmony_ci
561cb0ef41Sopenharmony_ciconst {
571cb0ef41Sopenharmony_ci  kHandle,
581cb0ef41Sopenharmony_ci} = require('internal/crypto/util');
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_cilet lazyTranslatePeerCertificate;
611cb0ef41Sopenharmony_ci
621cb0ef41Sopenharmony_ciconst kInternalState = Symbol('kInternalState');
631cb0ef41Sopenharmony_ci
641cb0ef41Sopenharmony_cifunction isX509Certificate(value) {
651cb0ef41Sopenharmony_ci  return value[kInternalState] !== undefined;
661cb0ef41Sopenharmony_ci}
671cb0ef41Sopenharmony_ci
681cb0ef41Sopenharmony_cifunction getFlags(options = kEmptyObject) {
691cb0ef41Sopenharmony_ci  validateObject(options, 'options');
701cb0ef41Sopenharmony_ci  const {
711cb0ef41Sopenharmony_ci    subject = 'default',  // Can be 'default', 'always', or 'never'
721cb0ef41Sopenharmony_ci    wildcards = true,
731cb0ef41Sopenharmony_ci    partialWildcards = true,
741cb0ef41Sopenharmony_ci    multiLabelWildcards = false,
751cb0ef41Sopenharmony_ci    singleLabelSubdomains = false,
761cb0ef41Sopenharmony_ci  } = { ...options };
771cb0ef41Sopenharmony_ci  let flags = 0;
781cb0ef41Sopenharmony_ci  validateString(subject, 'options.subject');
791cb0ef41Sopenharmony_ci  validateBoolean(wildcards, 'options.wildcards');
801cb0ef41Sopenharmony_ci  validateBoolean(partialWildcards, 'options.partialWildcards');
811cb0ef41Sopenharmony_ci  validateBoolean(multiLabelWildcards, 'options.multiLabelWildcards');
821cb0ef41Sopenharmony_ci  validateBoolean(singleLabelSubdomains, 'options.singleLabelSubdomains');
831cb0ef41Sopenharmony_ci  switch (subject) {
841cb0ef41Sopenharmony_ci    case 'default': /* Matches OpenSSL's default, no flags. */ break;
851cb0ef41Sopenharmony_ci    case 'always': flags |= X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT; break;
861cb0ef41Sopenharmony_ci    case 'never': flags |= X509_CHECK_FLAG_NEVER_CHECK_SUBJECT; break;
871cb0ef41Sopenharmony_ci    default:
881cb0ef41Sopenharmony_ci      throw new ERR_INVALID_ARG_VALUE('options.subject', subject);
891cb0ef41Sopenharmony_ci  }
901cb0ef41Sopenharmony_ci  if (!wildcards) flags |= X509_CHECK_FLAG_NO_WILDCARDS;
911cb0ef41Sopenharmony_ci  if (!partialWildcards) flags |= X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS;
921cb0ef41Sopenharmony_ci  if (multiLabelWildcards) flags |= X509_CHECK_FLAG_MULTI_LABEL_WILDCARDS;
931cb0ef41Sopenharmony_ci  if (singleLabelSubdomains) flags |= X509_CHECK_FLAG_SINGLE_LABEL_SUBDOMAINS;
941cb0ef41Sopenharmony_ci  return flags;
951cb0ef41Sopenharmony_ci}
961cb0ef41Sopenharmony_ci
971cb0ef41Sopenharmony_ciclass InternalX509Certificate extends JSTransferable {
981cb0ef41Sopenharmony_ci  [kInternalState] = new SafeMap();
991cb0ef41Sopenharmony_ci
1001cb0ef41Sopenharmony_ci  constructor(handle) {
1011cb0ef41Sopenharmony_ci    super();
1021cb0ef41Sopenharmony_ci    this[kHandle] = handle;
1031cb0ef41Sopenharmony_ci  }
1041cb0ef41Sopenharmony_ci}
1051cb0ef41Sopenharmony_ci
1061cb0ef41Sopenharmony_ciclass X509Certificate extends JSTransferable {
1071cb0ef41Sopenharmony_ci  [kInternalState] = new SafeMap();
1081cb0ef41Sopenharmony_ci
1091cb0ef41Sopenharmony_ci  constructor(buffer) {
1101cb0ef41Sopenharmony_ci    if (typeof buffer === 'string')
1111cb0ef41Sopenharmony_ci      buffer = Buffer.from(buffer);
1121cb0ef41Sopenharmony_ci    if (!isArrayBufferView(buffer)) {
1131cb0ef41Sopenharmony_ci      throw new ERR_INVALID_ARG_TYPE(
1141cb0ef41Sopenharmony_ci        'buffer',
1151cb0ef41Sopenharmony_ci        ['string', 'Buffer', 'TypedArray', 'DataView'],
1161cb0ef41Sopenharmony_ci        buffer);
1171cb0ef41Sopenharmony_ci    }
1181cb0ef41Sopenharmony_ci    super();
1191cb0ef41Sopenharmony_ci    this[kHandle] = parseX509(buffer);
1201cb0ef41Sopenharmony_ci  }
1211cb0ef41Sopenharmony_ci
1221cb0ef41Sopenharmony_ci  [kInspect](depth, options) {
1231cb0ef41Sopenharmony_ci    if (depth < 0)
1241cb0ef41Sopenharmony_ci      return this;
1251cb0ef41Sopenharmony_ci
1261cb0ef41Sopenharmony_ci    const opts = {
1271cb0ef41Sopenharmony_ci      ...options,
1281cb0ef41Sopenharmony_ci      depth: options.depth == null ? null : options.depth - 1,
1291cb0ef41Sopenharmony_ci    };
1301cb0ef41Sopenharmony_ci
1311cb0ef41Sopenharmony_ci    return `X509Certificate ${inspect({
1321cb0ef41Sopenharmony_ci      subject: this.subject,
1331cb0ef41Sopenharmony_ci      subjectAltName: this.subjectAltName,
1341cb0ef41Sopenharmony_ci      issuer: this.issuer,
1351cb0ef41Sopenharmony_ci      infoAccess: this.infoAccess,
1361cb0ef41Sopenharmony_ci      validFrom: this.validFrom,
1371cb0ef41Sopenharmony_ci      validTo: this.validTo,
1381cb0ef41Sopenharmony_ci      fingerprint: this.fingerprint,
1391cb0ef41Sopenharmony_ci      fingerprint256: this.fingerprint256,
1401cb0ef41Sopenharmony_ci      fingerprint512: this.fingerprint512,
1411cb0ef41Sopenharmony_ci      keyUsage: this.keyUsage,
1421cb0ef41Sopenharmony_ci      serialNumber: this.serialNumber,
1431cb0ef41Sopenharmony_ci    }, opts)}`;
1441cb0ef41Sopenharmony_ci  }
1451cb0ef41Sopenharmony_ci
1461cb0ef41Sopenharmony_ci  [kClone]() {
1471cb0ef41Sopenharmony_ci    const handle = this[kHandle];
1481cb0ef41Sopenharmony_ci    return {
1491cb0ef41Sopenharmony_ci      data: { handle },
1501cb0ef41Sopenharmony_ci      deserializeInfo: 'internal/crypto/x509:InternalX509Certificate',
1511cb0ef41Sopenharmony_ci    };
1521cb0ef41Sopenharmony_ci  }
1531cb0ef41Sopenharmony_ci
1541cb0ef41Sopenharmony_ci  [kDeserialize]({ handle }) {
1551cb0ef41Sopenharmony_ci    this[kHandle] = handle;
1561cb0ef41Sopenharmony_ci  }
1571cb0ef41Sopenharmony_ci
1581cb0ef41Sopenharmony_ci  get subject() {
1591cb0ef41Sopenharmony_ci    let value = this[kInternalState].get('subject');
1601cb0ef41Sopenharmony_ci    if (value === undefined) {
1611cb0ef41Sopenharmony_ci      value = this[kHandle].subject();
1621cb0ef41Sopenharmony_ci      this[kInternalState].set('subject', value);
1631cb0ef41Sopenharmony_ci    }
1641cb0ef41Sopenharmony_ci    return value;
1651cb0ef41Sopenharmony_ci  }
1661cb0ef41Sopenharmony_ci
1671cb0ef41Sopenharmony_ci  get subjectAltName() {
1681cb0ef41Sopenharmony_ci    let value = this[kInternalState].get('subjectAltName');
1691cb0ef41Sopenharmony_ci    if (value === undefined) {
1701cb0ef41Sopenharmony_ci      value = this[kHandle].subjectAltName();
1711cb0ef41Sopenharmony_ci      this[kInternalState].set('subjectAltName', value);
1721cb0ef41Sopenharmony_ci    }
1731cb0ef41Sopenharmony_ci    return value;
1741cb0ef41Sopenharmony_ci  }
1751cb0ef41Sopenharmony_ci
1761cb0ef41Sopenharmony_ci  get issuer() {
1771cb0ef41Sopenharmony_ci    let value = this[kInternalState].get('issuer');
1781cb0ef41Sopenharmony_ci    if (value === undefined) {
1791cb0ef41Sopenharmony_ci      value = this[kHandle].issuer();
1801cb0ef41Sopenharmony_ci      this[kInternalState].set('issuer', value);
1811cb0ef41Sopenharmony_ci    }
1821cb0ef41Sopenharmony_ci    return value;
1831cb0ef41Sopenharmony_ci  }
1841cb0ef41Sopenharmony_ci
1851cb0ef41Sopenharmony_ci  get issuerCertificate() {
1861cb0ef41Sopenharmony_ci    let value = this[kInternalState].get('issuerCertificate');
1871cb0ef41Sopenharmony_ci    if (value === undefined) {
1881cb0ef41Sopenharmony_ci      const cert = this[kHandle].getIssuerCert();
1891cb0ef41Sopenharmony_ci      if (cert)
1901cb0ef41Sopenharmony_ci        value = new InternalX509Certificate(this[kHandle].getIssuerCert());
1911cb0ef41Sopenharmony_ci      this[kInternalState].set('issuerCertificate', value);
1921cb0ef41Sopenharmony_ci    }
1931cb0ef41Sopenharmony_ci    return value;
1941cb0ef41Sopenharmony_ci  }
1951cb0ef41Sopenharmony_ci
1961cb0ef41Sopenharmony_ci  get infoAccess() {
1971cb0ef41Sopenharmony_ci    let value = this[kInternalState].get('infoAccess');
1981cb0ef41Sopenharmony_ci    if (value === undefined) {
1991cb0ef41Sopenharmony_ci      value = this[kHandle].infoAccess();
2001cb0ef41Sopenharmony_ci      this[kInternalState].set('infoAccess', value);
2011cb0ef41Sopenharmony_ci    }
2021cb0ef41Sopenharmony_ci    return value;
2031cb0ef41Sopenharmony_ci  }
2041cb0ef41Sopenharmony_ci
2051cb0ef41Sopenharmony_ci  get validFrom() {
2061cb0ef41Sopenharmony_ci    let value = this[kInternalState].get('validFrom');
2071cb0ef41Sopenharmony_ci    if (value === undefined) {
2081cb0ef41Sopenharmony_ci      value = this[kHandle].validFrom();
2091cb0ef41Sopenharmony_ci      this[kInternalState].set('validFrom', value);
2101cb0ef41Sopenharmony_ci    }
2111cb0ef41Sopenharmony_ci    return value;
2121cb0ef41Sopenharmony_ci  }
2131cb0ef41Sopenharmony_ci
2141cb0ef41Sopenharmony_ci  get validTo() {
2151cb0ef41Sopenharmony_ci    let value = this[kInternalState].get('validTo');
2161cb0ef41Sopenharmony_ci    if (value === undefined) {
2171cb0ef41Sopenharmony_ci      value = this[kHandle].validTo();
2181cb0ef41Sopenharmony_ci      this[kInternalState].set('validTo', value);
2191cb0ef41Sopenharmony_ci    }
2201cb0ef41Sopenharmony_ci    return value;
2211cb0ef41Sopenharmony_ci  }
2221cb0ef41Sopenharmony_ci
2231cb0ef41Sopenharmony_ci  get fingerprint() {
2241cb0ef41Sopenharmony_ci    let value = this[kInternalState].get('fingerprint');
2251cb0ef41Sopenharmony_ci    if (value === undefined) {
2261cb0ef41Sopenharmony_ci      value = this[kHandle].fingerprint();
2271cb0ef41Sopenharmony_ci      this[kInternalState].set('fingerprint', value);
2281cb0ef41Sopenharmony_ci    }
2291cb0ef41Sopenharmony_ci    return value;
2301cb0ef41Sopenharmony_ci  }
2311cb0ef41Sopenharmony_ci
2321cb0ef41Sopenharmony_ci  get fingerprint256() {
2331cb0ef41Sopenharmony_ci    let value = this[kInternalState].get('fingerprint256');
2341cb0ef41Sopenharmony_ci    if (value === undefined) {
2351cb0ef41Sopenharmony_ci      value = this[kHandle].fingerprint256();
2361cb0ef41Sopenharmony_ci      this[kInternalState].set('fingerprint256', value);
2371cb0ef41Sopenharmony_ci    }
2381cb0ef41Sopenharmony_ci    return value;
2391cb0ef41Sopenharmony_ci  }
2401cb0ef41Sopenharmony_ci
2411cb0ef41Sopenharmony_ci  get fingerprint512() {
2421cb0ef41Sopenharmony_ci    let value = this[kInternalState].get('fingerprint512');
2431cb0ef41Sopenharmony_ci    if (value === undefined) {
2441cb0ef41Sopenharmony_ci      value = this[kHandle].fingerprint512();
2451cb0ef41Sopenharmony_ci      this[kInternalState].set('fingerprint512', value);
2461cb0ef41Sopenharmony_ci    }
2471cb0ef41Sopenharmony_ci    return value;
2481cb0ef41Sopenharmony_ci  }
2491cb0ef41Sopenharmony_ci
2501cb0ef41Sopenharmony_ci  get keyUsage() {
2511cb0ef41Sopenharmony_ci    let value = this[kInternalState].get('keyUsage');
2521cb0ef41Sopenharmony_ci    if (value === undefined) {
2531cb0ef41Sopenharmony_ci      value = this[kHandle].keyUsage();
2541cb0ef41Sopenharmony_ci      this[kInternalState].set('keyUsage', value);
2551cb0ef41Sopenharmony_ci    }
2561cb0ef41Sopenharmony_ci    return value;
2571cb0ef41Sopenharmony_ci  }
2581cb0ef41Sopenharmony_ci
2591cb0ef41Sopenharmony_ci  get serialNumber() {
2601cb0ef41Sopenharmony_ci    let value = this[kInternalState].get('serialNumber');
2611cb0ef41Sopenharmony_ci    if (value === undefined) {
2621cb0ef41Sopenharmony_ci      value = this[kHandle].serialNumber();
2631cb0ef41Sopenharmony_ci      this[kInternalState].set('serialNumber', value);
2641cb0ef41Sopenharmony_ci    }
2651cb0ef41Sopenharmony_ci    return value;
2661cb0ef41Sopenharmony_ci  }
2671cb0ef41Sopenharmony_ci
2681cb0ef41Sopenharmony_ci  get raw() {
2691cb0ef41Sopenharmony_ci    let value = this[kInternalState].get('raw');
2701cb0ef41Sopenharmony_ci    if (value === undefined) {
2711cb0ef41Sopenharmony_ci      value = this[kHandle].raw();
2721cb0ef41Sopenharmony_ci      this[kInternalState].set('raw', value);
2731cb0ef41Sopenharmony_ci    }
2741cb0ef41Sopenharmony_ci    return value;
2751cb0ef41Sopenharmony_ci  }
2761cb0ef41Sopenharmony_ci
2771cb0ef41Sopenharmony_ci  get publicKey() {
2781cb0ef41Sopenharmony_ci    let value = this[kInternalState].get('publicKey');
2791cb0ef41Sopenharmony_ci    if (value === undefined) {
2801cb0ef41Sopenharmony_ci      value = new PublicKeyObject(this[kHandle].publicKey());
2811cb0ef41Sopenharmony_ci      this[kInternalState].set('publicKey', value);
2821cb0ef41Sopenharmony_ci    }
2831cb0ef41Sopenharmony_ci    return value;
2841cb0ef41Sopenharmony_ci  }
2851cb0ef41Sopenharmony_ci
2861cb0ef41Sopenharmony_ci  toString() {
2871cb0ef41Sopenharmony_ci    let value = this[kInternalState].get('pem');
2881cb0ef41Sopenharmony_ci    if (value === undefined) {
2891cb0ef41Sopenharmony_ci      value = this[kHandle].pem();
2901cb0ef41Sopenharmony_ci      this[kInternalState].set('pem', value);
2911cb0ef41Sopenharmony_ci    }
2921cb0ef41Sopenharmony_ci    return value;
2931cb0ef41Sopenharmony_ci  }
2941cb0ef41Sopenharmony_ci
2951cb0ef41Sopenharmony_ci  // There's no standardized JSON encoding for X509 certs so we
2961cb0ef41Sopenharmony_ci  // fallback to providing the PEM encoding as a string.
2971cb0ef41Sopenharmony_ci  toJSON() { return this.toString(); }
2981cb0ef41Sopenharmony_ci
2991cb0ef41Sopenharmony_ci  get ca() {
3001cb0ef41Sopenharmony_ci    let value = this[kInternalState].get('ca');
3011cb0ef41Sopenharmony_ci    if (value === undefined) {
3021cb0ef41Sopenharmony_ci      value = this[kHandle].checkCA();
3031cb0ef41Sopenharmony_ci      this[kInternalState].set('ca', value);
3041cb0ef41Sopenharmony_ci    }
3051cb0ef41Sopenharmony_ci    return value;
3061cb0ef41Sopenharmony_ci  }
3071cb0ef41Sopenharmony_ci
3081cb0ef41Sopenharmony_ci  checkHost(name, options) {
3091cb0ef41Sopenharmony_ci    validateString(name, 'name');
3101cb0ef41Sopenharmony_ci    return this[kHandle].checkHost(name, getFlags(options));
3111cb0ef41Sopenharmony_ci  }
3121cb0ef41Sopenharmony_ci
3131cb0ef41Sopenharmony_ci  checkEmail(email, options) {
3141cb0ef41Sopenharmony_ci    validateString(email, 'email');
3151cb0ef41Sopenharmony_ci    return this[kHandle].checkEmail(email, getFlags(options));
3161cb0ef41Sopenharmony_ci  }
3171cb0ef41Sopenharmony_ci
3181cb0ef41Sopenharmony_ci  checkIP(ip, options) {
3191cb0ef41Sopenharmony_ci    validateString(ip, 'ip');
3201cb0ef41Sopenharmony_ci    // The options argument is currently undocumented since none of the options
3211cb0ef41Sopenharmony_ci    // have any effect on the behavior of this function. However, we still parse
3221cb0ef41Sopenharmony_ci    // the options argument in case OpenSSL adds flags in the future that do
3231cb0ef41Sopenharmony_ci    // affect the behavior of X509_check_ip. This ensures that no invalid values
3241cb0ef41Sopenharmony_ci    // are passed as the second argument in the meantime.
3251cb0ef41Sopenharmony_ci    return this[kHandle].checkIP(ip, getFlags(options));
3261cb0ef41Sopenharmony_ci  }
3271cb0ef41Sopenharmony_ci
3281cb0ef41Sopenharmony_ci  checkIssued(otherCert) {
3291cb0ef41Sopenharmony_ci    if (!isX509Certificate(otherCert))
3301cb0ef41Sopenharmony_ci      throw new ERR_INVALID_ARG_TYPE('otherCert', 'X509Certificate', otherCert);
3311cb0ef41Sopenharmony_ci    return this[kHandle].checkIssued(otherCert[kHandle]);
3321cb0ef41Sopenharmony_ci  }
3331cb0ef41Sopenharmony_ci
3341cb0ef41Sopenharmony_ci  checkPrivateKey(pkey) {
3351cb0ef41Sopenharmony_ci    if (!isKeyObject(pkey))
3361cb0ef41Sopenharmony_ci      throw new ERR_INVALID_ARG_TYPE('pkey', 'KeyObject', pkey);
3371cb0ef41Sopenharmony_ci    if (pkey.type !== 'private')
3381cb0ef41Sopenharmony_ci      throw new ERR_INVALID_ARG_VALUE('pkey', pkey);
3391cb0ef41Sopenharmony_ci    return this[kHandle].checkPrivateKey(pkey[kHandle]);
3401cb0ef41Sopenharmony_ci  }
3411cb0ef41Sopenharmony_ci
3421cb0ef41Sopenharmony_ci  verify(pkey) {
3431cb0ef41Sopenharmony_ci    if (!isKeyObject(pkey))
3441cb0ef41Sopenharmony_ci      throw new ERR_INVALID_ARG_TYPE('pkey', 'KeyObject', pkey);
3451cb0ef41Sopenharmony_ci    if (pkey.type !== 'public')
3461cb0ef41Sopenharmony_ci      throw new ERR_INVALID_ARG_VALUE('pkey', pkey);
3471cb0ef41Sopenharmony_ci    return this[kHandle].verify(pkey[kHandle]);
3481cb0ef41Sopenharmony_ci  }
3491cb0ef41Sopenharmony_ci
3501cb0ef41Sopenharmony_ci  toLegacyObject() {
3511cb0ef41Sopenharmony_ci    // TODO(tniessen): do not depend on translatePeerCertificate here, return
3521cb0ef41Sopenharmony_ci    // the correct legacy representation from the binding
3531cb0ef41Sopenharmony_ci    lazyTranslatePeerCertificate ??=
3541cb0ef41Sopenharmony_ci      require('_tls_common').translatePeerCertificate;
3551cb0ef41Sopenharmony_ci    return lazyTranslatePeerCertificate(this[kHandle].toLegacy());
3561cb0ef41Sopenharmony_ci  }
3571cb0ef41Sopenharmony_ci}
3581cb0ef41Sopenharmony_ci
3591cb0ef41Sopenharmony_ciInternalX509Certificate.prototype.constructor = X509Certificate;
3601cb0ef41Sopenharmony_ciObjectSetPrototypeOf(
3611cb0ef41Sopenharmony_ci  InternalX509Certificate.prototype,
3621cb0ef41Sopenharmony_ci  X509Certificate.prototype);
3631cb0ef41Sopenharmony_ci
3641cb0ef41Sopenharmony_cimodule.exports = {
3651cb0ef41Sopenharmony_ci  X509Certificate,
3661cb0ef41Sopenharmony_ci  InternalX509Certificate,
3671cb0ef41Sopenharmony_ci  isX509Certificate,
3681cb0ef41Sopenharmony_ci};
369