Example #1
0
        private static Task<PreKeyRecord> generatePreKey(uint preKeyId)
        {
            return Task.Run(() =>
            {
                ECKeyPair keyPair = Curve.generateKeyPair();
                PreKeyRecord record = new PreKeyRecord(preKeyId, keyPair);

                return record;
            });
        }
 public void StorePreKey(uint preKeyId, PreKeyRecord record)
 {
     preKeyStore.StorePreKey(preKeyId, record);
 }
 /**
  * Register an identity key, last resort key, signed prekey, and list of one time prekeys
  * with the server.
  *
  * @param identityKey The client's long-term identity keypair.
  * @param lastResortKey The client's "last resort" prekey.
  * @param signedPreKey The client's signed prekey.
  * @param oneTimePreKeys The client's list of one-time prekeys.
  *
  * @throws IOException
  */
 public async Task<bool> setPreKeys(IdentityKey identityKey, PreKeyRecord lastResortKey,
                            SignedPreKeyRecord signedPreKey, IList<PreKeyRecord> oneTimePreKeys)
 //throws IOException
 {
     await this.pushServiceSocket.registerPreKeys(identityKey, lastResortKey, signedPreKey, oneTimePreKeys);
     return true;
 }
 public void StorePreKey(uint preKeyId, PreKeyRecord record)
 {
     conn.InsertOrReplace(new PreKeyRecordI() { PreKeyId = preKeyId, Record = record.serialize() });
 }
        public async Task<bool> registerPreKeys(IdentityKey identityKey,
                                    PreKeyRecord lastResortKey,
                                    SignedPreKeyRecord signedPreKey,
                                    IList<PreKeyRecord> records)
        //throws IOException
        {
            List<PreKeyEntity> entities = new List<PreKeyEntity>();

            foreach (PreKeyRecord record in records)
            {
                PreKeyEntity entity = new PreKeyEntity(record.getId(),
                                                       record.getKeyPair().getPublicKey());

                entities.Add(entity);
            }

            PreKeyEntity lastResortEntity = new PreKeyEntity(lastResortKey.getId(),
                                                     lastResortKey.getKeyPair().getPublicKey());

            SignedPreKeyEntity signedPreKeyEntity = new SignedPreKeyEntity(signedPreKey.getId(),
                                                                   signedPreKey.getKeyPair().getPublicKey(),
                                                                   signedPreKey.getSignature());

            await makeRequest(string.Format(PREKEY_PATH, ""), "PUT",
                JsonUtil.toJson(new PreKeyState(entities, lastResortEntity,
                                                signedPreKeyEntity, identityKey)));
            return true;
        }
Example #6
0
        public static Task<PreKeyRecord> generateLastResortKey()
        {
            return Task.Run(() =>
            {

                PreKeyStore preKeyStore = new TextSecurePreKeyStore(conn);

                if (preKeyStore.ContainsPreKey(Medium.MAX_VALUE))
                {
                    try
                    {
                        //return preKeyStore.loadPreKey(Medium.MAX_VALUE);
                        return preKeyStore.LoadPreKey(Medium.MAX_VALUE);
                    }
                    catch (InvalidKeyIdException e)
                    {
                        //Log.w("PreKeyUtil", e);
                        preKeyStore.RemovePreKey(Medium.MAX_VALUE);
                    }
                }

                ECKeyPair keyPair = Curve.generateKeyPair();
                PreKeyRecord record = new PreKeyRecord(Medium.MAX_VALUE, keyPair);

                preKeyStore.StorePreKey(Medium.MAX_VALUE, record);

                return record;
            });
        }
        public CryptoState()
        {
            identityKeyPair = KeyHelper.generateIdentityKeyPair();
            registrationId = KeyHelper.generateRegistrationId(false);
            lastResortKey = KeyHelper.generateLastResortPreKey();
            signedPreKey = KeyHelper.generateSignedPreKey(identityKeyPair, 5);//normally generate 100, but for a demo, 1 will do

            axolotlStore = new InMemoryAxolotlStore(identityKeyPair, registrationId);
            axolotlStore.StoreSignedPreKey(signedPreKey.getId(), signedPreKey);
        }