internal AuthenticationResponse (
   AuthenticationChallenge challenge,
   NetworkCredential credentials,
   uint nonceCount)
   : this (challenge.Scheme, challenge.Params, credentials, nonceCount)
 {
 }
예제 #2
0
 internal AuthenticationResponse (
   AuthenticationSchemes scheme,
   NameValueCollection parameters,
   NetworkCredential credentials,
   uint nonceCount)
   : base (scheme, parameters)
 {
   Parameters["username"] = credentials.UserName;
   Parameters["password"] = credentials.Password;
   Parameters["uri"] = credentials.Domain;
   _nonceCount = nonceCount;
   if (scheme == AuthenticationSchemes.Digest)
     initAsDigest ();
 }
 internal AuthenticationResponse (
   string authScheme,
   NameValueCollection authParams,
   NetworkCredential credentials,
   uint nonceCount)
 {
   _scheme = authScheme.ToLower ();
   _params = authParams;
   _params ["username"] = credentials.UserName;
   _params ["password"] = credentials.Password;
   _params ["uri"] = credentials.Domain;
   _nonceCount = nonceCount;
   if (_scheme == "digest")
     initAsDigest ();
 }
예제 #4
0
    /// <summary>
    /// Sets an HTTP proxy server URL to connect through, and if necessary,
    /// a pair of <paramref name="username"/> and <paramref name="password"/> for
    /// the proxy server authentication (Basic/Digest).
    /// </summary>
    /// <param name="url">
    /// A <see cref="string"/> that represents the proxy server URL to connect through.
    /// </param>
    /// <param name="username">
    /// A <see cref="string"/> that represents the user name used to authenticate.
    /// </param>
    /// <param name="password">
    /// A <see cref="string"/> that represents the password for <paramref name="username"/>
    /// used to authenticate.
    /// </param>
    public void SetProxy (string url, string username, string password)
    {
      lock (_forConn) {
        var msg = checkIfAvailable (true, false, true, false, false, true);
        if (msg == null) {
          if (url.IsNullOrEmpty ()) {
            _proxyUri = null;
            _proxyCredentials = null;
            _logger.Warn ("The proxy url and credentials were set back to the default.");

            return;
          }

          Uri uri;
          if (!Uri.TryCreate (url, UriKind.Absolute, out uri) ||
              uri.Scheme != "http" ||
              uri.Segments.Length > 1) {
            msg = "The syntax of a proxy url must be 'http://<host>[:<port>]'.";
          }
          else {
            _proxyUri = uri;

            if (username.IsNullOrEmpty ()) {
              _proxyCredentials = null;
              _logger.Warn ("The proxy credentials were set back to the default.");

              return;
            }

            msg = username.Contains (':') || !username.IsText ()
                  ? "'username' contains an invalid character."
                  : !password.IsNullOrEmpty () && !password.IsText ()
                    ? "'password' contains an invalid character."
                    : null;
          }
        }

        if (msg != null) {
          _logger.Error (msg);
          error ("An error has occurred in setting the proxy.", null);

          return;
        }

        _proxyCredentials = new NetworkCredential (
          username, password, String.Format ("{0}:{1}", _uri.DnsSafeHost, _uri.Port));
      }
    }
예제 #5
0
    /// <summary>
    /// Sets a pair of <paramref name="username"/> and <paramref name="password"/> for
    /// the HTTP authentication (Basic/Digest).
    /// </summary>
    /// <param name="username">
    /// A <see cref="string"/> that represents the user name used to authenticate.
    /// </param>
    /// <param name="password">
    /// A <see cref="string"/> that represents the password for <paramref name="username"/>
    /// used to authenticate.
    /// </param>
    /// <param name="preAuth">
    /// <c>true</c> if the <see cref="WebSocket"/> sends the Basic authentication credentials
    /// with the first connection request to the server; otherwise, <c>false</c>.
    /// </param>
    public void SetCredentials (string username, string password, bool preAuth)
    {
      lock (_forConn) {
        var msg = checkIfAvailable (true, false, true, false, false, true);
        if (msg == null) {
          if (username.IsNullOrEmpty ()) {
            _credentials = null;
            _preAuth = false;
            _logger.Warn ("The credentials were set back to the default.");

            return;
          }

          msg = username.Contains (':') || !username.IsText ()
                ? "'username' contains an invalid character."
                : !password.IsNullOrEmpty () && !password.IsText ()
                  ? "'password' contains an invalid character."
                  : null;
        }

        if (msg != null) {
          _logger.Error (msg);
          error ("An error has occurred in setting the credentials.", null);

          return;
        }

        _credentials = new NetworkCredential (username, password, _uri.PathAndQuery);
        _preAuth = preAuth;
      }
    }
예제 #6
0
        /// <summary>
        /// Sets the HTTP proxy server URL to connect through, and if necessary,
        /// a pair of <paramref name="username"/> and <paramref name="password"/> for
        /// the proxy server authentication (Basic/Digest).
        /// </summary>
        /// <param name="url">
        ///   <para>
        ///   A <see cref="string"/> that represents the HTTP proxy server URL to
        ///   connect through.
        ///   </para>
        ///   <para>
        ///   If <paramref name="url"/> is <see langword="null"/> or empty,
        ///   the url and credentials for the proxy will be initialized,
        ///   and the <see cref="WebSocket"/> will not use the proxy to
        ///   connect through.
        ///   </para>
        /// </param>
        /// <param name="username">
        ///   <para>
        ///   A <see cref="string"/> that represents the user name used to authenticate.
        ///   </para>
        ///   <para>
        ///   If <paramref name="username"/> is <see langword="null"/> or empty,
        ///   the credentials for the proxy will be initialized and not be sent.
        ///   </para>
        /// </param>
        /// <param name="password">
        /// A <see cref="string"/> that represents the password for
        /// <paramref name="username"/> used to authenticate.
        /// </param>
        public void SetProxy(string url, string username, string password)
        {
            string msg;
              if (!checkIfAvailable (true, false, true, false, false, true, out msg)) {
            _logger.Error (msg);
            error ("An error has occurred in setting the proxy.", null);

            return;
              }

              if (!checkParametersForSetProxy (url, username, password, out msg)) {
            _logger.Error (msg);
            error ("An error has occurred in setting the proxy.", null);

            return;
              }

              lock (_forState) {
            if (!checkIfAvailable (true, false, false, true, out msg)) {
              _logger.Error (msg);
              error ("An error has occurred in setting the proxy.", null);

              return;
            }

            if (url.IsNullOrEmpty ()) {
              _logger.Warn ("The url and credentials for the proxy are initialized.");
              _proxyUri = null;
              _proxyCredentials = null;

              return;
            }

            _proxyUri = new Uri (url);

            if (username.IsNullOrEmpty ()) {
              _logger.Warn ("The credentials for the proxy are initialized.");
              _proxyCredentials = null;

              return;
            }

            _proxyCredentials =
              new NetworkCredential (
            username, password, String.Format ("{0}:{1}", _uri.DnsSafeHost, _uri.Port)
              );
              }
        }
예제 #7
0
        /// <summary>
        /// Sets a pair of <paramref name="username"/> and <paramref name="password"/> for
        /// the HTTP authentication (Basic/Digest).
        /// </summary>
        /// <param name="username">
        ///   <para>
        ///   A <see cref="string"/> that represents the user name used to authenticate.
        ///   </para>
        ///   <para>
        ///   If <paramref name="username"/> is <see langword="null"/> or empty,
        ///   the credentials will be initialized and not be sent.
        ///   </para>
        /// </param>
        /// <param name="password">
        /// A <see cref="string"/> that represents the password for
        /// <paramref name="username"/> used to authenticate.
        /// </param>
        /// <param name="preAuth">
        /// <c>true</c> if the <see cref="WebSocket"/> sends the credentials for
        /// the Basic authentication with the first handshake request to the server;
        /// otherwise, <c>false</c>.
        /// </param>
        public void SetCredentials(string username, string password, bool preAuth)
        {
            string msg;
              if (!checkIfAvailable (true, false, true, false, false, true, out msg)) {
            _logger.Error (msg);
            error ("An error has occurred in setting the credentials.", null);

            return;
              }

              if (!checkParametersForSetCredentials (username, password, out msg)) {
            _logger.Error (msg);
            error ("An error has occurred in setting the credentials.", null);

            return;
              }

              lock (_forState) {
            if (!checkIfAvailable (true, false, false, true, out msg)) {
              _logger.Error (msg);
              error ("An error has occurred in setting the credentials.", null);

              return;
            }

            if (username.IsNullOrEmpty ()) {
              _logger.Warn ("The credentials are initialized.");
              _credentials = null;
              _preAuth = false;

              return;
            }

            _credentials = new NetworkCredential (username, password, _uri.PathAndQuery);
            _preAuth = preAuth;
              }
        }
예제 #8
0
 internal AuthenticationResponse (NetworkCredential credentials)
   : this (AuthenticationSchemes.Basic, new NameValueCollection (), credentials, 0)
 {
 }
예제 #9
0
    /// <summary>
    /// Sets a pair of the <paramref name="username"/> and
    /// <paramref name="password"/> for HTTP authentication (Basic/Digest).
    /// </summary>
    /// <param name="username">
    /// A <see cref="string"/> that represents the user name used to authenticate.
    /// </param>
    /// <param name="password">
    /// A <see cref="string"/> that represents the password for
    /// <paramref name="username"/> used to authenticate.
    /// </param>
    /// <param name="preAuth">
    /// <c>true</c> if the <see cref="WebSocket"/> sends a Basic authentication
    /// credentials with the first connection request; otherwise, <c>false</c>.
    /// </param>
    public void SetCredentials (string username, string password, bool preAuth)
    {
      lock (_forConnect) {
        string msg = null;
        if (!_client)
          msg = "SetCredentials isn't available as a server.";
        else if (IsOpened)
          msg = "A WebSocket connection has already been established.";
        else if (username.IsNullOrEmpty ()) {
          _credentials = null;
          _preAuth = false;
          _logger.Warn ("Credentials was set back to the default.");

          return;
        }
        else {
          msg = username.Contains (':') || !username.IsText ()
              ? "'username' contains an invalid character."
              : !password.IsNullOrEmpty () && !password.IsText ()
                ? "'password' contains an invalid character."
                : null;
        }

        if (msg != null) {
          _logger.Error (msg);
          error (msg);

          return;
        }

        _credentials = new NetworkCredential (
          username, password, _uri.PathAndQuery);
        _preAuth = preAuth;
      }
    }