2013-06-10 16:49:44 +08:00
|
|
|
#region License
|
|
|
|
/*
|
|
|
|
* AuthenticationChallenge.cs
|
|
|
|
*
|
|
|
|
* The MIT License
|
|
|
|
*
|
2014-01-01 20:43:18 +08:00
|
|
|
* Copyright (c) 2013-2014 sta.blockhead
|
|
|
|
*
|
2013-06-10 16:49:44 +08:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
2014-01-01 20:43:18 +08:00
|
|
|
*
|
2013-06-10 16:49:44 +08:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
using System;
|
2014-01-01 20:43:18 +08:00
|
|
|
using System.Collections.Specialized;
|
2013-06-10 16:49:44 +08:00
|
|
|
using System.Text;
|
|
|
|
|
2014-01-01 20:43:18 +08:00
|
|
|
namespace WebSocketSharp
|
|
|
|
{
|
|
|
|
internal class AuthenticationChallenge
|
|
|
|
{
|
2013-06-10 16:49:44 +08:00
|
|
|
#region Private Fields
|
|
|
|
|
2014-01-01 20:43:18 +08:00
|
|
|
private NameValueCollection _params;
|
|
|
|
private string _scheme;
|
2013-06-10 16:49:44 +08:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2014-01-01 20:43:18 +08:00
|
|
|
#region Internal Constructors
|
2013-06-10 16:49:44 +08:00
|
|
|
|
2014-01-01 20:43:18 +08:00
|
|
|
internal AuthenticationChallenge (string authScheme, string authParams)
|
2013-06-10 16:49:44 +08:00
|
|
|
{
|
2014-01-01 20:43:18 +08:00
|
|
|
_scheme = authScheme;
|
|
|
|
_params = authParams.ParseAuthParams ();
|
2013-06-10 16:49:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2014-01-01 20:43:18 +08:00
|
|
|
#region Internal Properties
|
2013-06-10 16:49:44 +08:00
|
|
|
|
2014-01-01 20:43:18 +08:00
|
|
|
internal NameValueCollection Params {
|
2013-06-10 16:49:44 +08:00
|
|
|
get {
|
2014-01-01 20:43:18 +08:00
|
|
|
return _params;
|
2013-06-10 16:49:44 +08:00
|
|
|
}
|
2014-01-01 20:43:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Public Properties
|
2013-06-10 16:49:44 +08:00
|
|
|
|
2014-01-01 20:43:18 +08:00
|
|
|
public string Algorithm {
|
|
|
|
get {
|
|
|
|
return _params ["algorithm"];
|
2013-06-10 16:49:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string Domain {
|
|
|
|
get {
|
2014-01-01 20:43:18 +08:00
|
|
|
return _params ["domain"];
|
2013-06-10 16:49:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string Nonce {
|
|
|
|
get {
|
2014-01-01 20:43:18 +08:00
|
|
|
return _params ["nonce"];
|
2013-06-10 16:49:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string Opaque {
|
|
|
|
get {
|
2014-01-01 20:43:18 +08:00
|
|
|
return _params ["opaque"];
|
2013-06-10 16:49:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string Qop {
|
|
|
|
get {
|
2014-01-01 20:43:18 +08:00
|
|
|
return _params ["qop"];
|
2013-06-10 16:49:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string Realm {
|
|
|
|
get {
|
2014-01-01 20:43:18 +08:00
|
|
|
return _params ["realm"];
|
2013-06-10 16:49:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string Scheme {
|
|
|
|
get {
|
2014-01-01 20:43:18 +08:00
|
|
|
return _scheme;
|
2013-06-10 16:49:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string Stale {
|
|
|
|
get {
|
2014-01-01 20:43:18 +08:00
|
|
|
return _params ["stale"];
|
2013-06-10 16:49:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Public Methods
|
|
|
|
|
2014-01-01 20:43:18 +08:00
|
|
|
public static AuthenticationChallenge Parse (string value)
|
2013-06-10 16:49:44 +08:00
|
|
|
{
|
2014-01-01 20:43:18 +08:00
|
|
|
var challenge = value.Split (new char [] {' '}, 2);
|
|
|
|
var scheme = challenge [0].ToLower ();
|
|
|
|
return scheme == "basic" || scheme == "digest"
|
|
|
|
? new AuthenticationChallenge (scheme, challenge [1])
|
|
|
|
: null;
|
2013-06-10 16:49:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|