Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -605,12 +605,22 @@ public OzoneOutputStream createKey(
HddsClientUtils.checkNotNull(keyName, type, factor);
String requestId = UUID.randomUUID().toString();

if(Boolean.valueOf(metadata.get(OzoneConsts.GDPR_FLAG))){
OmKeyArgs.Builder builder = new OmKeyArgs.Builder()
.setVolumeName(volumeName)
.setBucketName(bucketName)
.setKeyName(keyName)
.setDataSize(size)
.setType(HddsProtos.ReplicationType.valueOf(type.toString()))
.setFactor(HddsProtos.ReplicationFactor.valueOf(factor.getValue()))
.addAllMetadata(metadata)
.setAcls(getAclList());

if (Boolean.parseBoolean(metadata.get(OzoneConsts.GDPR_FLAG))) {
try{
GDPRSymmetricKey gKey = new GDPRSymmetricKey(new SecureRandom());
metadata.putAll(gKey.getKeyDetails());
}catch (Exception e) {
if(e instanceof InvalidKeyException &&
builder.addAllMetadata(gKey.getKeyDetails());
} catch (Exception e) {
if (e instanceof InvalidKeyException &&
e.getMessage().contains("Illegal key size or default parameters")) {
LOG.error("Missing Unlimited Strength Policy jars. Please install " +
"Java Cryptography Extension (JCE) Unlimited Strength " +
Expand All @@ -620,18 +630,7 @@ public OzoneOutputStream createKey(
}
}

OmKeyArgs keyArgs = new OmKeyArgs.Builder()
.setVolumeName(volumeName)
.setBucketName(bucketName)
.setKeyName(keyName)
.setDataSize(size)
.setType(HddsProtos.ReplicationType.valueOf(type.toString()))
.setFactor(HddsProtos.ReplicationFactor.valueOf(factor.getValue()))
.addAllMetadata(metadata)
.setAcls(getAclList())
.build();

OpenKeySession openKey = ozoneManagerClient.openKey(keyArgs);
OpenKeySession openKey = ozoneManagerClient.openKey(builder.build());
return createOutputStream(openKey, requestId, type, factor);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
import org.apache.hadoop.test.LambdaTestUtils;
import org.apache.hadoop.util.Time;

import com.google.common.collect.ImmutableMap;
import static java.nio.charset.StandardCharsets.UTF_8;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.RandomStringUtils;
Expand Down Expand Up @@ -693,10 +694,13 @@ public void testPutKey()

for (int i = 0; i < 10; i++) {
String keyName = UUID.randomUUID().toString();
Map<String, String> metadata = new HashMap<>(1);
metadata.put(OzoneConsts.GDPR_FLAG, Boolean.toString(i % 2 == 0));
Map<String, String> originalMetadata = ImmutableMap.copyOf(metadata);

OzoneOutputStream out = bucket.createKey(keyName,
value.getBytes().length, STAND_ALONE,
ONE, new HashMap<>());
ONE, metadata);
Comment thread
adoroszlai marked this conversation as resolved.
Outdated
out.write(value.getBytes());
out.close();
OzoneKey key = bucket.getKey(keyName);
Expand All @@ -710,6 +714,7 @@ public void testPutKey()
Assert.assertEquals(value, new String(fileContent));
Assert.assertTrue(key.getCreationTime() >= currentTime);
Assert.assertTrue(key.getModificationTime() >= currentTime);
Assert.assertEquals(originalMetadata, metadata);
}
}

Expand Down Expand Up @@ -2693,6 +2698,7 @@ public void testKeyReadWriteForGDPR() throws Exception {
text.getBytes().length, STAND_ALONE, ONE, keyMetadata);
out.write(text.getBytes());
out.close();
Assert.assertNull(keyMetadata.get(OzoneConsts.GDPR_SECRET));

//Step 3
OzoneKeyDetails key = bucket.getKey(keyName);
Expand All @@ -2701,7 +2707,7 @@ public void testKeyReadWriteForGDPR() throws Exception {
Assert.assertEquals("true", key.getMetadata().get(OzoneConsts.GDPR_FLAG));
Assert.assertEquals("AES",
key.getMetadata().get(OzoneConsts.GDPR_ALGORITHM));
Assert.assertTrue(key.getMetadata().get(OzoneConsts.GDPR_SECRET) != null);
Assert.assertNotNull(key.getMetadata().get(OzoneConsts.GDPR_SECRET));

OzoneInputStream is = bucket.readKey(keyName);
byte[] fileContent = new byte[text.getBytes().length];
Expand All @@ -2725,7 +2731,7 @@ public void testKeyReadWriteForGDPR() throws Exception {
//Step 5
key = bucket.getKey(keyName);
Assert.assertEquals(keyName, key.getName());
Assert.assertEquals(null, key.getMetadata().get(OzoneConsts.GDPR_FLAG));
Assert.assertNull(key.getMetadata().get(OzoneConsts.GDPR_FLAG));
is = bucket.readKey(keyName);
fileContent = new byte[text.getBytes().length];
is.read(fileContent);
Expand Down