Exemple #1
0
        private void UpdateNonce(HttpResponseHeaders headers)
        {
            List <string> newNonceHeaders = headers.GetValues("X-NEWNONCE").ToList();

            if (newNonceHeaders.Count != 1)
            {
                throw new ServerConnectionException($"{newNonceHeaders.Count} X-NEWNONCE headers were found, exactly 1 required");
            }

            string newNonce = newNonceHeaders.First();

            // TODO Nonce expiry!
            DateTime expiryDateTime = DateTime.Now.Add(new TimeSpan(10000000));

            byte[] newNonceBytes = Convert.FromBase64String(newNonce);
            string nonceSig      = Convert.ToBase64String(_deviceKey.Sign(newNonceBytes));

            _nonce          = newNonce;
            _nonceSig       = nonceSig;
            _expiryDateTime = expiryDateTime;
        }
Exemple #2
0
        // Returns the User UUID
        public async Task <string> RegisterUserAsync(string email, Curve25519KeyPair userKeyPair, Curve25519KeyPair signedPreKeyPair, string nickname = null,
                                                     string bio = null)
        {
            Dictionary <string, string> contentDict = new Dictionary <string, string>
            {
                { "email", email },
                { "identity_key", Convert.ToBase64String(userKeyPair.EdPublicKey) },
                { "signed_prekey", Convert.ToBase64String(signedPreKeyPair.XPublicKey) },
                { "prekey_signature", Convert.ToBase64String(userKeyPair.Sign(signedPreKeyPair.XPublicKey)) },
                { "nickname", nickname },
                { "bio", bio }
            };

            HttpResponseMessage response = await PostAuthenticatedAsync("/users/new", contentDict).ConfigureAwait(false);

            Dictionary <string, string> responseDict = await HandleResponse <string>(response).ConfigureAwait(false);

            if (!responseDict.ContainsKey("user_id"))
            {
                throw new ServerConnectionException($"User UUID not found in response content: {responseDict}");
            }

            return(responseDict["user_id"]);
        }