Repository: wicket Updated Branches: refs/heads/5756-improve-crypt 776c42dc0 -> e1b9f8954
WICKET-5756 Allow to use custom ciphers when using SunJceCrypt class Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/e1b9f895 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/e1b9f895 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/e1b9f895 Branch: refs/heads/5756-improve-crypt Commit: e1b9f895469acad98a731fdaca089d2e4b168320 Parents: 776c42d Author: Martin Tzvetanov Grigorov <[email protected]> Authored: Tue Nov 11 12:50:37 2014 +0200 Committer: Martin Tzvetanov Grigorov <[email protected]> Committed: Tue Nov 11 12:50:37 2014 +0200 ---------------------------------------------------------------------- .../core/request/mapper/CryptoMapper.java | 4 +-- .../crypt/KeyInSessionSunJceCryptFactory.java | 31 +++++++++++++++++++- .../apache/wicket/util/crypt/SunJceCrypt.java | 12 ++++---- 3 files changed, 39 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/e1b9f895/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/CryptoMapper.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/CryptoMapper.java b/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/CryptoMapper.java index e1ab3fb..e9034f6 100755 --- a/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/CryptoMapper.java +++ b/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/CryptoMapper.java @@ -41,7 +41,7 @@ import org.slf4j.LoggerFactory; /** * <p> * A request mapper that encrypts URLs generated by another mapper. This mapper encrypts the segments - * and query parameters of URLs starting with {@link IMapperContext#getNamespace()}, and the just the + * and query parameters of URLs starting with {@link IMapperContext#getNamespace()}, and just the * {@link PageComponentInfo} parameter for mounted URLs. * </p> * @@ -61,7 +61,7 @@ import org.slf4j.LoggerFactory; * encrypted URL until the encrypted URL has the same number of segments as the original URL had. * Each checksum segment has a precise 5 character value, calculated using a checksum. This helps in calculating * the relative distance from the original URL. When a URL is returned by the browser, we iterate through these - * checksummed placeholder URL segments. If the segment matches the expected checksum, then the segment it deemed + * checksummed placeholder URL segments. If the segment matches the expected checksum, then the segment is deemed * to be the corresponding segment in the original URL. If the segment does not match the expected checksum, then * the segment is deemed a plain text sibling of the corresponding segment in the original URL, and all subsequent * segments are considered plain text children of the current segment. http://git-wip-us.apache.org/repos/asf/wicket/blob/e1b9f895/wicket-core/src/main/java/org/apache/wicket/core/util/crypt/KeyInSessionSunJceCryptFactory.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/core/util/crypt/KeyInSessionSunJceCryptFactory.java b/wicket-core/src/main/java/org/apache/wicket/core/util/crypt/KeyInSessionSunJceCryptFactory.java index b6d25be..5b3bae6 100644 --- a/wicket-core/src/main/java/org/apache/wicket/core/util/crypt/KeyInSessionSunJceCryptFactory.java +++ b/wicket-core/src/main/java/org/apache/wicket/core/util/crypt/KeyInSessionSunJceCryptFactory.java @@ -23,6 +23,7 @@ import org.apache.wicket.Session; import org.apache.wicket.util.crypt.ICrypt; import org.apache.wicket.util.crypt.ICryptFactory; import org.apache.wicket.util.crypt.SunJceCrypt; +import org.apache.wicket.util.lang.Args; /** * Crypt factory that produces {@link SunJceCrypt} instances based on http session-specific @@ -41,6 +42,26 @@ public class KeyInSessionSunJceCryptFactory implements ICryptFactory private static final long serialVersionUID = 1L; }; + private final String cryptMethod; + + /** + * Constructor using {@link javax.crypto.Cipher} {@value org.apache.wicket.util.crypt.SunJceCrypt#DEFAULT_CRYPT_METHOD} + */ + public KeyInSessionSunJceCryptFactory() + { + this(SunJceCrypt.DEFAULT_CRYPT_METHOD); + } + + /** + * Constructor that uses a custom {@link javax.crypto.Cipher} + * + * @param cryptMethod + * the name of the crypt method (cipher) + */ + public KeyInSessionSunJceCryptFactory(String cryptMethod) + { + this.cryptMethod = Args.notNull(cryptMethod, "Crypt method"); + } @Override public ICrypt newCrypt() @@ -58,8 +79,16 @@ public class KeyInSessionSunJceCryptFactory implements ICryptFactory } // build the crypt based on session key - ICrypt crypt = new SunJceCrypt(); + ICrypt crypt = createCrypt(); crypt.setKey(key); return crypt; } + + /** + * @return the {@link org.apache.wicket.util.crypt.ICrypt} to use + */ + protected ICrypt createCrypt() + { + return new SunJceCrypt(cryptMethod); + } } http://git-wip-us.apache.org/repos/asf/wicket/blob/e1b9f895/wicket-util/src/main/java/org/apache/wicket/util/crypt/SunJceCrypt.java ---------------------------------------------------------------------- diff --git a/wicket-util/src/main/java/org/apache/wicket/util/crypt/SunJceCrypt.java b/wicket-util/src/main/java/org/apache/wicket/util/crypt/SunJceCrypt.java index 45642fb..3d229fd 100644 --- a/wicket-util/src/main/java/org/apache/wicket/util/crypt/SunJceCrypt.java +++ b/wicket-util/src/main/java/org/apache/wicket/util/crypt/SunJceCrypt.java @@ -49,13 +49,13 @@ public class SunJceCrypt extends AbstractCrypt private final static int COUNT = 17; /** Name of the default encryption method */ - private static final String CRYPT_METHOD = "PBEWithMD5AndDES"; + public static final String DEFAULT_CRYPT_METHOD = "PBEWithMD5AndDES"; /** Salt */ private final static byte[] salt = { (byte)0x15, (byte)0x8c, (byte)0xa3, (byte)0x4a, (byte)0x66, (byte)0x51, (byte)0x2a, (byte)0xbc }; - /** Name of encryption method */ + /** The name of encryption method (cipher) */ private final String cryptMethod; /** @@ -63,14 +63,16 @@ public class SunJceCrypt extends AbstractCrypt */ public SunJceCrypt() { - this(CRYPT_METHOD); + this(DEFAULT_CRYPT_METHOD); } /** - * Constructor. + * Constructor that uses a custom encryption method (cipher). + * You may need to override {@link #createKeySpec()} and/or + * {@link #createParameterSpec()} for the custom cipher. * * @param cryptMethod - * the name of encryption method + * the name of encryption method (the cipher) */ public SunJceCrypt(String cryptMethod) {
