Programmers of ieddit - I need your help. Ive literally spent 5 hours straight on this, and am no closer to figuring it out. Admin account to whoever can point out wtf is going wrong
  • comment-white.png
    *
    /i/ieddit
    3y
    Programmers of ieddit - I need your help. Ive literally spent 5 hours straight on this, and am no closer to figuring it out. Admin account to whoever can point out wtf is going wrong (text)
  • I don't use javascript so can't be of much direct help with that code, but having programmed this type of thing before, it's just in the nature of crypto that the slighest error or discrepancy makes stuff break completely. You have to trace the flow of a message step by step through the decoding process and see where it is going wrong, e.g. by testing that all the steps up to the current one reverse properly, etc. If the process uses random numbers, for debugging you should connect a deterministic RNG so you can repeat runs with the same numbers. The above stuff is not super difficult, but it can be tedious. I didn't even know there was such a thing as an in-browser openpgp module. That is cool.
    1
    reply
  • 3y
    parent [-]
    You have to trace the flow of a message step by step through the decoding process and see where it is going wrong, e.g. by testing that all the steps up to the current one reverse properly, etc
    I've did that. If you look at the code on github, there are quite a few console.logs in the function that is breaking. EVERY parameter has the correct data, it's just the final decrypt that things fail.


    Either the incorrect pubkey is being used for encryption, or the encrypted message is somehow becoming malformed, or there is a bug in the library which is above my pay grade (and VERY unlikely. it's astronomically more likely i'm the one fucking things up). There is also a chance the parameter data is correct, but being passed in a slightly incorrect format? IE 'string' instead of ['string']


    It's not an RNG issue.


    ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
    1
    reply
  • Sorry I forgot about this. Do you still want help? Is there a simple test case that shows the error? I can take a look at the code.
    2
    reply
  • everything was solved a few days ago :)
    1
    reply

  • Try decomposing your function soup to human-readable chunks.

    Human readable means this:
    function name(paramaters){
    code that deals with this function alone and only calls external functions like this
    a=func(b);
    }

    If you write it this way, the problem will reveal itself shortly.
    1
    reply
  • 3y
    parent [-]
    Ugh, I've been here before on an antiquated Perl environment with terrible documentation. I feel your pain. Sometimes trying it in different ways or seeing the other ways can help. I'm not sure what the specific issue is and don't have too much time to dive in. And I'm sure you've seen this version from the OpenPGP website, but I'm going to post it here for you and anyone else who it might help figure this out:
    const openpgp = require('openpgp') // use as CommonJS, AMD, ES6 module or via window.openpgp await openpgp.initWorker({ path:'openpgp.worker.js' }) // set the relative web worker path // put keys in backtick (``) to avoid errors caused by spaces or tabs const pubkey = `-----BEGIN PGP PUBLIC KEY BLOCK----- ... -----END PGP PUBLIC KEY BLOCK-----` const privkey = `-----BEGIN PGP PRIVATE KEY BLOCK----- ... -----END PGP PRIVATE KEY BLOCK-----` //encrypted private key const passphrase = `yourPassphrase` //what the privKey is encrypted with const encryptDecryptFunction = async() => { const privKeyObj = (await openpgp.key.readArmored(privkey)).keys[0] await privKeyObj.decrypt(passphrase) const options = { message: openpgp.message.fromText('Hello, World!'), // input as Message object publicKeys: (await openpgp.key.readArmored(pubkey)).keys, // for encryption privateKeys: [privKeyObj] // for signing (optional) } openpgp.encrypt(options).then(ciphertext => { encrypted = ciphertext.data // '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----' return encrypted }) .then(async encrypted => { const options = { message: await openpgp.message.readArmored(encrypted), // parse armored message publicKeys: (await openpgp.key.readArmored(pubkey)).keys, // for verification (optional) privateKeys: [privKeyObj] // for decryption } openpgp.decrypt(options).then(plaintext => { console.log(plaintext.data) return plaintext.data // 'Hello, World!' }) }) } encryptDecryptFunction()
    2
    reply
  • I've read this exact example actually.


    The issue with this example is that the encrypted message is meant for the same pubkey/privkey pair. Not two different pairs.


    https://blog.castiel.me/posts/2016-11-16-play-with-cryptography-with-openpgpjs/


    Is the main guide I was following when implementing this. It provides examples of encryption/decryption with two different keypairs.
    2
    reply