Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

let the encryption integration test pass.

  • Loading branch information...
commit c3404df9389cf7ef5f760e48568cfc2575b4a624 1 parent c192e96
Albert Cheng authored
View
68 ...-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ErrorDetailType.java
@@ -0,0 +1,68 @@
+/**
+ * Copyright 2012 Microsoft Corporation
+ *
+ * Licensed 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 com.microsoft.windowsazure.services.media.implementation.content;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+
+/**
+ * This type maps the XML returned in the odata ATOM serialization
+ * for Asset entities.
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+public class ErrorDetailType implements MediaServiceDTO {
+
+ @XmlElement(name = "Code", namespace = Constants.ODATA_DATA_NS)
+ protected String code;
+
+ @XmlElement(name = "Message", namespace = Constants.ODATA_DATA_NS)
+ protected String message;
+
+ /**
+ * @return the code
+ */
+ public String getCode() {
+ return code;
+ }
+
+ /**
+ * @param code
+ * the id to set
+ */
+ public ErrorDetailType setCode(String code) {
+ this.code = code;
+ return this;
+ }
+
+ /**
+ * @return the message
+ */
+ public String getMessage() {
+ return message;
+ }
+
+ /**
+ * @param message
+ * the message to set
+ */
+ public ErrorDetailType setMessage(String message) {
+ this.message = message;
+ return this;
+ }
+
+}
View
6 ...t-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/TaskType.java
@@ -40,7 +40,7 @@
protected Date endTime;
@XmlElement(name = "ErrorDetails", namespace = Constants.ODATA_DATA_NS)
- protected String errorDetails;
+ protected List<ErrorDetailType> errorDetails;
@XmlElement(name = "MediaProcessorId", namespace = Constants.ODATA_DATA_NS)
protected String mediaProcessorId;
@@ -112,11 +112,11 @@ public void setEndTime(Date endTime) {
this.endTime = endTime;
}
- public String getErrorDetails() {
+ public List<ErrorDetailType> getErrorDetails() {
return errorDetails;
}
- public void setErrorDetails(String errorDetails) {
+ public void setErrorDetails(List<ErrorDetailType> errorDetails) {
this.errorDetails = errorDetails;
}
View
34 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ErrorDetail.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2012 Microsoft Corporation
+ *
+ * Licensed 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 com.microsoft.windowsazure.services.media.models;
+
+public class ErrorDetail {
+ private final String code;
+ private final String message;
+
+ public ErrorDetail(String code, String message) {
+ this.code = code;
+ this.message = message;
+ }
+
+ public String getCode() {
+ return this.code;
+ }
+
+ public String getMessage() {
+ return this.message;
+ }
+}
View
16 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/TaskInfo.java
@@ -15,10 +15,13 @@
package com.microsoft.windowsazure.services.media.models;
+import java.util.ArrayList;
import java.util.Date;
+import java.util.List;
import com.microsoft.windowsazure.services.media.implementation.ODataEntity;
import com.microsoft.windowsazure.services.media.implementation.atom.EntryType;
+import com.microsoft.windowsazure.services.media.implementation.content.ErrorDetailType;
import com.microsoft.windowsazure.services.media.implementation.content.TaskType;
/**
@@ -70,8 +73,17 @@ public Date getEndTime() {
*
* @return the error details
*/
- public String getErrorDetails() {
- return getContent().getErrorDetails();
+ public List<ErrorDetail> getErrorDetails() {
+ List<ErrorDetail> result = new ArrayList<ErrorDetail>();
+ List<ErrorDetailType> errorDetailTypes = getContent().getErrorDetails();
+ if (errorDetailTypes != null) {
+ for (ErrorDetailType errorDetailType : getContent().getErrorDetails()) {
+ ErrorDetail errorDetail = new ErrorDetail(errorDetailType.getCode(), errorDetailType.getMessage());
+ result.add(errorDetail);
+ }
+ return result;
+ }
+ return null;
}
/**
View
25 microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/EncryptionHelper.java
@@ -18,6 +18,7 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
@@ -161,4 +162,28 @@ public static String calculateChecksum(UUID uuid, byte[] aesKey) throws NoSuchAl
return checksum;
}
+ public static byte[] EncryptFile(InputStream inputStream, byte[] aesKey, byte[] initializationVector)
+ throws NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, InvalidKeyException,
+ InvalidAlgorithmParameterException, IOException {
+ // preparation
+ SecretKeySpec key = new SecretKeySpec(aesKey, "AES");
+ IvParameterSpec ivParameterSpec = new IvParameterSpec(initializationVector);
+ Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding", "BC");
+
+ // encryption
+ cipher.init(Cipher.ENCRYPT_MODE, key, ivParameterSpec);
+ int maxKeyLen = Cipher.getMaxAllowedKeyLength("AES");
+ // teArrayInputStream byteArrayInputStream = new ByteArrayInputStream(input);
+ CipherInputStream cipherInputStream = new CipherInputStream(inputStream, cipher);
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+
+ int ch;
+ while ((ch = cipherInputStream.read()) >= 0) {
+ byteArrayOutputStream.write(ch);
+ }
+
+ byte[] cipherText = byteArrayOutputStream.toByteArray();
+ return cipherText;
+ }
+
}
View
34 microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/EncryptionIntegrationTest.java
@@ -18,13 +18,10 @@
import static org.junit.Assert.*;
import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLEncoder;
-import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
@@ -36,12 +33,8 @@
import java.util.UUID;
import javax.crypto.BadPaddingException;
-import javax.crypto.Cipher;
-import javax.crypto.CipherInputStream;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
-import javax.crypto.spec.IvParameterSpec;
-import javax.crypto.spec.SecretKeySpec;
import org.junit.Test;
@@ -110,7 +103,7 @@ public void uploadAesProtectedAssetAndDownloadSuccess() throws Exception {
// Arrange
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
InputStream smallWMVInputStream = getClass().getResourceAsStream("/media/SmallWMV.wmv");
- byte[] aesKey = EncryptionHelper.createRandomVector(128);
+ byte[] aesKey = EncryptionHelper.createRandomVector(256);
byte[] initializationVector = EncryptionHelper.createRandomVector(128);
int durationInMinutes = 10;
@@ -141,7 +134,7 @@ public void uploadAesProtectedAssetAndDownloadSuccess() throws Exception {
linkContentKey(assetInfo, contentKeyInfo);
// encrypt the file.
- byte[] encryptedContent = EncryptFile(smallWMVInputStream, aesKey, initializationVector);
+ byte[] encryptedContent = EncryptionHelper.EncryptFile(smallWMVInputStream, aesKey, initializationVector);
// upload the encrypted file to the server.
AssetFileInfo assetFileInfo = uploadEncryptedAssetFile(assetInfo, locatorInfo, contentKeyInfo,
@@ -230,29 +223,6 @@ private URI createContentKeyUri(String contentKeyId) throws UnsupportedEncodingE
return URI.create(String.format("ContentKeys('%s')", escapedContentKeyId));
}
- private byte[] EncryptFile(InputStream inputStream, byte[] aesKey, byte[] initializationVector)
- throws NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, InvalidKeyException,
- InvalidAlgorithmParameterException, IOException {
- // preparation
- SecretKeySpec key = new SecretKeySpec(aesKey, "AES");
- IvParameterSpec ivParameterSpec = new IvParameterSpec(initializationVector);
- Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding", "BC");
-
- // encryption
- cipher.init(Cipher.ENCRYPT_MODE, key, ivParameterSpec);
- // teArrayInputStream byteArrayInputStream = new ByteArrayInputStream(input);
- CipherInputStream cipherInputStream = new CipherInputStream(inputStream, cipher);
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
-
- int ch;
- while ((ch = cipherInputStream.read()) >= 0) {
- byteArrayOutputStream.write(ch);
- }
-
- byte[] cipherText = byteArrayOutputStream.toByteArray();
- return cipherText;
- }
-
private ContentKeyInfo createContentKey(byte[] aesKey, ContentKeyType contentKeyType, String protectionKeyId,
String protectionKey) throws InvalidKeyException, InvalidKeySpecException, NoSuchAlgorithmException,
NoSuchProviderException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException,
View
15 microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java
@@ -35,6 +35,7 @@
import com.microsoft.windowsazure.services.media.models.Asset;
import com.microsoft.windowsazure.services.media.models.AssetFile;
import com.microsoft.windowsazure.services.media.models.AssetInfo;
+import com.microsoft.windowsazure.services.media.models.ErrorDetail;
import com.microsoft.windowsazure.services.media.models.Job;
import com.microsoft.windowsazure.services.media.models.JobInfo;
import com.microsoft.windowsazure.services.media.models.JobState;
@@ -318,6 +319,20 @@ public void canGetTasksFromJob() throws Exception {
}
@Test
+ public void canGetErrorDetailsFromTask() throws Exception {
+ String name = testJobPrefix + "canGetErrorDetailsFromTask";
+
+ JobInfo actualJob = service.create(Job.create().setName(name).addInputMediaAsset(assetInfo.getId())
+ .addTaskCreator(getTaskCreator(0)));
+
+ ListResult<TaskInfo> tasks = service.list(Task.list(actualJob.getTasksLink()));
+ TaskInfo taskInfo = tasks.get(0);
+ List<ErrorDetail> errorDetails = taskInfo.getErrorDetails();
+
+ assertEquals(1, errorDetails.size());
+ }
+
+ @Test
public void canGetInputOutputAssetsFromTask() throws Exception {
String name = testJobPrefix + "canGetInputOutputAssetsFromTask";
int priority = 3;
Please sign in to comment.
Something went wrong with that request. Please try again.