You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2009/11/30 15:35:43 UTC

svn commit: r885435 - in /qpid/trunk/qpid/dotnet: Qpid.Client/Client/Security/CallbackHandlerRegistry.cs Qpid.Sasl/Callbacks.cs Qpid.Sasl/DefaultClientFactory.cs Qpid.Sasl/Mechanisms/CramMD5HexSaslClient.cs

Author: robbie
Date: Mon Nov 30 14:35:43 2009
New Revision: 885435

URL: http://svn.apache.org/viewvc?rev=885435&view=rev
Log:
QPID-2222: Added new CramMD5HexSaslClient.cs and registered it in the Sasl Factory and the client CallbackHandler

Merge code changes from M2.x branch r663999,r664020

Added:
    qpid/trunk/qpid/dotnet/Qpid.Sasl/Mechanisms/CramMD5HexSaslClient.cs
Modified:
    qpid/trunk/qpid/dotnet/Qpid.Client/Client/Security/CallbackHandlerRegistry.cs
    qpid/trunk/qpid/dotnet/Qpid.Sasl/Callbacks.cs
    qpid/trunk/qpid/dotnet/Qpid.Sasl/DefaultClientFactory.cs

Modified: qpid/trunk/qpid/dotnet/Qpid.Client/Client/Security/CallbackHandlerRegistry.cs
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Security/CallbackHandlerRegistry.cs?rev=885435&r1=885434&r2=885435&view=diff
==============================================================================
--- qpid/trunk/qpid/dotnet/Qpid.Client/Client/Security/CallbackHandlerRegistry.cs (original)
+++ qpid/trunk/qpid/dotnet/Qpid.Client/Client/Security/CallbackHandlerRegistry.cs Mon Nov 30 14:35:43 2009
@@ -96,6 +96,8 @@
             _mechanism2HandlerMap.Add(ExternalSaslClient.Mechanism, typeof(UsernamePasswordCallbackHandler));
          if ( !_mechanism2HandlerMap.Contains(CramMD5SaslClient.Mechanism) )
             _mechanism2HandlerMap.Add(CramMD5SaslClient.Mechanism, typeof(UsernamePasswordCallbackHandler));
+         if ( !_mechanism2HandlerMap.Contains(CramMD5HexSaslClient.Mechanism) )
+            _mechanism2HandlerMap.Add(CramMD5HexSaslClient.Mechanism, typeof(UsernamePasswordCallbackHandler));
          if ( !_mechanism2HandlerMap.Contains(PlainSaslClient.Mechanism) )
             _mechanism2HandlerMap.Add(PlainSaslClient.Mechanism, typeof(UsernamePasswordCallbackHandler));
 

Modified: qpid/trunk/qpid/dotnet/Qpid.Sasl/Callbacks.cs
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/Qpid.Sasl/Callbacks.cs?rev=885435&r1=885434&r2=885435&view=diff
==============================================================================
--- qpid/trunk/qpid/dotnet/Qpid.Sasl/Callbacks.cs (original)
+++ qpid/trunk/qpid/dotnet/Qpid.Sasl/Callbacks.cs Mon Nov 30 14:35:43 2009
@@ -21,6 +21,8 @@
 
 using System;
 using System.Text;
+using System.Globalization;
+using System.Security.Cryptography;
 
 namespace Apache.Qpid.Sasl
 {
@@ -87,6 +89,37 @@
          : base("password:", "", "")
       {
       }
+
+      public byte[] HashedText
+      {
+          get
+          {
+            string _text = this.Text;
+            System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
+            byte[] bs = x.ComputeHash(Encoding.UTF8.GetBytes(_text));
+            return bs;
+          }
+
+      }
+   } // class PasswordCallback
+
+   public class HashedPasswordCallback : TextSaslCallback
+   {
+       public HashedPasswordCallback()
+           : base("password:", "", "")
+       {
+       }
+
+       public byte[] HashedText
+       {
+        get {
+               string _text = this.Text;
+               System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
+               _text = _text.PadRight(16, '\0');
+               byte[] bs = x.ComputeHash(Encoding.UTF8.GetBytes(_text));
+               return bs;
+        }
+       }
    } // class PasswordCallback
 
    public class RealmCallback : TextSaslCallback

Modified: qpid/trunk/qpid/dotnet/Qpid.Sasl/DefaultClientFactory.cs
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/Qpid.Sasl/DefaultClientFactory.cs?rev=885435&r1=885434&r2=885435&view=diff
==============================================================================
--- qpid/trunk/qpid/dotnet/Qpid.Sasl/DefaultClientFactory.cs (original)
+++ qpid/trunk/qpid/dotnet/Qpid.Sasl/DefaultClientFactory.cs Mon Nov 30 14:35:43 2009
@@ -31,6 +31,7 @@
       private static readonly string[] SUPPORTED = new string[] {
                DigestSaslClient.Mechanism,
                CramMD5SaslClient.Mechanism,
+               CramMD5HexSaslClient.Mechanism,
                PlainSaslClient.Mechanism, 
                AnonymousSaslClient.Mechanism,
                ExternalSaslClient.Mechanism,
@@ -50,6 +51,7 @@
              props.Contains(SaslProperties.PolicyPassCredentials) )
          {
             vetoed.Add(CramMD5SaslClient.Mechanism);
+            vetoed.Add(CramMD5HexSaslClient.Mechanism);
             vetoed.Add(PlainSaslClient.Mechanism);
             vetoed.Add(AnonymousSaslClient.Mechanism);
             vetoed.Add(ExternalSaslClient.Mechanism);
@@ -81,6 +83,8 @@
             return new DigestSaslClient(authorizationId, serverName, protocol, props, handler);
          if ( mechs.Contains(CramMD5SaslClient.Mechanism) )
             return new CramMD5SaslClient(authorizationId, props, handler);
+         if ( mechs.Contains(CramMD5HexSaslClient.Mechanism) )
+            return new CramMD5HexSaslClient(authorizationId, props, handler);
          if ( mechs.Contains(PlainSaslClient.Mechanism) )
             return new PlainSaslClient(authorizationId, props, handler);
          if ( mechs.Contains(AnonymousSaslClient.Mechanism) )

Added: qpid/trunk/qpid/dotnet/Qpid.Sasl/Mechanisms/CramMD5HexSaslClient.cs
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/Qpid.Sasl/Mechanisms/CramMD5HexSaslClient.cs?rev=885435&view=auto
==============================================================================
--- qpid/trunk/qpid/dotnet/Qpid.Sasl/Mechanisms/CramMD5HexSaslClient.cs (added)
+++ qpid/trunk/qpid/dotnet/Qpid.Sasl/Mechanisms/CramMD5HexSaslClient.cs Mon Nov 30 14:35:43 2009
@@ -0,0 +1,93 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+using System;
+using System.Collections;
+using System.Security.Cryptography;
+using System.Text;
+
+namespace Apache.Qpid.Sasl.Mechanisms
+{
+   /// <summary>
+   /// Implements the CRAM-MD5 authentication mechanism as outlined
+   /// in RFC 2195
+   /// </summary>
+   public class CramMD5HexSaslClient : SaslClient
+   {
+      public const string Mechanism = "CRAM-MD5-HEX";
+      private const int MinPwdLen = 16;
+
+      public CramMD5HexSaslClient(
+         string authorizationId, 
+         IDictionary properties, 
+         ISaslCallbackHandler handler)
+         : base(authorizationId, null, null, properties, handler)
+      {
+      }
+
+      #region ISaslClient Implementation
+      //
+      // ISaslClient Implementation
+      //
+
+      public override string MechanismName
+      {
+         get { return Mechanism; }
+      }
+
+      public override bool HasInitialResponse
+      {
+         get { return false; }
+      }
+      
+      
+      public override byte[] EvaluateChallenge(byte[] challenge)
+      {
+        if ( challenge == null || challenge.Length == 0 )
+            throw new ArgumentNullException("challenge");
+
+
+        NameCallback nameCB = new NameCallback(AuthorizationId);
+        PasswordCallback pwdCB = new PasswordCallback();
+        ISaslCallback[] callbacks = { nameCB, pwdCB };
+        Handler.Handle(callbacks);
+
+        string username = nameCB.Text;
+        
+        //Encode the Hashed Password as Hex
+        byte[] passwd = Encoding.UTF8.GetBytes(ToHex(pwdCB.HashedText));
+
+        string s = System.Text.UTF8Encoding.UTF8.GetString(challenge);
+        
+        using ( HMAC hmac = new HMACMD5(passwd) )
+         {
+            byte[] value = hmac.ComputeHash(challenge);
+            string encoded = ToHex(value);
+            SetComplete();
+            return Encoding.UTF8.GetBytes(username + " " + encoded);
+         }
+      }
+
+      #endregion // ISaslClient Implementation
+
+   } // class CramMD5HashedSaslClient
+
+} // namespace Apache.Qpid.Sasl.Mechanisms



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org