예제 #1
0
        /// <summary>
        /// Prepares a message for sending based on the rules of this channel binding element.
        /// </summary>
        /// <param name="message">The message to prepare for sending.</param>
        /// <returns>
        /// True if the <paramref name="message"/> applied to this binding element
        /// and the operation was successful.  False otherwise.
        /// </returns>
        /// <remarks>
        /// Implementations that provide message protection must honor the
        /// <see cref="MessagePartAttribute.RequiredProtection"/> properties where applicable.
        /// </remarks>
        public bool PrepareMessageForSending(IProtocolMessage message)
        {
            // We only add a nonce to 1.x auth requests.
            SignedResponseRequest request = message as SignedResponseRequest;

            if (request != null && request.Version.Major < 2)
            {
                request.AddReturnToArguments(NonceParameter, CustomNonce.NewNonce().Serialize());

                return(true);
            }

            return(false);
        }
예제 #2
0
        /// <summary>
        /// Prepares a message for sending based on the rules of this channel binding element.
        /// </summary>
        /// <param name="message">The message to prepare for sending.</param>
        /// <returns>
        /// The protections (if any) that this binding element applied to the message.
        /// Null if this binding element did not even apply to this binding element.
        /// </returns>
        /// <remarks>
        /// Implementations that provide message protection must honor the
        /// <see cref="MessagePartAttribute.RequiredProtection"/> properties where applicable.
        /// </remarks>
        public MessageProtections?ProcessOutgoingMessage(IProtocolMessage message)
        {
            // We only add a nonce to some auth requests.
            SignedResponseRequest request = message as SignedResponseRequest;

            if (this.UseRequestNonce(request))
            {
                request.AddReturnToArguments(NonceParameter, CustomNonce.NewNonce().Serialize());
                request.SignReturnTo = true;                 // a nonce without a signature is completely pointless

                return(MessageProtections.ReplayProtection);
            }

            return(null);
        }
        /// <summary>
        /// Prepares a message for sending based on the rules of this channel binding element.
        /// </summary>
        /// <param name="message">The message to prepare for sending.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// The protections (if any) that this binding element applied to the message.
        /// Null if this binding element did not even apply to this binding element.
        /// </returns>
        /// <remarks>
        /// Implementations that provide message protection must honor the
        /// <see cref="MessagePartAttribute.RequiredProtection"/> properties where applicable.
        /// </remarks>
        public Task <MessageProtections?> ProcessOutgoingMessageAsync(IProtocolMessage message, CancellationToken cancellationToken)
        {
            // We only add a nonce to some auth requests.
            SignedResponseRequest request = message as SignedResponseRequest;

            if (this.UseRequestNonce(request))
            {
                request.AddReturnToArguments(Protocol.ReturnToNonceParameter, CustomNonce.NewNonce().Serialize());
                request.SignReturnTo = true;                 // a nonce without a signature is completely pointless

                return(ReplayProtectionTask);
            }

            return(NullTask);
        }