Пример #1
0
        public async Task <PreKeyBundle> GetPreKey(CancellationToken token, SignalServiceAddress destination, uint deviceId)// throws IOException
        {
            try
            {
                string path = string.Format(PREKEY_DEVICE_PATH, destination.E164number,
                                            deviceId.ToString());

                if (destination.Relay != null)
                {
                    path = path + "?relay=" + destination.Relay;
                }

                string responseText = await MakeServiceRequestAsync(token, path, "GET", null);

                PreKeyResponse response = JsonUtil.FromJson <PreKeyResponse>(responseText);

                if (response.Devices == null || response.Devices.Count < 1)
                {
                    throw new Exception("Empty prekey list");
                }

                PreKeyResponseItem device       = response.Devices[0];
                ECPublicKey?       preKey       = null;
                ECPublicKey?       signedPreKey = null;
                byte[]? signedPreKeySignature = null;
                int preKeyId       = -1;
                int signedPreKeyId = -1;

                if (device.PreKey != null)
                {
                    preKeyId = (int)device.PreKey.KeyId;
                    preKey   = device.PreKey.PublicKey;
                }

                if (device.SignedPreKey != null)
                {
                    signedPreKeyId        = (int)device.SignedPreKey.KeyId;
                    signedPreKey          = device.SignedPreKey.PublicKey;
                    signedPreKeySignature = device.SignedPreKey.Signature;
                }

                return(new PreKeyBundle(device.RegistrationId, device.DeviceId, (uint)preKeyId, preKey,
                                        (uint)signedPreKeyId, signedPreKey, signedPreKeySignature, response.IdentityKey));
            }

            /*catch (JsonUtil.JsonParseException e)
             * {
             *  throw new IOException(e);
             * }*/
            catch (NotFoundException nfe)
            {
                throw new UnregisteredUserException(destination.E164number, nfe);
            }
        }
Пример #2
0
        public async Task <PreKeyBundle> getPreKey(SignalServiceAddress destination, uint deviceId)// throws IOException
        {
            try
            {
                string path = string.Format(PREKEY_DEVICE_PATH, destination.getNumber(),
                                            deviceId.ToString());

                if (destination.getRelay().HasValue)
                {
                    path = path + "?relay=" + destination.getRelay().ForceGetValue();
                }

                string responseText = await makeRequest(path, "GET", null);

                PreKeyResponse response = JsonUtil.fromJson <PreKeyResponse>(responseText);

                if (response.getDevices() == null || response.getDevices().Count < 1)
                {
                    throw new Exception("Empty prekey list");
                }

                PreKeyResponseItem device                = response.getDevices()[0];
                ECPublicKey        preKey                = null;
                ECPublicKey        signedPreKey          = null;
                byte[]             signedPreKeySignature = null;
                int preKeyId       = -1;
                int signedPreKeyId = -1;

                if (device.getPreKey() != null)
                {
                    preKeyId = (int)device.getPreKey().getKeyId();// TODO: whacky
                    preKey   = device.getPreKey().getPublicKey();
                }

                if (device.getSignedPreKey() != null)
                {
                    signedPreKeyId        = (int)device.getSignedPreKey().getKeyId();// TODO: whacky
                    signedPreKey          = device.getSignedPreKey().getPublicKey();
                    signedPreKeySignature = device.getSignedPreKey().getSignature();
                }

                return(new PreKeyBundle(device.getRegistrationId(), device.getDeviceId(), (uint)preKeyId, preKey,
                                        (uint)signedPreKeyId, signedPreKey, signedPreKeySignature, response.getIdentityKey()));
            }

            /*catch (JsonUtil.JsonParseException e)
             * {
             *  throw new IOException(e);
             * }*/
            catch (NotFoundException nfe)
            {
                throw new UnregisteredUserException(destination.getNumber(), nfe);
            }
        }