private CipherOption getCipherOption(DataTransferEncryptorMessageProto proto, boolean isNegotiatedQopPrivacy, SaslClient saslClient) throws IOException { List<CipherOption> cipherOptions = PB_HELPER.convertCipherOptionProtos(proto.getCipherOptionList()); if (cipherOptions == null || cipherOptions.isEmpty()) { return null; } CipherOption cipherOption = cipherOptions.get(0); return isNegotiatedQopPrivacy ? unwrap(cipherOption, saslClient) : cipherOption; }
private void check(DataTransferEncryptorMessageProto proto) throws IOException { if (proto.getStatus() == DataTransferEncryptorStatus.ERROR_UNKNOWN_KEY) { dfsClient.clearDataEncryptionKey(); throw new InvalidEncryptionKeyException(proto.getMessage()); } else if (proto.getStatus() == DataTransferEncryptorStatus.ERROR) { throw new IOException(proto.getMessage()); } }
DataTransferEncryptorMessageProto proto = (DataTransferEncryptorMessageProto) msg; check(proto); byte[] challenge = proto.getPayload().toByteArray(); byte[] response = saslClient.evaluateChallenge(challenge); switch (step) {
public Builder mergeFrom(org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.DataTransferEncryptorMessageProto other) { if (other == org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.DataTransferEncryptorMessageProto.getDefaultInstance()) return this; if (other.hasStatus()) { setStatus(other.getStatus()); if (other.hasPayload()) { setPayload(other.getPayload()); if (other.hasMessage()) { bitField0_ |= 0x00000004; message_ = other.message_; this.mergeUnknownFields(other.getUnknownFields()); return this;
public Builder mergeFrom(org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.DataTransferEncryptorMessageProto other) { if (other == org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.DataTransferEncryptorMessageProto.getDefaultInstance()) return this; if (other.hasStatus()) { setStatus(other.getStatus()); if (other.hasPayload()) { setPayload(other.getPayload()); if (other.hasMessage()) { bitField0_ |= 0x00000004; message_ = other.message_; this.mergeUnknownFields(other.getUnknownFields()); return this;
public Builder mergeFrom(org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.DataTransferEncryptorMessageProto other) { if (other == org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.DataTransferEncryptorMessageProto.getDefaultInstance()) return this; if (other.hasStatus()) { setStatus(other.getStatus()); if (other.hasPayload()) { setPayload(other.getPayload()); if (other.hasMessage()) { bitField0_ |= 0x00000004; message_ = other.message_; this.mergeUnknownFields(other.getUnknownFields()); return this;
public org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.DataTransferEncryptorMessageProto buildPartial() { org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.DataTransferEncryptorMessageProto result = new org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.DataTransferEncryptorMessageProto(this); int from_bitField0_ = bitField0_; int to_bitField0_ = 0; if (((from_bitField0_ & 0x00000001) == 0x00000001)) { to_bitField0_ |= 0x00000001; } result.status_ = status_; if (((from_bitField0_ & 0x00000002) == 0x00000002)) { to_bitField0_ |= 0x00000002; } result.payload_ = payload_; if (((from_bitField0_ & 0x00000004) == 0x00000004)) { to_bitField0_ |= 0x00000004; } result.message_ = message_; if (cipherOptionBuilder_ == null) { if (((bitField0_ & 0x00000008) == 0x00000008)) { cipherOption_ = java.util.Collections.unmodifiableList(cipherOption_); bitField0_ = (bitField0_ & ~0x00000008); } result.cipherOption_ = cipherOption_; } else { result.cipherOption_ = cipherOptionBuilder_.build(); } result.bitField0_ = to_bitField0_; onBuilt(); return result; }
result = result && (hasStatus() == other.hasStatus()); if (hasStatus()) { result = result && (getStatus() == other.getStatus()); result = result && (hasPayload() == other.hasPayload()); if (hasPayload()) { result = result && getPayload() .equals(other.getPayload()); result = result && (hasMessage() == other.hasMessage()); if (hasMessage()) { result = result && getMessage() .equals(other.getMessage()); result = result && getCipherOptionList() .equals(other.getCipherOptionList()); result = result && getUnknownFields().equals(other.getUnknownFields()); return result;
public org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.DataTransferEncryptorMessageProto buildPartial() { org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.DataTransferEncryptorMessageProto result = new org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.DataTransferEncryptorMessageProto(this); int from_bitField0_ = bitField0_; int to_bitField0_ = 0; if (((from_bitField0_ & 0x00000001) == 0x00000001)) { to_bitField0_ |= 0x00000001; } result.status_ = status_; if (((from_bitField0_ & 0x00000002) == 0x00000002)) { to_bitField0_ |= 0x00000002; } result.payload_ = payload_; if (((from_bitField0_ & 0x00000004) == 0x00000004)) { to_bitField0_ |= 0x00000004; } result.message_ = message_; if (cipherOptionBuilder_ == null) { if (((bitField0_ & 0x00000008) == 0x00000008)) { cipherOption_ = java.util.Collections.unmodifiableList(cipherOption_); bitField0_ = (bitField0_ & ~0x00000008); } result.cipherOption_ = cipherOption_; } else { result.cipherOption_ = cipherOptionBuilder_.build(); } result.bitField0_ = to_bitField0_; onBuilt(); return result; }
result = result && (hasStatus() == other.hasStatus()); if (hasStatus()) { result = result && (getStatus() == other.getStatus()); result = result && (hasPayload() == other.hasPayload()); if (hasPayload()) { result = result && getPayload() .equals(other.getPayload()); result = result && (hasMessage() == other.hasMessage()); if (hasMessage()) { result = result && getMessage() .equals(other.getMessage()); result = result && getCipherOptionList() .equals(other.getCipherOptionList()); result = result && getUnknownFields().equals(other.getUnknownFields()); return result;
/** * Read SASL message and negotiated cipher option from server. * * @param in stream to read * @return SaslResponseWithNegotiatedCipherOption SASL message and * negotiated cipher option * @throws IOException for any error */ public static SaslResponseWithNegotiatedCipherOption readSaslMessageAndNegotiatedCipherOption(InputStream in) throws IOException { DataTransferEncryptorMessageProto proto = DataTransferEncryptorMessageProto.parseFrom(vintPrefixed(in)); if (proto.getStatus() == DataTransferEncryptorStatus.ERROR_UNKNOWN_KEY) { throw new InvalidEncryptionKeyException(proto.getMessage()); } else if (proto.getStatus() == DataTransferEncryptorStatus.ERROR) { throw new IOException(proto.getMessage()); } else { byte[] response = proto.getPayload().toByteArray(); List<CipherOption> options = PBHelper.convertCipherOptionProtos( proto.getCipherOptionList()); CipherOption option = null; if (options != null && !options.isEmpty()) { option = options.get(0); } return new SaslResponseWithNegotiatedCipherOption(response, option); } }
result = result && (hasStatus() == other.hasStatus()); if (hasStatus()) { result = result && (getStatus() == other.getStatus()); result = result && (hasPayload() == other.hasPayload()); if (hasPayload()) { result = result && getPayload() .equals(other.getPayload()); result = result && (hasMessage() == other.hasMessage()); if (hasMessage()) { result = result && getMessage() .equals(other.getMessage()); result = result && getCipherOptionList() .equals(other.getCipherOptionList()); result = result && getUnknownFields().equals(other.getUnknownFields()); return result;
/** * Read SASL message and negotiated cipher option from server. * * @param in stream to read * @return SaslResponseWithNegotiatedCipherOption SASL message and * negotiated cipher option * @throws IOException for any error */ public static SaslResponseWithNegotiatedCipherOption readSaslMessageAndNegotiatedCipherOption(InputStream in) throws IOException { DataTransferEncryptorMessageProto proto = DataTransferEncryptorMessageProto.parseFrom(vintPrefixed(in)); if (proto.getStatus() == DataTransferEncryptorStatus.ERROR_UNKNOWN_KEY) { throw new InvalidEncryptionKeyException(proto.getMessage()); } else if (proto.getStatus() == DataTransferEncryptorStatus.ERROR) { throw new IOException(proto.getMessage()); } else { byte[] response = proto.getPayload().toByteArray(); List<CipherOption> options = PBHelper.convertCipherOptionProtos( proto.getCipherOptionList()); CipherOption option = null; if (options != null && !options.isEmpty()) { option = options.get(0); } return new SaslResponseWithNegotiatedCipherOption(response, option); } }
/** * Read SASL message and negotiated cipher option from server. * * @param in stream to read * @return SaslResponseWithNegotiatedCipherOption SASL message and * negotiated cipher option * @throws IOException for any error */ public static SaslResponseWithNegotiatedCipherOption readSaslMessageAndNegotiatedCipherOption(InputStream in) throws IOException { DataTransferEncryptorMessageProto proto = DataTransferEncryptorMessageProto.parseFrom(vintPrefixed(in)); if (proto.getStatus() == DataTransferEncryptorStatus.ERROR_UNKNOWN_KEY) { throw new InvalidEncryptionKeyException(proto.getMessage()); } else if (proto.getStatus() == DataTransferEncryptorStatus.ERROR) { throw new IOException(proto.getMessage()); } else { byte[] response = proto.getPayload().toByteArray(); List<CipherOption> options = PBHelperClient.convertCipherOptionProtos( proto.getCipherOptionList()); CipherOption option = null; if (options != null && !options.isEmpty()) { option = options.get(0); } return new SaslResponseWithNegotiatedCipherOption(response, option); } }
public org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.DataTransferEncryptorMessageProto buildPartial() { org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.DataTransferEncryptorMessageProto result = new org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.DataTransferEncryptorMessageProto(this); int from_bitField0_ = bitField0_; int to_bitField0_ = 0; if (((from_bitField0_ & 0x00000001) == 0x00000001)) { to_bitField0_ |= 0x00000001; } result.status_ = status_; if (((from_bitField0_ & 0x00000002) == 0x00000002)) { to_bitField0_ |= 0x00000002; } result.payload_ = payload_; if (((from_bitField0_ & 0x00000004) == 0x00000004)) { to_bitField0_ |= 0x00000004; } result.message_ = message_; if (cipherOptionBuilder_ == null) { if (((bitField0_ & 0x00000008) == 0x00000008)) { cipherOption_ = java.util.Collections.unmodifiableList(cipherOption_); bitField0_ = (bitField0_ & ~0x00000008); } result.cipherOption_ = cipherOption_; } else { result.cipherOption_ = cipherOptionBuilder_.build(); } result.bitField0_ = to_bitField0_; onBuilt(); return result; }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptorForType().hashCode(); if (hasStatus()) { hash = (37 * hash) + STATUS_FIELD_NUMBER; hash = (53 * hash) + hashEnum(getStatus()); } if (hasPayload()) { hash = (37 * hash) + PAYLOAD_FIELD_NUMBER; hash = (53 * hash) + getPayload().hashCode(); } if (hasMessage()) { hash = (37 * hash) + MESSAGE_FIELD_NUMBER; hash = (53 * hash) + getMessage().hashCode(); } if (getCipherOptionCount() > 0) { hash = (37 * hash) + CIPHEROPTION_FIELD_NUMBER; hash = (53 * hash) + getCipherOptionList().hashCode(); } hash = (29 * hash) + getUnknownFields().hashCode(); memoizedHashCode = hash; return hash; }
/** * Sends a SASL negotiation message. * * @param out stream to receive message * @param status negotiation status * @param payload to send * @param message to send * @throws IOException for any error */ public static void sendSaslMessage(OutputStream out, DataTransferEncryptorStatus status, byte[] payload, String message) throws IOException { DataTransferEncryptorMessageProto.Builder builder = DataTransferEncryptorMessageProto.newBuilder(); builder.setStatus(status); if (payload != null) { builder.setPayload(ByteString.copyFrom(payload)); } if (message != null) { builder.setMessage(message); } DataTransferEncryptorMessageProto proto = builder.build(); proto.writeDelimitedTo(out); out.flush(); }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptorForType().hashCode(); if (hasStatus()) { hash = (37 * hash) + STATUS_FIELD_NUMBER; hash = (53 * hash) + hashEnum(getStatus()); } if (hasPayload()) { hash = (37 * hash) + PAYLOAD_FIELD_NUMBER; hash = (53 * hash) + getPayload().hashCode(); } if (hasMessage()) { hash = (37 * hash) + MESSAGE_FIELD_NUMBER; hash = (53 * hash) + getMessage().hashCode(); } if (getCipherOptionCount() > 0) { hash = (37 * hash) + CIPHEROPTION_FIELD_NUMBER; hash = (53 * hash) + getCipherOptionList().hashCode(); } hash = (29 * hash) + getUnknownFields().hashCode(); memoizedHashCode = hash; return hash; }
/** * Sends a SASL negotiation message. * * @param out stream to receive message * @param status negotiation status * @param payload to send * @param message to send * @throws IOException for any error */ public static void sendSaslMessage(OutputStream out, DataTransferEncryptorStatus status, byte[] payload, String message) throws IOException { DataTransferEncryptorMessageProto.Builder builder = DataTransferEncryptorMessageProto.newBuilder(); builder.setStatus(status); if (payload != null) { builder.setPayload(ByteString.copyFrom(payload)); } if (message != null) { builder.setMessage(message); } DataTransferEncryptorMessageProto proto = builder.build(); proto.writeDelimitedTo(out); out.flush(); }
/** * Reads a SASL negotiation message and negotiation cipher options. * * @param in stream to read * @param cipherOptions list to store negotiation cipher options * @return byte[] SASL negotiation message * @throws IOException for any error */ public static byte[] readSaslMessageAndNegotiationCipherOptions( InputStream in, List<CipherOption> cipherOptions) throws IOException { DataTransferEncryptorMessageProto proto = DataTransferEncryptorMessageProto.parseFrom(vintPrefixed(in)); if (proto.getStatus() == DataTransferEncryptorStatus.ERROR_UNKNOWN_KEY) { throw new InvalidEncryptionKeyException(proto.getMessage()); } else if (proto.getStatus() == DataTransferEncryptorStatus.ERROR) { throw new IOException(proto.getMessage()); } else { List<CipherOptionProto> optionProtos = proto.getCipherOptionList(); if (optionProtos != null) { for (CipherOptionProto optionProto : optionProtos) { cipherOptions.add(PBHelper.convert(optionProto)); } } return proto.getPayload().toByteArray(); } }