Error: Only 8, 16, 24, or 32 bits supported: 608 in certificationRequestFromPem

Aperta
#1,097 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
javascript

Direzione di ricerca

Reproduce the StackBlitz example and compare certificationRequestToPem with certificationRequestFromPem, focusing on the non-ASCII “№” subject values and the reported 608-bit error. Trace the PEM and ASN.1 decoding path from certificationRequestFromPem. Done means the shown CSR round-trips successfully without the error.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Hello!

When I create a certificate request, convert it to PEM format, and then decode it back, I get an error: Error: Only 8, 16, 24, or 32 bits supported: 608.

I'm guessing the problem is that there is a "№" character in my certificate parameters, which I think is causing problems when converting to base64 or vice versa.

Can I somehow avoid this problem?

Example:

https://stackblitz.com/edit/vitejs-vite-dmjz3f?file=main.js

    const keys = pki.rsa.generateKeyPair(2048);
    const csr = pki.createCertificationRequest();

    const subject = [
        {
            name: 'commonName',
            value: '"ITEM №1"',
        },
        {
            name: 'countryName',
            value: 'RU',
        },
        {
            name: 'localityName',
            value: 'G SAMARA',
        },
        {
            name: 'organizationName',
            value: '"ITEM №1"',
        },
        {
            name: 'stateOrProvinceName',
            value: 'SAMARSKAIA',
        },
        {
            name: 'emailAddress',
            value: '[email protected]',
        },
    ];

    const attributes = [
        {
            name: 'extensionRequest',
            extensions: [
                {
                    name: 'keyUsage',
                    digitalSignature: true,
                    nonRepudiation: true,
                    keyEncipherment: true,
                    dataEncipherment: true,
                    keyAgreement: true,
                },
                {
                    name: 'extKeyUsage',
                    clientAuth: true,
                },
            ],
        },
    ];

    csr.publicKey = keys.publicKey;
    csr.setSubject(subject);
    csr.setAttributes(attributes);
    csr.sign(keys.privateKey);

    const rsaPrivateKey = pki.privateKeyToAsn1(keys.privateKey);
    const privateKeyInfo = pki.wrapRsaPrivateKey(rsaPrivateKey);

    const output = {
        privateKey: pki.privateKeyInfoToPem(privateKeyInfo),
        publicKey: pki.publicKeyToPem(keys.publicKey),
        csrKey: pki.certificationRequestToPem(csr), // it's OK
    }

   // decode it
   pki.certificationRequestFromPem(output.csrKey) // Error

Lingua principale
JavaScript
Stelle
5.4k
Fork
874
Merge medio
3m
PR unite (30g)
6

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di digitalbazaar/forge

Tutte le issue di digitalbazaar/forge

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.