Esempio n. 1
0
        public async Task <List <PreKeyBundle> > getPreKeys(SignalServiceAddress destination, uint deviceIdInteger)// throws IOException
        {
            try
            {
                string deviceId = deviceIdInteger.ToString();

                if (deviceId.Equals("1"))
                {
                    deviceId = "*";
                }

                string path = string.Format(PREKEY_DEVICE_PATH, destination.getNumber(), deviceId);

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

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

                PreKeyResponse      response = JsonUtil.fromJson <PreKeyResponse>(responseText);
                List <PreKeyBundle> bundles  = new List <PreKeyBundle>();

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

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

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

                    bundles.Add(new PreKeyBundle(device.getRegistrationId(), device.getDeviceId(), (uint)preKeyId,
                                                 preKey, (uint)signedPreKeyId, signedPreKey, signedPreKeySignature,
                                                 response.getIdentityKey()));        // TODO: whacky
                }

                return(bundles);
            }

            /*catch (JsonUtil.JsonParseException e)
             * {
             *  throw new IOException(e);
             * }*/
            catch (NotFoundException nfe)
            {
                throw new UnregisteredUserException(destination.getNumber(), nfe);
            }
        }
        public async Task <List <PreKeyBundle> > GetPreKeys(CancellationToken token, SignalServiceAddress destination,
                                                            UnidentifiedAccess?unidentifiedAccess, uint deviceIdInteger)// throws IOException
        {
            try
            {
                string deviceId = deviceIdInteger.ToString();

                if (deviceId.Equals("1"))
                {
                    deviceId = "*";
                }

                string path = string.Format(PREKEY_DEVICE_PATH, destination.E164number, deviceId);

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

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

                PreKeyResponse      response = JsonUtil.FromJson <PreKeyResponse>(responseText);
                List <PreKeyBundle> bundles  = new List <PreKeyBundle>();

                foreach (PreKeyResponseItem device in response.Devices)
                {
                    ECPublicKey preKey                = null;
                    ECPublicKey signedPreKey          = null;
                    byte[]      signedPreKeySignature = null;
                    int         preKeyId              = -1;
                    int         signedPreKeyId        = -1;

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

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

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

                return(bundles);
            }

            /*catch (JsonUtil.JsonParseException e)
             * {
             *  throw new IOException(e);
             * }*/
            catch (NotFoundException nfe)
            {
                throw new UnregisteredUserException(destination.E164number, nfe);
            }
        }
Esempio n. 3
0
        public async Task <SignalServiceProfile> RetrieveProfile(CancellationToken token, SignalServiceAddress target)
        {
            try
            {
                string response = await MakeServiceRequestAsync(token, string.Format(PROFILE_PATH, target.E164number), "GET", null);

                return(JsonUtil.FromJson <SignalServiceProfile>(response));
            }
            catch (Exception e)
            {
                throw new NonSuccessfulResponseCodeException("Unable to parse entity: " + e.Message);
            }
        }