1
$\begingroup$

I'm trying to implement the Signal Protocol JavaScript library for a school project. On this page, the generatePreKey function takes as parameter a keyId. I can't find what that is in the specifications. Can somebody tell me where do I have to get it from or if it's just a random number I have to generate myself?

KeyHelper.generatePreKey(keyId).then(function(preKey) {
    store.storePreKey(preKey.keyId, preKey.keyPair);
});
$\endgroup$
1
  • $\begingroup$ Those lines explicitly tell. >// Process a prekey fetched from the server. Returns a promise that resolves // once a session is created and saved in the store, or rejects if the // identityKey differs from a previously seen identity for this address. There is not only one key, so each key is separated with an ID. Also, it is clear from InMemorySignalProtocolStore.js. However, there is no information that how it is used. $\endgroup$
    – kelalaka
    Commented Jul 27, 2020 at 20:20

1 Answer 1

0
$\begingroup$

Usually you use these identifiers only for permanent storage. Those keys you will have to look up again, and normally you'd do that using a unique identifier (e.g. a label). Those are generally not random, and if they are random, then they should be 128 bits or higher to avoid collisions (i.e. two keys possibly sharing the same number).

After some advanced Internet searching, I found the following tidbit:

After the account is created, the user can upload the keys to the server. The identity_key and public_keys are both Curve25519 Base64 encoded public keys with a size of 33 bytes. A client will publish 100 pre-keys when registering, see figure 4.2, however, this is not a restriction. Along with these keys, a signed pre-key will be sent with a signature over the public_key. The key_id is an identifier of 3 bytes.

After that there is a code example that clearly shows it is a 24 bit sequential number, presumably unsigned, so you can supply it a non-random number [0, 2^24).

$\endgroup$
6
  • $\begingroup$ Non described parameters. Such badly defined API's suck. $\endgroup$
    – Maarten Bodewes
    Commented Jul 27, 2020 at 20:12
  • $\begingroup$ Great finding! Yes, I agree, the documentation sucks. You say that generally those identifiers are not random. What do you think Signal uses? Can you give an example? $\endgroup$
    – Thomas
    Commented Jul 27, 2020 at 20:46
  • $\begingroup$ Have you looked at the link I've given you? There should be a few examples in there. The big question is of course the handling of the keys / key ID's after they are created, I presume you have to do that yourself as well, probably using a sliding window approach $\endgroup$
    – Maarten Bodewes
    Commented Jul 27, 2020 at 21:46
  • $\begingroup$ Ok thanks for your post edit. I didn't see that they were sequential and not random. $\endgroup$
    – Thomas
    Commented Jul 28, 2020 at 16:53
  • $\begingroup$ I think you overlooked something, cause I didn't actually edit anything. Edits (if not made within a couple of minutes) are always visible as edits (edited xxx ago under the post) with a history. $\endgroup$
    – Maarten Bodewes
    Commented Jul 28, 2020 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.