use of org.apache.accumulo.core.spi.crypto.CryptoService in project accumulo by apache.
the class SplitLarge method execute.
@Override
public void execute(String[] args) throws Exception {
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(conf);
Opts opts = new Opts();
opts.parseArgs("accumulo split-large", args);
for (String file : opts.files) {
AccumuloConfiguration aconf = opts.getSiteConfiguration();
CryptoService cryptoService = CryptoServiceFactory.newInstance(aconf, CryptoServiceFactory.ClassloaderType.JAVA);
Path path = new Path(file);
CachableBuilder cb = new CachableBuilder().fsPath(fs, path).conf(conf).cryptoService(cryptoService);
try (Reader iter = new RFile.Reader(cb)) {
if (!file.endsWith(".rf")) {
throw new IllegalArgumentException("File must end with .rf");
}
String smallName = file.substring(0, file.length() - 3) + "_small.rf";
String largeName = file.substring(0, file.length() - 3) + "_large.rf";
int blockSize = (int) aconf.getAsBytes(Property.TABLE_FILE_BLOCK_SIZE);
try (Writer small = new RFile.Writer(new BCFile.Writer(fs.create(new Path(smallName)), null, "gz", conf, cryptoService), blockSize);
Writer large = new RFile.Writer(new BCFile.Writer(fs.create(new Path(largeName)), null, "gz", conf, cryptoService), blockSize)) {
small.startDefaultLocalityGroup();
large.startDefaultLocalityGroup();
iter.seek(new Range(), new ArrayList<>(), false);
while (iter.hasTop()) {
Key key = iter.getTopKey();
Value value = iter.getTopValue();
if (key.getSize() + value.getSize() < opts.maxSize) {
small.append(key, value);
} else {
large.append(key, value);
}
iter.next();
}
}
}
}
}
use of org.apache.accumulo.core.spi.crypto.CryptoService in project accumulo by apache.
the class CryptoTest method testMissingConfigProperties.
@Test
public void testMissingConfigProperties() throws ReflectiveOperationException {
ConfigurationCopy aconf = new ConfigurationCopy(DefaultConfiguration.getInstance());
Configuration conf = new Configuration(false);
for (Map.Entry<String, String> e : conf) {
aconf.set(e.getKey(), e.getValue());
}
aconf.set(Property.INSTANCE_CRYPTO_SERVICE, "org.apache.accumulo.core.spi.crypto.AESCryptoService");
String configuredClass = aconf.get(Property.INSTANCE_CRYPTO_SERVICE.getKey());
Class<? extends CryptoService> clazz = ClassLoaderUtil.loadClass(configuredClass, CryptoService.class);
CryptoService cs = clazz.getDeclaredConstructor().newInstance();
assertEquals(AESCryptoService.class, cs.getClass());
assertThrows(NullPointerException.class, () -> cs.init(aconf.getAllPropertiesWithPrefix(Property.TABLE_PREFIX)));
}
use of org.apache.accumulo.core.spi.crypto.CryptoService in project accumulo by apache.
the class DfsLogger method getDecryptingStream.
/**
* Reads the WAL file header, and returns a decrypting stream which wraps the original stream. If
* the file is not encrypted, the original stream is returned.
*
* @throws LogHeaderIncompleteException
* if the header cannot be fully read (can happen if the tserver died before finishing)
*/
public static DataInputStream getDecryptingStream(FSDataInputStream input, AccumuloConfiguration conf) throws LogHeaderIncompleteException, IOException {
DataInputStream decryptingInput;
byte[] magic4 = DfsLogger.LOG_FILE_HEADER_V4.getBytes(UTF_8);
byte[] magic3 = DfsLogger.LOG_FILE_HEADER_V3.getBytes(UTF_8);
if (magic4.length != magic3.length)
throw new AssertionError("Always expect log file headers to be same length : " + magic4.length + " != " + magic3.length);
byte[] magicBuffer = new byte[magic4.length];
try {
input.readFully(magicBuffer);
if (Arrays.equals(magicBuffer, magic4)) {
CryptoService cryptoService = CryptoServiceFactory.newInstance(conf, ClassloaderType.ACCUMULO);
FileDecrypter decrypter = CryptoUtils.getFileDecrypter(cryptoService, Scope.WAL, input);
log.debug("Using {} for decrypting WAL", cryptoService.getClass().getSimpleName());
decryptingInput = cryptoService instanceof NoCryptoService ? input : new DataInputStream(decrypter.decryptStream(input));
} else if (Arrays.equals(magicBuffer, magic3)) {
// Read logs files from Accumulo 1.9
String cryptoModuleClassname = input.readUTF();
if (!cryptoModuleClassname.equals("NullCryptoModule")) {
throw new IllegalArgumentException("Old encryption modules not supported at this time. Unsupported module : " + cryptoModuleClassname);
}
decryptingInput = input;
} else {
throw new IllegalArgumentException("Unsupported write ahead log version " + new String(magicBuffer));
}
} catch (EOFException e) {
// A TabletServer might have died before the (complete) header was written
throw new LogHeaderIncompleteException(e);
}
return decryptingInput;
}
Aggregations