org.apache.hadoop.crypto.key.KeyProvider.Metadata Java Examples

The following examples show how to use org.apache.hadoop.crypto.key.KeyProvider.Metadata. 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: KeyShell.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public void execute() throws IOException {
  try {
    final List<String> keys = provider.getKeys();
    out.println("Listing keys for KeyProvider: " + provider);
    if (metadata) {
      final Metadata[] meta =
        provider.getKeysMetadata(keys.toArray(new String[keys.size()]));
      for (int i = 0; i < meta.length; ++i) {
        out.println(keys.get(i) + " : " + meta[i]);
      }
    } else {
      for (String keyName : keys) {
        out.println(keyName);
      }
    }
  } catch (IOException e) {
    out.println("Cannot list keys for KeyProvider: " + provider
        + ": " + e.toString());
    throw e;
  }
}
 
Example #2
Source File: KeyShell.java    From big-c with Apache License 2.0 6 votes vote down vote up
public void execute() throws IOException {
  try {
    final List<String> keys = provider.getKeys();
    out.println("Listing keys for KeyProvider: " + provider);
    if (metadata) {
      final Metadata[] meta =
        provider.getKeysMetadata(keys.toArray(new String[keys.size()]));
      for (int i = 0; i < meta.length; ++i) {
        out.println(keys.get(i) + " : " + meta[i]);
      }
    } else {
      for (String keyName : keys) {
        out.println(keyName);
      }
    }
  } catch (IOException e) {
    out.println("Cannot list keys for KeyProvider: " + provider
        + ": " + e.toString());
    throw e;
  }
}
 
Example #3
Source File: RangerKeyStore.java    From ranger with Apache License 2.0 5 votes vote down vote up
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
	  byte[] metadataBuf = new byte[in.readInt()];
      in.readFully(metadataBuf);
      metadata = new Metadata(metadataBuf);
      byte[] keybyteBuf = new byte[in.readInt()];
      in.readFully(keybyteBuf);
      keyByte = keybyteBuf;
}
 
Example #4
Source File: RangerKeyStore.java    From ranger with Apache License 2.0 4 votes vote down vote up
public Key engineGetDecryptedZoneKey(String alias) throws Exception {
	byte[] decryptKeyByte = engineGetDecryptedZoneKeyByte(alias);
	Metadata metadata = engineGetKeyMetadata(alias); 
	Key k = new KeyByteMetadata(metadata, decryptKeyByte);
	return k;
}
 
Example #5
Source File: RangerKeyStore.java    From ranger with Apache License 2.0 4 votes vote down vote up
public void engineLoadToKeyStoreFile(OutputStream stream, char[] storePass,
                                     char[] keyPass, char[] masterKey, String fileFormat)
        throws IOException, NoSuchAlgorithmException, CertificateException {
    if (logger.isDebugEnabled()) {
        logger.debug("==> RangerKeyStoreProvider.engineLoadToKeyStoreFile()");
    }

    synchronized (keyEntries) {
        KeyStore ks;
        try {
            ks = KeyStore.getInstance(fileFormat);
            if (ks != null) {
                ks.load(null, storePass);
                String alias = null;
                engineLoad(null, masterKey);
                Enumeration<String> e = engineAliases();
                Key key;
                while (e.hasMoreElements()) {
                    alias = e.nextElement();
                    if(azureKeyVaultEnabled){
                    	key = engineGetDecryptedZoneKey(alias);
		} else {
			key = engineGetKey(alias, masterKey);
			if (key instanceof KeyMetadata) {
				Metadata meta = ((KeyMetadata) key).metadata;
				if (meta != null) {
					key = new KeyMetadata(meta);
				}
			}

		}
                    ks.setKeyEntry(alias, key, keyPass, null);
                    
                }
                ks.store(stream, storePass);
            }
        } catch (Throwable t) {
            logger.error("Unable to load keystore file ", t);
            throw new IOException(t);
        }
    }
}
 
Example #6
Source File: RangerKeyStore.java    From ranger with Apache License 2.0 4 votes vote down vote up
private KeyByteMetadata(Metadata meta, byte[] encoded) {
    this.metadata = meta;
    this.keyByte = encoded;
}