Repository: cxf Updated Branches: refs/heads/master aa08a3348 -> 8ac7958af
[CXF-5311] Fixing RSA encryptor/decryptor helpers Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/8ac7958a Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/8ac7958a Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/8ac7958a Branch: refs/heads/master Commit: 8ac7958afa1dc027ec80b85ff78d5ec33f9cd236 Parents: aa08a33 Author: Sergey Beryozkin <[email protected]> Authored: Wed May 21 21:54:09 2014 +0100 Committer: Sergey Beryozkin <[email protected]> Committed: Wed May 21 21:54:09 2014 +0100 ---------------------------------------------------------------------- .../rs/security/oauth2/jwe/JweDecryptor.java | 14 ++++++------- .../rs/security/oauth2/jwe/RSAJweDecryptor.java | 13 ++++++------ .../rs/security/oauth2/jwe/RSAJweEncryptor.java | 22 ++++++++++---------- .../oauth2/jwe/JweCompactReaderWriterTest.java | 9 ++++---- 4 files changed, 29 insertions(+), 29 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/8ac7958a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwe/JweDecryptor.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwe/JweDecryptor.java b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwe/JweDecryptor.java index f23cdbb..9cf1f17 100644 --- a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwe/JweDecryptor.java +++ b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwe/JweDecryptor.java @@ -27,17 +27,17 @@ import org.apache.cxf.rs.security.oauth2.utils.crypto.KeyProperties; public class JweDecryptor { private JweCompactConsumer jweConsumer; - private Key privateKey; + private Key decryptionKey; private boolean unwrap; private CeProvider ceProvider = new CeProvider(); - public JweDecryptor(String jweContent, Key privateKey, boolean unwrap) { + public JweDecryptor(String jweContent, Key decryptionKey, boolean unwrap) { this.jweConsumer = new JweCompactConsumer(jweContent); - this.privateKey = privateKey; + this.decryptionKey = decryptionKey; this.unwrap = unwrap; } - protected Key getPrivateKey() { - return privateKey; + protected Key getDecryptionKey() { + return decryptionKey; } protected byte[] getDecryptedContentEncryptionKey() { @@ -45,11 +45,11 @@ public class JweDecryptor { KeyProperties keyProps = new KeyProperties(getKeyEncryptionAlgorithm()); if (!unwrap) { keyProps.setBlockSize(getKeyCipherBlockSize()); - return CryptoUtils.decryptBytes(getEncryptedContentEncryptionKey(), privateKey, keyProps); + return CryptoUtils.decryptBytes(getEncryptedContentEncryptionKey(), decryptionKey, keyProps); } else { return CryptoUtils.unwrapSecretKey(getEncryptedContentEncryptionKey(), getContentEncryptionAlgorithm(), - privateKey, + decryptionKey, keyProps).getEncoded(); } } http://git-wip-us.apache.org/repos/asf/cxf/blob/8ac7958a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwe/RSAJweDecryptor.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwe/RSAJweDecryptor.java b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwe/RSAJweDecryptor.java index dfb4b61..7f4829a 100644 --- a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwe/RSAJweDecryptor.java +++ b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwe/RSAJweDecryptor.java @@ -18,16 +18,17 @@ */ package org.apache.cxf.rs.security.oauth2.jwe; -import java.security.interfaces.RSAPrivateKey; +import java.security.interfaces.RSAPublicKey; + public class RSAJweDecryptor extends JweDecryptor { - public RSAJweDecryptor(String jweContent, RSAPrivateKey privateKey, boolean unwrap) { - super(jweContent, privateKey, unwrap); + public RSAJweDecryptor(String jweContent, RSAPublicKey publicKey, boolean unwrap) { + super(jweContent, publicKey, unwrap); } - public RSAJweDecryptor(String jweContent, RSAPrivateKey privateKey) { - this(jweContent, privateKey, true); + public RSAJweDecryptor(String jweContent, RSAPublicKey publicKey) { + this(jweContent, publicKey, true); } protected int getKeyCipherBlockSize() { - return ((RSAPrivateKey)getPrivateKey()).getModulus().toByteArray().length; + return ((RSAPublicKey)getDecryptionKey()).getModulus().toByteArray().length; } } http://git-wip-us.apache.org/repos/asf/cxf/blob/8ac7958a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwe/RSAJweEncryptor.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwe/RSAJweEncryptor.java b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwe/RSAJweEncryptor.java index 2311c26..8727430 100644 --- a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwe/RSAJweEncryptor.java +++ b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwe/RSAJweEncryptor.java @@ -18,7 +18,7 @@ */ package org.apache.cxf.rs.security.oauth2.jwe; -import java.security.interfaces.RSAPublicKey; +import java.security.interfaces.RSAPrivateKey; import javax.crypto.SecretKey; @@ -26,28 +26,28 @@ import org.apache.cxf.rs.security.oauth2.jwt.Algorithms; import org.apache.cxf.rs.security.oauth2.jwt.JwtHeadersWriter; public class RSAJweEncryptor extends JweEncryptor { - public RSAJweEncryptor(RSAPublicKey publicKey, JweHeaders headers, byte[] cek, byte[] iv) { - this(publicKey, headers, cek, iv, 128, true); + public RSAJweEncryptor(RSAPrivateKey privateKey, JweHeaders headers, byte[] cek, byte[] iv) { + this(privateKey, headers, cek, iv, 128, true); } - public RSAJweEncryptor(RSAPublicKey publicKey, SecretKey secretKey, byte[] iv) { - this(publicKey, + public RSAJweEncryptor(RSAPrivateKey privateKey, SecretKey secretKey, byte[] iv) { + this(privateKey, new JweHeaders(Algorithms.RSA_OAEP_ALGO.getJwtName(), Algorithms.toJwtName(secretKey.getAlgorithm())), secretKey.getEncoded(), iv, 128, true); } - public RSAJweEncryptor(RSAPublicKey publicKey, JweHeaders headers, byte[] cek, byte[] iv, + public RSAJweEncryptor(RSAPrivateKey privateKey, JweHeaders headers, byte[] cek, byte[] iv, int authTagLen, boolean wrap) { - this(publicKey, headers, cek, iv, authTagLen, wrap, null); + this(privateKey, headers, cek, iv, authTagLen, wrap, null); } - public RSAJweEncryptor(RSAPublicKey publicKey, JweHeaders headers, byte[] cek, byte[] iv, + public RSAJweEncryptor(RSAPrivateKey privateKey, JweHeaders headers, byte[] cek, byte[] iv, JwtHeadersWriter writer) { - this(publicKey, headers, cek, iv, 128, true, null); + this(privateKey, headers, cek, iv, 128, true, null); } - public RSAJweEncryptor(RSAPublicKey publicKey, JweHeaders headers, byte[] cek, byte[] iv, + public RSAJweEncryptor(RSAPrivateKey privateKey, JweHeaders headers, byte[] cek, byte[] iv, int authTagLen, boolean wrap, JwtHeadersWriter writer) { - super(headers, publicKey, cek, iv, authTagLen, wrap, writer); + super(headers, privateKey, cek, iv, authTagLen, wrap, writer); } } http://git-wip-us.apache.org/repos/asf/cxf/blob/8ac7958a/rt/rs/security/oauth-parent/oauth2-jwt/src/test/java/org/apache/cxf/rs/security/oauth2/jwe/JweCompactReaderWriterTest.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/oauth-parent/oauth2-jwt/src/test/java/org/apache/cxf/rs/security/oauth2/jwe/JweCompactReaderWriterTest.java b/rt/rs/security/oauth-parent/oauth2-jwt/src/test/java/org/apache/cxf/rs/security/oauth2/jwe/JweCompactReaderWriterTest.java index e3f8d9b..66ff518 100644 --- a/rt/rs/security/oauth-parent/oauth2-jwt/src/test/java/org/apache/cxf/rs/security/oauth2/jwe/JweCompactReaderWriterTest.java +++ b/rt/rs/security/oauth-parent/oauth2-jwt/src/test/java/org/apache/cxf/rs/security/oauth2/jwe/JweCompactReaderWriterTest.java @@ -104,16 +104,15 @@ public class JweCompactReaderWriterTest extends Assert { } private String encryptContent(String content) throws Exception { - RSAPublicKey publicKey = CryptoUtils.getRSAPublicKey(RSA_MODULUS_ENCODED, RSA_PUBLIC_EXPONENT_ENCODED); + RSAPrivateKey privateKey = CryptoUtils.getRSAPrivateKey(RSA_MODULUS_ENCODED, RSA_PRIVATE_EXPONENT_ENCODED); SecretKey key = CryptoUtils.createSecretKeySpec(CONTENT_ENCRYPTION_KEY, Algorithms.A256GCM_ALGO.getJavaName()); - RSAJweEncryptor encryptor = new RSAJweEncryptor(publicKey, key, INIT_VECTOR); + RSAJweEncryptor encryptor = new RSAJweEncryptor(privateKey, key, INIT_VECTOR); return encryptor.getJweContent(content); } private void decrypt(String jweContent, String plainContent) throws Exception { - - RSAPrivateKey privateKey = CryptoUtils.getRSAPrivateKey(RSA_MODULUS_ENCODED, RSA_PRIVATE_EXPONENT_ENCODED); - RSAJweDecryptor decryptor = new RSAJweDecryptor(jweContent, privateKey); + RSAPublicKey publicKey = CryptoUtils.getRSAPublicKey(RSA_MODULUS_ENCODED, RSA_PUBLIC_EXPONENT_ENCODED); + RSAJweDecryptor decryptor = new RSAJweDecryptor(jweContent, publicKey); String decryptedText = decryptor.getDecryptedContentText(); assertEquals(decryptedText, plainContent); }
