public void Authenticate(string username, string password, string realm, string hostname)
 {
     Initiate("DIGEST-MD5");
     string challenge = ReadInitialChallenge();
     var digestMD5Authentication = new DigestMD5Authentication(challenge);
     SendInitialChallengeResponse(digestMD5Authentication.GetDigestResponse(username, password, realm, hostname));
     string rspAuth =  ReadRspAuthChallenge(); //TODO: what to do with rspauth?
     SendRspAuthChallengeResposne();
 }
        public void TestUsingRFCExampleData()
        {
            //using values from RFC 2831
            const string challenge = "realm=\"elwood.innosoft.com\",nonce=\"OA6MG9tEQGm2hh\",qop=\"auth\",algorithm=md5-sess,charset=utf-8";
            var digestAuthentication = new DigestMD5Authentication(challenge);
            string digestResponse = digestAuthentication.GetDigestResponse("chris", "secret", "elwood.innosoft.com", "elwood.innosoft.com", "OA6MHXh6VqTrRk", "imap");

            //extract the response value from the digestResponse string
            string response = digestResponse.Split(',').Where(x => x.StartsWith("response")).First().Split('=')[1];

            Assert.Equal("d388dad90d4bbd760a152321f2143af7", response);
        }
Esempio n. 3
0
 internal override void Handle()
 {
     if (!_serverFeatures.Mechanisms.Contains("DIGEST-MD5")) {
         //throw new NotSupportedException("No supported auth mechanisms");
     }
     Context.OnConnectionStateChanged(ConnectionStateType.Authenticating);
     Context.Connection.Send(new DigestMD5SaslAuth());
     SaslChallenge saslChallenge = SaslChallenge.CreateFromXml(Context.Connection.Receive());
     var digestMD5Authentication = new DigestMD5Authentication(saslChallenge.ChallangeString);
     string response = digestMD5Authentication.GetDigestResponse(Context.Settings.UserJId.User, Context.Settings.Password, digestMD5Authentication.Realms[0], Context.Settings.UserJId.Domain);
     Context.Connection.Send(new SaslResponse(response));
     SaslAuthResult saslAuthResult = SaslAuthResult.CreateFromXml(Context.Connection.Receive());
     if (!saslAuthResult.Success) {
         StreamException.ThrowStreamException(saslAuthResult.FailReason);
     }
     Context.Connection.InitializeStream();
     _serverFeatures = ServerFeatures.CreateFromXml(Context.Connection.Receive());
     NextState = new BindResourceState(Context, _serverFeatures);
 }