Class DataTransferSaslUtil
java.lang.Object
org.apache.hadoop.hdfs.protocol.datatransfer.sasl.DataTransferSaslUtil
Utility methods implementing SASL negotiation for DataTransferProtocol.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDelimiter for the three-part SASL username string.static final intSent by clients and validated by servers. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckSaslComplete(org.apache.hadoop.hdfs.protocol.datatransfer.sasl.SaslParticipant sasl, Map<String, String> saslProps) Checks that SASL negotiation has completed for the given participant, and the negotiated quality of protection is included in the given SASL properties and therefore acceptable.createSaslPropertiesForEncryption(String encryptionAlgorithm) Creates SASL properties required for an encrypted SASL negotiation.static IOStreamPaircreateStreamPair(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.crypto.CipherOption cipherOption, OutputStream out, InputStream in, boolean isServer) Create IOStreamPair ofCryptoInputStreamandCryptoOutputStreamstatic char[]encryptionKeyToPassword(byte[] encryptionKey) For an encrypted SASL negotiation, encodes an encryption key to a SASL password.static InetAddressgetPeerAddress(Peer peer) Returns InetAddress from peer.static org.apache.hadoop.security.SaslPropertiesResolvergetSaslPropertiesResolver(org.apache.hadoop.conf.Configuration conf) Creates a SaslPropertiesResolver from the given configuration.static org.apache.hadoop.crypto.CipherOptionnegotiateCipherOption(org.apache.hadoop.conf.Configuration conf, List<org.apache.hadoop.crypto.CipherOption> options) Negotiate a cipher option which server supports.static byte[]Reads a SASL negotiation message.Read SASL message and negotiated cipher option from server.static byte[]readSaslMessageAndNegotiationCipherOptions(InputStream in, List<org.apache.hadoop.crypto.CipherOption> cipherOptions) Reads a SASL negotiation message and negotiation cipher options.static org.apache.hadoop.hdfs.protocol.datatransfer.sasl.DataTransferSaslUtil.SaslMessageWithHandshakestatic booleanrequestedQopContainsPrivacy(Map<String, String> saslProps) Check whether requested SASL Qop contains privacy.static voidsendGenericSaslErrorMessage(OutputStream out, String message) Sends a SASL negotiation message indicating an error.static voidsendSaslMessage(OutputStream out, byte[] payload) Sends a SASL negotiation message.static voidsendSaslMessage(OutputStream out, org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.DataTransferEncryptorMessageProto.DataTransferEncryptorStatus status, byte[] payload, String message) Sends a SASL negotiation message.static voidsendSaslMessage(OutputStream out, org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.DataTransferEncryptorMessageProto.DataTransferEncryptorStatus status, byte[] payload, String message, org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.HandshakeSecretProto handshakeSecret) static voidsendSaslMessage(OutputStream out, org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.DataTransferEncryptorMessageProto.DataTransferEncryptorStatus status, byte[] payload, String message, org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.HandshakeSecretProto handshakeSecret, boolean accessTokenError) static voidsendSaslMessageAndNegotiatedCipherOption(OutputStream out, byte[] payload, org.apache.hadoop.crypto.CipherOption option) Send SASL message and negotiated cipher option to client.static voidsendSaslMessageAndNegotiationCipherOptions(OutputStream out, byte[] payload, List<org.apache.hadoop.crypto.CipherOption> options) Send a SASL negotiation message and negotiation cipher options to server.static voidsendSaslMessageHandshakeSecret(OutputStream out, byte[] payload, byte[] secret, String bpid) static voidsendSaslMessageHandshakeSecret(OutputStream out, org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.DataTransferEncryptorMessageProto.DataTransferEncryptorStatus status, byte[] payload, String message, byte[] secret, String bpid) static org.apache.hadoop.crypto.CipherOptionunwrap(org.apache.hadoop.crypto.CipherOption option, org.apache.hadoop.hdfs.protocol.datatransfer.sasl.SaslParticipant sasl) Decrypt the key and iv of the negotiated cipher option.static org.apache.hadoop.crypto.CipherOptionwrap(org.apache.hadoop.crypto.CipherOption option, org.apache.hadoop.hdfs.protocol.datatransfer.sasl.SaslParticipant sasl) Encrypt the key and iv of the negotiated cipher option.
-
Field Details
-
NAME_DELIMITER
Delimiter for the three-part SASL username string.- See Also:
-
SASL_TRANSFER_MAGIC_NUMBER
public static final int SASL_TRANSFER_MAGIC_NUMBERSent by clients and validated by servers. We use a number that's unlikely to ever be sent as the value of the DATA_TRANSFER_VERSION.- See Also:
-
-
Method Details
-
checkSaslComplete
public static void checkSaslComplete(org.apache.hadoop.hdfs.protocol.datatransfer.sasl.SaslParticipant sasl, Map<String, String> saslProps) throws IOExceptionChecks that SASL negotiation has completed for the given participant, and the negotiated quality of protection is included in the given SASL properties and therefore acceptable.- Parameters:
sasl- participant to checksaslProps- properties of SASL negotiation- Throws:
IOException- for any error
-
requestedQopContainsPrivacy
Check whether requested SASL Qop contains privacy.- Parameters:
saslProps- properties of SASL negotiation- Returns:
- boolean true if privacy exists
-
createSaslPropertiesForEncryption
Creates SASL properties required for an encrypted SASL negotiation.- Parameters:
encryptionAlgorithm- to use for SASL negotation- Returns:
- properties of encrypted SASL negotiation
-
encryptionKeyToPassword
public static char[] encryptionKeyToPassword(byte[] encryptionKey) For an encrypted SASL negotiation, encodes an encryption key to a SASL password.- Parameters:
encryptionKey- to encode- Returns:
- key encoded as SASL password
-
getPeerAddress
Returns InetAddress from peer. The getRemoteAddressString has the form [host][/ip-address]:port. The host may be missing. The IP address (and preceding '/') may be missing. The port preceded by ':' is always present.- Returns:
- InetAddress from peer
-
getSaslPropertiesResolver
public static org.apache.hadoop.security.SaslPropertiesResolver getSaslPropertiesResolver(org.apache.hadoop.conf.Configuration conf) Creates a SaslPropertiesResolver from the given configuration. This method works by cloning the configuration, translating configuration properties specific to DataTransferProtocol to what SaslPropertiesResolver expects, and then delegating to SaslPropertiesResolver for initialization. This method returns null if SASL protection has not been configured for DataTransferProtocol.- Parameters:
conf- configuration to read- Returns:
- SaslPropertiesResolver for DataTransferProtocol, or null if not configured
-
readSaslMessage
Reads a SASL negotiation message.- Parameters:
in- stream to read- Returns:
- bytes of SASL negotiation messsage
- Throws:
IOException- for any error
-
readSaslMessageAndNegotiationCipherOptions
public static byte[] readSaslMessageAndNegotiationCipherOptions(InputStream in, List<org.apache.hadoop.crypto.CipherOption> cipherOptions) throws IOException Reads a SASL negotiation message and negotiation cipher options.- Parameters:
in- stream to readcipherOptions- list to store negotiation cipher options- Returns:
- byte[] SASL negotiation message
- Throws:
IOException- for any error
-
readSaslMessageWithHandshakeSecret
public static org.apache.hadoop.hdfs.protocol.datatransfer.sasl.DataTransferSaslUtil.SaslMessageWithHandshake readSaslMessageWithHandshakeSecret(InputStream in) throws IOException - Throws:
IOException
-
negotiateCipherOption
public static org.apache.hadoop.crypto.CipherOption negotiateCipherOption(org.apache.hadoop.conf.Configuration conf, List<org.apache.hadoop.crypto.CipherOption> options) throws IOException Negotiate a cipher option which server supports.- Parameters:
conf- the configurationoptions- the cipher options which client supports- Returns:
- CipherOption negotiated cipher option
- Throws:
IOException
-
sendSaslMessageAndNegotiatedCipherOption
public static void sendSaslMessageAndNegotiatedCipherOption(OutputStream out, byte[] payload, org.apache.hadoop.crypto.CipherOption option) throws IOException Send SASL message and negotiated cipher option to client.- Parameters:
out- stream to receive messagepayload- to sendoption- negotiated cipher option- Throws:
IOException- for any error
-
createStreamPair
public static IOStreamPair createStreamPair(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.crypto.CipherOption cipherOption, OutputStream out, InputStream in, boolean isServer) throws IOException Create IOStreamPair ofCryptoInputStreamandCryptoOutputStream- Parameters:
conf- the configurationcipherOption- negotiated cipher optionout- underlying output streamin- underlying input streamisServer- is server side- Returns:
- IOStreamPair the stream pair
- Throws:
IOException- for any error
-
sendGenericSaslErrorMessage
Sends a SASL negotiation message indicating an error.- Parameters:
out- stream to receive messagemessage- to send- Throws:
IOException- for any error
-
sendSaslMessage
Sends a SASL negotiation message.- Parameters:
out- stream to receive messagepayload- to send- Throws:
IOException- for any error
-
sendSaslMessageHandshakeSecret
public static void sendSaslMessageHandshakeSecret(OutputStream out, byte[] payload, byte[] secret, String bpid) throws IOException - Throws:
IOException
-
sendSaslMessageAndNegotiationCipherOptions
public static void sendSaslMessageAndNegotiationCipherOptions(OutputStream out, byte[] payload, List<org.apache.hadoop.crypto.CipherOption> options) throws IOException Send a SASL negotiation message and negotiation cipher options to server.- Parameters:
out- stream to receive messagepayload- to sendoptions- cipher options to negotiate- Throws:
IOException- for any error
-
readSaslMessageAndNegotiatedCipherOption
public static SaslResponseWithNegotiatedCipherOption readSaslMessageAndNegotiatedCipherOption(InputStream in) throws IOException Read SASL message and negotiated cipher option from server.- Parameters:
in- stream to read- Returns:
- SaslResponseWithNegotiatedCipherOption SASL message and negotiated cipher option
- Throws:
IOException- for any error
-
wrap
public static org.apache.hadoop.crypto.CipherOption wrap(org.apache.hadoop.crypto.CipherOption option, org.apache.hadoop.hdfs.protocol.datatransfer.sasl.SaslParticipant sasl) throws IOException Encrypt the key and iv of the negotiated cipher option.- Parameters:
option- negotiated cipher optionsasl- SASL participant representing server- Returns:
- CipherOption negotiated cipher option which contains the encrypted key and iv
- Throws:
IOException- for any error
-
unwrap
public static org.apache.hadoop.crypto.CipherOption unwrap(org.apache.hadoop.crypto.CipherOption option, org.apache.hadoop.hdfs.protocol.datatransfer.sasl.SaslParticipant sasl) throws IOException Decrypt the key and iv of the negotiated cipher option.- Parameters:
option- negotiated cipher optionsasl- SASL participant representing client- Returns:
- CipherOption negotiated cipher option which contains the decrypted key and iv
- Throws:
IOException- for any error
-
sendSaslMessage
public static void sendSaslMessage(OutputStream out, org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.DataTransferEncryptorMessageProto.DataTransferEncryptorStatus status, byte[] payload, String message) throws IOException Sends a SASL negotiation message.- Parameters:
out- stream to receive messagestatus- negotiation statuspayload- to sendmessage- to send- Throws:
IOException- for any error
-
sendSaslMessage
public static void sendSaslMessage(OutputStream out, org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.DataTransferEncryptorMessageProto.DataTransferEncryptorStatus status, byte[] payload, String message, org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.HandshakeSecretProto handshakeSecret) throws IOException - Throws:
IOException
-
sendSaslMessage
public static void sendSaslMessage(OutputStream out, org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.DataTransferEncryptorMessageProto.DataTransferEncryptorStatus status, byte[] payload, String message, org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.HandshakeSecretProto handshakeSecret, boolean accessTokenError) throws IOException - Throws:
IOException
-
sendSaslMessageHandshakeSecret
public static void sendSaslMessageHandshakeSecret(OutputStream out, org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.DataTransferEncryptorMessageProto.DataTransferEncryptorStatus status, byte[] payload, String message, byte[] secret, String bpid) throws IOException - Throws:
IOException
-