Search in sources :

Example 1 with CryptoOutputStream

use of org.apache.hadoop.crypto.CryptoOutputStream in project hadoop by apache.

the class DFSClient method createWrappedOutputStream.

/**
   * Wraps the stream in a CryptoOutputStream if the underlying file is
   * encrypted.
   */
public HdfsDataOutputStream createWrappedOutputStream(DFSOutputStream dfsos, FileSystem.Statistics statistics, long startPos) throws IOException {
    final FileEncryptionInfo feInfo = dfsos.getFileEncryptionInfo();
    if (feInfo != null) {
        // File is encrypted, wrap the stream in a crypto stream.
        // Currently only one version, so no special logic based on the version #
        getCryptoProtocolVersion(feInfo);
        final CryptoCodec codec = getCryptoCodec(conf, feInfo);
        KeyVersion decrypted = decryptEncryptedDataEncryptionKey(feInfo);
        final CryptoOutputStream cryptoOut = new CryptoOutputStream(dfsos, codec, decrypted.getMaterial(), feInfo.getIV(), startPos);
        return new HdfsDataOutputStream(cryptoOut, statistics, startPos);
    } else {
        // No FileEncryptionInfo present so no encryption.
        return new HdfsDataOutputStream(dfsos, statistics, startPos);
    }
}
Also used : KeyVersion(org.apache.hadoop.crypto.key.KeyProvider.KeyVersion) EncryptedKeyVersion(org.apache.hadoop.crypto.key.KeyProviderCryptoExtension.EncryptedKeyVersion) CryptoCodec(org.apache.hadoop.crypto.CryptoCodec) CryptoOutputStream(org.apache.hadoop.crypto.CryptoOutputStream) HdfsDataOutputStream(org.apache.hadoop.hdfs.client.HdfsDataOutputStream) FileEncryptionInfo(org.apache.hadoop.fs.FileEncryptionInfo)

Example 2 with CryptoOutputStream

use of org.apache.hadoop.crypto.CryptoOutputStream in project hadoop by apache.

the class HdfsDataOutputStream method hsync.

/**
   * Sync buffered data to DataNodes (flush to disk devices).
   *
   * @param syncFlags
   *          Indicate the detailed semantic and actions of the hsync.
   * @throws IOException
   * @see FSDataOutputStream#hsync()
   */
public void hsync(EnumSet<SyncFlag> syncFlags) throws IOException {
    OutputStream wrappedStream = getWrappedStream();
    if (wrappedStream instanceof CryptoOutputStream) {
        wrappedStream.flush();
        wrappedStream = ((CryptoOutputStream) wrappedStream).getWrappedStream();
    }
    ((DFSOutputStream) wrappedStream).hsync(syncFlags);
}
Also used : OutputStream(java.io.OutputStream) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) CryptoOutputStream(org.apache.hadoop.crypto.CryptoOutputStream) DFSOutputStream(org.apache.hadoop.hdfs.DFSOutputStream) CryptoOutputStream(org.apache.hadoop.crypto.CryptoOutputStream) DFSOutputStream(org.apache.hadoop.hdfs.DFSOutputStream)

Example 3 with CryptoOutputStream

use of org.apache.hadoop.crypto.CryptoOutputStream in project hadoop by apache.

the class DataTransferSaslUtil method createStreamPair.

/**
   * 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 {
    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);
}
Also used : CryptoInputStream(org.apache.hadoop.crypto.CryptoInputStream) IOStreamPair(org.apache.hadoop.hdfs.protocol.datatransfer.IOStreamPair) CryptoInputStream(org.apache.hadoop.crypto.CryptoInputStream) InputStream(java.io.InputStream) CryptoOutputStream(org.apache.hadoop.crypto.CryptoOutputStream) OutputStream(java.io.OutputStream) CryptoCodec(org.apache.hadoop.crypto.CryptoCodec) CryptoOutputStream(org.apache.hadoop.crypto.CryptoOutputStream)

Aggregations

CryptoOutputStream (org.apache.hadoop.crypto.CryptoOutputStream)3 OutputStream (java.io.OutputStream)2 CryptoCodec (org.apache.hadoop.crypto.CryptoCodec)2 InputStream (java.io.InputStream)1 CryptoInputStream (org.apache.hadoop.crypto.CryptoInputStream)1 KeyVersion (org.apache.hadoop.crypto.key.KeyProvider.KeyVersion)1 EncryptedKeyVersion (org.apache.hadoop.crypto.key.KeyProviderCryptoExtension.EncryptedKeyVersion)1 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)1 FileEncryptionInfo (org.apache.hadoop.fs.FileEncryptionInfo)1 DFSOutputStream (org.apache.hadoop.hdfs.DFSOutputStream)1 HdfsDataOutputStream (org.apache.hadoop.hdfs.client.HdfsDataOutputStream)1 IOStreamPair (org.apache.hadoop.hdfs.protocol.datatransfer.IOStreamPair)1