How to use the pkijs.AttributeTypeAndValue function in pkijs

To help you get started, we’ve selected a few pkijs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PeculiarVentures / fortify / src / main / ssl.ts View on Github external
async function GenerateCertificate(keyPair: CryptoKeyPair, caKey: CryptoKey) {
  const certificate = new pkijs.Certificate();

  // region Put a static values
  certificate.version = 2;
  const serialNumber = crypto.getRandomValues(new Uint8Array(10));
  certificate.serialNumber = new asn1js.Integer();
  certificate.serialNumber.valueBlock.valueHex = serialNumber.buffer;

  const commonName = new pkijs.AttributeTypeAndValue({
    type: "2.5.4.3", // Common name
    value: new asn1js.PrintableString({ value: process.env.FORTIFY_SSL_CN || "127.0.0.1" }),
  });

  certificate.subject.typesAndValues.push(commonName);
  certificate.issuer.typesAndValues.push(new pkijs.AttributeTypeAndValue({
    type: "2.5.4.3", // Common name
    value: new asn1js.PrintableString({ value: "Fortify Local CA" }),
  }));

  // Valid period is 1 year
  certificate.notBefore.value = new Date(); // current date
  const notAfter = new Date();
  notAfter.setFullYear(notAfter.getFullYear() + 1);
  certificate.notAfter.value = notAfter;

  certificate.extensions = []; // Extensions are not a part of certificate by default, it's an optional array

  // Extended key usage
  const extKeyUsage = new pkijs.ExtKeyUsage({
    keyPurposes: ["1.3.6.1.5.5.7.3.1"],
  });
github PeculiarVentures / fortify / src / main / ssl.ts View on Github external
async function GenerateCertificate(keyPair: CryptoKeyPair, caKey: CryptoKey) {
  const certificate = new pkijs.Certificate();

  // region Put a static values
  certificate.version = 2;
  const serialNumber = crypto.getRandomValues(new Uint8Array(10));
  certificate.serialNumber = new asn1js.Integer();
  certificate.serialNumber.valueBlock.valueHex = serialNumber.buffer;

  const commonName = new pkijs.AttributeTypeAndValue({
    type: "2.5.4.3", // Common name
    value: new asn1js.PrintableString({ value: process.env.FORTIFY_SSL_CN || "fortifyapp.com" }),
  });

  certificate.subject.typesAndValues.push(commonName);
  certificate.issuer.typesAndValues.push(new pkijs.AttributeTypeAndValue({
    type: "2.5.4.3", // Common name
    value: new asn1js.PrintableString({ value: "Fortify Local CA" }),
  }));

  // Valid period is 1 year
  certificate.notBefore.value = new Date(); // current date
  const notAfter = new Date();
  notAfter.setFullYear(notAfter.getFullYear() + 1);
  certificate.notAfter.value = notAfter;

  certificate.extensions = []; // Extensions are not a part of certificate by default, it's an optional array

  // Extended key usage
  const extKeyUsage = new pkijs.ExtKeyUsage({
    keyPurposes: ["1.3.6.1.5.5.7.3.1"],
  });
github PeculiarVentures / fortify / src / main / ssl.ts View on Github external
async function GenerateCertificate(keyPair: CryptoKeyPair, caKey: CryptoKey) {
  const certificate = new pkijs.Certificate();

  // region Put a static values
  certificate.version = 2;
  const serialNumber = crypto.getRandomValues(new Uint8Array(10));
  certificate.serialNumber = new asn1js.Integer();
  certificate.serialNumber.valueBlock.valueHex = serialNumber.buffer;

  const commonName = new pkijs.AttributeTypeAndValue({
    type: "2.5.4.3", // Common name
    value: new asn1js.PrintableString({ value: process.env.FORTIFY_SSL_CN || "127.0.0.1" }),
  });

  certificate.subject.typesAndValues.push(commonName);
  certificate.issuer.typesAndValues.push(new pkijs.AttributeTypeAndValue({
    type: "2.5.4.3", // Common name
    value: new asn1js.PrintableString({ value: "Fortify Local CA" }),
  }));

  // Valid period is 1 year
  certificate.notBefore.value = new Date(); // current date
  const notAfter = new Date();
  notAfter.setFullYear(notAfter.getFullYear() + 1);
  certificate.notAfter.value = notAfter;
github PeculiarVentures / fortify / src / main / ssl.ts View on Github external
async function GenerateCertificateCA(keyPair: CryptoKeyPair) {
  const certificate = new pkijs.Certificate();

  // region Put a static values
  certificate.version = 2;
  const serialNumber = crypto.getRandomValues(new Uint8Array(10));
  certificate.serialNumber = new asn1js.Integer();
  certificate.serialNumber.valueBlock.valueHex = serialNumber.buffer;

  const commonName = new pkijs.AttributeTypeAndValue({
    type: "2.5.4.3", // Common name
    value: new asn1js.PrintableString({ value: "Fortify Local CA" }),
  });

  certificate.issuer.typesAndValues.push(commonName);
  certificate.subject.typesAndValues.push(commonName);

  // Valid period is 1 year
  certificate.notBefore.value = new Date(); // current date
  const notAfter = new Date();
  notAfter.setFullYear(notAfter.getFullYear() + 1);
  certificate.notAfter.value = notAfter;

  certificate.extensions = []; // Extensions are not a part of certificate by default, it's an optional array

  // Basic constraints
github PeculiarVentures / fortify / src / main / ssl.ts View on Github external
async function GenerateCertificate(keyPair: CryptoKeyPair, caKey: CryptoKey) {
  const certificate = new pkijs.Certificate();

  // region Put a static values
  certificate.version = 2;
  const serialNumber = crypto.getRandomValues(new Uint8Array(10));
  certificate.serialNumber = new asn1js.Integer();
  certificate.serialNumber.valueBlock.valueHex = serialNumber.buffer;

  const commonName = new pkijs.AttributeTypeAndValue({
    type: "2.5.4.3", // Common name
    value: new asn1js.PrintableString({ value: process.env.FORTIFY_SSL_CN || "fortifyapp.com" }),
  });

  certificate.subject.typesAndValues.push(commonName);
  certificate.issuer.typesAndValues.push(new pkijs.AttributeTypeAndValue({
    type: "2.5.4.3", // Common name
    value: new asn1js.PrintableString({ value: "Fortify Local CA" }),
  }));

  // Valid period is 1 year
  certificate.notBefore.value = new Date(); // current date
  const notAfter = new Date();
  notAfter.setFullYear(notAfter.getFullYear() + 1);
  certificate.notAfter.value = notAfter;
github PeculiarVentures / fortify / src / main / ssl.ts View on Github external
async function GenerateCertificateCA(keyPair: CryptoKeyPair) {
  const certificate = new pkijs.Certificate();

  // region Put a static values
  certificate.version = 2;
  const serialNumber = crypto.getRandomValues(new Uint8Array(10));
  certificate.serialNumber = new asn1js.Integer();
  certificate.serialNumber.valueBlock.valueHex = serialNumber.buffer;

  const commonName = new pkijs.AttributeTypeAndValue({
    type: "2.5.4.3", // Common name
    value: new asn1js.PrintableString({ value: "Fortify Local CA" }),
  });

  certificate.issuer.typesAndValues.push(commonName);
  certificate.subject.typesAndValues.push(commonName);

  // Valid period is 1 year
  certificate.notBefore.value = new Date(); // current date
  const notAfter = new Date();
  notAfter.setFullYear(notAfter.getFullYear() + 1);
  certificate.notAfter.value = notAfter;

  certificate.extensions = []; // Extensions are not a part of certificate by default, it's an optional array

  // Basic constraints

pkijs

Public Key Infrastructure (PKI) is the basis of how identity and key management is performed on the web today. PKIjs is a pure JavaScript library implementing the formats that are used in PKI applications. It is built on WebCrypto and aspires to make it p

BSD-3-Clause
Latest version published 4 months ago

Package Health Score

80 / 100
Full package analysis