public void JavaUUIDToCSharpGuid()
        {
            long mostSigBits  = 4822678189205111;
            long leastSigBits = -8603657889541918977;

            Assert.AreEqual(new Guid("00112233-4455-6677-8899-aabbccddeeff"), UuidUtil.JavaUUIDToCSharpGuid(mostSigBits, leastSigBits));
        }
Ejemplo n.º 2
0
        public async Task <Dictionary <string, Guid> > GetRegisteredUsersAsync(IList <string> e164numbers, string mrenclave, CancellationToken?token = null)
        {
            if (token == null)
            {
                token = CancellationToken.None;
            }

            try
            {
                string authorization = await pushServiceSocket.GetContactDiscoveryAuthorizationAsync(token);

                Dictionary <string, RemoteAttestation> attestations = await RemoteAttestationUtil.GetAndVerifyMultiRemoteAttestation(pushServiceSocket,
                                                                                                                                     PushServiceSocket.ClientSet.ContactDiscovery,
                                                                                                                                     mrenclave,
                                                                                                                                     mrenclave,
                                                                                                                                     authorization);

                List <string> addressBook = new List <string>(e164numbers.Count);

                foreach (string e164number in e164numbers)
                {
                    addressBook.Add(e164number.Substring(1));
                }

                IList <string>    cookies  = attestations.Values.ToList()[0].Cookies;
                DiscoveryRequest  request  = ContactDiscoveryCipher.CreateDiscoveryRequest(addressBook, attestations);
                DiscoveryResponse response = await pushServiceSocket.GetContactDiscoveryRegisteredUsersAsync(authorization, request, cookies, mrenclave);

                byte[] data = ContactDiscoveryCipher.GetDiscoveryResponseData(response, attestations.Values);

                Dictionary <string, Guid> results         = new Dictionary <string, Guid>(addressBook.Count);
                BeBinaryReader            uuidInputStream = new BeBinaryReader(new MemoryStream(data));

                foreach (string candidate in addressBook)
                {
                    long candidateUuidHigh = uuidInputStream.ReadInt64();
                    long candidateUuidLow  = uuidInputStream.ReadInt64();
                    if (candidateUuidHigh != 0 || candidateUuidLow != 0)
                    {
                        results.Add($"+{candidate}", UuidUtil.JavaUUIDToCSharpGuid(candidateUuidHigh, candidateUuidLow));
                    }
                }

                return(results);
            }
            catch (InvalidCiphertextException ex)
            {
                throw new UnauthenticatedResponseException(ex);
            }
        }