Skip to content

Trouble using pkcs12 with https server #406

@dondod

Description

@dondod

Hi, I'm currently trying to upgrade an application from node 10.x to node 22.10.0 and the following now fails for me (when it worked in node 10).

const https = require('https')
const pem = require('pem')
const passphrase = 'topsecret';

pem.createPrivateKey((err, privateKey) => {
    if (err) {
        throw err;
    }

    pem.createCertificate({days: 1, selfSigned: true, clientKey: privateKey.key}, (err, keys) => {
        if (err) {
            throw err;
        }

        pem.createPkcs12(keys.clientKey, keys.certificate, passphrase, (err, pkcs12) => {
            if (err) {
                throw err;
            }

            https.createServer({pfx: pkcs12.pkcs12, passphrase: passphrase}, (req, res) => {
                res.end('foo');
            }).listen(443);
        });
    });
});

The error is thrown at https.createServer. Error message:

Error: Unsupported PKCS12 PFX data
    at configSecureContext (node:internal/tls/secure-context:290:15)
    at Object.createSecureContext (node:_tls_common:114:3)
    at Server.setSecureContext (node:_tls_wrap:1490:27)
    at Server (node:_tls_wrap:1354:8)
    at new Server (node:https:80:3)
    at Object.createServer (node:https:135:10)

Any ideas?

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