You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2010/03/23 09:49:48 UTC
svn commit: r926499 [2/3] - in /camel/trunk: apache-camel/
apache-camel/src/main/descriptors/
camel-core/src/main/java/org/apache/camel/model/
camel-core/src/main/java/org/apache/camel/model/dataformat/
camel-core/src/main/resources/org/apache/camel/mo...
Added: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/HMACAccumulator.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/HMACAccumulator.java?rev=926499&view=auto
==============================================================================
--- camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/HMACAccumulator.java (added)
+++ camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/HMACAccumulator.java Tue Mar 23 08:49:46 2010
@@ -0,0 +1,200 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.camel.converter.crypto;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.security.Key;
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+
+import static org.apache.camel.converter.crypto.HexUtils.byteArrayToHexString;
+
+/**
+ * <code>HMACAccumulator</code> is used to build Hash Message Authentication
+ * Codes. It has two modes, one where all the data acquired is used to build the
+ * MAC and a second that assumes that the last n bytes of the acquired data will
+ * contain a MAC for all the data previous.
+ * <p>
+ * The first mode it used in an encryption phase to create a MAC for the
+ * encrypted data. The second mode is used in the decryption phase and
+ * recalculates the MAC taking into account that for cases where the encrypted
+ * data MAC has been appended. Internally the accumulator uses a circular buffer
+ * to simplify the housekeeping of avoiding the last n bytes.
+ * <p>
+ * It is assumed that the supplied buffersize is always greater than or equal to
+ * the mac length.
+ */
+public class HMACAccumulator {
+
+ protected OutputStream outputStream;
+ private CircularBuffer unprocessed;
+ private byte[] calculatedMac;
+ private Mac hmac;
+ private int maclength;
+ private byte[] appended;
+
+ HMACAccumulator() {
+ }
+
+ public HMACAccumulator(Key key, String macAlgorithm, String cryptoProvider, int buffersize) throws Exception {
+ hmac = cryptoProvider == null ? Mac.getInstance(macAlgorithm) : Mac.getInstance(macAlgorithm, cryptoProvider);
+ Key hmacKey = new SecretKeySpec(key.getEncoded(), macAlgorithm);
+ hmac.init(hmacKey);
+ maclength = hmac.getMacLength();
+ unprocessed = new CircularBuffer(buffersize + maclength);
+ }
+
+ /**
+ * Update buffer with MAC. Typically used in the encryption phase where no
+ * hmac is appended to the buffer.
+ */
+ public void encryptUpdate(byte[] buffer, int read) {
+ hmac.update(buffer, 0, read);
+ }
+
+ /**
+ * Update buffer with MAC taking into account that a MAC is appended to the
+ * buffer and should be precluded from the MAC calculation.
+ */
+ public void decryptUpdate(byte[] buffer, int read) throws IOException {
+ unprocessed.write(buffer, 0, read);
+ int safe = unprocessed.availableForRead() - maclength;
+ if (safe > 0) {
+ unprocessed.read(buffer, 0, safe);
+ hmac.update(buffer, 0, safe);
+ if (outputStream != null) {
+ outputStream.write(buffer, 0, safe);
+ }
+ }
+ }
+
+ public byte[] getCalculatedMac() {
+ if (calculatedMac == null) {
+ calculatedMac = hmac.doFinal();
+ }
+ return calculatedMac;
+ }
+
+ public byte[] getAppendedMac() {
+ if (appended == null) {
+ appended = new byte[maclength];
+ unprocessed.read(appended, 0, maclength);
+ }
+ return appended;
+ }
+
+ public void validate() {
+ byte[] actual = getCalculatedMac();
+ byte[] expected = getAppendedMac();
+ for (int x = 0; x < actual.length; x++) {
+ if (expected[x] != actual[x]) {
+ throw new IllegalStateException("Expected mac did not match actual mac\nexpected:"
+ + byteArrayToHexString(expected) + "\n actual:" + byteArrayToHexString(actual));
+ }
+ }
+ }
+
+ public int getMaclength() {
+ return maclength;
+ }
+
+ public void attachStream(ByteArrayOutputStream outputStream) {
+ this.outputStream = outputStream;
+ }
+
+ static class CircularBuffer {
+ private byte[] buffer;
+ private int write;
+ private int read;
+ private int available;
+
+ public CircularBuffer(int bufferSize) {
+ buffer = new byte[bufferSize];
+ available = bufferSize;
+ }
+
+ public void write(byte[] data, int pos, int len) {
+ if (available >= len) {
+ if (write + len > buffer.length) {
+ int overlap = write + len % buffer.length;
+ System.arraycopy(data, 0, buffer, write, len - overlap);
+ System.arraycopy(data, len - overlap, buffer, 0, overlap);
+ } else {
+ System.arraycopy(data, pos, buffer, write, len);
+ }
+ write = (write + len) % buffer.length;
+ available -= len;
+ }
+ }
+
+ public int read(byte[] dest, int position, int len) {
+ if (dest.length - position >= len) {
+ if (buffer.length - available >= len) {
+ int overlap = (read + len) % buffer.length;
+ if (read > write) {
+ int x = buffer.length - read;
+ System.arraycopy(buffer, read, dest, position, buffer.length - read);
+ System.arraycopy(buffer, 0, dest, position + x, overlap);
+ } else {
+ System.arraycopy(buffer, read, dest, position, len);
+ }
+ read = (read + len) % buffer.length;
+ available += len;
+ return len;
+ }
+ }
+ return 0;
+ }
+
+ public boolean compareTo(byte[] compare, int pos, int len) {
+ boolean equal = false;
+ if (len <= availableForRead()) {
+ int x = 0;
+ while (equal && x < len) {
+ equal = compare[pos + x] != buffer[read + x % buffer.length];
+ }
+ }
+ return equal;
+ }
+
+ public int availableForRead() {
+ return buffer.length - available;
+ }
+
+ public int availableForWrite() {
+ return available;
+ }
+
+ public String show() {
+ StringBuffer b = new StringBuffer(HexUtils.byteArrayToHexString(buffer)).append("\n");
+ for (int x = read; --x >= 0;) {
+ b.append("--");
+ }
+ b.append("r");
+ b.append("\n");
+ for (int x = write; --x >= 0;) {
+ b.append("--");
+ }
+ b.append("w");
+ b.append("\n");
+ return b.toString();
+ }
+ }
+
+}
Propchange: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/HMACAccumulator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/HMACAccumulator.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/HexUtils.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/HexUtils.java?rev=926499&view=auto
==============================================================================
--- camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/HexUtils.java (added)
+++ camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/HexUtils.java Tue Mar 23 08:49:46 2010
@@ -0,0 +1,107 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.camel.converter.crypto;
+
+/**
+ * <code>HexUtils</code> provides utility methods for hex conversions
+ */
+public final class HexUtils {
+
+ private static char hexChars[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
+
+ private HexUtils() { }
+
+ /**
+ * Creates a string representation of the supplied byte array in Hexidecimal
+ * format
+ *
+ * @param in the byte array to convert to a hex string.
+ * @param start where to begin in the array
+ * @param length how many bytes from the array to include in the hexidecimal
+ * representation
+ * @return a string containing the hexidecimal representation of the
+ * requested bytes from the array
+ */
+ public static String byteArrayToHexString(byte in[], int start, int length) {
+ String asHexString = null;
+ if (in != null) {
+ StringBuffer out = new StringBuffer(in.length * 2);
+ for (int x = start; x < length; x++) {
+ int nybble = in[x] & 0xF0;
+ nybble = nybble >>> 4;
+ out.append(hexChars[nybble]);
+ out.append(hexChars[in[x] & 0x0F]);
+ }
+ asHexString = out.toString();
+ }
+ return asHexString;
+ }
+
+ /**
+ * Creates a string representation of the supplied byte array in Hexidecimal
+ * format
+ *
+ * @param in the byte array to convert to a hex string.
+ * @return a string containing the hexidecimal representation of the array
+ */
+ public static String byteArrayToHexString(byte in[]) {
+ return byteArrayToHexString(in, 0, in.length);
+ }
+
+ /**
+ * Convert a hex string into an array of bytes. The string is expected to
+ * consist entirely of valid Hex characters i.e. 0123456789abcdefABCDEF. The
+ * array is calculated by traversing the string from from left to right,
+ * ignoring whitespace. Every 2 valid hex chars will constitute a new byte
+ * for the array. If the string is uneven then it the last byte will be
+ * padded with a '0'.
+ *
+ * @param hexString String to be converted
+ */
+ public static byte[] hexToByteArray(String hexString) {
+
+ StringBuilder normalize = new StringBuilder(hexString.length());
+ for (int x = 0; x < hexString.length(); x++) {
+ char current = Character.toLowerCase(hexString.charAt(x));
+ if (isHexChar(current)) {
+ normalize.append(current);
+ } else if (!Character.isWhitespace(current)) {
+ throw new IllegalStateException(String.format("Conversion of hex string to array failed. '%c' is not a valid hex character", current));
+ }
+ }
+ // pad with a zero if we have an uneven number of characters.
+ if (normalize.length() % 2 > 0) {
+ normalize.append('0');
+ }
+ byte[] hexArray = new byte[hexString.length() + 1 >> 1];
+ for (int x = 0; x < hexArray.length; x++) {
+ int ni = x << 1;
+
+ int mostSignificantNybble = Character.digit(normalize.charAt(ni), 16);
+ int leastSignificantNybble = Character.digit(normalize.charAt(ni + 1), 16);
+
+ int value = ((mostSignificantNybble << 4)) | (leastSignificantNybble & 0x0F);
+ hexArray[x] = (byte)value;
+ }
+ return hexArray;
+ }
+
+ public static boolean isHexChar(char current) {
+ return Character.digit(current, 16) >= 0;
+ }
+
+}
Propchange: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/HexUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/HexUtils.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-crypto/src/main/resources/META-INF/LICENSE.txt
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/main/resources/META-INF/LICENSE.txt?rev=926499&view=auto
==============================================================================
--- camel/trunk/components/camel-crypto/src/main/resources/META-INF/LICENSE.txt (added)
+++ camel/trunk/components/camel-crypto/src/main/resources/META-INF/LICENSE.txt Tue Mar 23 08:49:46 2010
@@ -0,0 +1,203 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
+
Propchange: camel/trunk/components/camel-crypto/src/main/resources/META-INF/LICENSE.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-crypto/src/main/resources/META-INF/LICENSE.txt
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: camel/trunk/components/camel-crypto/src/main/resources/META-INF/NOTICE.txt
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/main/resources/META-INF/NOTICE.txt?rev=926499&view=auto
==============================================================================
--- camel/trunk/components/camel-crypto/src/main/resources/META-INF/NOTICE.txt (added)
+++ camel/trunk/components/camel-crypto/src/main/resources/META-INF/NOTICE.txt Tue Mar 23 08:49:46 2010
@@ -0,0 +1,11 @@
+ =========================================================================
+ == NOTICE file corresponding to the section 4 d of ==
+ == the Apache License, Version 2.0, ==
+ == in this case for the Apache Camel distribution. ==
+ =========================================================================
+
+ This product includes software developed by
+ The Apache Software Foundation (http://www.apache.org/).
+
+ Please read the different LICENSE files present in the licenses directory of
+ this distribution.
Propchange: camel/trunk/components/camel-crypto/src/main/resources/META-INF/NOTICE.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-crypto/src/main/resources/META-INF/NOTICE.txt
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: camel/trunk/components/camel-crypto/src/main/resources/META-INF/services/org/apache/camel/component/sign
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/main/resources/META-INF/services/org/apache/camel/component/sign?rev=926499&view=auto
==============================================================================
--- camel/trunk/components/camel-crypto/src/main/resources/META-INF/services/org/apache/camel/component/sign (added)
+++ camel/trunk/components/camel-crypto/src/main/resources/META-INF/services/org/apache/camel/component/sign Tue Mar 23 08:49:46 2010
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+
+class=org.apache.camel.component.crypto.DigitalSignatureComponent
Added: camel/trunk/components/camel-crypto/src/main/resources/META-INF/services/org/apache/camel/component/verify
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/main/resources/META-INF/services/org/apache/camel/component/verify?rev=926499&view=auto
==============================================================================
--- camel/trunk/components/camel-crypto/src/main/resources/META-INF/services/org/apache/camel/component/verify (added)
+++ camel/trunk/components/camel-crypto/src/main/resources/META-INF/services/org/apache/camel/component/verify Tue Mar 23 08:49:46 2010
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+
+class=org.apache.camel.component.crypto.DigitalSignatureComponent
Added: camel/trunk/components/camel-crypto/src/main/resources/META-INF/services/org/apache/camel/dataformat/crypto
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/main/resources/META-INF/services/org/apache/camel/dataformat/crypto?rev=926499&view=auto
==============================================================================
--- camel/trunk/components/camel-crypto/src/main/resources/META-INF/services/org/apache/camel/dataformat/crypto (added)
+++ camel/trunk/components/camel-crypto/src/main/resources/META-INF/services/org/apache/camel/dataformat/crypto Tue Mar 23 08:49:46 2010
@@ -0,0 +1,17 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+class=org.apache.camel.converter.crypto.CryptoDataFormat
Added: camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/component/crypto/SignatureTests.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/component/crypto/SignatureTests.java?rev=926499&view=auto
==============================================================================
--- camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/component/crypto/SignatureTests.java (added)
+++ camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/component/crypto/SignatureTests.java Tue Mar 23 08:49:46 2010
@@ -0,0 +1,331 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.camel.component.crypto;
+
+import java.io.InputStream;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.KeyStore;
+import java.security.NoSuchAlgorithmException;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.SecureRandom;
+import java.security.cert.Certificate;
+import java.util.Collections;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+
+import static org.apache.camel.component.crypto.DigitalSignatureConstants.KEYSTORE_ALIAS;
+import static org.apache.camel.component.crypto.DigitalSignatureConstants.SIGNATURE_PRIVATE_KEY;
+import static org.apache.camel.component.crypto.DigitalSignatureConstants.SIGNATURE_PUBLIC_KEY_OR_CERT;
+
+public class SignatureTests extends ContextTestSupport {
+
+ private KeyPair keyPair;
+
+ private String payload = "Dear Alice, Rest assured it's me, signed Bob";
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ Logger.getRootLogger().addAppender(new ConsoleAppender(new PatternLayout("%c - %m%n")));
+ JndiRegistry registry = super.createRegistry();
+ KeyStore keystore = loadKeystore();
+ Certificate cert = keystore.getCertificate("bob");
+ registry.bind("keystore", keystore);
+ registry.bind("myPublicKey", cert.getPublicKey());
+ registry.bind("myCert", cert);
+ registry.bind("myPrivateKey", keystore.getKey("bob", "letmein".toCharArray()));
+ return registry;
+ }
+
+ @Override
+ protected RouteBuilder[] createRouteBuilders() throws Exception {
+ return new RouteBuilder[] {new RouteBuilder() {
+ public void configure() throws Exception {
+ // START SNIPPET: basic
+ from("direct:keypair").to("sign://basic?privateKey=myPrivateKey", "verify://basic?publicKey=myPublicKey", "mock:result");
+ // END SNIPPET: basic
+ }
+ }, new RouteBuilder() {
+ public void configure() throws Exception {
+ // START SNIPPET: algorithm
+ KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
+ keyGen.initialize(512, new SecureRandom());
+ keyPair = keyGen.generateKeyPair();
+ PrivateKey privateKey = keyPair.getPrivate();
+ PublicKey publicKey = keyPair.getPublic();
+
+ // we can set the keys explicitly on the endpoint instances.
+ context.getEndpoint("sign://rsa?algorithm=MD5withRSA", DigitalSignatureEndpoint.class).setPrivateKey(privateKey);
+ context.getEndpoint("verify://rsa?algorithm=MD5withRSA", DigitalSignatureEndpoint.class).setPublicKey(publicKey);
+ from("direct:algorithm").to("sign://rsa?algorithm=MD5withRSA", "verify://rsa?algorithm=MD5withRSA", "mock:result");
+ // END SNIPPET: algorithm
+ }
+ }, new RouteBuilder() {
+ public void configure() throws Exception {
+ // START SNIPPET: buffersize
+ from("direct:buffersize").to("sign://buffer?privateKey=myPrivateKey&buffersize=1024", "verify://buffer?publicKey=myPublicKey&buffersize=1024", "mock:result");
+ // END SNIPPET: buffersize
+ }
+ }, new RouteBuilder() {
+ public void configure() throws Exception {
+ // START SNIPPET: provider
+ from("direct:provider").to("sign://provider?privateKey=myPrivateKey&provider=SUN", "verify://provider?publicKey=myPublicKey&provider=SUN", "mock:result");
+ // END SNIPPET: provider
+ }
+ }, new RouteBuilder() {
+ public void configure() throws Exception {
+ // START SNIPPET: certificate
+ from("direct:certificate").to("sign://withcert?privateKey=myPrivateKey", "verify://withcert?certificate=myCert", "mock:result");
+ // END SNIPPET: certificate
+ }
+ }, new RouteBuilder() {
+ public void configure() throws Exception {
+ // START SNIPPET: keystore
+ from("direct:keystore").to("sign://keystore?keystore=keystore&alias=bob&password=letmein", "verify://keystore?keystore=keystore&alias=bob", "mock:result");
+ // END SNIPPET: keystore
+ }
+ }, new RouteBuilder() {
+ public void configure() throws Exception {
+ // START SNIPPET: signature-header
+ from("direct:signature-header").to("sign://another?privateKey=myPrivateKey&signatureHeader=AnotherDigitalSignature",
+ "verify://another?publicKey=myPublicKey&signatureHeader=AnotherDigitalSignature", "mock:result");
+ // END SNIPPET: signature-header
+ }
+ }, new RouteBuilder() {
+ public void configure() throws Exception {
+ // START SNIPPET: random
+ from("direct:random").to("sign://another?privateKey=myPrivateKey&secureRandom=someRandom", "verify://another?publicKey=myPublicKey&secureRandom=someRandom",
+ "mock:result");
+ // END SNIPPET: random
+ }
+ }, new RouteBuilder() {
+ public void configure() throws Exception {
+ // START SNIPPET: alias
+ from("direct:alias-sign").to("sign://alias?keystore=keystore");
+ from("direct:alias-verify").to("verify://alias?keystore=keystore", "mock:result");
+ // END SNIPPET: alias
+ }
+ }, new RouteBuilder() {
+ public void configure() throws Exception {
+ // START SNIPPET: headerkey
+ from("direct:headerkey-sign").to("sign://alais");
+ from("direct:headerkey-verify").to("verify://alias", "mock:result");
+ // END SNIPPET: headerkey
+ }
+ }};
+ }
+
+ public void testBasicSignatureRoute() throws Exception {
+ MockEndpoint mock = setupMock();
+ sendBody("direct:keypair", payload);
+ verify(mock);
+ }
+
+ public void testSetAlgorithmInRouteDefinition() throws Exception {
+ MockEndpoint mock = setupMock();
+ sendBody("direct:algorithm", payload);
+ verify(mock);
+ }
+
+ public void testSetBufferInRouteDefinition() throws Exception {
+ MockEndpoint mock = setupMock();
+ sendBody("direct:buffersize", payload);
+ verify(mock);
+ }
+
+ public void testSetRandomInRouteDefinition() throws Exception {
+ MockEndpoint mock = setupMock();
+ sendBody("direct:random", payload);
+ verify(mock);
+ }
+
+ public void testSetProviderInRouteDefinition() throws Exception {
+ MockEndpoint mock = setupMock();
+ sendBody("direct:provider", payload);
+ verify(mock);
+ }
+
+ public void testSetCertificateInRouteDefinition() throws Exception {
+ MockEndpoint mock = setupMock();
+ sendBody("direct:certificate", payload);
+ verify(mock);
+ }
+
+ public void testSetKeystoreInRouteDefinition() throws Exception {
+ MockEndpoint mock = setupMock();
+ sendBody("direct:keystore", payload);
+ verify(mock);
+ }
+
+ public void testSignatureHeaderInRouteDefinition() throws Exception {
+ MockEndpoint mock = setupMock();
+ Exchange signed = getMandatoryEndpoint("direct:signature-header").createExchange();
+ signed.getIn().setBody(payload);
+ template.send("direct:signature-header", signed);
+ assertNotNull(signed.getOut().getHeader("AnotherDigitalSignature"));
+ verify(mock);
+ }
+
+ public void testProvideAliasInHeader() throws Exception {
+
+ MockEndpoint mock = setupMock();
+ // START SNIPPET: alias-send
+ Exchange unsigned = getMandatoryEndpoint("direct:alias-sign").createExchange();
+ unsigned.getIn().setBody(payload);
+ unsigned.getIn().setHeader(DigitalSignatureConstants.KEYSTORE_ALIAS, "bob");
+ unsigned.getIn().setHeader(DigitalSignatureConstants.KEYSTORE_PASSWORD, "letmein".toCharArray());
+ template.send("direct:alias-sign", unsigned);
+
+ Exchange signed = getMandatoryEndpoint("direct:alias-sign").createExchange();
+ signed.getIn().copyFrom(unsigned.getOut());
+ signed.getIn().setHeader(KEYSTORE_ALIAS, "bob");
+ template.send("direct:alias-verify", signed);
+ // START SNIPPET: alias-send
+
+ verify(mock);
+
+ }
+
+ public void testProvideKeysInHeader() throws Exception {
+
+ MockEndpoint mock = setupMock();
+ Exchange unsigned = getMandatoryEndpoint("direct:headerkey-sign").createExchange();
+ unsigned.getIn().setBody(payload);
+
+ // create a keypair
+ KeyPair pair = getKeyPair("DSA");
+
+ // sign with the private key
+ unsigned.getIn().setHeader(SIGNATURE_PRIVATE_KEY, pair.getPrivate());
+ template.send("direct:headerkey-sign", unsigned);
+
+ // verify with the public key
+ Exchange signed = getMandatoryEndpoint("direct:alias-sign").createExchange();
+ signed.getIn().copyFrom(unsigned.getOut());
+ signed.getIn().setHeader(SIGNATURE_PUBLIC_KEY_OR_CERT, pair.getPublic());
+ template.send("direct:headerkey-verify", signed);
+ verify(mock);
+ }
+
+ public void testProvideCertificateInHeader() throws Exception {
+
+ MockEndpoint mock = setupMock();
+ Exchange unsigned = getMandatoryEndpoint("direct:signature-property").createExchange();
+ unsigned.getIn().setBody(payload);
+
+ // create a keypair
+ KeyStore keystore = loadKeystore();
+ Certificate certificate = keystore.getCertificate("bob");
+ PrivateKey pk = (PrivateKey)keystore.getKey("bob", "letmein".toCharArray());
+
+ // sign with the private key
+ unsigned.getIn().setHeader(SIGNATURE_PRIVATE_KEY, pk);
+ template.send("direct:headerkey-sign", unsigned);
+
+ // verify with the public key
+ Exchange signed = getMandatoryEndpoint("direct:alias-sign").createExchange();
+ signed.getIn().copyFrom(unsigned.getOut());
+ signed.getIn().setHeader(SIGNATURE_PUBLIC_KEY_OR_CERT, certificate);
+ template.send("direct:headerkey-verify", signed);
+ verify(mock);
+ }
+
+ private void verify(MockEndpoint mock) throws InterruptedException {
+ mock.await(4, TimeUnit.SECONDS);
+ mock.assertIsSatisfied();
+ }
+
+ private MockEndpoint setupMock() {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceived(payload);
+ return mock;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Exchange doTestSignatureRoute(RouteBuilder builder) throws Exception {
+
+ return doSignatureRouteTest(builder, null, Collections.EMPTY_MAP);
+ }
+
+ public Exchange doSignatureRouteTest(RouteBuilder builder, Exchange e, Map<String, Object> headers) throws Exception {
+ CamelContext context = new DefaultCamelContext();
+ try {
+ context.addRoutes(builder);
+ context.start();
+
+ MockEndpoint mock = context.getEndpoint("mock:result", MockEndpoint.class);
+ mock.setExpectedMessageCount(1);
+
+ ProducerTemplate template = context.createProducerTemplate();
+ if (e != null) {
+ template.send("direct:in", e);
+ } else {
+ template.sendBodyAndHeaders("direct:in", payload, headers);
+ }
+ verify(mock);
+ return mock.getReceivedExchanges().get(0);
+ } finally {
+ context.stop();
+ }
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ setUpKeys("DSA");
+ super.setUp();
+ }
+
+ public void setUpKeys(String algorithm) throws Exception {
+ keyPair = getKeyPair(algorithm);
+ }
+
+ public KeyPair getKeyPair(String algorithm) throws NoSuchAlgorithmException {
+ KeyPairGenerator keyGen = KeyPairGenerator.getInstance(algorithm);
+ keyGen.initialize(512, new SecureRandom());
+ return keyGen.generateKeyPair();
+ }
+
+ public static KeyStore loadKeystore() throws Exception {
+ KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
+ InputStream in = SignatureTests.class.getResourceAsStream("/.keystore");
+ keystore.load(in, "letmein".toCharArray());
+ return keystore;
+ }
+
+ public Certificate getCertificateFromKeyStore() throws Exception {
+ Certificate c = loadKeystore().getCertificate("bob");
+ return c;
+ }
+
+ public PrivateKey getKeyFromKeystore() throws Exception {
+ return (PrivateKey)loadKeystore().getKey("bob", "letmein".toCharArray());
+
+ }
+}
Propchange: camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/component/crypto/SignatureTests.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/component/crypto/SignatureTests.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/component/crypto/SpringSignatureTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/component/crypto/SpringSignatureTest.java?rev=926499&view=auto
==============================================================================
--- camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/component/crypto/SpringSignatureTest.java (added)
+++ camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/component/crypto/SpringSignatureTest.java Tue Mar 23 08:49:46 2010
@@ -0,0 +1,86 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.camel.component.crypto;
+
+import java.security.KeyPair;
+import java.security.KeyStore;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.SecureRandom;
+import java.security.cert.Certificate;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.JndiRegistry;
+
+import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+public class SpringSignatureTest extends SignatureTests {
+
+ private static KeyPair rsaPair;
+
+ protected CamelContext createCamelContext() throws Exception {
+ rsaPair = getKeyPair("RSA");
+ return createSpringCamelContext(this, "org/apache/camel/component/crypto/SpringSignatureTests.xml");
+ }
+
+ public static KeyStore keystore() throws Exception {
+ return loadKeystore();
+ }
+
+ public static PrivateKey privateKeyFromKeystore() throws Exception {
+ return new SignatureTests().getKeyFromKeystore();
+ }
+
+ public static Certificate certificateFromKeystore() throws Exception {
+ KeyStore keystore = loadKeystore();
+ return keystore.getCertificate("bob");
+ }
+
+ public static PrivateKey privateKey() throws Exception {
+ KeyStore keystore = loadKeystore();
+ return (PrivateKey)keystore.getKey("bob", "letmein".toCharArray());
+ }
+
+ public static PublicKey publicKey() throws Exception {
+ KeyStore keystore = loadKeystore();
+ Certificate cert = keystore.getCertificate("bob");
+ return cert.getPublicKey();
+ }
+
+ public static PrivateKey privateRSAKey() throws Exception {
+ return rsaPair.getPrivate();
+ }
+
+ public static PublicKey publicRSAKey() throws Exception {
+ return rsaPair.getPublic();
+ }
+
+ public static SecureRandom random() throws Exception {
+ return new SecureRandom();
+ }
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ return super.createRegistry();
+ }
+
+ @Override
+ protected RouteBuilder[] createRouteBuilders() throws Exception {
+ return new RouteBuilder[] {};
+ }
+}
Propchange: camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/component/crypto/SpringSignatureTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/component/crypto/SpringSignatureTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/CryptoDataFormatTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/CryptoDataFormatTest.java?rev=926499&view=auto
==============================================================================
--- camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/CryptoDataFormatTest.java (added)
+++ camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/CryptoDataFormatTest.java Tue Mar 23 08:49:46 2010
@@ -0,0 +1,207 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.camel.converter.crypto;
+
+import java.io.ByteArrayInputStream;
+import java.security.Key;
+import java.util.Collections;
+import java.util.Map;
+
+import javax.crypto.KeyGenerator;
+import javax.crypto.SecretKey;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.InvalidPayloadException;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.util.ExchangeHelper;
+
+public class CryptoDataFormatTest extends ContextTestSupport {
+
+ public void testBasicSymmetric() throws Exception {
+ doRoundTripEncryptionTests("direct:basic-encryption");
+ }
+
+ public void testSymmetricWithInitVector() throws Exception {
+ doRoundTripEncryptionTests("direct:init-vector");
+ }
+
+ public void testSymmetricWithInlineInitVector() throws Exception {
+ doRoundTripEncryptionTests("direct:inline");
+ }
+
+ public void testSymmetricWithHMAC() throws Exception {
+ doRoundTripEncryptionTests("direct:hmac");
+ }
+
+ public void testSymmetricWithMD5HMAC() throws Exception {
+ doRoundTripEncryptionTests("direct:hmac-algorithm");
+ }
+
+ public void testKeySuppliedAsHeader() throws Exception {
+ KeyGenerator generator = KeyGenerator.getInstance("DES");
+ Key key = generator.generateKey();
+
+ Exchange unecrypted = getMandatoryEndpoint("direct:key-in-header-encrypt").createExchange();
+ unecrypted.getIn().setBody("Hi Alice, Be careful Eve is listening, signed Bob");
+ unecrypted.getIn().setHeader(CryptoDataFormat.KEY, key);
+ unecrypted = template.send("direct:key-in-header-encrypt", unecrypted);
+ validateHeaderIsCleared(unecrypted);
+
+ MockEndpoint mock = setupExpectations(context, 1, "mock:unencrypted");
+ Exchange encrypted = getMandatoryEndpoint("direct:key-in-header-decrypt").createExchange();
+ encrypted.getIn().copyFrom(unecrypted.getOut());
+ encrypted.getIn().setHeader(CryptoDataFormat.KEY, key);
+ template.send("direct:key-in-header-decrypt", encrypted);
+ awaitAndAssert(mock);
+
+ Exchange received = mock.getReceivedExchanges().get(0);
+ validateHeaderIsCleared(received);
+
+ }
+
+ private void validateHeaderIsCleared(Exchange ex) {
+ Object header = ex.getIn().getHeader(CryptoDataFormat.KEY);
+ assertTrue(!ex.getIn().getHeaders().containsKey(CryptoDataFormat.KEY) || "".equals(header) || header == null);
+ }
+
+ @SuppressWarnings("unchecked")
+ private void doRoundTripEncryptionTests(String endpointUri) throws Exception, InterruptedException, InvalidPayloadException {
+ doRoundTripEncryptionTests(endpointUri, Collections.EMPTY_MAP);
+ }
+
+ private void doRoundTripEncryptionTests(String endpoint, Map<String, Object> headers) throws Exception, InterruptedException, InvalidPayloadException {
+
+ MockEndpoint encrypted = setupExpectations(context, 3, "mock:encrypted");
+ MockEndpoint unencrypted = setupExpectations(context, 3, "mock:unencrypted");
+ String payload = "Hi Alice, Be careful Eve is listening, signed Bob";
+ template.sendBodyAndHeaders(endpoint, payload, headers);
+ template.sendBodyAndHeaders(endpoint, payload.getBytes(), headers);
+ template.sendBodyAndHeaders(endpoint, new ByteArrayInputStream(payload.getBytes()), headers);
+ assertMocksSatisfied(encrypted, unencrypted, payload);
+ }
+
+ private void assertMocksSatisfied(MockEndpoint encrypted, MockEndpoint unencrypted, String payload) throws InterruptedException, InvalidPayloadException {
+ awaitAndAssert(unencrypted);
+ awaitAndAssert(encrypted);
+ for (Exchange e : unencrypted.getReceivedExchanges()) {
+ assertEquals(payload, ExchangeHelper.getMandatoryInBody(e, String.class));
+ }
+ for (Exchange e : encrypted.getReceivedExchanges()) {
+ byte[] ciphertext = ExchangeHelper.getMandatoryInBody(e, byte[].class);
+ assertNotSame(payload, new String(ciphertext));
+ }
+ }
+
+ protected RouteBuilder[] createRouteBuilders() throws Exception {
+ return new RouteBuilder[] {new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // START SNIPPET: basic
+ KeyGenerator generator = KeyGenerator.getInstance("DES");
+ CryptoDataFormat cryptoFormat = new CryptoDataFormat("DES", generator.generateKey());
+ from("direct:basic-encryption").marshal(cryptoFormat).to("mock:encrypted").unmarshal(cryptoFormat).to("mock:unencrypted");
+ // END SNIPPET: basic
+ }
+ }, new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // START SNIPPET: init-vector
+ KeyGenerator generator = KeyGenerator.getInstance("DES");
+ byte[] initializationVector = new byte[] {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
+ CryptoDataFormat cryptoFormat = new CryptoDataFormat("DES/CBC/PKCS5Padding", generator.generateKey());
+ cryptoFormat.setInitializationVector(initializationVector);
+ from("direct:init-vector").marshal(cryptoFormat).to("mock:encrypted").unmarshal(cryptoFormat).to("mock:unencrypted");
+ // END SNIPPET: init-vector
+ }
+ }, new RouteBuilder() {
+
+ public void configure() throws Exception {
+ // START SNIPPET: inline-init-vector
+ KeyGenerator generator = KeyGenerator.getInstance("DES");
+ byte[] initializationVector = new byte[] {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
+ SecretKey key = generator.generateKey();
+ CryptoDataFormat cryptoFormat = new CryptoDataFormat("DES/CBC/PKCS5Padding", key);
+ cryptoFormat.setInitializationVector(initializationVector);
+ cryptoFormat.setShouldInlineInitializationVector(true);
+ CryptoDataFormat decryptFormat = new CryptoDataFormat("DES/CBC/PKCS5Padding", key);
+ decryptFormat.setShouldInlineInitializationVector(true);
+ from("direct:inline").marshal(cryptoFormat).to("mock:encrypted").unmarshal(decryptFormat).to("mock:unencrypted");
+ // END SNIPPET: inline-init-vector
+ }
+ }, new RouteBuilder() {
+
+ public void configure() throws Exception {
+ // START SNIPPET: hmac
+ KeyGenerator generator = KeyGenerator.getInstance("DES");
+ CryptoDataFormat cryptoFormat = new CryptoDataFormat("DES", generator.generateKey());
+ cryptoFormat.setShouldAppendHMAC(true);
+ from("direct:hmac").marshal(cryptoFormat).to("mock:encrypted").unmarshal(cryptoFormat).to("mock:unencrypted");
+ // END SNIPPET: hmac
+ }
+ }, new RouteBuilder() {
+
+ public void configure() throws Exception {
+ // START SNIPPET: hmac-algorithm
+ KeyGenerator generator = KeyGenerator.getInstance("DES");
+ CryptoDataFormat cryptoFormat = new CryptoDataFormat("DES", generator.generateKey());
+ cryptoFormat.setShouldAppendHMAC(true);
+ cryptoFormat.setMacAlgorithm("HmacMD5");
+ from("direct:hmac-algorithm").marshal(cryptoFormat).to("mock:encrypted").unmarshal(cryptoFormat).to("mock:unencrypted");
+ // END SNIPPET: hmac-algorithm
+ }
+ }, new RouteBuilder() {
+
+ public void configure() throws Exception {
+ // START SNIPPET: key-in-header
+ CryptoDataFormat cryptoFormat = new CryptoDataFormat("DES", null);
+ /**
+ * Note: the header containing the key should be cleared after
+ * marshalling to stop it from leaking by accident and
+ * potentially being compromised. The processor version below is
+ * arguably better as the key is left in the header when you use
+ * the DSL leaks the fact that camel encryption was used.
+ */
+ from("direct:key-in-header-encrypt").marshal(cryptoFormat).setHeader(CryptoDataFormat.KEY, constant(null)).setOutHeader(CryptoDataFormat.KEY, constant(null))
+ .to("mock:encrypted");
+
+ from("direct:key-in-header-decrypt").unmarshal(cryptoFormat).process(new Processor() {
+
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().getHeaders().remove(CryptoDataFormat.KEY);
+ exchange.getOut().copyFrom(exchange.getIn());
+ }
+ }).to("mock:unencrypted");
+ // END SNIPPET: key-in-header
+ }
+ }};
+ }
+
+ private void awaitAndAssert(MockEndpoint mock) throws InterruptedException {
+ mock.await();
+ mock.assertIsSatisfied();
+ }
+
+ public MockEndpoint setupExpectations(CamelContext context, int expected, String mock) {
+ MockEndpoint mockEp = context.getEndpoint(mock, MockEndpoint.class);
+ mockEp.expectedMessageCount(expected);
+ return mockEp;
+ }
+}
Propchange: camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/CryptoDataFormatTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/CryptoDataFormatTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/HMACAccumulatorTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/HMACAccumulatorTest.java?rev=926499&view=auto
==============================================================================
--- camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/HMACAccumulatorTest.java (added)
+++ camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/HMACAccumulatorTest.java Tue Mar 23 08:49:46 2010
@@ -0,0 +1,177 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.camel.converter.crypto;
+
+import java.security.InvalidKeyException;
+import java.security.Key;
+import java.security.NoSuchAlgorithmException;
+
+import javax.crypto.KeyGenerator;
+import javax.crypto.Mac;
+
+import org.apache.camel.converter.crypto.HMACAccumulator.CircularBuffer;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class HMACAccumulatorTest {
+ private byte[] payload = {0x00, 0x00, 0x11, 0x11, 0x22, 0x22, 0x33, 0x33, 0x44, 0x44, 0x55, 0x55, 0x66, 0x66, 0x77, 0x77, (byte)0x88, (byte)0x88, (byte)0x99, (byte)0x99};
+ private byte[] expected;
+ private Key key;
+
+ @Before
+ public void setupKeyAndExpectedMac() throws Exception {
+ KeyGenerator generator = KeyGenerator.getInstance("DES");
+ key = generator.generateKey();
+ createExpectedMac();
+ }
+
+ private void createExpectedMac() throws NoSuchAlgorithmException, InvalidKeyException {
+ Mac mac = Mac.getInstance("HmacSHA1");
+ mac.init(key);
+ expected = mac.doFinal(payload);
+ }
+
+ @Test
+ public void testEncryptionPhaseCalculation() throws Exception {
+ int buffersize = 256;
+ byte[] buffer = new byte[buffersize];
+ System.arraycopy(payload, 0, buffer, 0, payload.length);
+
+ HMACAccumulator builder = new HMACAccumulator(key, "HmacSHA1", null, buffersize);
+ builder.encryptUpdate(buffer, 20);
+ assertMacs(expected, builder.getCalculatedMac());
+ }
+
+ @Test
+ public void testDecryptionWhereBufferSizeIsGreaterThanDataSize() throws Exception {
+ int buffersize = 256;
+ byte[] buffer = initializeBuffer(buffersize);
+
+ HMACAccumulator builder = new HMACAccumulator(key, "HmacSHA1", null, buffersize);
+ builder.decryptUpdate(buffer, 40);
+ validate(builder);
+ }
+
+ @Test
+ public void testDecryptionWhereMacOverlaps() throws Exception {
+ int buffersize = 32;
+ byte[] buffer = new byte[buffersize];
+ int overlap = buffersize - payload.length;
+ System.arraycopy(payload, 0, buffer, 0, payload.length);
+ System.arraycopy(expected, 0, buffer, payload.length, overlap);
+
+ HMACAccumulator builder = new HMACAccumulator(key, "HmacSHA1", null, buffersize);
+ builder.decryptUpdate(buffer, buffersize);
+ System.arraycopy(expected, overlap, buffer, 0, 20 - overlap);
+ builder.decryptUpdate(buffer, 20 - overlap);
+ validate(builder);
+ }
+
+ @Test
+ public void testDecryptionWhereDataIsMultipleOfBufferLength() throws Exception {
+ int buffersize = 20;
+ byte[] buffer = new byte[buffersize];
+ System.arraycopy(payload, 0, buffer, 0, payload.length);
+
+ HMACAccumulator builder = new HMACAccumulator(key, "HmacSHA1", null, buffersize);
+ builder.decryptUpdate(buffer, buffersize);
+ System.arraycopy(expected, 0, buffer, 0, expected.length);
+ builder.decryptUpdate(buffer, 20);
+ validate(builder);
+ }
+
+ @Test
+ public void testDecryptionWhereThereIsNoPayloadData() throws Exception {
+ int buffersize = 20;
+ byte[] buffer = new byte[buffersize];
+ payload = new byte[0];
+ createExpectedMac();
+
+ HMACAccumulator builder = new HMACAccumulator(key, "HmacSHA1", null, buffersize);
+ System.arraycopy(expected, 0, buffer, 0, expected.length);
+ builder.decryptUpdate(buffer, 20);
+ validate(builder);
+ }
+
+ @Test
+ public void testDecryptionMultipleReadsSmallerThanBufferSize() throws Exception {
+ int buffersize = 256;
+ byte[] buffer = new byte[buffersize];
+
+ HMACAccumulator builder = new HMACAccumulator(key, "HmacSHA1", null, buffersize);
+ int read = payload.length / 2;
+ System.arraycopy(payload, 0, buffer, 0, read);
+ builder.decryptUpdate(buffer, read);
+ System.arraycopy(payload, read, buffer, 0, read);
+ builder.decryptUpdate(buffer, read);
+ System.arraycopy(expected, 0, buffer, 0, expected.length);
+ builder.decryptUpdate(buffer, 20);
+ validate(builder);
+ }
+
+ private void validate(HMACAccumulator builder) {
+ assertMacs(builder.getCalculatedMac(), builder.getCalculatedMac());
+ assertMacs(builder.getAppendedMac(), builder.getAppendedMac());
+ assertMacs(expected, builder.getCalculatedMac());
+ assertMacs(expected, builder.getAppendedMac());
+ builder.validate();
+ }
+
+ private void assertMacs(byte[] expected, byte[] actual) {
+ assertEquals(HexUtils.byteArrayToHexString(expected), HexUtils.byteArrayToHexString(actual));
+
+ }
+
+ @Test
+ public void testBufferAdd() throws Exception {
+ CircularBuffer buffer = new CircularBuffer(payload.length * 2);
+ buffer.write(payload, 0, payload.length);
+ assertEquals(payload.length, buffer.availableForWrite());
+ buffer.write(payload, 0, payload.length);
+ assertEquals(0, buffer.availableForWrite());
+ buffer.write(payload, 0, payload.length);
+ assertEquals(0, buffer.availableForWrite());
+ }
+
+ @Test
+ public void testBufferDrain() throws Exception {
+ CircularBuffer buffer = new CircularBuffer(payload.length * 2);
+ buffer.write(payload, 0, payload.length);
+
+ byte[] data = new byte[payload.length >> 1];
+ assertEquals(data.length, buffer.read(data, 0, data.length));
+ assertEquals(data.length, buffer.read(data, 0, data.length));
+ assertEquals(0, buffer.read(data, 0, data.length));
+ }
+
+ @Test
+ public void testBufferCompare() throws Exception {
+ CircularBuffer buffer = new CircularBuffer(payload.length * 2);
+ buffer.write(new byte[payload.length >> 1], 0, payload.length >> 1);
+ buffer.write(payload, 0, payload.length);
+ buffer.compareTo(payload, 0, payload.length);
+ }
+
+ private byte[] initializeBuffer(int buffersize) {
+ byte[] buffer = new byte[buffersize];
+ System.arraycopy(payload, 0, buffer, 0, payload.length);
+ System.arraycopy(expected, 0, buffer, payload.length, expected.length);
+ return buffer;
+ }
+}
Propchange: camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/HMACAccumulatorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/HMACAccumulatorTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/HexUtilsTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/HexUtilsTest.java?rev=926499&view=auto
==============================================================================
--- camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/HexUtilsTest.java (added)
+++ camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/HexUtilsTest.java Tue Mar 23 08:49:46 2010
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.camel.converter.crypto;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.apache.camel.converter.crypto.HexUtils.byteArrayToHexString;
+import static org.apache.camel.converter.crypto.HexUtils.hexToByteArray;
+
+public class HexUtilsTest {
+
+ byte[] array = {(byte)0x01, (byte)0x23, (byte)0x45, (byte)0x67, (byte)0x89, (byte)0xAB, (byte)0xCD, (byte)0xEF};
+
+ @Test
+ public void testByteArrayToHex() throws Exception {
+ Assert.assertEquals("0123456789abcdef", byteArrayToHexString(array));
+ }
+
+ @Test
+ public void roundtripArray() {
+ Assert.assertArrayEquals(array, hexToByteArray(byteArrayToHexString(array)));
+ }
+
+ @Test
+ public void roundtrip() {
+ String hexchars = "01234567890abcdefABCDEF";
+
+ for (int x = 0; x < 100000; x++) {
+ int r = (int)(Math.random() * 50);
+
+ StringBuilder b = new StringBuilder(r);
+ for (int y = 0; y < r; y++) {
+ b.append(hexchars.charAt((int)(Math.random() * hexchars.length())));
+ }
+ String hexString = b.toString().toLowerCase();
+ if (b.length() % 2 > 0) {
+ // add the padded byte if odd
+ Assert.assertEquals(hexString + '0', byteArrayToHexString(hexToByteArray(hexString)));
+ } else {
+ Assert.assertEquals(hexString, byteArrayToHexString(hexToByteArray(hexString)));
+ }
+
+ }
+ }
+
+}
Propchange: camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/HexUtilsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/HexUtilsTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/SpringCryptoDataFormatTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/SpringCryptoDataFormatTest.java?rev=926499&view=auto
==============================================================================
--- camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/SpringCryptoDataFormatTest.java (added)
+++ camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/SpringCryptoDataFormatTest.java Tue Mar 23 08:49:46 2010
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.camel.converter.crypto;
+
+import java.security.Key;
+
+import javax.crypto.KeyGenerator;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+
+import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+public class SpringCryptoDataFormatTest extends CryptoDataFormatTest {
+
+ private static Key deskey;
+
+ @Override
+ protected RouteBuilder[] createRouteBuilders() throws Exception {
+ return new RouteBuilder[] {};
+ }
+
+ protected CamelContext createCamelContext() throws Exception {
+ KeyGenerator generator = KeyGenerator.getInstance("DES");
+ deskey = generator.generateKey();
+ return createSpringCamelContext(this, "/org/apache/camel/component/crypto/SpringCryptoDataFormatTest.xml");
+ }
+
+ public static Key getDesKey() {
+ return deskey;
+ }
+
+ public static byte[] getIV() {
+ return new byte[] {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
+ }
+
+}
Propchange: camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/SpringCryptoDataFormatTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/SpringCryptoDataFormatTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-crypto/src/test/resources/.keystore
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/test/resources/.keystore?rev=926499&view=auto
==============================================================================
Binary file - no diff available.
Propchange: camel/trunk/components/camel-crypto/src/test/resources/.keystore
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: camel/trunk/components/camel-crypto/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/test/resources/log4j.properties?rev=926499&view=auto
==============================================================================
--- camel/trunk/components/camel-crypto/src/test/resources/log4j.properties (added)
+++ camel/trunk/components/camel-crypto/src/test/resources/log4j.properties Tue Mar 23 08:49:46 2010
@@ -0,0 +1,36 @@
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements. See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You 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.
+## ---------------------------------------------------------------------------
+
+#
+# The logging properties used during tests..
+#
+log4j.rootLogger=INFO, file
+
+# uncomment this to turn on debug of camel
+#log4j.logger.org.apache.camel=DEBUG
+
+# CONSOLE appender not used by default
+log4j.appender.out=org.apache.log4j.ConsoleAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+
+# File appender
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.appender.file.file=target/camel-crypto-test.log
+log4j.appender.file.append=true
Propchange: camel/trunk/components/camel-crypto/src/test/resources/log4j.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-crypto/src/test/resources/log4j.properties
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: camel/trunk/components/camel-crypto/src/test/resources/log4j.properties
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: camel/trunk/components/camel-crypto/src/test/resources/org/apache/camel/component/crypto/SpringCryptoDataFormatTest.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/test/resources/org/apache/camel/component/crypto/SpringCryptoDataFormatTest.xml?rev=926499&view=auto
==============================================================================
--- camel/trunk/components/camel-crypto/src/test/resources/org/apache/camel/component/crypto/SpringCryptoDataFormatTest.xml (added)
+++ camel/trunk/components/camel-crypto/src/test/resources/org/apache/camel/component/crypto/SpringCryptoDataFormatTest.xml Tue Mar 23 08:49:46 2010
@@ -0,0 +1,108 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <!--
+ Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE
+ file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
+ to You 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.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <!-- START SNIPPET: e1 -->
+ <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+ <dataFormats>
+ <crypto id="basic" algorithm="DES" keyRef="desKey" />
+
+ <!-- START SNIPPET: init-vector -->
+ <crypto id="initvector" algorithm="DES/CBC/PKCS5Padding" keyRef="desKey" initVectorRef="initializationVector" />
+ <!-- END SNIPPET: init-vector -->
+
+ <!-- START SNIPPET: inline -->
+ <crypto id="inline" algorithm="DES/CBC/PKCS5Padding" keyRef="desKey" initVectorRef="initializationVector"
+ inline="true" />
+ <crypto id="inline-decrypt" algorithm="DES/CBC/PKCS5Padding" keyRef="desKey" inline="true" />
+ <!-- END SNIPPET: inline -->
+
+ <!-- START SNIPPET: hmac -->
+ <crypto id="hmac" algorithm="DES" keyRef="desKey" shouldAppendHMAC="true" />
+ <!-- END SNIPPET: hmac -->
+
+ <!-- START SNIPPET: hmac-algorithm -->
+ <crypto id="hmac-algorithm" algorithm="DES" keyRef="desKey" macAlgorithm="HmacMD5" shouldAppendHMAC="true" />
+ <!-- END SNIPPET: hmac-algorithm -->
+
+ <!-- START SNIPPET: header-key -->
+ <crypto id="nokey" algorithm="DES" />
+ <!-- END SNIPPET: header-key -->
+ </dataFormats>
+
+ <route>
+ <from uri="direct:basic-encryption" />
+ <marshal ref="basic" />
+ <to uri="mock:encrypted" />
+ <unmarshal ref="basic" />
+ <to uri="mock:unencrypted" />
+ </route>
+
+ <route>
+ <from uri="direct:init-vector" />
+ <marshal ref="initvector" />
+ <to uri="mock:encrypted" />
+ <unmarshal ref="initvector" />
+ <to uri="mock:unencrypted" />
+ </route>
+
+ <route>
+ <from uri="direct:inline" />
+ <marshal ref="inline" />
+ <to uri="mock:encrypted" />
+ <unmarshal ref="inline-decrypt" />
+ <to uri="mock:unencrypted" />
+ </route>
+
+ <route>
+ <from uri="direct:hmac" />
+ <marshal ref="hmac" />
+ <to uri="mock:encrypted" />
+ <unmarshal ref="hmac" />
+ <to uri="mock:unencrypted" />
+ </route>
+
+ <route>
+ <from uri="direct:hmac-algorithm" />
+ <marshal ref="hmac-algorithm" />
+ <to uri="mock:encrypted" />
+ <unmarshal ref="hmac-algorithm" />
+ <to uri="mock:unencrypted" />
+ </route>
+
+ <route>
+ <from uri="direct:key-in-header-encrypt" />
+ <marshal ref="nokey" />
+ <setHeader headerName="CamelCryptoKey">
+ <constant />
+ </setHeader>
+ <to uri="mock:encrypted" />
+ </route>
+
+ <route>
+ <from uri="direct:key-in-header-decrypt" />
+ <unmarshal ref="nokey" />
+ <setHeader headerName="CamelCryptoKey">
+ <constant />
+ </setHeader>
+ <to uri="mock:unencrypted" />
+ </route>
+
+ </camelContext>
+
+ <bean id="desKey" class="org.apache.camel.converter.crypto.SpringCryptoDataFormatTest" factory-method="getDesKey" />
+ <bean id="initializationVector" class="org.apache.camel.converter.crypto.SpringCryptoDataFormatTest" factory-method="getIV" />
+
+</beans>
\ No newline at end of file
Propchange: camel/trunk/components/camel-crypto/src/test/resources/org/apache/camel/component/crypto/SpringCryptoDataFormatTest.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-crypto/src/test/resources/org/apache/camel/component/crypto/SpringCryptoDataFormatTest.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: camel/trunk/components/camel-crypto/src/test/resources/org/apache/camel/component/crypto/SpringCryptoDataFormatTest.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml