You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@turbine.apache.org by sg...@apache.org on 2008/07/21 18:35:32 UTC
svn commit: r678465 [1/3] - in /turbine/fulcrum/trunk/yaafi-crypto: ./ src/
src/java/ src/java/org/ src/java/org/apache/ src/java/org/apache/fulcrum/
src/java/org/apache/fulcrum/jce/ src/java/org/apache/fulcrum/jce/crypto/
src/main/ src/main/assembly/ ...
Author: sgoeschl
Date: Mon Jul 21 09:35:30 2008
New Revision: 678465
URL: http://svn.apache.org/viewvc?rev=678465&view=rev
Log:
Refactored the transparent decryption of configuration files into seperate/optional project because most people don't need that functionality.
Added:
turbine/fulcrum/trunk/yaafi-crypto/
turbine/fulcrum/trunk/yaafi-crypto/LICENSE.txt
turbine/fulcrum/trunk/yaafi-crypto/NOTICE.txt
turbine/fulcrum/trunk/yaafi-crypto/pom.xml
turbine/fulcrum/trunk/yaafi-crypto/project.properties
turbine/fulcrum/trunk/yaafi-crypto/project.xml
turbine/fulcrum/trunk/yaafi-crypto/src/
turbine/fulcrum/trunk/yaafi-crypto/src/java/
turbine/fulcrum/trunk/yaafi-crypto/src/java/org/
turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/
turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/
turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/
turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/
turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/CryptoParameters.java
turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/CryptoStreamFactory.java
turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/CryptoStreamFactoryImpl.java
turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/CryptoUtil.java
turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/HexConverter.java
turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/PasswordFactory.java
turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/PasswordParameters.java
turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/SmartDecryptingInputStream.java
turbine/fulcrum/trunk/yaafi-crypto/src/main/
turbine/fulcrum/trunk/yaafi-crypto/src/main/assembly/
turbine/fulcrum/trunk/yaafi-crypto/src/main/assembly/bin.xml
turbine/fulcrum/trunk/yaafi-crypto/src/main/assembly/src.xml
turbine/fulcrum/trunk/yaafi-crypto/src/site/
turbine/fulcrum/trunk/yaafi-crypto/src/site/site.xml
turbine/fulcrum/trunk/yaafi-crypto/src/test/
turbine/fulcrum/trunk/yaafi-crypto/src/test/data/
turbine/fulcrum/trunk/yaafi-crypto/src/test/data/empty.txt
turbine/fulcrum/trunk/yaafi-crypto/src/test/data/plain-iso-8859-1.xml
turbine/fulcrum/trunk/yaafi-crypto/src/test/data/plain-utf16.xml (with props)
turbine/fulcrum/trunk/yaafi-crypto/src/test/data/plain-utf8.xml
turbine/fulcrum/trunk/yaafi-crypto/src/test/data/plain.groovy
turbine/fulcrum/trunk/yaafi-crypto/src/test/data/plain.pdf
turbine/fulcrum/trunk/yaafi-crypto/src/test/data/plain.txt
turbine/fulcrum/trunk/yaafi-crypto/src/test/data/plain.xml (with props)
turbine/fulcrum/trunk/yaafi-crypto/src/test/data/plain.zip (with props)
turbine/fulcrum/trunk/yaafi-crypto/src/test/org/
turbine/fulcrum/trunk/yaafi-crypto/src/test/org/apache/
turbine/fulcrum/trunk/yaafi-crypto/src/test/org/apache/fulcrum/
turbine/fulcrum/trunk/yaafi-crypto/src/test/org/apache/fulcrum/jce/
turbine/fulcrum/trunk/yaafi-crypto/src/test/org/apache/fulcrum/jce/crypto/
turbine/fulcrum/trunk/yaafi-crypto/src/test/org/apache/fulcrum/jce/crypto/CryptoUtilTest.java
turbine/fulcrum/trunk/yaafi-crypto/src/test/org/apache/fulcrum/jce/crypto/Main.java
turbine/fulcrum/trunk/yaafi-crypto/src/test/org/apache/fulcrum/jce/crypto/MainTest.java
turbine/fulcrum/trunk/yaafi-crypto/src/test/org/apache/fulcrum/jce/crypto/SmartDecryptingInputStreamTest.java
turbine/fulcrum/trunk/yaafi-crypto/xdocs/
turbine/fulcrum/trunk/yaafi-crypto/xdocs/changes.xml
turbine/fulcrum/trunk/yaafi-crypto/xdocs/index.xml
Added: turbine/fulcrum/trunk/yaafi-crypto/LICENSE.txt
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/LICENSE.txt?rev=678465&view=auto
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/LICENSE.txt (added)
+++ turbine/fulcrum/trunk/yaafi-crypto/LICENSE.txt Mon Jul 21 09:35:30 2008
@@ -0,0 +1,202 @@
+
+ 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.
Added: turbine/fulcrum/trunk/yaafi-crypto/NOTICE.txt
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/NOTICE.txt?rev=678465&view=auto
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/NOTICE.txt (added)
+++ turbine/fulcrum/trunk/yaafi-crypto/NOTICE.txt Mon Jul 21 09:35:30 2008
@@ -0,0 +1,6 @@
+Turbine Fulcrum ServiceManager
+Copyright 2002-2007 The Apache Software Foundation.
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
Added: turbine/fulcrum/trunk/yaafi-crypto/pom.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/pom.xml?rev=678465&view=auto
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/pom.xml (added)
+++ turbine/fulcrum/trunk/yaafi-crypto/pom.xml Mon Jul 21 09:35:30 2008
@@ -0,0 +1,77 @@
+<?xml version="1.0"?>
+<!--
+ 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.
+-->
+<project
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>fulcrum</groupId>
+ <artifactId>fulcrum-parent</artifactId>
+ <version>1-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>fulcrum-yaafi-crypto</artifactId>
+ <version>1.0.6-SNAPSHOT</version>
+ <name>Fulcrum YAAFI Crypto</name>
+ <inceptionYear>2008</inceptionYear>
+ <description>Fulcrum YAAFI Crypto Library</description>
+ <url>http://turbine.apache.org/fulcrum/fulcrum-yaafi-crytpo</url>
+
+ <scm>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/turbine/fulcrum/trunk/yaafi-crypto/</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/turbine/fulcrum/trunk/yaafi-crypto/</developerConnection>
+ <url>http://svn.apache.org/viewcvs/turbine/fulcrum/trunk/yaafi-crypto/</url>
+ </scm>
+
+ <distributionManagement>
+ <site>
+ <id>fulcrum.website</id>
+ <name>Fulcrum Website</name>
+ <url>${fulcrum.deployment.protocol}://people.apache.org/www/turbine.apache.org/fulcrum/fulcrum-yaafi-crypto/</url>
+ </site>
+ </distributionManagement>
+
+ <developers>
+ <developer>
+ <name>Siegfried Goeschl</name>
+ <id>sgoeschl</id>
+ <email>sgoeschl@apache.org</email>
+ <organization></organization>
+ <roles>
+ <role>Java Developer</role>
+ </roles>
+ </developer>
+ </developers>
+
+ <dependencies>
+ <!-- testing dependencies -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <sourceDirectory>${basedir}/src/java</sourceDirectory>
+ <testSourceDirectory>${basedir}/src/test</testSourceDirectory>
+ </build>
+
+</project>
Added: turbine/fulcrum/trunk/yaafi-crypto/project.properties
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/project.properties?rev=678465&view=auto
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/project.properties (added)
+++ turbine/fulcrum/trunk/yaafi-crypto/project.properties Mon Jul 21 09:35:30 2008
@@ -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.
+
Added: turbine/fulcrum/trunk/yaafi-crypto/project.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/project.xml?rev=678465&view=auto
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/project.xml (added)
+++ turbine/fulcrum/trunk/yaafi-crypto/project.xml Mon Jul 21 09:35:30 2008
@@ -0,0 +1,36 @@
+<?xml version="1.0"?>
+<!--
+ 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.
+-->
+<project>
+ <extend>${basedir}/../project.xml</extend>
+ <id>fulcrum-yaafi-crypto</id>
+ <name>Fulcrum Yaafi Cryptp Library</name>
+ <currentVersion>1.0.6-dev</currentVersion>
+
+ <dependencies>
+ <!-- Needed only for testing -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ </dependency>
+ </dependencies>
+
+</project>
+
Added: turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/CryptoParameters.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/CryptoParameters.java?rev=678465&view=auto
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/CryptoParameters.java (added)
+++ turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/CryptoParameters.java Mon Jul 21 09:35:30 2008
@@ -0,0 +1,42 @@
+package org.apache.fulcrum.jce.crypto;
+
+/*
+ * 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.
+ */
+
+
+/**
+ * CryptoParameters used for encryption/decrytpion.
+ *
+ * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
+ */
+
+public interface CryptoParameters
+{
+ /** Parameter for PBEParameterSpec */
+ int COUNT = 20;
+
+ /** The password salt */
+ byte[] SALT = {
+ (byte)0xc7, (byte)0x73, (byte)0x21, (byte)0x8c,
+ (byte)0x7e, (byte)0xc8, (byte)0xee, (byte)0x99
+ };
+
+ /** The crypto algorithm being used */
+ String ALGORITHM = "PBEWithMD5AndDES";
+}
Added: turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/CryptoStreamFactory.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/CryptoStreamFactory.java?rev=678465&view=auto
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/CryptoStreamFactory.java (added)
+++ turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/CryptoStreamFactory.java Mon Jul 21 09:35:30 2008
@@ -0,0 +1,136 @@
+package org.apache.fulcrum.jce.crypto;
+
+/*
+ * 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.
+ */
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.security.GeneralSecurityException;
+
+/**
+ * Interface for creating encrypting/decrypting streams.
+ *
+ * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl </a>
+ */
+
+public interface CryptoStreamFactory
+{
+ /**
+ * Creates input stream based on the decryption mode
+ * using the default password.
+ *
+ * @param is the input stream to be wrapped
+ * @param decryptionMode the decryption mode (true|false|auto)
+ * @return an decrypting input stream
+ * @throws GeneralSecurityException creating the input stream failed
+ * @throws IOException creating the input stream failed
+ */
+ InputStream getInputStream(InputStream is, String decryptionMode)
+ throws GeneralSecurityException, IOException;
+
+ /**
+ * Creates input stream based on the decryption mode
+ * using the given password.
+ *
+ * @param is the input stream to be wrapped
+ * @param decryptionMode the decryption mode (true|false|auto)
+ * @param password the password to be used
+ * @return an decrypting input stream
+ * @throws GeneralSecurityException creating the input stream failed
+ * @throws IOException creating the input stream failed
+ */
+ InputStream getInputStream(InputStream is, String decryptionMode, char[] password)
+ throws GeneralSecurityException, IOException;
+
+ /**
+ * Creates a decrypting input stream using the default password.
+ *
+ * @param is the input stream to be wrapped
+ * @return an decrypting input stream
+ * @throws GeneralSecurityException creating the input stream failed
+ * @throws IOException creating the input stream failed
+ */
+ InputStream getInputStream(InputStream is)
+ throws GeneralSecurityException, IOException;
+
+ /**
+ * Creates an decrypting input stream using a given password.
+ *
+ * @param is the input stream to be wrapped
+ * @param password the password to be used
+ * @return an decrypting input stream
+ * @throws GeneralSecurityException creating the input stream failed
+ * @throws IOException creating the input stream failed
+ */
+ InputStream getInputStream(InputStream is, char[] password)
+ throws GeneralSecurityException, IOException;
+
+ /**
+ * Creates a smart decrypting input stream using the default
+ * password. The implementation looks at the binary content
+ * to decide if it was encrypted or not thereby providing
+ * transparent access to encrypted/unencrypted files.
+ *
+ * @param is the input stream to be wrapped
+ * @return an decrypting input stream
+ * @throws GeneralSecurityException creating the input stream failed
+ * @throws IOException creating the input stream failed
+ */
+ InputStream getSmartInputStream(InputStream is)
+ throws GeneralSecurityException, IOException;
+
+ /**
+ * Creates a smart decrypting input stream using a given
+ * password. The implementation looks at the binary content
+ * to decide if it was encrypted or not thereby providing
+ * transparent access to encrypted/unencrypted files.
+ *
+ * @param is the input stream to be wrapped
+ * @param password the password to be used
+ * @return an decrypting input stream
+ * @throws GeneralSecurityException creating the input stream failed
+ * @throws IOException creating the input stream failed
+ */
+ InputStream getSmartInputStream(InputStream is, char[] password)
+ throws GeneralSecurityException, IOException;
+
+ /**
+ * Creates an encrypting output stream using the default password.
+ *
+ * @param os the output stream to be wrapped
+ * @return an decrypting input stream
+ * @throws GeneralSecurityException creating the ouptut stream failed
+ * @throws IOException creating the ouptut stream failed
+ */
+ OutputStream getOutputStream(OutputStream os)
+ throws GeneralSecurityException, IOException;
+
+ /**
+ * Creates an encrypting output stream using the given password.
+ *
+ * @param os the output stream to be wrapped
+ * @param password the password to be used
+ * @return an decrypting input stream
+ * @throws GeneralSecurityException creating the ouptut stream failed
+ * @throws IOException creating the ouptut stream failed
+ */
+ OutputStream getOutputStream(OutputStream os, char[] password)
+ throws GeneralSecurityException, IOException;
+}
Added: turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/CryptoStreamFactoryImpl.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/CryptoStreamFactoryImpl.java?rev=678465&view=auto
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/CryptoStreamFactoryImpl.java (added)
+++ turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/CryptoStreamFactoryImpl.java Mon Jul 21 09:35:30 2008
@@ -0,0 +1,326 @@
+package org.apache.fulcrum.jce.crypto;
+
+/*
+ * 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.
+ */
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.security.GeneralSecurityException;
+import java.security.Key;
+
+import javax.crypto.Cipher;
+import javax.crypto.CipherInputStream;
+import javax.crypto.CipherOutputStream;
+import javax.crypto.SecretKeyFactory;
+import javax.crypto.spec.PBEKeySpec;
+import javax.crypto.spec.PBEParameterSpec;
+
+/**
+ * Concrete factory for creating encrypting/decrypting streams. The
+ * implementation uses the JCA (Java Crypto Extension) supplied
+ * by SUN (using SunJCE 1.42).
+ *
+ * The implementation uses as PBEWithMD5AndDES for encryption which
+ * should be sufficent for most applications.
+ *
+ * The implementation also supplies a default password in the case that
+ * the programmer don't want to have additional hassles. It is easy to
+ * reengineer the password being used but much better than a hard-coded
+ * password in the application.
+ *
+ * The code uses parts from Markus Hahn's Blowfish library found at
+ * http://blowfishj.sourceforge.net/
+ *
+ * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl </a>
+ * @author <a href="mailto:maakus@earthlink.net">Markus Hahn</a>
+ */
+
+public final class CryptoStreamFactoryImpl implements CryptoStreamFactory
+{
+ /** the salt for the PBE algorithm */
+ private byte[] salt;
+
+ /** the count paramter for the PBE algorithm */
+ private int count;
+
+ /** the name of the JCE provider */
+ private String providerName;
+
+ /** the algorithm to use */
+ private String algorithm;
+
+ /** the default instance */
+ private static CryptoStreamFactory instance;
+
+ /**
+ * The JCE provider name known to work. If the value
+ * is set to null an appropriate provider will be
+ * used.
+ */
+ private static final String PROVIDERNAME = null;
+
+ /**
+ * Factory method to get a default instance
+ * @return an instance of the CryptoStreamFactory
+ */
+ public synchronized static CryptoStreamFactory getInstance()
+ {
+ if( CryptoStreamFactoryImpl.instance == null )
+ {
+ CryptoStreamFactoryImpl.instance = new CryptoStreamFactoryImpl();
+ }
+
+ return CryptoStreamFactoryImpl.instance;
+ }
+
+ /**
+ * Set the default instance from an external application.
+ * @param instance the new default instance
+ */
+ public static void setInstance( CryptoStreamFactory instance )
+ {
+ CryptoStreamFactoryImpl.instance = instance;
+ }
+
+ /**
+ * Constructor
+ */
+ public CryptoStreamFactoryImpl()
+ {
+ this.salt = CryptoParameters.SALT;
+ this.count = CryptoParameters.COUNT;
+ this.providerName = PROVIDERNAME;
+ this.algorithm = CryptoParameters.ALGORITHM;
+ }
+
+ /**
+ * Constructor
+ *
+ * @param salt the salt for the PBE algorithm
+ * @param count the iteration for PBEParameterSpec
+ */
+ public CryptoStreamFactoryImpl( byte[] salt, int count)
+ {
+ this.salt = salt;
+ this.count = count;
+ this.providerName = PROVIDERNAME;
+ this.algorithm = CryptoParameters.ALGORITHM;
+ }
+
+
+ /**
+ * @see org.apache.fulcrum.jce.crypto.CryptoStreamFactory#getInputStream(java.io.InputStream, String)
+ */
+ public InputStream getInputStream(InputStream is, String decryptionMode) throws GeneralSecurityException, IOException {
+
+ InputStream result = null;
+
+ if( "auto".equalsIgnoreCase(decryptionMode) )
+ {
+ result = CryptoStreamFactoryImpl.getInstance().getSmartInputStream(is);
+ }
+ else if( "true".equalsIgnoreCase(decryptionMode) )
+ {
+ result = CryptoStreamFactoryImpl.getInstance().getInputStream(is);
+ }
+ else
+ {
+ result = is;
+ }
+ return result;
+ }
+
+ /**
+ * @see org.apache.fulcrum.jce.crypto.CryptoStreamFactory#getInputStream(java.io.InputStream, String, char[])
+ */
+ public InputStream getInputStream(InputStream is, String decryptionMode, char[] password) throws GeneralSecurityException, IOException {
+
+ InputStream result = null;
+
+ if( "auto".equalsIgnoreCase(decryptionMode) )
+ {
+ result = CryptoStreamFactoryImpl.getInstance().getSmartInputStream(is, password);
+ }
+ else if( "true".equalsIgnoreCase(decryptionMode) )
+ {
+ result = CryptoStreamFactoryImpl.getInstance().getInputStream(is, password);
+ }
+ else
+ {
+ result = is;
+ }
+ return result;
+ }
+
+ /**
+ * @see org.apache.fulcrum.jce.crypto.CryptoStreamFactory#getInputStream(java.io.InputStream)
+ */
+ public InputStream getInputStream( InputStream is )
+ throws GeneralSecurityException, IOException
+ {
+ Cipher cipher = this.createCipher( Cipher.DECRYPT_MODE, PasswordFactory.create() );
+ return new CipherInputStream( is, cipher );
+ }
+
+ /**
+ * @see org.apache.fulcrum.jce.crypto.CryptoStreamFactory#getInputStream(java.io.InputStream,char[])
+ */
+ public InputStream getInputStream( InputStream is, char[] password )
+ throws GeneralSecurityException, IOException
+ {
+ Cipher cipher = this.createCipher( Cipher.DECRYPT_MODE, password );
+ return new CipherInputStream( is, cipher );
+ }
+
+ /**
+ * @see org.apache.fulcrum.jce.crypto.CryptoStreamFactory#getSmartInputStream(java.io.InputStream)
+ */
+ public InputStream getSmartInputStream(InputStream is)
+ throws GeneralSecurityException, IOException
+ {
+ return this.getSmartInputStream(
+ is,
+ PasswordFactory.create()
+ );
+ }
+
+ /**
+ * @see org.apache.fulcrum.jce.crypto.CryptoStreamFactory#getSmartInputStream(java.io.InputStream,char[])
+ */
+ public InputStream getSmartInputStream(InputStream is, char[] password )
+ throws GeneralSecurityException, IOException
+ {
+ SmartDecryptingInputStream result;
+
+ result = new SmartDecryptingInputStream(
+ getInstance(),
+ is,
+ password
+ );
+
+ return result;
+ }
+
+ /**
+ * @see org.apache.fulcrum.jce.crypto.CryptoStreamFactory#getOutputStream(java.io.OutputStream)
+ */
+ public OutputStream getOutputStream( OutputStream os )
+ throws GeneralSecurityException, IOException
+ {
+ Cipher cipher = this.createCipher( Cipher.ENCRYPT_MODE, PasswordFactory.create() );
+ return new CipherOutputStream( os, cipher ); }
+
+ /**
+ * @see org.apache.fulcrum.jce.crypto.CryptoStreamFactory#getOutputStream(java.io.OutputStream, char[])
+ */
+ public OutputStream getOutputStream( OutputStream os, char[] password )
+ throws GeneralSecurityException, IOException
+ {
+ Cipher cipher = this.createCipher( Cipher.ENCRYPT_MODE, password );
+ return new CipherOutputStream( os, cipher );
+ }
+
+ /**
+ * @return Returns the algorithm.
+ */
+ private String getAlgorithm()
+ {
+ return algorithm;
+ }
+
+ /**
+ * @return Returns the count.
+ */
+ private int getCount()
+ {
+ return count;
+ }
+
+ /**
+ * @return Returns the providerName.
+ */
+ private String getProviderName()
+ {
+ return providerName;
+ }
+
+ /**
+ * @return Returns the salt.
+ */
+ private byte [] getSalt()
+ {
+ return salt;
+ }
+
+ /**
+ * Create a PBE key.
+ *
+ * @param password the password to use.
+ * @return the key
+ * @throws GeneralSecurityException creating the key failed
+ */
+ private Key createKey( char[] password )
+ throws GeneralSecurityException
+ {
+ SecretKeyFactory keyFactory;
+ String algorithm = this.getAlgorithm();
+ PBEKeySpec keySpec = new PBEKeySpec(password);
+
+ if( this.getProviderName() == null )
+ {
+ keyFactory = SecretKeyFactory.getInstance( algorithm );
+ }
+ else
+ {
+ keyFactory = SecretKeyFactory.getInstance( algorithm, this.getProviderName() );
+ }
+
+ return keyFactory.generateSecret(keySpec);
+ }
+
+ /**
+ * Create a Cipher.
+ *
+ * @param mode the cipher mode
+ * @param password the password
+ * @return an instance of a cipher
+ * @throws GeneralSecurityException creating a cipher failed
+ * @throws IOException creating a cipher failed
+ */
+ private Cipher createCipher( int mode, char[] password )
+ throws GeneralSecurityException, IOException
+ {
+ Cipher cipher;
+ PBEParameterSpec paramSpec = new PBEParameterSpec( this.getSalt(), this.getCount() );
+ Key key = this.createKey( password );
+
+ if( this.getProviderName() == null )
+ {
+ cipher = Cipher.getInstance( this.getAlgorithm() );
+ }
+ else
+ {
+ cipher = Cipher.getInstance( this.getAlgorithm(), this.getProviderName() );
+ }
+
+ cipher.init( mode, key, paramSpec );
+ return cipher;
+ }
+}
Added: turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/CryptoUtil.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/CryptoUtil.java?rev=678465&view=auto
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/CryptoUtil.java (added)
+++ turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/CryptoUtil.java Mon Jul 21 09:35:30 2008
@@ -0,0 +1,332 @@
+package org.apache.fulcrum.jce.crypto;
+
+/*
+ * 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.
+ */
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.security.GeneralSecurityException;
+
+/**
+ * Helper class to provde generic functions to work with CryptoStreams.
+ *
+ * The code uses parts from Markus Hahn's Blowfish library found at
+ * http://blowfishj.sourceforge.net/
+ *
+ * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl </a>
+ * @author <a href="mailto:maakus@earthlink.net">Markus Hahn</a>
+ */
+
+public final class CryptoUtil
+{
+ /** the size of the internal buffer to copy streams */
+ private static final int BUFFER_SIZE = 1024;
+
+ /**
+ * Copies from a source to a target object using encryption
+ *
+ * @param source the source object
+ * @param target the target object
+ * @param password the password to use for encryption
+ * @throws GeneralSecurityException accessing JCE failed
+ * @throws IOException accessing the souce failed
+ *
+ */
+ public static void encrypt( Object source, Object target, char[] password )
+ throws GeneralSecurityException, IOException
+ {
+ CryptoUtil.encrypt(
+ CryptoUtil.getCryptoStreamFactory(),
+ source,
+ target,
+ password
+ );
+ }
+
+ /**
+ * Copies from a source to a target object using encryption and a
+ * caller supplied CryptoStreamFactory.
+ *
+ * @param factory the factory to create the crypto streams
+ * @param source the source object
+ * @param target the target object
+ * @param password the password to use for encryption
+ * @throws GeneralSecurityException accessing JCE failed
+ * @throws IOException accessing the souce failed
+ */
+ public static void encrypt(
+ CryptoStreamFactory factory, Object source, Object target, char[] password )
+ throws GeneralSecurityException, IOException
+ {
+ InputStream is = CryptoUtil.createInputStream( source );
+ OutputStream os = CryptoUtil.createOutputStream( target );
+ OutputStream eos = factory.getOutputStream( os, password );
+ CryptoUtil.copy( is, eos );
+ }
+
+ /**
+ * Copies from a source to a target object using decryption.
+ *
+ * @param source the source object
+ * @param target the target object
+ * @param password the password to use for decryption
+ * @throws GeneralSecurityException accessing JCE failed
+ * @throws IOException accessing the souce failed
+ */
+ public static void decrypt( Object source, Object target, char[] password )
+ throws GeneralSecurityException, IOException
+ {
+ CryptoUtil.decrypt(
+ CryptoUtil.getCryptoStreamFactory(),
+ source,
+ target,
+ password
+ );
+ }
+
+ /**
+ * Copies from a source to a target object using decryption and a
+ * caller-suppier CryptoStreamFactory.
+ *
+ * @param factory the factory to create the crypto streams
+ * @param source the source object
+ * @param target the target object
+ * @param password the password to use for decryption
+ * @throws GeneralSecurityException accessing JCE failed
+ * @throws IOException accessing the souce failed
+ */
+ public static void decrypt(
+ CryptoStreamFactory factory, Object source, Object target, char[] password )
+ throws GeneralSecurityException, IOException
+ {
+ InputStream is = CryptoUtil.createInputStream( source );
+ OutputStream os = CryptoUtil.createOutputStream( target );
+ InputStream dis = factory.getInputStream( is, password );
+ CryptoUtil.copy( dis, os );
+ }
+
+ /**
+ * Encrypts a string into a hex string.
+ *
+ * @param plainText the plain text to be encrypted
+ * @param password the password for encryption
+ * @return the encrypted string
+ * @throws GeneralSecurityException accessing JCE failed
+ * @throws IOException accessing the souce failed
+ */
+ public static String encryptString( String plainText, char[] password )
+ throws GeneralSecurityException, IOException
+ {
+ return CryptoUtil.encryptString(
+ CryptoUtil.getCryptoStreamFactory(),
+ plainText,
+ password
+ );
+ }
+
+ /**
+ * Encrypts a string into a hex string.
+ *
+ * @param factory the factory to create the crypto streams
+ * @param plainText the plain text to be encrypted
+ * @param password the password for encryption
+ * @return the encrypted string
+ * @throws GeneralSecurityException accessing JCE failed
+ * @throws IOException accessing the souce failed
+ */
+ public static String encryptString(
+ CryptoStreamFactory factory, String plainText, char[] password )
+ throws GeneralSecurityException, IOException
+ {
+ ByteArrayOutputStream bais = new ByteArrayOutputStream();
+ CryptoUtil.encrypt( factory, plainText, bais, password );
+ return HexConverter.toString( bais.toByteArray() );
+ }
+
+ /**
+ * Decrypts an encrypted string into the plain text. The encrypted
+ * string must be a hex string created by encryptString.
+ *
+ * @param cipherText the encrypted text to be decrypted
+ * @param password the password for decryption
+ * @return the decrypted string
+ * @throws GeneralSecurityException accessing JCE failed
+ * @throws IOException accessing the souce failed
+ */
+ public static String decryptString( String cipherText, char[] password )
+ throws GeneralSecurityException, IOException
+ {
+ return CryptoUtil.decryptString(
+ CryptoUtil.getCryptoStreamFactory(),
+ cipherText,
+ password
+ );
+ }
+
+ /**
+ * Decrypts an encrypted string into the plain text. The encrypted
+ * string must be a hex string created by encryptString.
+ *
+ * @param factory the factory to create the crypto streams
+ * @param cipherText the encrypted text to be decrypted
+ * @param password the password for decryption
+ * @return the decrypted string
+ * @throws GeneralSecurityException accessing JCE failed
+ * @throws IOException accessing the souce failed
+ */
+ public static String decryptString(
+ CryptoStreamFactory factory, String cipherText, char[] password )
+ throws GeneralSecurityException, IOException
+ {
+ byte[] buffer = HexConverter.toBytes( cipherText );
+ ByteArrayOutputStream bais = new ByteArrayOutputStream();
+ CryptoUtil.decrypt( factory, buffer, bais, password );
+ return new String( bais.toByteArray(), "utf-8" );
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Private Implementation
+ ///////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Create an input stream supporting the following types
+ *
+ * <ul>
+ * <li>String</li>
+ * <li>File</li>
+ * <li>byte[]</li>
+ * <li>char[]</li>
+ * <li>ByteArrayOutputStream</li>
+ * <li>InputStream</li>
+ * </ul>
+ *
+ * @param source the source object
+ * @return the created input stream
+ * @throws IOException creating the input stream failed
+ */
+ private static InputStream createInputStream( Object source )
+ throws IOException
+ {
+ InputStream is;
+
+ // create an InputStream
+
+ if( source instanceof String )
+ {
+ byte[] content = ((String) source).getBytes("utf-8");
+ is = new ByteArrayInputStream( content );
+ }
+ else if( source instanceof File )
+ {
+ is = new FileInputStream( (File) source );
+ }
+ else if( source instanceof byte[] )
+ {
+ is = new ByteArrayInputStream( (byte[]) source );
+ }
+ else if( source instanceof char[] )
+ {
+ byte[] content = new String((char[])source).getBytes("utf-8");
+ is = new ByteArrayInputStream( content );
+ }
+ else if( source instanceof ByteArrayOutputStream )
+ {
+ byte[] content = ((ByteArrayOutputStream) source).toByteArray();
+ is = new ByteArrayInputStream( content );
+ }
+ else
+ {
+ is = (InputStream) source;
+ }
+
+ return is;
+ }
+
+ /**
+ * Create an output stream supporting the following types
+ *
+ * <ul>
+ * <li>File</li>
+ * <li>OutputStream</li>
+ * </ul>
+ *
+ * @param target the target object
+ * @return the output stream
+ * @throws IOException creating the output stream failed
+ */
+ private static OutputStream createOutputStream( Object target )
+ throws IOException
+ {
+ OutputStream os;
+
+ if( target instanceof File )
+ {
+ os = new FileOutputStream( (File) target );
+ }
+ else
+ {
+ os = (OutputStream) target;
+ }
+
+ return os;
+ }
+
+ /**
+ * Pumps the input stream to the output stream.
+ *
+ * @param is the source input stream
+ * @param os the target output stream
+ * @return the number of bytes copied
+ * @throws IOException the copying failed
+ */
+ public static long copy( InputStream is, OutputStream os )
+ throws IOException
+ {
+ byte[] buf = new byte[BUFFER_SIZE];
+ int n = 0;
+ long total = 0;
+
+ while ((n = is.read(buf)) > 0)
+ {
+ os.write(buf, 0, n);
+ total += n;
+ }
+
+ is.close();
+
+ os.flush();
+ os.close();
+
+ return total;
+ }
+
+ /**
+ * @return the CryptoStreamFactory to be used
+ */
+ public static CryptoStreamFactory getCryptoStreamFactory()
+ {
+ return CryptoStreamFactoryImpl.getInstance();
+ }
+}
Added: turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/HexConverter.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/HexConverter.java?rev=678465&view=auto
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/HexConverter.java (added)
+++ turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/HexConverter.java Mon Jul 21 09:35:30 2008
@@ -0,0 +1,174 @@
+package org.apache.fulcrum.jce.crypto;
+
+/*
+ * 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.
+ */
+
+
+/**
+ * Helper class to for HEX conversion.
+ *
+ * The code uses parts from Markus Hahn's Blowfish library found at
+ * http://blowfishj.sourceforge.net/
+ *
+ * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl </a>
+ * @author <a href="mailto:maakus@earthlink.net">Markus Hahn</a>
+ */
+
+public final class HexConverter
+{
+ /**
+ * Table for byte to hex conversion
+ */
+ final private static char[] HEXTAB =
+ {
+ '0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
+ };
+
+ /**
+ * Converts a byte array to a hex string.
+ *
+ * @param data the byte array
+ * @return the hex string
+ */
+ public static String toString( byte[] data )
+ {
+ return bytesToHexStr(data, 0, data.length);
+ }
+
+ /**
+ * Converts a hex string into a byte[]
+ *
+ * @param data the hex string
+ * @return the byte[]
+ */
+
+ public static byte[] toBytes( String data )
+ {
+ byte[] result = new byte[data.length()/2];
+ hexStrToBytes( data, result, 0, 0, result.length );
+ return result;
+ }
+
+ /**
+ * Converts a byte array to a hex string.
+ * @param data the byte array
+ * @param nOfs start index where to get the bytes
+ * @param nLen number of bytes to convert
+ * @return the hex string
+ */
+ private static String bytesToHexStr(
+ byte[] data,
+ int nOfs,
+ int nLen)
+ {
+ StringBuffer sbuf;
+
+ sbuf = new StringBuffer();
+ sbuf.setLength(nLen << 1);
+
+ int nPos = 0;
+ int nC = nOfs + nLen;
+
+ while (nOfs < nC)
+ {
+ sbuf.setCharAt(nPos++, HEXTAB[(data[nOfs ] >> 4) & 0x0f]);
+ sbuf.setCharAt(nPos++, HEXTAB[ data[nOfs++] & 0x0f]);
+ }
+
+ return sbuf.toString();
+ }
+
+ /**
+ * Converts a hex string back into a byte array (invalid codes will be
+ * skipped).
+ * @param sHex hex string
+ * @param data the target array
+ * @param nSrcOfs from which character in the string the conversion should
+ * begin, remember that (nSrcPos modulo 2) should equals 0 normally
+ * @param nDstOfs to store the bytes from which position in the array
+ * @param nLen number of bytes to extract
+ * @return number of extracted bytes
+ */
+ private static int hexStrToBytes(
+ String sHex,
+ byte[] data,
+ int nSrcOfs,
+ int nDstOfs,
+ int nLen)
+ {
+ int nI, nJ, nStrLen, nAvailBytes, nDstOfsBak;
+ byte bActByte;
+ boolean blConvertOK;
+
+ // check for correct ranges
+
+ nStrLen = sHex.length();
+
+ nAvailBytes = (nStrLen - nSrcOfs) >> 1;
+ if (nAvailBytes < nLen)
+ {
+ nLen = nAvailBytes;
+ }
+
+ int nOutputCapacity = data.length - nDstOfs;
+ if (nLen > nOutputCapacity)
+ {
+ nLen = nOutputCapacity;
+ }
+
+ // convert now
+
+ nDstOfsBak = nDstOfs;
+
+ for (nI = 0; nI < nLen; nI++)
+ {
+ bActByte = 0;
+ blConvertOK = true;
+
+ for (nJ = 0; nJ < 2; nJ++)
+ {
+ bActByte <<= 4;
+ char cActChar = sHex.charAt(nSrcOfs++);
+
+ if ((cActChar >= 'a') && (cActChar <= 'f'))
+ {
+ bActByte |= (byte) (cActChar - 'a') + 10;
+ }
+ else
+ {
+ if ((cActChar >= '0') && (cActChar <= '9'))
+ {
+ bActByte |= (byte) (cActChar - '0');
+ }
+ else
+ {
+ blConvertOK = false;
+ }
+ }
+ }
+ if (blConvertOK)
+ {
+ data[nDstOfs++] = bActByte;
+ }
+ }
+
+ return (nDstOfs - nDstOfsBak);
+ }
+}
Added: turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/PasswordFactory.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/PasswordFactory.java?rev=678465&view=auto
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/PasswordFactory.java (added)
+++ turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/PasswordFactory.java Mon Jul 21 09:35:30 2008
@@ -0,0 +1,171 @@
+package org.apache.fulcrum.jce.crypto;
+
+/*
+ * 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.
+ */
+
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+/**
+ * The implementation supplies a default password in the case that
+ * the programmer don't want to have additional hassles. It is easy to
+ * reengineer the password being used but much better than a hard-coded
+ * password in the application.
+ *
+ * The code uses parts from Markus Hahn's Blowfish library found at
+ * http://blowfishj.sourceforge.net/
+ *
+ * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl </a>
+ * @author <a href="mailto:maakus@earthlink.net">Markus Hahn</a>
+ */
+
+public class PasswordFactory implements PasswordParameters
+{
+
+ /**
+ * @return a default password using "xxxx-xxxx-xxxx-xxxxx"
+ */
+ public static char[] create()
+ throws NoSuchAlgorithmException, UnsupportedEncodingException
+ {
+ return create(
+ PasswordParameters.DEFAULTPASSWORD,
+ PasswordParameters.SALT,
+ PasswordParameters.COUNT
+ );
+ }
+
+ /**
+ * @param seed the default password supplied by the caller
+ * @return a password using "xxxx-xxxx-xxxx-xxxxx"
+ */
+ public static char[] create( String seed )
+ throws NoSuchAlgorithmException, UnsupportedEncodingException
+ {
+ return create(
+ seed.toCharArray()
+ );
+ }
+
+ /**
+ * @param seed the default password supplied by the caller
+ * @return a password using "xxxx-xxxx-xxxx-xxxxx"
+ */
+ public static final char[] create( char[] seed )
+ throws NoSuchAlgorithmException, UnsupportedEncodingException
+ {
+ return create(
+ seed,
+ PasswordFactory.SALT,
+ PasswordFactory.COUNT
+ );
+ }
+
+ /**
+ * Creates a default password using "xxxx-xxxx-xxxx-xxxxx".
+ *
+ * @param salt the password salt
+ * @param password the default password
+ * @param count number of MessageDigest iterations
+ * @return the default password
+ * @throws NoSuchAlgorithmException the encryption algorithm is not supported
+ * @throws UnsupportedEncodingException the requested encoding is not supported
+ */
+ public static char [] create( char[] password, byte[] salt, int count )
+ throws NoSuchAlgorithmException, UnsupportedEncodingException
+ {
+ char [] result = null;
+ MessageDigest sha1 = MessageDigest.getInstance( "SHA1" );
+ byte [] passwordMask = new String( password ).getBytes( "UTF-8" );
+ byte [] temp = new byte[salt.length + passwordMask.length];
+ byte [] digest = null;
+
+ StringBuffer stringBuffer = new StringBuffer();
+
+ // combine the password with the salt string into a byte[9
+
+ System.arraycopy( passwordMask, 0, temp, 0, passwordMask.length );
+ System.arraycopy( salt, 0, temp, passwordMask.length, salt.length );
+
+ // create a hash over and over to make it a bit random
+
+ digest = temp;
+
+ for (int i = 0; i < count; i++)
+ {
+ sha1.update( digest );
+ digest = sha1.digest();
+ }
+
+ // build a well-formed password string to be usable
+ // by a human
+
+ long long1 = createLong( digest, 0 );
+ long long2 = createLong( digest, 4 );
+ long long3 = createLong( digest, 8 );
+ long long4 = createLong( digest, 12 );
+
+ stringBuffer.append( Long.toHexString( long1 ).substring( 0, 4 ) );
+ stringBuffer.append( '-' );
+ stringBuffer.append( Long.toHexString( long2 ).substring( 0, 4 ) );
+ stringBuffer.append( '-' );
+ stringBuffer.append( Long.toHexString( long3 ).substring( 0, 4 ) );
+ stringBuffer.append( '-' );
+ stringBuffer.append( Long.toHexString( long4 ).substring( 0, 5 ) );
+
+ // copy the password
+
+ result = new char[stringBuffer.length()];
+
+ for (int i = 0; i < stringBuffer.length(); i++)
+ {
+ result[i] = stringBuffer.charAt( i );
+ }
+
+ // wipe out the StringBuffer
+
+ for (int i = 0; i < stringBuffer.length(); i++)
+ {
+ stringBuffer.setCharAt( i, ' ' );
+ }
+
+ return result;
+ }
+
+ /**
+ * Gets bytes from an array into a long.
+ *
+ * @param buf where to get the bytes
+ * @param nOfs index from where to read the data
+ * @return the 64bit integer
+ */
+ private static long createLong(byte [] buf, int nOfs)
+ {
+ return
+ ((long)(( buf[nOfs ] << 24) |
+ ((buf[nOfs + 1] & 0x0ff) << 16) |
+ ((buf[nOfs + 2] & 0x0ff) << 8) |
+ ( buf[nOfs + 3] & 0x0ff )) << 32) |
+ ((long)(( buf[nOfs + 4] << 24) |
+ ((buf[nOfs + 5] & 0x0ff) << 16) |
+ ((buf[nOfs + 6] & 0x0ff) << 8) |
+ ( buf[nOfs + 7] & 0x0ff )) & 0x0ffffffffL);
+ }
+}
Added: turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/PasswordParameters.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/PasswordParameters.java?rev=678465&view=auto
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/PasswordParameters.java (added)
+++ turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/PasswordParameters.java Mon Jul 21 09:35:30 2008
@@ -0,0 +1,46 @@
+package org.apache.fulcrum.jce.crypto;
+
+/*
+ * 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.
+ */
+
+/**
+ * Parameters for creating a password.
+ *
+ * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
+ */
+
+public interface PasswordParameters
+{
+ /** Parameter for the number of SHA1 invocation */
+ int COUNT = 20;
+
+ /** The default password used for creating the internal password */
+ char[] DEFAULTPASSWORD = {
+ (char) 'f', (char) 'u', (char) 'l', (char) 'c',
+ (char) 'r', (char) 'u', (char) 'm', (char) '-',
+ (char) 'y', (char) 'a', (char) 'a', (char) 'f',
+ (char) 'i'
+ };
+
+ /** The password salt */
+ byte[] SALT = {
+ (byte)0xc6, (byte)0x74, (byte)0x81, (byte)0x8a,
+ (byte)0x7b, (byte)0xe8, (byte)0xfe, (byte)0x99
+ };
+}
Added: turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/SmartDecryptingInputStream.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/SmartDecryptingInputStream.java?rev=678465&view=auto
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/SmartDecryptingInputStream.java (added)
+++ turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/SmartDecryptingInputStream.java Mon Jul 21 09:35:30 2008
@@ -0,0 +1,376 @@
+package org.apache.fulcrum.jce.crypto;
+
+/*
+ * 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.
+ */
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.security.GeneralSecurityException;
+
+
+/**
+ * An input stream that determine if the originating input stream
+ * was encrypted or not. This magic only works for well-known file
+ * types though.
+ *
+ * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
+ */
+public class SmartDecryptingInputStream extends ByteArrayInputStream
+{
+ /** The encodings to be checked for XML */
+ private static final String[] ENCODINGS = { "ISO-8859-1", "UTF-8", "UTF-16" };
+
+ /**
+ * Constructor
+ *
+ * @param cryptoStreamFactory the CryptoStreamFactory for creating a cipher stream
+ * @param is the input stream to be decrypted
+ */
+ public SmartDecryptingInputStream(
+ CryptoStreamFactory cryptoStreamFactory,
+ InputStream is )
+ throws IOException, GeneralSecurityException
+ {
+ this( cryptoStreamFactory, is, null );
+ }
+
+ /**
+ * Constructor
+ *
+ * @param cryptoStreamFactory the CryptoStreamFactory for creating a cipher stream
+ * @param is the input stream to be decrypted
+ * @param password the password for decryption
+ */
+ public SmartDecryptingInputStream(
+ CryptoStreamFactory cryptoStreamFactory,
+ InputStream is,
+ char[] password )
+ throws IOException, GeneralSecurityException
+ {
+ super( new byte[0] );
+
+ byte[] content = null;
+ byte[] plain = null;
+
+ // store the data from the input stream
+
+ ByteArrayOutputStream baosCipher = new ByteArrayOutputStream();
+ ByteArrayOutputStream baosPlain = new ByteArrayOutputStream();
+ this.copy( is, baosCipher );
+
+ content = baosCipher.toByteArray();
+ plain = content;
+
+ if( this.isEncrypted(content) == true )
+ {
+ InputStream cis = null;
+ ByteArrayInputStream bais = new ByteArrayInputStream(content);
+
+ if( ( password != null ) && ( password.length > 0 ) )
+ {
+ cis = cryptoStreamFactory.getInputStream( bais, password );
+ }
+ else
+ {
+ cis = cryptoStreamFactory.getInputStream( bais );
+ }
+
+ copy( cis, baosPlain );
+ plain = baosPlain.toByteArray();
+ }
+
+ // initialize the inherited instance
+
+ if( plain != null )
+ {
+ this.buf = plain;
+ this.pos = 0;
+ this.count = buf.length;
+ }
+ }
+
+ /**
+ * Determine if the content is encrypted. We are
+ * using our knowledge about block lenght, check
+ * for XML, ZIP and PDF files and at the end of
+ * the day we are just guessing.
+ *
+ * @param content the data to be examined
+ * @return true if this is an encrypted file
+ * @exception IOException unable to read the content
+ */
+ private boolean isEncrypted( byte[] content )
+ throws IOException
+ {
+ if( content.length == 0 )
+ {
+ return false;
+ }
+ else if( ( content.length % 8 ) != 0 )
+ {
+ // the block length is 8 bytes - if the length
+ // is not a multipe of 8 then the content was
+ // definitely not encrypted
+ return false;
+ }
+ else if( this.isPDF(content) )
+ {
+ return false;
+ }
+ else if( this.isXML(content) )
+ {
+ return false;
+ }
+ else if( this.isZip(content) )
+ {
+ return false;
+ }
+ else if( this.isUtf16Text(content) )
+ {
+ return false;
+ }
+ else
+ {
+ for( int i=0; i<content.length; i++ )
+ {
+ // do we have control characters in it?
+
+ char ch = (char) content[i];
+
+ if( this.isAsciiControl(ch) )
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+ }
+
+ /**
+ * Pumps the input stream to the output stream.
+ *
+ * @param is the source input stream
+ * @param os the target output stream
+ * @return the number of bytes copied
+ * @throws IOException the copying failed
+ */
+ public long copy( InputStream is, OutputStream os )
+ throws IOException
+ {
+ byte[] buf = new byte[1024];
+ int n = 0;
+ long total = 0;
+
+ while ((n = is.read(buf)) > 0)
+ {
+ os.write(buf, 0, n);
+ total += n;
+ }
+
+ is.close();
+ os.flush();
+ os.close();
+
+ return total;
+ }
+
+ /**
+ * Count the number of occurences for the given value
+ * @param content the content to examine
+ * @param value the value to look fo
+ * @return the number of matches
+ */
+ private int count( byte[] content, byte value )
+ {
+ int result = 0;
+
+ for( int i=0; i<content.length; i++ )
+ {
+ if( content[i] == value )
+ {
+ result++;
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Detect the BOM of an UTF-16 (mandatory) or UTF-8 document (optional)
+ * @param content the content to examine
+ * @return true if the content contains a BOM
+ */
+ private boolean hasByteOrderMark( byte[] content )
+ {
+ if( ( (content[0] == 0xFF) && (content[1] == 0xFF) ) ||
+ ( (content[0] == 0xFF) && (content[1] == 0xFF) ) )
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ /**
+ * Check this is a UTF-16 text document.
+ *
+ * @param content the content to examine
+ * @return true if it is a XML document
+ * @throws IOException unable to read the content
+ */
+ private boolean isUtf16Text( byte[] content ) throws IOException
+ {
+ if( content.length < 2 )
+ {
+ return false;
+ }
+
+ if( this.hasByteOrderMark( content ) )
+ {
+ // we should have plenty of 0x00 in a text file
+
+ int estimate = (content.length-2)/3;
+
+ if( this.count(content,(byte)0) > estimate )
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Check various encondings to determine if "<?xml"
+ * and "?>" appears in the data.
+ *
+ * @param content the content to examine
+ * @return true if it is a XML document
+ * @throws IOException unable to read the content
+ */
+ private boolean isXML( byte[] content ) throws IOException
+ {
+ if( content.length < 3 )
+ {
+ return false;
+ }
+
+ for( int i=0; i<ENCODINGS.length; i++ )
+ {
+ String currEncoding = ENCODINGS[i];
+
+ String temp = new String( content, currEncoding );
+
+ if( ( temp.indexOf("<?xml") >= 0 ) && ( temp.indexOf("?>") > 0 ) )
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Check if this is a ZIP document
+ *
+ * @param content the content to examine
+ * @return true if it is a PDF document
+ */
+
+ private boolean isZip( byte[] content )
+ {
+ if( content.length < 64 )
+ {
+ return false;
+ }
+ else
+ {
+ // A ZIP starts with Hex: "50 4B 03 04"
+
+ if( ( content[0] == (byte) 0x50 ) &&
+ ( content[1] == (byte) 0x4B ) &&
+ ( content[2] == (byte) 0x03 ) &&
+ ( content[3] == (byte) 0x04 ) )
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ }
+
+ /**
+ * Check if this is a PDF document
+ *
+ * @param content the content to examine
+ * @return true if it is a PDF document
+ * @throws IOException unable to read the content
+ */
+ private boolean isPDF(byte[] content) throws IOException
+ {
+ if( content.length < 64 )
+ {
+ return false;
+ }
+ else
+ {
+ // A PDF starts with HEX "25 50 44 46 2D 31 2E"
+
+ if( ( content[0] == (byte) 0x25 ) &&
+ ( content[1] == (byte) 0x50 ) &&
+ ( content[2] == (byte) 0x44 ) &&
+ ( content[3] == (byte) 0x46 ) &&
+ ( content[4] == (byte) 0x2D ) &&
+ ( content[5] == (byte) 0x31 ) &&
+ ( content[6] == (byte) 0x2E ) )
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ }
+
+ /**
+ * Is this an ASCII control character?
+ * @param ch the charcter
+ * @return true is this in an ASCII character
+ */
+ private boolean isAsciiControl(char ch)
+ {
+ if( ( ch >= 0x0000 ) && ( ch <= 0x001F) )
+ {
+ return true;
+ }
+ else
+ {
+ return true;
+ }
+ }
+}
Added: turbine/fulcrum/trunk/yaafi-crypto/src/main/assembly/bin.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/src/main/assembly/bin.xml?rev=678465&view=auto
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/src/main/assembly/bin.xml (added)
+++ turbine/fulcrum/trunk/yaafi-crypto/src/main/assembly/bin.xml Mon Jul 21 09:35:30 2008
@@ -0,0 +1,43 @@
+<!--
+ 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.
+-->
+<assembly>
+ <id>bin</id>
+ <formats>
+ <format>tar.gz</format>
+ <format>zip</format>
+ </formats>
+ <includeSiteDirectory>false</includeSiteDirectory>
+ <fileSets>
+ <fileSet>
+ <includes>
+ <include>LICENSE.txt</include>
+ <include>NOTICE.txt</include>
+ </includes>
+ </fileSet>
+ <fileSet>
+ <directory>target</directory>
+ <outputDirectory></outputDirectory>
+ <includes>
+ <include>*.jar</include>
+ </includes>
+ </fileSet>
+ <fileSet>
+ <directory>target/site/apidocs</directory>
+ <outputDirectory>apidocs</outputDirectory>
+ </fileSet>
+ </fileSets>
+</assembly>
Added: turbine/fulcrum/trunk/yaafi-crypto/src/main/assembly/src.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/src/main/assembly/src.xml?rev=678465&view=auto
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/src/main/assembly/src.xml (added)
+++ turbine/fulcrum/trunk/yaafi-crypto/src/main/assembly/src.xml Mon Jul 21 09:35:30 2008
@@ -0,0 +1,41 @@
+<!--
+ 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.
+-->
+<assembly>
+ <id>src</id>
+ <formats>
+ <format>tar.gz</format>
+ <format>zip</format>
+ </formats>
+ <baseDirectory>${artifactId}-${version}-src</baseDirectory>
+ <fileSets>
+ <fileSet>
+ <includes>
+ <include>build.xml</include>
+ <include>LICENSE.txt</include>
+ <include>NOTICE.txt</include>
+ <include>pom.xml</include>
+ <include>STATUS</include>
+ </includes>
+ </fileSet>
+ <fileSet>
+ <directory>src</directory>
+ </fileSet>
+ <fileSet>
+ <directory>xdocs</directory>
+ </fileSet>
+ </fileSets>
+</assembly>
Added: turbine/fulcrum/trunk/yaafi-crypto/src/site/site.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/src/site/site.xml?rev=678465&view=auto
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/src/site/site.xml (added)
+++ turbine/fulcrum/trunk/yaafi-crypto/src/site/site.xml Mon Jul 21 09:35:30 2008
@@ -0,0 +1,27 @@
+<?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.
+-->
+<project name="Fulcrum YAAFI Crypto Library">
+ <body>
+ <menu name="Overview">
+ <item name="Overview" href="/index.html"/>
+ </menu>
+ ${reports}
+ </body>
+</project>
Added: turbine/fulcrum/trunk/yaafi-crypto/src/test/data/empty.txt
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/src/test/data/empty.txt?rev=678465&view=auto
==============================================================================
(empty)
Added: turbine/fulcrum/trunk/yaafi-crypto/src/test/data/plain-iso-8859-1.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/src/test/data/plain-iso-8859-1.xml?rev=678465&view=auto
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/src/test/data/plain-iso-8859-1.xml (added)
+++ turbine/fulcrum/trunk/yaafi-crypto/src/test/data/plain-iso-8859-1.xml Mon Jul 21 09:35:30 2008
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ 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.
+-->
+
+<role-list>
+ <!-- Use minimal role entry -->
+ <role
+ name="org.apache.fulcrum.yaafi.service.servicemanager.ServiceManagerService"
+ default-class="org.apache.fulcrum.yaafi.service.servicemanager.ServiceManagerServiceImpl"
+ />
+ <!-- For the rest of the services use a full-blown role entry -->
+ <role
+ name="org.apache.fulcrum.yaafi.service.systemproperty.SystemPropertyService"
+ shorthand="SystemPropertyService"
+ default-class="org.apache.fulcrum.yaafi.service.systemproperty.SystemPropertyServiceImpl"
+ early-init="true"
+ description="ÜÖÄüöäß"
+ />
+ <!--
+ This ReconfigurationService is instantiated during the first access. Until
+ then it is doing nothing.
+ -->
+ <role
+ name="org.apache.fulcrum.yaafi.service.reconfiguration.ReconfigurationService"
+ shorthand="ReconfigurationService"
+ default-class="org.apache.fulcrum.yaafi.service.reconfiguration.ReconfigurationServiceImpl"
+ early-init="false"
+ component-type="avalon"
+ component-flavour="yaafi"
+ description="Monitors the componentConfiguration.xml to reconfigure YAAFI"
+ />
+ <role
+ name="org.apache.fulcrum.yaafi.TestComponent"
+ shorthand="test"
+ default-class="org.apache.fulcrum.yaafi.TestComponentImpl"
+ early-init="true"
+ component-type="merlin"
+ description="A simple test component"
+ />
+</role-list>
Added: turbine/fulcrum/trunk/yaafi-crypto/src/test/data/plain-utf16.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/src/test/data/plain-utf16.xml?rev=678465&view=auto
==============================================================================
Binary file - no diff available.
Propchange: turbine/fulcrum/trunk/yaafi-crypto/src/test/data/plain-utf16.xml
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: turbine/fulcrum/trunk/yaafi-crypto/src/test/data/plain-utf8.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/src/test/data/plain-utf8.xml?rev=678465&view=auto
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/src/test/data/plain-utf8.xml (added)
+++ turbine/fulcrum/trunk/yaafi-crypto/src/test/data/plain-utf8.xml Mon Jul 21 09:35:30 2008
@@ -0,0 +1,56 @@
+<?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.
+-->
+
+<role-list>
+ <!-- Use minimal role entry -->
+ <role
+ name="org.apache.fulcrum.yaafi.service.servicemanager.ServiceManagerService"
+ default-class="org.apache.fulcrum.yaafi.service.servicemanager.ServiceManagerServiceImpl"
+ />
+ <!-- For the rest of the services use a full-blown role entry -->
+ <role
+ name="org.apache.fulcrum.yaafi.service.systemproperty.SystemPropertyService"
+ shorthand="SystemPropertyService"
+ default-class="org.apache.fulcrum.yaafi.service.systemproperty.SystemPropertyServiceImpl"
+ early-init="true"
+ description="ÃÃÃüöäÃ"
+ />
+ <!--
+ This ReconfigurationService is instantiated during the first access. Until
+ then it is doing nothing.
+ -->
+ <role
+ name="org.apache.fulcrum.yaafi.service.reconfiguration.ReconfigurationService"
+ shorthand="ReconfigurationService"
+ default-class="org.apache.fulcrum.yaafi.service.reconfiguration.ReconfigurationServiceImpl"
+ early-init="false"
+ component-type="avalon"
+ component-flavour="yaafi"
+ description="Monitors the componentConfiguration.xml to reconfigure YAAFI"
+ />
+ <role
+ name="org.apache.fulcrum.yaafi.TestComponent"
+ shorthand="test"
+ default-class="org.apache.fulcrum.yaafi.TestComponentImpl"
+ early-init="true"
+ component-type="merlin"
+ description="A simple test component"
+ />
+</role-list>