Skip to content

the certificate cannot be created on node 18 #80

@bjohansebas

Description

@bjohansebas

Hi! When running the following code, the certificate cannot be created. This happens when running on Node.js 18; it works on Node.js 20. For now, I haven’t investigated the root cause in depth—I only know that it’s related to the @peculiar/x509 package. This issue prevents webpack from being able to update (webpack/webpack-dev-server#5618).

const selfsigned = require("selfsigned");

const attributes = [{ name: "commonName", value: "localhost" }];
const notBeforeDate = new Date();
const notAfterDate = new Date();
notAfterDate.setDate(notAfterDate.getDate() + 30);
(async () => {
    await selfsigned.generate(attributes, {
    algorithm: "sha256",
    keySize: 2048,
    notBeforeDate,
    notAfterDate,
    extensions: [
      {
        name: "basicConstraints",
        cA: true,
      },
      {
        name: "keyUsage",
        keyCertSign: true,
        digitalSignature: true,
        nonRepudiation: true,
        keyEncipherment: true,
        dataEncipherment: true,
      },
      {
        name: "extKeyUsage",
        serverAuth: true,
        clientAuth: true,
        codeSigning: true,
        timeStamping: true,
      },
      {
        name: "subjectAltName",
        altNames: [
          {
            // type 2 is DNS
            type: 2,
            value: "localhost",
          },
          {
            type: 2,
            value: "localhost.localdomain",
          },
          {
            type: 2,
            value: "lvh.me",
          },
          {
            type: 2,
            value: "*.lvh.me",
          },
          {
            type: 2,
            value: "[::1]",
          },
          {
            // type 7 is IP
            type: 7,
            ip: "127.0.0.1",
          },
          {
            type: 7,
            ip: "fe80::1",
          },
        ],
      },
    ],
  });
})()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions