Java Code Examples for org.apache.hadoop.hdfs.protocol.proto.HdfsProtos#PerFileEncryptionInfoProto

The following examples show how to use org.apache.hadoop.hdfs.protocol.proto.HdfsProtos#PerFileEncryptionInfoProto . 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: FSDirectory.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Set the FileEncryptionInfo for an INode.
 */
void setFileEncryptionInfo(String src, FileEncryptionInfo info)
    throws IOException {
  // Make the PB for the xattr
  final HdfsProtos.PerFileEncryptionInfoProto proto =
      PBHelper.convertPerFileEncInfo(info);
  final byte[] protoBytes = proto.toByteArray();
  final XAttr fileEncryptionAttr =
      XAttrHelper.buildXAttr(CRYPTO_XATTR_FILE_ENCRYPTION_INFO, protoBytes);
  final List<XAttr> xAttrs = Lists.newArrayListWithCapacity(1);
  xAttrs.add(fileEncryptionAttr);

  writeLock();
  try {
    FSDirXAttrOp.unprotectedSetXAttrs(this, src, xAttrs,
                                      EnumSet.of(XAttrSetFlag.CREATE));
  } finally {
    writeUnlock();
  }
}
 
Example 2
Source File: FSDirectory.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Set the FileEncryptionInfo for an INode.
 */
void setFileEncryptionInfo(String src, FileEncryptionInfo info)
    throws IOException {
  // Make the PB for the xattr
  final HdfsProtos.PerFileEncryptionInfoProto proto =
      PBHelper.convertPerFileEncInfo(info);
  final byte[] protoBytes = proto.toByteArray();
  final XAttr fileEncryptionAttr =
      XAttrHelper.buildXAttr(CRYPTO_XATTR_FILE_ENCRYPTION_INFO, protoBytes);
  final List<XAttr> xAttrs = Lists.newArrayListWithCapacity(1);
  xAttrs.add(fileEncryptionAttr);

  writeLock();
  try {
    FSDirXAttrOp.unprotectedSetXAttrs(this, src, xAttrs,
                                      EnumSet.of(XAttrSetFlag.CREATE));
  } finally {
    writeUnlock();
  }
}
 
Example 3
Source File: PBHelper.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public static HdfsProtos.PerFileEncryptionInfoProto convertPerFileEncInfo(
    FileEncryptionInfo info) {
  if (info == null) {
    return null;
  }
  return HdfsProtos.PerFileEncryptionInfoProto.newBuilder()
      .setKey(getByteString(info.getEncryptedDataEncryptionKey()))
      .setIv(getByteString(info.getIV()))
      .setEzKeyVersionName(info.getEzKeyVersionName())
      .build();
}
 
Example 4
Source File: PBHelper.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public static FileEncryptionInfo convert(
    HdfsProtos.PerFileEncryptionInfoProto fileProto,
    CipherSuite suite, CryptoProtocolVersion version, String keyName) {
  if (fileProto == null || suite == null || version == null ||
      keyName == null) {
    return null;
  }
  byte[] key = fileProto.getKey().toByteArray();
  byte[] iv = fileProto.getIv().toByteArray();
  String ezKeyVersionName = fileProto.getEzKeyVersionName();
  return new FileEncryptionInfo(suite, version, key, iv, keyName,
      ezKeyVersionName);
}
 
Example 5
Source File: PBHelper.java    From big-c with Apache License 2.0 5 votes vote down vote up
public static HdfsProtos.PerFileEncryptionInfoProto convertPerFileEncInfo(
    FileEncryptionInfo info) {
  if (info == null) {
    return null;
  }
  return HdfsProtos.PerFileEncryptionInfoProto.newBuilder()
      .setKey(getByteString(info.getEncryptedDataEncryptionKey()))
      .setIv(getByteString(info.getIV()))
      .setEzKeyVersionName(info.getEzKeyVersionName())
      .build();
}
 
Example 6
Source File: PBHelper.java    From big-c with Apache License 2.0 5 votes vote down vote up
public static FileEncryptionInfo convert(
    HdfsProtos.PerFileEncryptionInfoProto fileProto,
    CipherSuite suite, CryptoProtocolVersion version, String keyName) {
  if (fileProto == null || suite == null || version == null ||
      keyName == null) {
    return null;
  }
  byte[] key = fileProto.getKey().toByteArray();
  byte[] iv = fileProto.getIv().toByteArray();
  String ezKeyVersionName = fileProto.getEzKeyVersionName();
  return new FileEncryptionInfo(suite, version, key, iv, keyName,
      ezKeyVersionName);
}
 
Example 7
Source File: FSDirectory.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * This function combines the per-file encryption info (obtained
 * from the inode's XAttrs), and the encryption info from its zone, and
 * returns a consolidated FileEncryptionInfo instance. Null is returned
 * for non-encrypted files.
 *
 * @param inode inode of the file
 * @param snapshotId ID of the snapshot that
 *                   we want to get encryption info from
 * @param iip inodes in the path containing the file, passed in to
 *            avoid obtaining the list of inodes again; if iip is
 *            null then the list of inodes will be obtained again
 * @return consolidated file encryption info; null for non-encrypted files
 */
FileEncryptionInfo getFileEncryptionInfo(INode inode, int snapshotId,
    INodesInPath iip) throws IOException {
  if (!inode.isFile()) {
    return null;
  }
  readLock();
  try {
    EncryptionZone encryptionZone = getEZForPath(iip);
    if (encryptionZone == null) {
      // not an encrypted file
      return null;
    } else if(encryptionZone.getPath() == null
        || encryptionZone.getPath().isEmpty()) {
      if (NameNode.LOG.isDebugEnabled()) {
        NameNode.LOG.debug("Encryption zone " +
            encryptionZone.getPath() + " does not have a valid path.");
      }
    }

    final CryptoProtocolVersion version = encryptionZone.getVersion();
    final CipherSuite suite = encryptionZone.getSuite();
    final String keyName = encryptionZone.getKeyName();

    XAttr fileXAttr = FSDirXAttrOp.unprotectedGetXAttrByName(inode,
                                                             snapshotId,
                                                             CRYPTO_XATTR_FILE_ENCRYPTION_INFO);

    if (fileXAttr == null) {
      NameNode.LOG.warn("Could not find encryption XAttr for file " +
          iip.getPath() + " in encryption zone " + encryptionZone.getPath());
      return null;
    }

    try {
      HdfsProtos.PerFileEncryptionInfoProto fileProto =
          HdfsProtos.PerFileEncryptionInfoProto.parseFrom(
              fileXAttr.getValue());
      return PBHelper.convert(fileProto, suite, version, keyName);
    } catch (InvalidProtocolBufferException e) {
      throw new IOException("Could not parse file encryption info for " +
          "inode " + inode, e);
    }
  } finally {
    readUnlock();
  }
}
 
Example 8
Source File: FSDirectory.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * This function combines the per-file encryption info (obtained
 * from the inode's XAttrs), and the encryption info from its zone, and
 * returns a consolidated FileEncryptionInfo instance. Null is returned
 * for non-encrypted files.
 *
 * @param inode inode of the file
 * @param snapshotId ID of the snapshot that
 *                   we want to get encryption info from
 * @param iip inodes in the path containing the file, passed in to
 *            avoid obtaining the list of inodes again; if iip is
 *            null then the list of inodes will be obtained again
 * @return consolidated file encryption info; null for non-encrypted files
 */
FileEncryptionInfo getFileEncryptionInfo(INode inode, int snapshotId,
    INodesInPath iip) throws IOException {
  if (!inode.isFile()) {
    return null;
  }
  readLock();
  try {
    EncryptionZone encryptionZone = getEZForPath(iip);
    if (encryptionZone == null) {
      // not an encrypted file
      return null;
    } else if(encryptionZone.getPath() == null
        || encryptionZone.getPath().isEmpty()) {
      if (NameNode.LOG.isDebugEnabled()) {
        NameNode.LOG.debug("Encryption zone " +
            encryptionZone.getPath() + " does not have a valid path.");
      }
    }

    final CryptoProtocolVersion version = encryptionZone.getVersion();
    final CipherSuite suite = encryptionZone.getSuite();
    final String keyName = encryptionZone.getKeyName();

    XAttr fileXAttr = FSDirXAttrOp.unprotectedGetXAttrByName(inode,
                                                             snapshotId,
                                                             CRYPTO_XATTR_FILE_ENCRYPTION_INFO);

    if (fileXAttr == null) {
      NameNode.LOG.warn("Could not find encryption XAttr for file " +
          iip.getPath() + " in encryption zone " + encryptionZone.getPath());
      return null;
    }

    try {
      HdfsProtos.PerFileEncryptionInfoProto fileProto =
          HdfsProtos.PerFileEncryptionInfoProto.parseFrom(
              fileXAttr.getValue());
      return PBHelper.convert(fileProto, suite, version, keyName);
    } catch (InvalidProtocolBufferException e) {
      throw new IOException("Could not parse file encryption info for " +
          "inode " + inode, e);
    }
  } finally {
    readUnlock();
  }
}