mikewalch commented on a change in pull request #560: Provide new Crypto 
interface & impl
URL: https://github.com/apache/accumulo/pull/560#discussion_r202412318
 
 

 ##########
 File path: 
core/src/main/java/org/apache/accumulo/core/security/crypto/impl/AESCryptoService.java
 ##########
 @@ -0,0 +1,530 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations 
under
+ * the License.
+ */
+package org.apache.accumulo.core.security.crypto.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.charset.Charset;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.Key;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.SecureRandom;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.StringJoiner;
+
+import javax.crypto.Cipher;
+import javax.crypto.CipherInputStream;
+import javax.crypto.CipherOutputStream;
+import javax.crypto.NoSuchPaddingException;
+import javax.crypto.spec.GCMParameterSpec;
+import javax.crypto.spec.IvParameterSpec;
+
+import org.apache.accumulo.core.security.crypto.BlockedInputStream;
+import org.apache.accumulo.core.security.crypto.BlockedOutputStream;
+import org.apache.accumulo.core.security.crypto.CryptoEnvironment;
+import org.apache.accumulo.core.security.crypto.CryptoService;
+import org.apache.accumulo.core.security.crypto.CryptoUtils;
+import org.apache.accumulo.core.security.crypto.DiscardCloseOutputStream;
+import org.apache.accumulo.core.security.crypto.FileDecrypter;
+import org.apache.accumulo.core.security.crypto.FileEncrypter;
+
+/**
+ * Example implementation of AES encryption for Accumulo
+ */
+public class AESCryptoService implements CryptoService {
+
+  private Key encryptingKek = null;
+  private String encryptingKekId = null;
+  private String encryptingKeyManager = null;
+  // Lets just load keks for reading once
+  private static HashMap<String,Key> decryptingKeys = new 
HashMap<String,Key>();
+
+  // Each byte has a valid unicode representation
+  private static final String unicodeCharset = "ISO_8859_1";
+
+  @Override
+  public void init(Map<String,String> conf) throws CryptoException {
+    String kekId = conf.get("table.crypto.opts.kekId");
+    String keyMgr = conf.get("table.crypto.opts.keyManager");
+    Objects.requireNonNull(kekId, "Config property table.crypto.opts.kekId is 
required.");
+    Objects.requireNonNull(keyMgr, "Config property 
table.crypto.opts.keyManager is required.");
+    switch (keyMgr) {
+      case KeyManager.URI:
+        this.encryptingKeyManager = keyMgr;
+        this.encryptingKekId = kekId;
+        this.encryptingKek = KeyManager.loadKekFromUri(kekId);
+        break;
+      default:
+        throw new CryptoException("Unrecognized key manager");
+    }
+
+  }
+
+  @Override
+  public FileEncrypter getFileEncrypter(CryptoEnvironment environment) {
+    CryptoModule cm;
+    switch (environment.getScope()) {
+      case WAL:
+        cm = new AESCBCCryptoModule(this.encryptingKek, this.encryptingKekId,
+            this.encryptingKeyManager);
+        return cm.getEncrypter();
+
+      case RFILE:
+        cm = new AESGCMCryptoModule(this.encryptingKek, this.encryptingKekId,
+            this.encryptingKeyManager);
+        return cm.getEncrypter();
+
+      default:
+        throw new CryptoException("Unknown scope: " + environment.getScope());
+    }
+  }
+
+  @Override
+  public FileDecrypter getFileDecrypter(CryptoEnvironment environment) {
+    CryptoModule cm;
+    ParsedCryptoParameters parsed = 
parseCryptoParameters(environment.getParameters());
+    Key kek = loadDecryptionKek(parsed);
+    Key fek = KeyManager.unwrapKey(parsed.getEncFek(), kek);
+    switch (parsed.getCryptoServiceVersion()) {
+      case AESCBCCryptoModule.VERSION:
+        cm = new AESCBCCryptoModule(this.encryptingKek, this.encryptingKekId,
+            this.encryptingKeyManager);
+        return (cm.getDecrypter(fek));
+      case AESGCMCryptoModule.VERSION:
+        cm = new AESGCMCryptoModule(this.encryptingKek, this.encryptingKekId,
+            this.encryptingKeyManager);
+        return (cm.getDecrypter(fek));
+
+      // TODO I suspect we want to leave "U+1F47B" and create an internal 
NoFileDecrypter
 
 Review comment:
   I am OK with the comment bu there should be a corresponding issue if this is 
left in.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to