private static HttpResponseMessageProperty CreateResponseProperty(DigestHeader digestHeader) { var responseProperty = new HttpResponseMessageProperty(); responseProperty.StatusCode = HttpStatusCode.Unauthorized; responseProperty.Headers.Add(DigestAuthenticationHeaderName, digestHeader.GenerateHeaderString()); return responseProperty; }
public static DigestHeader CreateHeader() { var header = new DigestHeader(); header.Method = "GET"; header.Nonce = GeneratedValidNonce; return header; }
internal virtual Message CreateInvalidAuthorizationMessage(DigestHeader digestHeader) { var responseMessage = Message.CreateMessage(MessageVersion.None, null); HttpResponseMessageProperty responseProperty = CreateResponseProperty(digestHeader); responseMessage.Properties.Add(HttpResponseMessageProperty.Name, responseProperty); return responseMessage; }
public void ShouldGenerateDefaultDigestResponseHeader() { var digestResponseHeaderGenerator = new DigestHeader(); digestResponseHeaderGenerator.Realm = "MyRealm"; digestResponseHeaderGenerator.Nonce = "BABABABABABASD"; string digestHeader = digestResponseHeaderGenerator.GenerateHeaderString(); Assert.That(digestHeader, Is.EqualTo("Digest realm=\"MyRealm\", nonce=\"BABABABABABASD\"")); }
public override string CreateResponse(DigestHeader digestHeader, string ha1, string ha2) { return md5Encoder.Encode( string.Format( CultureInfo.InvariantCulture, "{0}:{1}:{2}:{3}:{4}:{5}", ha1, digestHeader.Nonce, digestHeader.NounceCounter, digestHeader.Cnonce, digestHeader.Qop.ToString().ToLower(CultureInfo.InvariantCulture), ha2)); }
public void When_Qop_Is_None_Digest_Should_Be_Encoded_Using_RFC2069() { var digestHeader = new DigestHeader(); digestHeader.Method = "GET"; digestHeader.Uri = "/Service.svc"; digestHeader.Response = "0fa5ded47c396ecb28c5c3a7a8a6ca42"; digestHeader.UserName = "******"; digestHeader.Realm = "*****@*****.**"; digestHeader.Nonce = "NjM0MzI2MjAyMTY3OTcsNjpBRjE1NTlBQkMwNjU2MTMxMzZDNjU1MTVDMDEwNEEyOA=="; digestHeader.Qop = DigestQop.None; DigestEncoderBase digestValidator = new DefaultDigestEncoder(new MD5Encoder()); string response = digestValidator.Encode(digestHeader, TestResources.Password); Assert.That(response, Is.EqualTo(digestHeader.Response)); }
public void ShouldGenerateMD5SessDigestResponseHeader() { var digestResponseHeaderGenerator = new DigestHeader(); digestResponseHeaderGenerator.Realm = "MyRealm"; digestResponseHeaderGenerator.Domain = "www.test.com www.semanticarchitecture.net"; digestResponseHeaderGenerator.Nonce = "BABABABABABASD"; digestResponseHeaderGenerator.Opaque = "3332211VVVV"; digestResponseHeaderGenerator.Stale = false; digestResponseHeaderGenerator.Algoritm = DigestAlgorithm.MD5Sess; digestResponseHeaderGenerator.Qop = DigestQop.AuthInt; string digestHeader = digestResponseHeaderGenerator.GenerateHeaderString(); Assert.That(digestHeader, Is.EqualTo( "Digest realm=\"MyRealm\", domain=\"www.test.com www.semanticarchitecture.net\", nonce=\"BABABABABABASD\", opaque=\"3332211VVVV\", stale=\"false\", algorithm=\"MD5-sess\", qop=\"auth-int\"")); }
public void When_Qop_Is_Auth_Digest_Should_Be_Encoded_Using_CNonce_NounceCounter_Qop() { var digestHeader = new DigestHeader(); digestHeader.Method = "GET"; digestHeader.Uri = "/Service.svc"; digestHeader.Response = "6d2c6ad771845799dbf3e4ed88b9d8a4"; digestHeader.UserName = "******"; digestHeader.Realm = "*****@*****.**"; digestHeader.Nonce = "NjM0MzMwMzMzODE5NTMsNjo2Yzc0MThkMTEzN2IzMGZmODBiMjU3YzM4Y2Y3YTg3MA=="; digestHeader.Qop = DigestQop.Auth; digestHeader.Cnonce = "4847b4c6baa838ed21969a50e03fd333"; digestHeader.NounceCounter = "00000001"; var digestEncoder = new AuthDigestEncoder(new MD5Encoder()); string result = digestEncoder.Encode(digestHeader, TestResources.Password); Assert.That(result, Is.EqualTo(digestHeader.Response)); }
private string CreateHa2(DigestHeader digestHeader) { return md5Encoder.Encode(string.Format(CultureInfo.InvariantCulture, "{0}:{1}", digestHeader.Method, digestHeader.Uri)); }
private string CreateHa1(DigestHeader digestHeader, string password) { return md5Encoder.Encode(string.Format(CultureInfo.InvariantCulture, "{0}:{1}:{2}", digestHeader.UserName, digestHeader.Realm, password)); }
public virtual string Encode(DigestHeader digestHeader, string password) { string ha1 = CreateHa1(digestHeader, password); string ha2 = CreateHa2(digestHeader); return CreateResponse(digestHeader, ha1, ha2); }
public abstract string CreateResponse(DigestHeader digestHeader, string ha1, string ha2);
public void ShouldThrowExceptionWhenNotAllMandatoryFieldsAreFilled() { var digestResponseHeaderGenerator = new DigestHeader(); digestResponseHeaderGenerator.GenerateHeaderString(); }
public override string CreateResponse(DigestHeader digestHeader, string ha1, string ha2) { return md5Encoder.Encode(string.Format(CultureInfo.InvariantCulture, "{0}:{1}:{2}", ha1, digestHeader.Nonce, ha2)); }