Skip to content

Commit 405b23b

Browse files
sweisdbNgone51
authored andcommitted
[SPARK-47172][CORE][3.5] Add support for AES-GCM for RPC encryption
### What changes were proposed in this pull request? This change adds AES-GCM as an optional AES cipher mode for RPC encryption. The current default is using AES-CTR without any authentication. That would allow someone on the network to easily modify RPC contents on the wire and impact Spark behavior. See [SPARK-47172](https://issues.apache.org/jira/browse/SPARK-47172) for more details. ### Why are the changes needed? The current default is using AES-CTR without any authentication. That would allow someone on the network to easily modify RPC contents on the wire and impact Spark behavior. ### Does this PR introduce _any_ user-facing change? Yes, it adds an additional configuration flag is reflected in the documentation. ### How was this patch tested? Existing unit tests are all ensured to pass. New unit tests are written to explicitly test GCM support and to verify that modifying ciphertext content will cause an exception and fail. `build/sbt "network-common/test:testOnly"` `build/sbt "network-common/test:testOnly org.apache.spark.network.crypto.AuthIntegrationSuite"` `build/sbt "network-common/test:testOnly org.apache.spark.network.crypto.AuthEngineSuite"` ### Was this patch authored or co-authored using generative AI tooling? Nope. Closes #47060 from sweisdb/SPARK-47172-3.5. Authored-by: Steve Weis <steve.weis@databricks.com> Signed-off-by: Yi Wu <yi.wu@databricks.com>
1 parent 0db5bde commit 405b23b

File tree

11 files changed

+1534
-541
lines changed

11 files changed

+1534
-541
lines changed

common/network-common/src/main/java/org/apache/spark/network/crypto/AuthEngine.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class AuthEngine implements Closeable {
4545
public static final byte[] INPUT_IV_INFO = "inputIv".getBytes(UTF_8);
4646
public static final byte[] OUTPUT_IV_INFO = "outputIv".getBytes(UTF_8);
4747
private static final String MAC_ALGORITHM = "HMACSHA256";
48+
private static final String LEGACY_CIPHER_ALGORITHM = "AES/CTR/NoPadding";
49+
private static final String CIPHER_ALGORITHM = "AES/GCM/NoPadding";
4850
private static final int AES_GCM_KEY_SIZE_BYTES = 16;
4951
private static final byte[] EMPTY_TRANSCRIPT = new byte[0];
5052
private static final int UNSAFE_SKIP_HKDF_VERSION = 1;
@@ -227,12 +229,19 @@ private TransportCipher generateTransportCipher(
227229
OUTPUT_IV_INFO, // This is the HKDF info field used to differentiate IV values
228230
AES_GCM_KEY_SIZE_BYTES);
229231
SecretKeySpec sessionKey = new SecretKeySpec(derivedKey, "AES");
230-
return new TransportCipher(
231-
cryptoConf,
232-
conf.cipherTransformation(),
233-
sessionKey,
234-
isClient ? clientIv : serverIv, // If it's the client, use the client IV first
235-
isClient ? serverIv : clientIv);
232+
if (LEGACY_CIPHER_ALGORITHM.equalsIgnoreCase(conf.cipherTransformation())) {
233+
return new CtrTransportCipher(
234+
cryptoConf,
235+
sessionKey,
236+
isClient ? clientIv : serverIv, // If it's the client, use the client IV first
237+
isClient ? serverIv : clientIv);
238+
} else if (CIPHER_ALGORITHM.equalsIgnoreCase(conf.cipherTransformation())) {
239+
return new GcmTransportCipher(sessionKey);
240+
} else {
241+
throw new IllegalArgumentException(
242+
String.format("Unsupported cipher mode: %s. %s and %s are supported.",
243+
conf.cipherTransformation(), CIPHER_ALGORITHM, LEGACY_CIPHER_ALGORITHM));
244+
}
236245
}
237246

238247
private byte[] getTranscript(AuthMessage... encryptedPublicKeys) {

0 commit comments

Comments
 (0)