Java Code Examples for org.apache.hadoop.crypto.CipherOption#getOutKey()

The following examples show how to use org.apache.hadoop.crypto.CipherOption#getOutKey() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataTransferSaslUtil.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Create IOStreamPair of {@link org.apache.hadoop.crypto.CryptoInputStream}
 * and {@link org.apache.hadoop.crypto.CryptoOutputStream}
 * 
 * @param conf the configuration
 * @param cipherOption negotiated cipher option
 * @param out underlying output stream
 * @param in underlying input stream
 * @param isServer is server side
 * @return IOStreamPair the stream pair
 * @throws IOException for any error
 */
public static IOStreamPair createStreamPair(Configuration conf,
    CipherOption cipherOption, OutputStream out, InputStream in, 
    boolean isServer) throws IOException {
  if (LOG.isDebugEnabled()) {
    LOG.debug("Creating IOStreamPair of CryptoInputStream and " +
        "CryptoOutputStream.");
  }
  CryptoCodec codec = CryptoCodec.getInstance(conf, 
      cipherOption.getCipherSuite());
  byte[] inKey = cipherOption.getInKey();
  byte[] inIv = cipherOption.getInIv();
  byte[] outKey = cipherOption.getOutKey();
  byte[] outIv = cipherOption.getOutIv();
  InputStream cIn = new CryptoInputStream(in, codec, 
      isServer ? inKey : outKey, isServer ? inIv : outIv);
  OutputStream cOut = new CryptoOutputStream(out, codec, 
      isServer ? outKey : inKey, isServer ? outIv : inIv);
  return new IOStreamPair(cIn, cOut);
}
 
Example 2
Source File: DataTransferSaslUtil.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Encrypt the key and iv of the negotiated cipher option.
 * 
 * @param option negotiated cipher option
 * @param sasl SASL participant representing server
 * @return CipherOption negotiated cipher option which contains the 
 * encrypted key and iv
 * @throws IOException for any error
 */
public static CipherOption wrap(CipherOption option, SaslParticipant sasl) 
    throws IOException {
  if (option != null) {
    byte[] inKey = option.getInKey();
    if (inKey != null) {
      inKey = sasl.wrap(inKey, 0, inKey.length);
    }
    byte[] outKey = option.getOutKey();
    if (outKey != null) {
      outKey = sasl.wrap(outKey, 0, outKey.length);
    }
    return new CipherOption(option.getCipherSuite(), inKey, option.getInIv(),
        outKey, option.getOutIv());
  }
  
  return null;
}
 
Example 3
Source File: DataTransferSaslUtil.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Decrypt the key and iv of the negotiated cipher option.
 * 
 * @param option negotiated cipher option
 * @param sasl SASL participant representing client
 * @return CipherOption negotiated cipher option which contains the 
 * decrypted key and iv
 * @throws IOException for any error
 */
public static CipherOption unwrap(CipherOption option, SaslParticipant sasl)
    throws IOException {
  if (option != null) {
    byte[] inKey = option.getInKey();
    if (inKey != null) {
      inKey = sasl.unwrap(inKey, 0, inKey.length);
    }
    byte[] outKey = option.getOutKey();
    if (outKey != null) {
      outKey = sasl.unwrap(outKey, 0, outKey.length);
    }
    return new CipherOption(option.getCipherSuite(), inKey, option.getInIv(),
        outKey, option.getOutIv());
  }
  
  return null;
}
 
Example 4
Source File: PBHelper.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public static CipherOptionProto convert(CipherOption option) {
  if (option != null) {
    CipherOptionProto.Builder builder = CipherOptionProto.
        newBuilder();
    if (option.getCipherSuite() != null) {
      builder.setSuite(convert(option.getCipherSuite()));
    }
    if (option.getInKey() != null) {
      builder.setInKey(ByteString.copyFrom(option.getInKey()));
    }
    if (option.getInIv() != null) {
      builder.setInIv(ByteString.copyFrom(option.getInIv()));
    }
    if (option.getOutKey() != null) {
      builder.setOutKey(ByteString.copyFrom(option.getOutKey()));
    }
    if (option.getOutIv() != null) {
      builder.setOutIv(ByteString.copyFrom(option.getOutIv()));
    }
    return builder.build();
  }
  return null;
}
 
Example 5
Source File: DataTransferSaslUtil.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Create IOStreamPair of {@link org.apache.hadoop.crypto.CryptoInputStream}
 * and {@link org.apache.hadoop.crypto.CryptoOutputStream}
 * 
 * @param conf the configuration
 * @param cipherOption negotiated cipher option
 * @param out underlying output stream
 * @param in underlying input stream
 * @param isServer is server side
 * @return IOStreamPair the stream pair
 * @throws IOException for any error
 */
public static IOStreamPair createStreamPair(Configuration conf,
    CipherOption cipherOption, OutputStream out, InputStream in, 
    boolean isServer) throws IOException {
  if (LOG.isDebugEnabled()) {
    LOG.debug("Creating IOStreamPair of CryptoInputStream and " +
        "CryptoOutputStream.");
  }
  CryptoCodec codec = CryptoCodec.getInstance(conf, 
      cipherOption.getCipherSuite());
  byte[] inKey = cipherOption.getInKey();
  byte[] inIv = cipherOption.getInIv();
  byte[] outKey = cipherOption.getOutKey();
  byte[] outIv = cipherOption.getOutIv();
  InputStream cIn = new CryptoInputStream(in, codec, 
      isServer ? inKey : outKey, isServer ? inIv : outIv);
  OutputStream cOut = new CryptoOutputStream(out, codec, 
      isServer ? outKey : inKey, isServer ? outIv : inIv);
  return new IOStreamPair(cIn, cOut);
}
 
Example 6
Source File: DataTransferSaslUtil.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Encrypt the key and iv of the negotiated cipher option.
 * 
 * @param option negotiated cipher option
 * @param sasl SASL participant representing server
 * @return CipherOption negotiated cipher option which contains the 
 * encrypted key and iv
 * @throws IOException for any error
 */
public static CipherOption wrap(CipherOption option, SaslParticipant sasl) 
    throws IOException {
  if (option != null) {
    byte[] inKey = option.getInKey();
    if (inKey != null) {
      inKey = sasl.wrap(inKey, 0, inKey.length);
    }
    byte[] outKey = option.getOutKey();
    if (outKey != null) {
      outKey = sasl.wrap(outKey, 0, outKey.length);
    }
    return new CipherOption(option.getCipherSuite(), inKey, option.getInIv(),
        outKey, option.getOutIv());
  }
  
  return null;
}
 
Example 7
Source File: DataTransferSaslUtil.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Decrypt the key and iv of the negotiated cipher option.
 * 
 * @param option negotiated cipher option
 * @param sasl SASL participant representing client
 * @return CipherOption negotiated cipher option which contains the 
 * decrypted key and iv
 * @throws IOException for any error
 */
public static CipherOption unwrap(CipherOption option, SaslParticipant sasl)
    throws IOException {
  if (option != null) {
    byte[] inKey = option.getInKey();
    if (inKey != null) {
      inKey = sasl.unwrap(inKey, 0, inKey.length);
    }
    byte[] outKey = option.getOutKey();
    if (outKey != null) {
      outKey = sasl.unwrap(outKey, 0, outKey.length);
    }
    return new CipherOption(option.getCipherSuite(), inKey, option.getInIv(),
        outKey, option.getOutIv());
  }
  
  return null;
}
 
Example 8
Source File: PBHelper.java    From big-c with Apache License 2.0 6 votes vote down vote up
public static CipherOptionProto convert(CipherOption option) {
  if (option != null) {
    CipherOptionProto.Builder builder = CipherOptionProto.
        newBuilder();
    if (option.getCipherSuite() != null) {
      builder.setSuite(convert(option.getCipherSuite()));
    }
    if (option.getInKey() != null) {
      builder.setInKey(ByteString.copyFrom(option.getInKey()));
    }
    if (option.getInIv() != null) {
      builder.setInIv(ByteString.copyFrom(option.getInIv()));
    }
    if (option.getOutKey() != null) {
      builder.setOutKey(ByteString.copyFrom(option.getOutKey()));
    }
    if (option.getOutIv() != null) {
      builder.setOutIv(ByteString.copyFrom(option.getOutIv()));
    }
    return builder.build();
  }
  return null;
}
 
Example 9
Source File: FanOutOneBlockAsyncDFSOutputSaslHelper.java    From hbase with Apache License 2.0 5 votes vote down vote up
private CipherOption unwrap(CipherOption option, SaslClient saslClient) throws IOException {
  byte[] inKey = option.getInKey();
  if (inKey != null) {
    inKey = saslClient.unwrap(inKey, 0, inKey.length);
  }
  byte[] outKey = option.getOutKey();
  if (outKey != null) {
    outKey = saslClient.unwrap(outKey, 0, outKey.length);
  }
  return new CipherOption(option.getCipherSuite(), inKey, option.getInIv(), outKey,
      option.getOutIv());
}