joebandenburg / libaxolotl-javascript

A JavaScript implementation of axolotl. Axolotl is a ratcheting forward secrecy protocol.
GNU Lesser General Public License v3.0
75 stars 13 forks source link

handlePreKeyWhisperMessage does not return any results #13

Open eduardosan opened 8 years ago

eduardosan commented 8 years ago

Hi, I'm trying to use axolotl to open an encrypted message and I believe I'm missing something. I have created a class that implements store interface with all the mandatory methods. The axolotl is used like this:

function LiteAxolotlStore() {
    this.db = new JsonDB('/tmp/whatsapp', true, true);
    this.identityKeyStore = new LiteIdentityKeyStore(this.db);

    // This is axol instance with mandatory methods
    this.axol = axolotl(this.identityKeyStore);

}

This class is called by another one later like this:

function AxolotlLayer() {
    this.store = new LiteAxolotlStore();
}

Then I use it to unencrypt and incoming pkmsg like this:

AxolotlLayer.prototype.handlePreKeyWhisperMessage = function(node, callback) {
    var context = this;
    var from = node.attribute('from');
    var data = node.child('enc').data();

      this.store.axol.decryptPreKeyWhisperMessage(from, data).then(function(plaintext, err) {

        if (err) {
            console.error("AXOLOTL: Decryption error!");
            console.error(err);
        } else {
            console.log("AXOLOTL: Decryption completed!");
            console.log(plaintext);

            if (node.child('enc').attribute('v') == 2) {
                plaintext = context.unpadV2Plaintext(plaintext);
            }

            // Execute callback to send the message
            callback(plaintext);
        }
    });
};

The problem is: nothing happens when I call decryptPreKeyWhisperMessage. It does not write anything to log, neither show any error messages. Can you tell me what am I missing? How can I debug decryptPreKeyWhisperMessage?

yahely commented 8 years ago

Hi Eduard, Can you write here your implementation of Store.js ? We are also trying to implement and having some problems in storing keys in chrome storage

joebandenburg commented 8 years ago

@eduardosan The documentation is a little out of date, sorry about that.

Check out the source. Here's the JSDoc:

    /**
     * Unwrap the WhisperMessage from a PreKeyWhisperMessage and attempt to decrypt it using session. If a session does
     * not already exist, it will be created.
     *
     * @method
     * @param {Session} session - a session, if one exists, or null otherwise.
     * @param {ArrayBuffer} preKeyWhisperMessageBytes - the encrypted message bytes
     * @returns {Promise.<Object, InvalidMessageException>} an object containing the decrypted message and a new session
     */

I changed the API so that Axolotl itself is stateless and you need to explicitly pass in a session object. You'll get a new session in the response, which should replace the one that was passed in.

joebandenburg commented 8 years ago

As mentioned in #14 I think the documentation could use some improvements.