コード例 #1
0
ファイル: PreKeyUtil.cs プロジェクト: smndtrl/Signal-UWP
        private static SignedPreKeyRecord generateSignedPreKey(IdentityKeyPair identityKeyPair, uint signedPreKeyId)
        {
            //return Task.Run(() =>
            //{
            ECKeyPair keyPair = Curve.generateKeyPair();
            byte[] signature = Curve.calculateSignature(identityKeyPair.getPrivateKey(), keyPair.getPublicKey().serialize());
            SignedPreKeyRecord record = new SignedPreKeyRecord(signedPreKeyId, (ulong)TimeUtil.GetUnixTimestampMillis() , keyPair, signature);

            return record;
            // });
        }
コード例 #2
0
 public void StoreSignedPreKey(uint signedPreKeyId, SignedPreKeyRecord record)
 {
     signedPreKeyStore.StoreSignedPreKey(signedPreKeyId, record);
 }
コード例 #3
0
 /**
  * Set the client's signed prekey.
  *
  * @param signedPreKey The client's new signed prekey.
  * @throws IOException
  */
 public async void setSignedPreKey(SignedPreKeyRecord signedPreKey)// throws IOException
 {
     await this.pushServiceSocket.setCurrentSignedPreKey(signedPreKey);
 }
コード例 #4
0
 /**
  * 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;
 }
コード例 #5
0
 public void StoreSignedPreKey(uint signedPreKeyId, SignedPreKeyRecord record)
 {
     conn.InsertOrReplace(new SignedPreKeyRecordI() { SignedPreKeyId = signedPreKeyId, Record = record.serialize() });
 }
コード例 #6
0
 public async Task<bool> setCurrentSignedPreKey(SignedPreKeyRecord signedPreKey)// throws IOException
 {
     SignedPreKeyEntity signedPreKeyEntity = new SignedPreKeyEntity(signedPreKey.getId(),
                                                                    signedPreKey.getKeyPair().getPublicKey(),
                                                                    signedPreKey.getSignature());
     await makeRequest(SIGNED_PREKEY_PATH, "PUT", JsonUtil.toJson(signedPreKeyEntity));
     return true;
 }
コード例 #7
0
        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;
        }
コード例 #8
0
        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);
        }