Only 8, 16, 24, or 32 bits supported: 248

Aperta
#1,059 4 commenti 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
25/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
javascript

Direzione di ricerca

Start with forge.pki.decryptRsaPrivateKey and its forge.min.js stack frames, especially forge.asn1.fromDer and ByteStringBuffer.getInt. Reproduce the failure with the private keys that produce the 248-bit error, then determine whether the parser should reject or handle that input and add a regression case if a supported-key failure is confirmed.

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

Descrizione

Hello,

I'm trying to decrypt a private key but am getting the following error when trying to decrypt - I was wondering if anyone has seen this before please?

Weirdly, this only seems to be from 'certain' private keys - we have lots of users that decrypt without issue, but every so often we get this error from Forge,

Thanks,

Will.

requestdownload:524 Error: Error: Only 8, 16, 24, or 32 bits supported: 248
    at s (forge.min.js:1:1)
    at i.ByteStringBuffer.getInt (forge.min.js:1:1)
    at forge.min.js:1:1
    at e (forge.min.js:1:1)
    at n.fromDer (forge.min.js:1:1)
    at s.decryptPrivateKeyInfo (forge.min.js:1:1)
    at s.decryptRsaPrivateKey (forge.min.js:1:1)
    at HTMLAnchorElement.<anonymous> (requestdownload:501:54)
    at HTMLAnchorElement.dispatch (jquery.min.js:2:43064)
    at v.handle (jquery.min.js:2:41048)

The code used is as follows:

    const fileSelector = document.getElementById('privateKeyPicker');
    fileSelector.addEventListener('change', () => {
        const fileReader = new FileReader();
        fileReader.onloadend = (function (loadEvent) {
            let textFromFileLoaded = loadEvent.target.result;
            $("#certkey").val(textFromFileLoaded);
            keyValid();
        });
        fileReader.readAsText(document.getElementById('privateKeyPicker').files[0])
    });

    function downloadCert(b64p12) {
        const myBuffer = base64DecToArr(b64p12).buffer;
        const p12blob = new Blob([myBuffer], {type: 'application/x-pkcs12'});
        saveAs(p12blob, "certBundle.p12");
    }

    $(document).ready(function () {
        $("#createP12Button").click(function () {
            //error checking to ensure all fields are filled in
            if ($('#keypass').val() === "" && $('#certkey').val() === "=") {
                alert("Please enter private key password and use 'Choose File' and 'Load File' buttons to select private key (or paste private key into textarea)");
            } else if ($('#keypass').val() === "") {
                alert("Please enter private key password");
            } else if ($('#certkey').val() === "") {
                alert("Please use 'Choose File' and 'Load File' buttons to select your private key (or paste private key into textarea)");
            } else {
                //regex to ensure only private key used from text pasted in
                const regexPrivKey = $("#certkey").val().match(/(-----BEGIN \b(ENCRYPTED|RSA)\b PRIVATE KEY-----)[\s\S]*(-----END \b(ENCRYPTED|RSA)\b PRIVATE KEY-----)/);
                if (regexPrivKey === null) {
                    alert("Private key not found, please ensure correct file has been selected or pasted into text area.");
                } else {
                    const _pem = {
                        certificateDev: $("#certpem").val(),
                        privateKeyDev: regexPrivKey[0]
                    };
                    // Try to parse certificate and private key object
                    try {
                        const cert = forge.pki.certificateFromPem(_pem.certificateDev, true);
                        const password = $('#keypass').val();
                        const privateKey = forge.pki.decryptRsaPrivateKey(_pem.privateKeyDev, password);
                        if (privateKey !== null) {
                            if (privateKey.n.toString() !== cert.publicKey.n.toString()) {
                                alert("Private and public key modulo do not match. Are you sure you uploaded the correct file?")
                            } else {
                                const chain = [cert];
                                //create PKCS12
                                console.log('\nCreating PKCS#12...');
                                const newPkcs12Asn1 = forge.pkcs12.toPkcs12Asn1(privateKey, chain, password,
                                    {generateLocalKeyId: true, friendlyName: 'myUkCaCertificate', algorithm: '3des'});
                                const newPkcs12Der = forge.asn1.toDer(newPkcs12Asn1).getBytes();
                                console.log('\nBase64-encoded new PKCS#12:');
                                const b64p12 = forge.util.encode64(newPkcs12Der);
                                downloadCert(b64p12);
                            }
                        } else {
                            alert("Please enter the correct password for the private key");
                        }
                    } catch (ex) {
                        alert("Could not create private key object - please contact [email protected]");
                        if (ex.stack) {
                            console.log('Error name:', ex.name);
                            console.log('Error message:', ex.message);
                            console.log('Error:', ex);
                            console.log(ex.stack);
                        } else {
                            console.log('Error name:', ex.name);
                            console.log('Error message:', ex.message);
                            console.log('Error:', ex);
                        }
                    }
                }
            }
        });

    });  // end on ready
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.