Permalink
Browse files

address code review feedback.

  • Loading branch information...
1 parent 53b73c6 commit 9d189ef5b72c09552f7edcccc7ee57aad9969177 Albert Cheng committed Dec 18, 2012
@@ -27,7 +27,6 @@
import com.microsoft.windowsazure.services.media.implementation.entities.EntityOperationSingleResultBase;
import com.sun.jersey.api.client.GenericType;
-// TODO: Auto-generated Javadoc
/**
* Class for creating operations to manipulate content key entities.
*
@@ -82,6 +81,9 @@ public static Creator create(String id, ContentKeyType contentKeyType, String en
/** The protection key id. */
private String protectionKeyId;
+ /** The protection key type. */
+ private ProtectionKeyType protectionKeyType;
+
/**
* Instantiates a new creator.
*
@@ -110,6 +112,9 @@ public Object getRequestContents() {
if (contentKeyType != null) {
contentKeyRestType.setContentKeyType(contentKeyType.getCode());
}
+ if (protectionKeyType != null) {
+ contentKeyRestType.setProtectionKeyType(protectionKeyType.getCode());
+ }
contentKeyRestType.setEncryptedContentKey(encryptedContentKey);
contentKeyRestType.setName(name);
contentKeyRestType.setChecksum(checksum);
@@ -152,6 +157,18 @@ public Creator setProtectionKeyId(String protectionKeyId) {
this.protectionKeyId = protectionKeyId;
return this;
}
+
+ /**
+ * Sets the protection key type.
+ *
+ * @param protectionKeyType
+ * the protection key type
+ * @return the creator
+ */
+ public Creator setProtectionKeyType(ProtectionKeyType protectionKeyType) {
+ this.protectionKeyType = protectionKeyType;
+ return this;
+ }
}
/**
@@ -17,7 +17,6 @@
import java.security.InvalidParameterException;
-// TODO: Auto-generated Javadoc
/**
*
* Specifies the type of a content key.
@@ -77,11 +77,9 @@ public Date getEndTime() {
List<ErrorDetail> result = new ArrayList<ErrorDetail>();
List<ErrorDetailType> errorDetailTypes = getContent().getErrorDetails();
if (errorDetailTypes != null) {
- for (ErrorDetailType errorDetailType : getContent().getErrorDetails()) {
- if ((errorDetailType.getCode() != null) || (errorDetailType.getMessage() != null)) {
- ErrorDetail errorDetail = new ErrorDetail(errorDetailType.getCode(), errorDetailType.getMessage());
- result.add(errorDetail);
- }
+ for (ErrorDetailType errorDetailType : errorDetailTypes) {
+ ErrorDetail errorDetail = new ErrorDetail(errorDetailType.getCode(), errorDetailType.getMessage());
+ result.add(errorDetail);
}
return result;
}
@@ -28,7 +28,6 @@
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
-import java.security.spec.InvalidKeySpecException;
import java.util.Random;
import java.util.UUID;
@@ -46,15 +45,13 @@
public static byte[] createRandomVector(int numberOfBits) {
int numberOfBytes = numberOfBits / 8;
- byte[] aesKey = new byte[numberOfBytes];
+ byte[] randomVector = new byte[numberOfBytes];
Random random = new Random();
- random.nextBytes(aesKey);
- return aesKey;
+ random.nextBytes(randomVector);
+ return randomVector;
}
- public static byte[] EncryptSymmetricKey(String protectionKey, byte[] inputData) throws InvalidKeySpecException,
- NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, NoSuchPaddingException,
- IllegalBlockSizeException, BadPaddingException, CertificateException {
+ public static byte[] EncryptSymmetricKey(String protectionKey, byte[] inputData) throws Exception {
X509Certificate x509Certificate = createX509CertificateFromString(protectionKey);
return EncryptSymmetricKey(x509Certificate.getPublicKey(), inputData);
@@ -22,20 +22,11 @@
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLEncoder;
-import java.security.InvalidKeyException;
-import java.security.NoSuchAlgorithmException;
-import java.security.NoSuchProviderException;
import java.security.Security;
-import java.security.cert.CertificateException;
-import java.security.spec.InvalidKeySpecException;
import java.util.EnumSet;
import java.util.List;
import java.util.UUID;
-import javax.crypto.BadPaddingException;
-import javax.crypto.IllegalBlockSizeException;
-import javax.crypto.NoSuchPaddingException;
-
import org.junit.Test;
import com.microsoft.windowsazure.services.core.ServiceException;
@@ -68,37 +59,13 @@
public class EncryptionIntegrationTest extends IntegrationTestBase {
- private final String validButNonexistContentKeyId = "nb:kid:UUID:80dfe751-e5a1-4b29-a992-4a75276473af";
- private final ContentKeyType testContentKeyType = ContentKeyType.CommonEncryption;
- private final String testEncryptedContentKey = "ThisIsEncryptedContentKey";
- private final String expressionEncoder = "Windows Azure Media Encoder";
- private final String wameV1Preset = "H.264 256k DSL CBR";
- private final String wameV2Preset = "H264 Broadband SD 4x3";
private final String strorageDecryptionProcessor = "Storage Decryption";
private String createContentKeyId(UUID uuid) {
String randomContentKey = String.format("nb:kid:UUID:%s", uuid);
return randomContentKey;
}
- private String getProtectionKey(ContentKeyType contentKeyType) {
- String protectionKeyId = null;
- try {
- protectionKeyId = (String) service.action(ProtectionKey.getProtectionKeyId(contentKeyType));
- }
- catch (ServiceException e) {
- throw new RuntimeException(e);
- }
- String protectionKey;
- try {
- protectionKey = (String) service.action(ProtectionKey.getProtectionKey(protectionKeyId));
- }
- catch (ServiceException e) {
- throw new RuntimeException(e);
- }
- return protectionKey;
- }
-
private String getProtectionKeyId() throws ServiceException {
String protectionKeyId = (String) service.action(ProtectionKey
.getProtectionKeyId(ContentKeyType.StorageEncryption));
@@ -170,9 +137,7 @@ private URI createContentKeyUri(String contentKeyId) throws UnsupportedEncodingE
}
private ContentKeyInfo createContentKey(byte[] aesKey, ContentKeyType contentKeyType, String protectionKeyId,
- String protectionKey) throws InvalidKeyException, InvalidKeySpecException, NoSuchAlgorithmException,
- NoSuchProviderException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException,
- ServiceException, CertificateException {
+ String protectionKey) throws Exception {
UUID contentKeyIdUuid = UUID.randomUUID();
String contentKeyId = createContentKeyId(contentKeyIdUuid);
byte[] encryptedContentKey = EncryptionHelper.EncryptSymmetricKey(protectionKey, aesKey);

0 comments on commit 9d189ef

Please sign in to comment.