Github user cjjnjust commented on a diff in the pull request:
https://github.com/apache/spark/pull/15172#discussion_r85875690
--- Diff:
common/network-common/src/main/java/org/apache/spark/network/sasl/SaslRpcHandler.java
---
@@ -80,46 +84,71 @@ public void receive(TransportClient client, ByteBuffer
message, RpcResponseCallb
delegate.receive(client, message, callback);
return;
}
+ if (saslServer == null || !saslServer.isComplete()) {
+ ByteBuf nettyBuf = Unpooled.wrappedBuffer(message);
+ SaslMessage saslMessage;
+ try {
+ saslMessage = SaslMessage.decode(nettyBuf);
+ } finally {
+ nettyBuf.release();
+ }
- ByteBuf nettyBuf = Unpooled.wrappedBuffer(message);
- SaslMessage saslMessage;
- try {
- saslMessage = SaslMessage.decode(nettyBuf);
- } finally {
- nettyBuf.release();
- }
-
- if (saslServer == null) {
- // First message in the handshake, setup the necessary state.
- client.setClientId(saslMessage.appId);
- saslServer = new SparkSaslServer(saslMessage.appId, secretKeyHolder,
- conf.saslServerAlwaysEncrypt());
- }
+ if (saslServer == null) {
+ // First message in the handshake, setup the necessary state.
+ client.setClientId(saslMessage.appId);
+ saslServer = new SparkSaslServer(saslMessage.appId,
secretKeyHolder,
+ conf.saslServerAlwaysEncrypt());
+ }
- byte[] response;
- try {
- response = saslServer.response(JavaUtils.bufferToArray(
- saslMessage.body().nioByteBuffer()));
- } catch (IOException ioe) {
- throw new RuntimeException(ioe);
+ byte[] response;
+ try {
+ response = saslServer.response(JavaUtils.bufferToArray(
+ saslMessage.body().nioByteBuffer()));
+ } catch (IOException ioe) {
+ throw new RuntimeException(ioe);
+ }
+ callback.onSuccess(ByteBuffer.wrap(response));
}
- callback.onSuccess(ByteBuffer.wrap(response));
// Setup encryption after the SASL response is sent, otherwise the
client can't parse the
// response. It's ok to change the channel pipeline here since we are
processing an incoming
// message, so the pipeline is busy and no new incoming messages will
be fed to it before this
// method returns. This assumes that the code ensures, through other
means, that no outbound
// messages are being written to the channel while negotiation is
still going on.
if (saslServer.isComplete()) {
- logger.debug("SASL authentication successful for channel {}",
client);
- isComplete = true;
- if
(SparkSaslServer.QOP_AUTH_CONF.equals(saslServer.getNegotiatedProperty(Sasl.QOP)))
{
+ if
(!SparkSaslServer.QOP_AUTH_CONF.equals(saslServer.getNegotiatedProperty(Sasl.QOP)))
{
+ logger.debug("SASL authentication successful for channel {}",
client);
+ complete(true);
+ return ;
+ }
+
+ if (!conf.AesEncryptionEnabled()) {
logger.debug("Enabling encryption for channel {}", client);
SaslEncryption.addToChannel(channel, saslServer,
conf.maxSaslEncryptedBlockSize());
- saslServer = null;
- } else {
- saslServer.dispose();
- saslServer = null;
+ complete(false);
+ return;
+ }
+
+ // Extra negotiation should happen after authentication, so return
directly while
+ // processing authenticate.
+ if (!isAuthenticated) {
+ logger.debug("SASL authentication successful for channel {}",
client);
+ isAuthenticated = true;
+ return;
+ }
+
+ // Create AES cipher when it is authenticated
+ try {
+ AesConfigMessage configMessage =
AesConfigMessage.decodeMessage(message);
+ AesCipher cipher = new AesCipher(configMessage);
+
+ // Send response back to client to confirm that server accept
config.
+ callback.onSuccess(JavaUtils.stringToBytes(AesCipher.TRANSFORM));
--- End diff --
This should be call after AddtoChannel, otherwise it will be sent with
encrypted data while at the moment client is not ready for decryption.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]