Author: wang Date: Fri Jun 27 20:43:41 2014 New Revision: 1606220 URL: http://svn.apache.org/r1606220 Log: HDFS-6391. Get the Key/IV from the NameNode for encrypted files in DFSClient. Contributed by Charles Lamb and Andrew Wang.
Added: hadoop/common/branches/fs-encryption/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/CipherSuite.java (with props) hadoop/common/branches/fs-encryption/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileEncryptionInfo.java (with props) Added: hadoop/common/branches/fs-encryption/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/CipherSuite.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/fs-encryption/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/CipherSuite.java?rev=1606220&view=auto ============================================================================== --- hadoop/common/branches/fs-encryption/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/CipherSuite.java (added) +++ hadoop/common/branches/fs-encryption/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/CipherSuite.java Fri Jun 27 20:43:41 2014 @@ -0,0 +1,62 @@ +/** + * 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.hadoop.crypto; + +import org.apache.hadoop.classification.InterfaceAudience; +import org.apache.hadoop.classification.InterfaceStability; + +/** + * Defines properties of a CipherSuite. Modeled after the ciphers in + * {@link javax.crypto.Cipher}. + */ +@InterfaceAudience.Private +public enum CipherSuite { + AES_CTR_NOPADDING("AES/CTR/NoPadding", 128); + + private final String name; + private final int blockBits; + + CipherSuite(String name, int blockBits) { + this.name = name; + this.blockBits = blockBits; + } + + /** + * @return name of cipher suite, as in {@link javax.crypto.Cipher} + */ + public String getName() { + return name; + } + + /** + * @return size of an algorithm block in bits + */ + public int getNumberBlockBits() { + return blockBits; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder("{"); + builder.append("name: " + getName() + ", "); + builder.append("numBlockBits: " + getNumberBlockBits()); + builder.append("}"); + return builder.toString(); + } +} Propchange: hadoop/common/branches/fs-encryption/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/CipherSuite.java ------------------------------------------------------------------------------ svn:eol-style = native Added: hadoop/common/branches/fs-encryption/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileEncryptionInfo.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/fs-encryption/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileEncryptionInfo.java?rev=1606220&view=auto ============================================================================== --- hadoop/common/branches/fs-encryption/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileEncryptionInfo.java (added) +++ hadoop/common/branches/fs-encryption/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileEncryptionInfo.java Fri Jun 27 20:43:41 2014 @@ -0,0 +1,83 @@ +/** + * 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.hadoop.fs; + +import org.apache.commons.codec.binary.Hex; +import org.apache.hadoop.classification.InterfaceAudience; +import org.apache.hadoop.classification.InterfaceStability; +import org.apache.hadoop.crypto.CipherSuite; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * FileEncryptionInfo encapsulates all the encryption-related information for + * an encrypted file. + */ +@InterfaceAudience.Private +public class FileEncryptionInfo { + + private final CipherSuite cipherSuite; + private final byte[] key; + private final byte[] iv; + + public FileEncryptionInfo(CipherSuite suite, byte[] key, byte[] iv) { + checkNotNull(suite); + checkNotNull(key); + checkNotNull(iv); + checkArgument(key.length == suite.getNumberBlockBits() / 8, + "Unexpected key length"); + checkArgument(iv.length == suite.getNumberBlockBits() / 8, + "Unexpected IV length"); + this.cipherSuite = suite; + this.key = key; + this.iv = iv; + } + + /** + * @return {@link org.apache.hadoop.crypto.CipherSuite} used to encrypt + * the file. + */ + public CipherSuite getCipherSuite() { + return cipherSuite; + } + + /** + * @return encrypted data encryption key for the file + */ + public byte[] getEncryptedDataEncryptionKey() { + return key; + } + + /** + * @return initialization vector for the cipher used to encrypt the file + */ + public byte[] getIV() { + return iv; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder("{"); + builder.append("cipherSuite: " + cipherSuite); + builder.append(", key: " + Hex.encodeHexString(key)); + builder.append(", iv: " + Hex.encodeHexString(iv)); + builder.append("}"); + return builder.toString(); + } +} Propchange: hadoop/common/branches/fs-encryption/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileEncryptionInfo.java ------------------------------------------------------------------------------ svn:eol-style = native