Пример #1
0
        public async Task <Auth> CreateAuthRequestAsync(AuthNonce nonce, uint keyIndex = 0)
        {
            if (IsLocked)
            {
                Log.Warning("Wallet locked");
                return(null);
            }

            using var securePublicKey = Wallet.GetServicePublicKey(keyIndex);
            using var publicKey       = securePublicKey.ToUnsecuredBytes();

            var auth = new Auth
            {
                TimeStamp    = DateTime.UtcNow,
                Nonce        = nonce.Nonce,
                ClientNonce  = Guid.NewGuid().ToString(),
                PublicKeyHex = publicKey.Data.ToHexString(),
                Version      = ApiVersion
            };

            var signature = await Wallet
                            .SignByServiceKeyAsync(auth.SignedData, keyIndex)
                            .ConfigureAwait(false);

            auth.Signature = Convert.ToBase64String(signature);

            return(auth);
        }
Пример #2
0
        /// <summary>
        /// Stores a given nonce and timestamp.
        /// </summary>
        /// <param name="context">The context, or namespace, within which the
        /// <paramref name="nonce"/> must be unique.
        /// The context SHOULD be treated as case-sensitive.
        /// The value will never be <c>null</c> but may be the empty string.</param>
        /// <param name="nonce">A series of random characters.</param>
        /// <param name="timestampUtc">The UTC timestamp that together with the nonce string make it unique
        /// within the given <paramref name="context"/>.
        /// The timestamp may also be used by the data store to clear out old nonces.</param>
        /// <returns>
        /// True if the context+nonce+timestamp (combination) was not previously in the database.
        /// False if the nonce was stored previously with the same timestamp and context.
        /// </returns>
        /// <remarks>
        /// The nonce must be stored for no less than the maximum time window a message may
        /// be processed within before being discarded as an expired message.
        /// This maximum message age can be looked up via the
        /// <see cref="DotNetOpenAuth.Configuration.MessagingElement.MaximumMessageLifetime"/>
        /// property, accessible via the <see cref="DotNetOpenAuth.Configuration.DotNetOpenAuthSection.Configuration"/>
        /// property.
        /// </remarks>
        public bool StoreNonce(string context, string nonce, DateTime timestampUtc)
        {
            AuthNonce authNonce = new AuthNonce {
                Context = context, Code = nonce, Timestamp = timestampUtc
            };

            Repository.Save(authNonce);
            Repository.Flush();
            return(true);
        }
        private void AuthNonceHandler(MemoryStream stream)
        {
            Nonce = Schemes.AuthNonce.DeserializeWithLengthPrefix(stream);

            AuthNonce?.Invoke(this, EventArgs.Empty);
        }