[
https://issues.apache.org/jira/browse/ARTEMIS-3106?focusedWorklogId=568445&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-568445
]
ASF GitHub Bot logged work on ARTEMIS-3106:
-------------------------------------------
Author: ASF GitHub Bot
Created on: 18/Mar/21 15:42
Start Date: 18/Mar/21 15:42
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_r596992275
##########
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:
There are two "phases" in the Artemis Workflow (you can take a look at
kerberos auth for example that uses a similar scheme:
1. The user autenticates/login with username-password on the
**transport-layer** (AMQP). That means, at this point the user is not logged in
on the application level, we only collect the user and group principals here.
2. If the user has passed transport authentication Artemis asks for the user
credentials on the **application-layer**, normally this would for example query
a user-database. Now the aquired data from phase-1 are passed to the
application layer and the user is logged in with his naem+roles.
That's why there are two provider: SCRAMLoginModule for the application
layer and SCRAMPropertiesLoginModule for the transport-layer.
So if the login succeeds in an intermediate SASL-Phase but fails later the
information is simply thrown away and never gets to the application layer. This
allows users to plugin alternative User-Information sources (e.g. fetching from
a database or LDAP or whatever) instead of the SCRAMPropertiesLoginModule.
--
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:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 568445)
Time Spent: 7h 10m (was: 7h)
> 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: 7h 10m
> 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)