Inheritance: PreKeyStore, SignedPreKeyStore
Beispiel #1
0
        public static async Task<List<PreKeyRecord>> generatePreKeys()
        {
            PreKeyStore preKeyStore = new TextSecurePreKeyStore(conn);
            List<PreKeyRecord> records = new List<PreKeyRecord>();
            uint preKeyIdOffset = getNextPreKeyId();

            for (uint i = 0; i < BATCH_SIZE; i++)
            {
                uint preKeyId = (preKeyIdOffset + i) % Medium.MAX_VALUE;

                PreKeyRecord record = await generatePreKey(preKeyId);

                preKeyStore.StorePreKey(preKeyId, record);
                records.Add(record);
            }

            setNextPreKeyId((preKeyIdOffset + BATCH_SIZE + 1) % Medium.MAX_VALUE);
            return records;
        }
Beispiel #2
0
        public static SignedPreKeyRecord generateSignedPreKey(IdentityKeyPair identityKeyPair)
        {
            try
            {
                SignedPreKeyStore signedPreKeyStore = new TextSecurePreKeyStore(conn);
                uint signedPreKeyId = getNextSignedPreKeyId();
                /*ECKeyPair keyPair = Curve.generateKeyPair();
                byte[] signature = Curve.calculateSignature(identityKeyPair.getPrivateKey(), keyPair.getPublicKey().serialize());
                SignedPreKeyRecord record = new SignedPreKeyRecord(signedPreKeyId, KeyHelper.getTime(), keyPair, signature);*/
                SignedPreKeyRecord record = generateSignedPreKey(identityKeyPair, signedPreKeyId);

                signedPreKeyStore.StoreSignedPreKey(signedPreKeyId, record);
                setNextSignedPreKeyId((signedPreKeyId + 1) % Medium.MAX_VALUE);

                return record;
            }
            catch (InvalidKeyException e)
            {
                throw new Exception(e.Message);
            }
        }
Beispiel #3
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;
            });
        }