Github user vanzin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/15172#discussion_r83515036
  
    --- Diff: 
common/network-common/src/main/java/org/apache/spark/network/sasl/SparkSaslServer.java
 ---
    @@ -150,6 +161,62 @@ public synchronized void dispose() {
       }
     
       /**
    +   * Negotiate with peer for extended options, such as using AES cipher.
    +   * @param message is message receive from peer which may contains 
communication parameters.
    +   * @param callback is rpc callback.
    +   * @param conf contains transport configuration.
    +   * @return Object which represent the result of negotiate.
    +   */
    +  public Object negotiate(ByteBuffer message, RpcResponseCallback 
callback, TransportConf conf)
    +    throws SaslException {
    +    AesCipher cipher;
    +
    +    // Receive initial option from client
    +    AesCipherOption cipherOption = 
AesCipherOption.decode(Unpooled.wrappedBuffer(message));
    +    String transformation = AesCipher.TRANSFORM;
    +    Properties properties = new Properties();
    +
    +    try {
    +      // Generate key and iv
    +      if (conf.saslEncryptionAesCipherKeySizeBits() % 8 != 0) {
    +        throw new IllegalArgumentException("The AES cipher key size in 
bits should be a multiple " +
    +          "of byte");
    +      }
    +
    +      int keyLen = conf.saslEncryptionAesCipherKeySizeBits() / 8;
    +      int paramLen = 
CryptoCipherFactory.getCryptoCipher(transformation,properties).getBlockSize();
    +      byte[] inKey = new byte[keyLen];
    +      byte[] outKey = new byte[keyLen];
    +      byte[] inIv = new byte[paramLen];
    +      byte[] outIv = new byte[paramLen];
    +
    +      // Get the 'CryptoRandom' instance.
    +      CryptoRandom random = 
CryptoRandomFactory.getCryptoRandom(properties);
    +      random.nextBytes(inKey);
    +      random.nextBytes(outKey);
    +      random.nextBytes(inIv);
    +      random.nextBytes(outIv);
    +
    +      // Update cipher option for client. The key is encrypted.
    +      cipherOption.setParameters(wrap(inKey, 0, inKey.length), inIv,
    --- End diff --
    
    There's a slight irony here in that you're using 3DES to encrypt the AES 
keys...


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to