Skip to content

Commit 573a8f3

Browse files
author
Junjie Chen
committed
[SPARK-13331] AES support for over-the-wire encryption
Encrypt the config message since it was removed by mistake.
1 parent c50e088 commit 573a8f3

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

common/network-common/src/main/java/org/apache/spark/network/sasl/SaslClientBootstrap.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,20 @@ public void doBootstrap(TransportClient client, Channel channel) {
9595
// Generate a request config message to send to server.
9696
AesConfigMessage configMessage = AesCipher.createConfigMessage(conf);
9797
ByteBuffer buf = configMessage.encodeMessage();
98-
client.sendRpcSync(buf, conf.saslRTTimeoutMs());
98+
99+
// Encrypted the config message.
100+
ByteBuffer encrypted = ByteBuffer.wrap(
101+
saslClient.wrap(buf.array(), 0, buf.array().length));
102+
103+
client.sendRpcSync(encrypted, conf.saslRTTimeoutMs());
99104
AesCipher cipher = new AesCipher(configMessage);
100105
logger.info("Enabling AES cipher for client channel {}", client);
101106
cipher.addToChannel(channel);
102107
} else {
103108
SaslEncryption.addToChannel(channel, saslClient, conf.maxSaslEncryptedBlockSize());
104109
}
110+
111+
saslClient.dispose();
105112
saslClient = null;
106113
logger.debug("Channel {} configured for encryption.", client);
107114
}

common/network-common/src/main/java/org/apache/spark/network/sasl/SaslRpcHandler.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,16 @@ public void receive(TransportClient client, ByteBuffer message, RpcResponseCallb
139139

140140
// Create AES cipher when it is authenticated
141141
try {
142-
AesConfigMessage configMessage = AesConfigMessage.decodeMessage(message);
142+
byte[] encrypted;
143+
if (message.hasArray()) {
144+
encrypted = message.array();
145+
} else {
146+
encrypted = new byte[message.remaining()];
147+
message.get(encrypted);
148+
}
149+
ByteBuffer decrypted = ByteBuffer.wrap(saslServer.unwrap(encrypted, 0 , encrypted.length));
150+
151+
AesConfigMessage configMessage = AesConfigMessage.decodeMessage(decrypted);
143152
AesCipher cipher = new AesCipher(configMessage);
144153

145154
// Send response back to client to confirm that server accept config.

0 commit comments

Comments
 (0)