public static CryptoModuleParameters createParamsObjectFromAccumuloConfiguration( AccumuloConfiguration conf) { CryptoModuleParameters params = new CryptoModuleParameters(); return fillParamsObjectFromConfiguration(params, conf); }
@Override public CryptoModuleParameters decryptSecretKey(CryptoModuleParameters params) { params.setPlaintextKey(params.getEncryptedKey()); return params; }
@Override public CryptoModuleParameters getDecryptingInputStream(CryptoModuleParameters params) throws IOException { params.setPlaintextInputStream(params.getEncryptedInputStream()); return params; }
@Override public CryptoModuleParameters generateNewRandomSessionKey(CryptoModuleParameters params) { if (params.getSecureRandom() == null) { params.setSecureRandom(DefaultCryptoModuleUtils.getSecureRandom( params.getRandomNumberGenerator(), params.getRandomNumberGeneratorProvider())); } byte[] newSessionKey = new byte[params.getKeyLength() / 8]; params.getSecureRandom().nextBytes(newSessionKey); params.setPlaintextKey(newSessionKey); return params; }
@Override public CryptoModuleParameters encryptSecretKey(CryptoModuleParameters params) { params.setEncryptedKey(params.getPlaintextKey()); params.setOpaqueKeyEncryptionKeyID(""); return params; }
private String getCipherTransformation(CryptoModuleParameters params) { String cipherSuite = params.getAlgorithmName() + "/" + params.getEncryptionMode() + "/" + params.getPadding(); return cipherSuite; }
/** * This method returns a crypto module based on settings in the given configuration parameter. * * @return a class implementing the CryptoModule interface. It will *never* return null; rather, * it will return a class which obeys the interface but makes no changes to the underlying * data. */ public static CryptoModule getCryptoModule(AccumuloConfiguration conf) { String cryptoModuleClassname = conf.get(Property.CRYPTO_MODULE_CLASS); return getCryptoModule(cryptoModuleClassname); }
@Override public CryptoModuleParameters decryptSecretKey(CryptoModuleParameters context) { try { secretKeyCache.ensureSecretKeyCacheInitialized(context); doKeyEncryptionOperation(Cipher.UNWRAP_MODE, context); } catch (IOException e) { log.error("{}", e.getMessage(), e); throw new RuntimeException(e); } return context; }
@Override public int read() throws IOException { if (remaining() > 0) return (array[readAndIncrement(1)] & 0xFF); return -1; }
@Override public CryptoModuleParameters getEncryptingOutputStream(CryptoModuleParameters params) throws IOException { params.setEncryptedOutputStream(params.getPlaintextOutputStream()); return params; }
public static CryptoModule getCryptoModule(String cryptoModuleClassname) { if (cryptoModuleClassname != null) { cryptoModuleClassname = cryptoModuleClassname.trim(); } if (cryptoModuleClassname == null || cryptoModuleClassname.equals("NullCryptoModule")) { return new NullCryptoModule(); } CryptoModule cryptoModule = null; synchronized (cryptoModulesCache) { if (cryptoModulesCache.containsKey(cryptoModuleClassname)) { cryptoModule = cryptoModulesCache.get(cryptoModuleClassname); } else { cryptoModule = instantiateCryptoModule(cryptoModuleClassname); cryptoModulesCache.put(cryptoModuleClassname, cryptoModule); } } return cryptoModule; }
public static SecretKeyEncryptionStrategy getSecretKeyEncryptionStrategy(String className) { if (className != null) { className = className.trim(); } if (className == null || className.equals("NullSecretKeyEncryptionStrategy")) { return new NullSecretKeyEncryptionStrategy(); } SecretKeyEncryptionStrategy strategy = null; synchronized (secretKeyEncryptionStrategyCache) { if (secretKeyEncryptionStrategyCache.containsKey(className)) { strategy = secretKeyEncryptionStrategyCache.get(className); } else { strategy = instantiateSecreteKeyEncryptionStrategy(className); secretKeyEncryptionStrategyCache.put(className, strategy); } } return strategy; }
@Override public void close() throws IOException { flush(); out.close(); } }
@Override public CryptoModuleParameters generateNewRandomSessionKey(CryptoModuleParameters params) { params.setPlaintextKey(new byte[0]); return params; }
@Override public void write(byte b[]) throws IOException { write(b, 0, b.length); }
public static SecretKeyEncryptionStrategy getSecretKeyEncryptionStrategy( AccumuloConfiguration conf) { String className = conf.get(Property.CRYPTO_SECRET_KEY_ENCRYPTION_STRATEGY_CLASS); return getSecretKeyEncryptionStrategy(className); }
@Override public CryptoModuleParameters encryptSecretKey(CryptoModuleParameters context) { try { secretKeyCache.ensureSecretKeyCacheInitialized(context); doKeyEncryptionOperation(Cipher.WRAP_MODE, context); } catch (IOException e) { log.error("{}", e.getMessage(), e); throw new RuntimeException(e); } return context; }
@Override public void write(int b) throws IOException { // Checking before provides same functionality but causes the case of previous flush() failing // to now throw a buffer out of bounds error if (bb.remaining() == 0) flush(); bb.put((byte) b); }
@Override public void write(byte b[], int off, int len) throws IOException { // Can't recurse here in case the len is large and the blocksize is small (and the stack is // small) // So we'll just fill up the buffer over and over while (len >= bb.remaining()) { int remaining = bb.remaining(); bb.put(b, off, remaining); // This is guaranteed to have the buffer filled, so we'll just flush it. No check needed flush(); off += remaining; len -= remaining; } // And then write the remainder (and this is guaranteed to not fill the buffer, so we won't // flush afteward bb.put(b, off, len); }