public static Guid ParseOrThrow(byte[] bytes)
        {
            using MemoryStream stream = new MemoryStream(bytes);
            // Needs to be big-endian because the Java ByteBuffer defaults to big-endian.
            using BeBinaryReader byteBuffer = new BeBinaryReader(stream);
            long high = byteBuffer.ReadInt64();
            long low  = byteBuffer.ReadInt64();

            return(JavaUUIDToCSharpGuid(high, low));
        }
示例#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);
            }
        }