Permalink
Browse files

add protection key id to content key implementation.

  • Loading branch information...
1 parent d5dde55 commit c192e969ec720450527c116541f0e7de73d8a0e2 Albert Cheng committed Dec 17, 2012
@@ -27,6 +27,7 @@
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.
*
@@ -78,6 +79,9 @@ public static Creator create(String id, ContentKeyType contentKeyType, String en
/** The checksum. */
private String checksum;
+ /** The protection key id. */
+ private String protectionKeyId;
+
/**
* Instantiates a new creator.
*
@@ -89,7 +93,6 @@ public static Creator create(String id, ContentKeyType contentKeyType, String en
* the encrypted content key
*/
public Creator(String id, ContentKeyType contentKeyType, String encryptedContentKey) {
-
super(ENTITY_SET, ContentKeyInfo.class);
this.id = id;
@@ -110,6 +113,7 @@ public Object getRequestContents() {
contentKeyRestType.setEncryptedContentKey(encryptedContentKey);
contentKeyRestType.setName(name);
contentKeyRestType.setChecksum(checksum);
+ contentKeyRestType.setProtectionKeyId(protectionKeyId);
return contentKeyRestType;
}
@@ -136,6 +140,18 @@ public Creator setChecksum(String checksum) {
this.checksum = checksum;
return this;
}
+
+ /**
+ * Sets the protection key id.
+ *
+ * @param protectionKeyId
+ * the protection key id
+ * @return the creator
+ */
+ public Creator setProtectionKeyId(String protectionKeyId) {
+ this.protectionKeyId = protectionKeyId;
+ return this;
+ }
}
/**
@@ -130,10 +130,12 @@ public void uploadAesProtectedAssetAndDownloadSuccess() throws Exception {
// gets the public key for storage encryption.
- String protectionKey = getProtectionKey();
+ String protectionKeyId = getProtectionKeyId();
+ String protectionKey = getProtectionKey(protectionKeyId);
// creates the content key with encrypted
- ContentKeyInfo contentKeyInfo = createContentKey(aesKey, ContentKeyType.StorageEncryption, protectionKey);
+ ContentKeyInfo contentKeyInfo = createContentKey(aesKey, ContentKeyType.StorageEncryption, protectionKeyId,
+ protectionKey);
// link the content key with the asset.
linkContentKey(assetInfo, contentKeyInfo);
@@ -158,6 +160,12 @@ public void uploadAesProtectedAssetAndDownloadSuccess() throws Exception {
}
+ private String getProtectionKeyId() throws ServiceException {
+ String protectionKeyId = (String) service.action(ProtectionKey
+ .getProtectionKeyId(ContentKeyType.StorageEncryption));
+ return protectionKeyId;
+ }
+
private JobInfo decodeAsset(String name, AssetInfo assetInfo) throws ServiceException, InterruptedException {
MediaProcessorInfo mediaProcessorInfo = GetMediaProcessor(strorageDecryptionProcessor);
JobInfo jobInfo = createJob(name, assetInfo, mediaProcessorInfo);
@@ -200,9 +208,7 @@ private void linkContentKey(AssetInfo assetInfo, ContentKeyInfo contentKeyInfo)
service.action(Asset.linkContentKey(assetInfo.getId(), contentKeyUri));
}
- private String getProtectionKey() throws ServiceException {
- String protectionKeyId = (String) service.action(ProtectionKey
- .getProtectionKeyId(ContentKeyType.StorageEncryption));
+ private String getProtectionKey(String protectionKeyId) throws ServiceException {
String protectionKey = (String) service.action(ProtectionKey.getProtectionKey(protectionKeyId));
return protectionKey;
}
@@ -247,17 +253,18 @@ private URI createContentKeyUri(String contentKeyId) throws UnsupportedEncodingE
return cipherText;
}
- private ContentKeyInfo createContentKey(byte[] aesKey, ContentKeyType contentKeyType, String protectionKey)
- throws InvalidKeyException, InvalidKeySpecException, NoSuchAlgorithmException, NoSuchProviderException,
- NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, ServiceException,
- CertificateException {
+ private ContentKeyInfo createContentKey(byte[] aesKey, ContentKeyType contentKeyType, String protectionKeyId,
+ String protectionKey) throws InvalidKeyException, InvalidKeySpecException, NoSuchAlgorithmException,
+ NoSuchProviderException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException,
+ ServiceException, CertificateException {
UUID contentKeyIdUuid = UUID.randomUUID();
String contentKeyId = createContentKeyId(contentKeyIdUuid);
byte[] encryptedContentKey = EncryptionHelper.EncryptSymmetricKey(protectionKey, aesKey);
String encryptedContentKeyString = Base64.encode(encryptedContentKey);
String checksum = EncryptionHelper.calculateChecksum(contentKeyIdUuid, aesKey);
- ContentKeyInfo contentKeyInfo = service.create(ContentKey.create(contentKeyId, contentKeyType,
- encryptedContentKeyString).setChecksum(checksum));
+ ContentKeyInfo contentKeyInfo = service.create(ContentKey
+ .create(contentKeyId, contentKeyType, encryptedContentKeyString).setChecksum(checksum)
+ .setProtectionKeyId(protectionKeyId));
return contentKeyInfo;
}

0 comments on commit c192e96

Please sign in to comment.