[ 
https://issues.apache.org/jira/browse/ARTEMIS-3106?focusedWorklogId=568470&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-568470
 ]

ASF GitHub Bot logged work on ARTEMIS-3106:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 18/Mar/21 16:25
            Start Date: 18/Mar/21 16:25
    Worklog Time Spent: 10m 
      Work Description: laeubi commented on a change in pull request #3470:
URL: https://github.com/apache/activemq-artemis/pull/3470#discussion_r597042491



##########
File path: 
artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/sasl/scram/SCRAMServerSASLFactory.java
##########
@@ -0,0 +1,241 @@
+/*
+ * 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.
+ */
+package org.apache.activemq.artemis.protocol.amqp.sasl.scram;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.security.GeneralSecurityException;
+import java.security.NoSuchAlgorithmException;
+import java.security.Principal;
+import java.util.Iterator;
+import java.util.UUID;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.auth.login.LoginContext;
+
+import org.apache.activemq.artemis.core.server.ActiveMQServer;
+import org.apache.activemq.artemis.protocol.amqp.broker.AmqpInterceptor;
+import org.apache.activemq.artemis.protocol.amqp.broker.ProtonProtocolManager;
+import org.apache.activemq.artemis.protocol.amqp.sasl.SASLResult;
+import org.apache.activemq.artemis.protocol.amqp.sasl.ServerSASL;
+import org.apache.activemq.artemis.protocol.amqp.sasl.ServerSASLFactory;
+import org.apache.activemq.artemis.spi.core.protocol.ProtocolManager;
+import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection;
+import org.apache.activemq.artemis.spi.core.remoting.Connection;
+import org.apache.activemq.artemis.spi.core.security.jaas.DigestCallback;
+import org.apache.activemq.artemis.spi.core.security.jaas.HmacCallback;
+import 
org.apache.activemq.artemis.spi.core.security.jaas.SCRAMMechanismCallback;
+import org.apache.activemq.artemis.spi.core.security.scram.SCRAM;
+import org.apache.activemq.artemis.spi.core.security.scram.ScramException;
+import org.apache.activemq.artemis.spi.core.security.scram.UserData;
+import org.jboss.logging.Logger;
+
+/**
+ * abstract class that implements the SASL-SCRAM authentication scheme, 
concrete implementations
+ * must supply the {@link SCRAM} type to use and be register via SPI
+ */
+public abstract class SCRAMServerSASLFactory implements ServerSASLFactory {
+
+   private final Logger logger = Logger.getLogger(getClass());
+   private final SCRAM scramType;
+
+   public SCRAMServerSASLFactory(SCRAM scram) {
+      this.scramType = scram;
+   }
+
+   @Override
+   public String getMechanism() {
+      return scramType.getName();
+   }
+
+   @Override
+   public boolean isDefaultPermitted() {
+      return false;
+   }
+
+   @Override
+   public ServerSASL create(ActiveMQServer server, 
ProtocolManager<AmqpInterceptor> manager, Connection connection,
+                            RemotingConnection remotingConnection) {
+      try {
+         if (manager instanceof ProtonProtocolManager) {
+            ScramServerFunctionalityImpl scram =
+                     new ScramServerFunctionalityImpl(scramType.getDigest(), 
scramType.getHmac(),
+                                                      
UUID.randomUUID().toString());
+            String loginConfigScope = ((ProtonProtocolManager) 
manager).getSaslLoginConfigScope();
+            return new SCRAMServerSASL(scramType.getName(), scram, 
loginConfigScope, logger);
+         }
+      } catch (NoSuchAlgorithmException e) {
+         // can't be used then...
+      }
+      return null;
+   }
+
+   private static final class SCRAMServerSASL implements ServerSASL {
+
+      private final String name;
+      private final ScramServerFunctionality scram;
+      private SASLResult result;
+      private final String loginConfigScope;
+      private final Logger logger;
+
+      SCRAMServerSASL(String name, ScramServerFunctionality scram, String 
loginConfigScope, Logger logger) {
+         this.name = name;
+         this.scram = scram;
+         this.loginConfigScope = loginConfigScope;
+         this.logger = logger;
+      }
+
+      @Override
+      public String getName() {
+         return name;
+      }
+
+      @Override
+      public byte[] processSASL(byte[] bytes) {
+         String message = new String(bytes, StandardCharsets.US_ASCII);
+         try {
+            switch (scram.getState()) {
+               case INITIAL: {
+                  String userName = scram.handleClientFirstMessage(message);
+                  if (userName != null) {
+
+                     LoginContext loginContext = new 
LoginContext(loginConfigScope, new CallbackHandler() {
+
+                        @Override
+                        public void handle(Callback[] callbacks) throws 
IOException, UnsupportedCallbackException {
+                           for (Callback callback : callbacks) {
+                              if (callback instanceof NameCallback) {
+                                 ((NameCallback) callback).setName(userName);
+                              } else if (callback instanceof 
SCRAMMechanismCallback) {
+                                 ((SCRAMMechanismCallback) 
callback).setMechanism(name);
+                              } else if (callback instanceof DigestCallback) {
+                                 ((DigestCallback) 
callback).setDigest(scram.getDigest());
+                              } else if (callback instanceof HmacCallback) {
+                                 ((HmacCallback) 
callback).setHmac(scram.getHmac());
+                              } else {
+                                 throw new 
UnsupportedCallbackException(callback, "Unrecognized Callback " +
+                                          callback.getClass().getSimpleName());
+                              }
+                           }
+                        }
+                     });
+                     loginContext.login();

Review comment:
       Yes kerberos is the source for the roles. As mentioned above, there 
might be other sources as well but for the properties case its the properties 
file... One might even think about only having users in transport-phase and 
enhance with groups on application-phase then one needs to have a matching 
application-login-module also.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 568470)
    Time Spent: 9h  (was: 8h 50m)

> Support for SASL-SCRAM
> ----------------------
>
>                 Key: ARTEMIS-3106
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-3106
>             Project: ActiveMQ Artemis
>          Issue Type: New Feature
>          Components: AMQP
>            Reporter: Christoph Läubrich
>            Priority: Major
>          Time Spent: 9h
>  Remaining Estimate: 0h
>
> With the enhancements in ARTEMIS-33 / [PR 
> 3432|https://github.com/apache/activemq-artemis/pull/3432] it would be now 
> possible to plug-in new SASL mechanism.
> One popular one is 
> [SASL-SCRAM|https://en.wikipedia.org/wiki/Salted_Challenge_Response_Authentication_Mechanism]
>  because it allows channelbinding together with secure storage of 
> user-credential.
> I have created an [implementation of this for Artemis 
> AMQP|https://github.com/laeubi/scram-sasl/tree/artemis/artemis] based on the 
> [SCRAM SASL authentication for Java|https://github.com/ogrebgr/scram-sasl] 
> code with some enhancements/cleanups to the original.
> As the source is already Apache licensed I'd like to propose to include this 
> in the Artemis code-base. This would greatly enhance the interoperability 
> with other implementations e.g. Apache QPID. 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to