Skip to content

Commit

Permalink
Merge pull request #30 from gcheng/rebindcontentkey
Browse files Browse the repository at this point in the history
ensure unit tests can pass on CI machine
  • Loading branch information
Albert Cheng committed Apr 11, 2013
2 parents 44e2421 + 5e17ffd commit 90b28e1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.List;
import java.util.UUID;

import org.junit.BeforeClass;
import org.junit.Test;

import com.microsoft.windowsazure.services.core.ServiceException;
Expand Down Expand Up @@ -118,6 +119,11 @@ private void verifyContentKeyProperties(String message, String id, ContentKeyTyp
assertEquals(message + " Checksum", checksum, actual.getChecksum());
}

@BeforeClass
public static void Setup() {
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
}

@Test
public void canCreateContentKey() throws Exception {
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.InputStream;
import java.math.BigInteger;
import java.net.URL;
import java.net.URLDecoder;
import java.security.Key;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
Expand Down Expand Up @@ -147,15 +148,16 @@ public void uploadAesProtectedAssetAndDownloadSuccess() throws Exception {
}

@Test
public void encryptedContentCanBeDecrypted() throws Exception {
public void testEncryptedContentCanBeDecrypted() throws Exception {
byte[] aesKey = new byte[32];
for (int i = 0; i < 32; i++) {
aesKey[i] = 1;
}
URL serverCertificateUri = getClass().getResource("/certificate/server.crt");
X509Certificate x509Certificate = EncryptionHelper.loadX509Certificate(serverCertificateUri.getFile());
X509Certificate x509Certificate = EncryptionHelper.loadX509Certificate(URLDecoder.decode(
serverCertificateUri.getFile(), "UTF-8"));
URL serverPrivateKey = getClass().getResource("/certificate/server.der");
PrivateKey privateKey = EncryptionHelper.getPrivateKey(serverPrivateKey.getFile());
PrivateKey privateKey = EncryptionHelper.getPrivateKey(URLDecoder.decode(serverPrivateKey.getFile(), "UTF-8"));
byte[] encryptedAesKey = EncryptionHelper.encryptSymmetricKey(x509Certificate, aesKey);
byte[] decryptedAesKey = EncryptionHelper.decryptSymmetricKey(encryptedAesKey, privateKey);

Expand All @@ -168,9 +170,10 @@ public void testEncryptedContentCanBeDecryptedUsingPreGeneratedKeyPair() throws
Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA1AndMGF1Padding", "BC");
SecureRandom random = new SecureRandom();
URL serverCertificateUri = getClass().getResource("/certificate/server.crt");
X509Certificate x509Certificate = EncryptionHelper.loadX509Certificate(serverCertificateUri.getFile());
X509Certificate x509Certificate = EncryptionHelper.loadX509Certificate(URLDecoder.decode(
serverCertificateUri.getFile(), "UTF-8"));
URL serverPrivateKey = getClass().getResource("/certificate/server.der");
PrivateKey privateKey = EncryptionHelper.getPrivateKey(serverPrivateKey.getFile());
PrivateKey privateKey = EncryptionHelper.getPrivateKey(URLDecoder.decode(serverPrivateKey.getFile(), "UTF-8"));
Key pubKey = x509Certificate.getPublicKey();
cipher.init(Cipher.ENCRYPT_MODE, pubKey, random);
byte[] cipherText = cipher.doFinal(input);
Expand Down

0 comments on commit 90b28e1

Please sign in to comment.