Java 类org.apache.hadoop.hbase.util.EncryptionTest 实例源码

项目:ditb    文件:IntegrationTestIngestWithEncryption.java   
@Override
public void setUpCluster() throws Exception {
  util = getTestingUtil(null);
  Configuration conf = util.getConfiguration();
  if (!util.isDistributedCluster()) {
    // Inject required configuration if we are not running in distributed mode
    conf.setInt(HFile.FORMAT_VERSION_KEY, 3);
    conf.set(HConstants.CRYPTO_KEYPROVIDER_CONF_KEY, KeyProviderForTesting.class.getName());
    conf.set(HConstants.CRYPTO_MASTERKEY_NAME_CONF_KEY, "hbase");
    conf.setClass("hbase.regionserver.hlog.reader.impl", SecureProtobufLogReader.class,
      Reader.class);
    conf.setClass("hbase.regionserver.hlog.writer.impl", SecureProtobufLogWriter.class,
      Writer.class);
    conf.setBoolean(HConstants.ENABLE_WAL_ENCRYPTION, true);
  }
  // Check if the cluster configuration can support this test
  try {
    EncryptionTest.testEncryption(conf, "AES", null);
  } catch (Exception e) {
    LOG.warn("Encryption configuration test did not pass, skipping test");
    return;
  }
  super.setUpCluster();
  initialized = true;
}
项目:hbase    文件:IntegrationTestIngestWithEncryption.java   
@Override
public void setUpCluster() throws Exception {
  util = getTestingUtil(null);
  Configuration conf = util.getConfiguration();
  if (!util.isDistributedCluster()) {
    // Inject required configuration if we are not running in distributed mode
    conf.setInt(HFile.FORMAT_VERSION_KEY, 3);
    conf.set(HConstants.CRYPTO_KEYPROVIDER_CONF_KEY, KeyProviderForTesting.class.getName());
    conf.set(HConstants.CRYPTO_MASTERKEY_NAME_CONF_KEY, "hbase");
    conf.setClass("hbase.regionserver.hlog.reader.impl", SecureProtobufLogReader.class,
      Reader.class);
    conf.setClass("hbase.regionserver.hlog.writer.impl", SecureProtobufLogWriter.class,
      Writer.class);
    conf.setBoolean(HConstants.ENABLE_WAL_ENCRYPTION, true);
  }
  // Check if the cluster configuration can support this test
  try {
    EncryptionTest.testEncryption(conf, "AES", null);
  } catch (Exception e) {
    LOG.warn("Encryption configuration test did not pass, skipping test", e);
    return;
  }
  super.setUpCluster();
  initialized = true;
}
项目:ditb    文件:SecureProtobufLogWriter.java   
@Override
protected WALHeader buildWALHeader(Configuration conf, WALHeader.Builder builder)
    throws IOException {
  builder.setWriterClsName(SecureProtobufLogWriter.class.getSimpleName());
  if (conf.getBoolean(HConstants.ENABLE_WAL_ENCRYPTION, false)) {
    EncryptionTest.testKeyProvider(conf);
    EncryptionTest.testCipherProvider(conf);

    // Get an instance of our cipher
    final String cipherName =
        conf.get(HConstants.CRYPTO_WAL_ALGORITHM_CONF_KEY, HConstants.CIPHER_AES);
    Cipher cipher = Encryption.getCipher(conf, cipherName);
    if (cipher == null) {
      throw new RuntimeException("Cipher '" + cipherName + "' is not available");
    }

    // Generate an encryption key for this WAL
    SecureRandom rng = new SecureRandom();
    byte[] keyBytes = new byte[cipher.getKeyLength()];
    rng.nextBytes(keyBytes);
    Key key = new SecretKeySpec(keyBytes, cipher.getName());
    builder.setEncryptionKey(ByteStringer.wrap(EncryptionUtil.wrapKey(conf,
        conf.get(HConstants.CRYPTO_WAL_KEY_NAME_CONF_KEY,
            conf.get(HConstants.CRYPTO_MASTERKEY_NAME_CONF_KEY,
                User.getCurrent().getShortName())),
        key)));

    // Set up the encryptor
    encryptor = cipher.getEncryptor();
    encryptor.setKey(key);

    if (LOG.isTraceEnabled()) {
      LOG.trace("Initialized secure protobuf WAL: cipher=" + cipher.getName());
    }
  }
  builder.setCellCodecClsName(SecureWALCellCodec.class.getName());
  return super.buildWALHeader(conf, builder);
}
项目:pbase    文件:SecureProtobufLogWriter.java   
@Override
protected WALHeader buildWALHeader(Configuration conf, WALHeader.Builder builder)
    throws IOException {
  builder.setWriterClsName(SecureProtobufLogWriter.class.getSimpleName());
  if (conf.getBoolean(HConstants.ENABLE_WAL_ENCRYPTION, false)) {
    EncryptionTest.testKeyProvider(conf);
    EncryptionTest.testCipherProvider(conf);

    // Get an instance of our cipher
    final String cipherName = conf.get(HConstants.CRYPTO_WAL_ALGORITHM_CONF_KEY, DEFAULT_CIPHER);
    Cipher cipher = Encryption.getCipher(conf, cipherName);
    if (cipher == null) {
      throw new RuntimeException("Cipher '" + cipherName + "' is not available");
    }

    // Generate an encryption key for this WAL
    SecureRandom rng = new SecureRandom();
    byte[] keyBytes = new byte[cipher.getKeyLength()];
    rng.nextBytes(keyBytes);
    Key key = new SecretKeySpec(keyBytes, cipher.getName());
    builder.setEncryptionKey(ByteStringer.wrap(EncryptionUtil.wrapKey(conf,
        conf.get(HConstants.CRYPTO_WAL_KEY_NAME_CONF_KEY,
            conf.get(HConstants.CRYPTO_MASTERKEY_NAME_CONF_KEY,
                User.getCurrent().getShortName())),
        key)));

    // Set up the encryptor
    encryptor = cipher.getEncryptor();
    encryptor.setKey(key);

    if (LOG.isTraceEnabled()) {
      LOG.trace("Initialized secure protobuf WAL: cipher=" + cipher.getName());
    }
  }
  builder.setCellCodecClsName(SecureWALCellCodec.class.getName());
  return super.buildWALHeader(conf, builder);
}
项目:hbase    文件:AbstractProtobufLogWriter.java   
protected final WALHeader buildSecureWALHeader(Configuration conf, WALHeader.Builder builder)
    throws IOException {
  builder.setWriterClsName(getWriterClassName());
  if (conf.getBoolean(HConstants.ENABLE_WAL_ENCRYPTION, false)) {
    EncryptionTest.testKeyProvider(conf);
    EncryptionTest.testCipherProvider(conf);

    // Get an instance of our cipher
    final String cipherName =
        conf.get(HConstants.CRYPTO_WAL_ALGORITHM_CONF_KEY, HConstants.CIPHER_AES);
    Cipher cipher = Encryption.getCipher(conf, cipherName);
    if (cipher == null) {
      throw new RuntimeException("Cipher '" + cipherName + "' is not available");
    }

    // Generate an encryption key for this WAL
    SecureRandom rng = new SecureRandom();
    byte[] keyBytes = new byte[cipher.getKeyLength()];
    rng.nextBytes(keyBytes);
    Key key = new SecretKeySpec(keyBytes, cipher.getName());
    builder.setEncryptionKey(UnsafeByteOperations.unsafeWrap(EncryptionUtil.wrapKey(conf,
        conf.get(HConstants.CRYPTO_WAL_KEY_NAME_CONF_KEY,
            conf.get(HConstants.CRYPTO_MASTERKEY_NAME_CONF_KEY,
                User.getCurrent().getShortName())),
        key)));

    // Set up the encryptor
    Encryptor encryptor = cipher.getEncryptor();
    encryptor.setKey(key);
    setEncryptor(encryptor);
    if (LOG.isTraceEnabled()) {
      LOG.trace("Initialized secure protobuf WAL: cipher=" + cipher.getName());
    }
  }
  builder.setCellCodecClsName(SecureWALCellCodec.class.getName());
  return buildWALHeader0(conf, builder);
}
项目:ditb    文件:HMaster.java   
private void checkEncryption(final Configuration conf, final HColumnDescriptor hcd)
throws IOException {
  if (!this.masterCheckEncryption) return;
  EncryptionTest.testEncryption(conf, hcd.getEncryptionType(), hcd.getEncryptionKey());
}
项目:ditb    文件:HRegion.java   
private void checkEncryption() throws IOException {
  for (HColumnDescriptor fam : this.htableDescriptor.getColumnFamilies()) {
    EncryptionTest.testEncryption(conf, fam.getEncryptionType(), fam.getEncryptionKey());
  }
}
项目:pbase    文件:HMaster.java   
private void checkEncryption(final Configuration conf, final HColumnDescriptor hcd)
        throws IOException {
    if (!this.masterCheckEncryption) return;
    EncryptionTest.testEncryption(conf, hcd.getEncryptionType(), hcd.getEncryptionKey());
}
项目:pbase    文件:HRegion.java   
private void checkEncryption() throws IOException {
    for (HColumnDescriptor fam : this.htableDescriptor.getColumnFamilies()) {
        EncryptionTest.testEncryption(conf, fam.getEncryptionType(), fam.getEncryptionKey());
    }
}
项目:hbase    文件:HMaster.java   
private void checkEncryption(final Configuration conf, final ColumnFamilyDescriptor hcd)
throws IOException {
  if (!this.masterCheckEncryption) return;
  EncryptionTest.testEncryption(conf, hcd.getEncryptionType(), hcd.getEncryptionKey());
}
项目:hbase    文件:HRegion.java   
private void checkEncryption() throws IOException {
  for (ColumnFamilyDescriptor fam: this.htableDescriptor.getColumnFamilies()) {
    EncryptionTest.testEncryption(conf, fam.getEncryptionType(), fam.getEncryptionKey());
  }
}