incubator-amber-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1243343 - in /incubator/amber/trunk/signature-api: ./ src/main/java/org/apache/amber/signature/ src/main/java/org/apache/amber/signature/rsa/ src/main/javacc/ src/test/java/org/apache/amber/signature/rsa/
Date Sun, 12 Feb 2012 22:21:12 GMT
Author: simonetripodi
Date: Sun Feb 12 22:21:11 2012
New Revision: 1243343

URL: http://svn.apache.org/viewvc?rev=1243343&view=rev
Log:
plugged not-yet-commons-ssl to resolve Rsa signature issue
looks like pem resources in test are not valid PKCS8 nor OpenSSL keys

Added:
    incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1SigningKey.java
      - copied, changed from r1233290, incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/PemRsaSha1SigningKey.java
    incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1VerifyingKey.java
      - copied, changed from r1233290, incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/PemRsaSha1VerifyingKey.java
Removed:
    incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/PemRsaSha1SigningKey.java
    incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/PemRsaSha1VerifyingKey.java
    incubator/amber/trunk/signature-api/src/main/javacc/
Modified:
    incubator/amber/trunk/signature-api/pom.xml
    incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/AbstractMethod.java
    incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/AbstractRsaSha1Key.java
    incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1Method.java
    incubator/amber/trunk/signature-api/src/test/java/org/apache/amber/signature/rsa/RsaSha1MethodTestCase.java

Modified: incubator/amber/trunk/signature-api/pom.xml
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/signature-api/pom.xml?rev=1243343&r1=1243342&r2=1243343&view=diff
==============================================================================
--- incubator/amber/trunk/signature-api/pom.xml (original)
+++ incubator/amber/trunk/signature-api/pom.xml Sun Feb 12 22:21:11 2012
@@ -39,10 +39,16 @@
         </dependency>
 
         <dependency>
-            <groupId>commons-codec</groupId>
-            <artifactId>commons-codec</artifactId>
-            <version>1.4</version>
-            <scope>compile</scope>
+          <groupId>ca.juliusdavies</groupId>
+          <artifactId>not-yet-commons-ssl</artifactId>
+          <version>0.3.11</version>
+        </dependency>
+
+        <dependency>
+          <groupId>commons-codec</groupId>
+          <artifactId>commons-codec</artifactId>
+          <version>1.4</version>
+          <scope>compile</scope>
         </dependency>
 
         <dependency>
@@ -71,26 +77,4 @@
         </plugins>
     </reporting>
 
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>javacc-maven-plugin</artifactId>
-                <version>2.5</version>
-                <executions>
-                    <execution>
-                        <id>javacc</id>
-                        <goals>
-                            <goal>javacc</goal>
-                        </goals>
-                        <configuration>
-                            <lookAhead>2</lookAhead>
-                            <isStatic>false</isStatic>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
-        </plugins>
-    </build>
-
 </project>

Modified: incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/AbstractMethod.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/AbstractMethod.java?rev=1243343&r1=1243342&r2=1243343&view=diff
==============================================================================
--- incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/AbstractMethod.java
(original)
+++ incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/AbstractMethod.java
Sun Feb 12 22:21:11 2012
@@ -186,7 +186,7 @@ public abstract class AbstractMethod imp
     protected abstract boolean verify(String signature, VerifyingKey verifyingKey, String
tokenSecret, String baseString) throws SignatureException;
 
     /**
-     * 
+     *
      *
      * @param key
      * @throws SignatureException

Modified: incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/AbstractRsaSha1Key.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/AbstractRsaSha1Key.java?rev=1243343&r1=1243342&r2=1243343&view=diff
==============================================================================
--- incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/AbstractRsaSha1Key.java
(original)
+++ incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/AbstractRsaSha1Key.java
Sun Feb 12 22:21:11 2012
@@ -24,26 +24,29 @@ import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
 
+import org.apache.amber.signature.Key;
 import org.apache.amber.signature.SignatureException;
+import org.apache.commons.ssl.PKCS8Key;
 
 /**
  * Abstract implementation of RSA-SHA1 key.
  *
  * @version $Id$
  */
-abstract class AbstractRsaSha1Key<T extends java.security.Key> implements org.apache.amber.signature.Key
{
+abstract class AbstractRsaSha1Key implements Key {
 
     private static final String[] METHODS = { "RSA-SHA1" };
 
-    private final T rsaKey;
+    private final PKCS8Key rsaKey;
 
     /**
      * Loads a key from a certificate located in the classpath.
      *
      * @param certificateClasspathLocation
+     * @param the certificate password
      * @throws SignatureException
      */
-    public AbstractRsaSha1Key(String certificateClasspathLocation) throws SignatureException
{
+    public AbstractRsaSha1Key(String certificateClasspathLocation, String password) throws
SignatureException {
         if (certificateClasspathLocation == null) {
             throw new SignatureException("parameter 'certificateClasspathLocation' must not
be null");
         }
@@ -62,16 +65,17 @@ abstract class AbstractRsaSha1Key<T exte
                     + "' not found, please make sure it exists in the classpath");
         }
 
-        this.rsaKey = this.readCertificate(certificateURL);
+        this.rsaKey = this.readCertificate(certificateURL, password);
     }
 
     /**
      * Loads a key from a certificate located in a file.
      *
      * @param certificateFileLocation
+     * @param the certificate password
      * @throws SignatureException
      */
-    public AbstractRsaSha1Key(File certificateFileLocation) throws SignatureException {
+    public AbstractRsaSha1Key(File certificateFileLocation, String password) throws SignatureException
{
         if (certificateFileLocation == null) {
             throw new SignatureException("parameter 'certificateFileLocation' must not be
null");
         }
@@ -82,7 +86,7 @@ abstract class AbstractRsaSha1Key<T exte
         }
 
         try {
-            this.rsaKey = this.readCertificate(certificateFileLocation.toURI().toURL());
+            this.rsaKey = this.readCertificate(certificateFileLocation.toURI().toURL(), password);
         } catch (MalformedURLException e) {
             throw new SignatureException("Impossible to read the certificate from '"
                     + certificateFileLocation
@@ -94,25 +98,32 @@ abstract class AbstractRsaSha1Key<T exte
      * Loads a key from a certificate located in an URL.
      *
      * @param certificateURL
+     * @param the certificate password
      * @throws SignatureException
      */
-    public AbstractRsaSha1Key(URL certificateURL) throws SignatureException {
+    public AbstractRsaSha1Key(URL certificateURL, String password) throws SignatureException
{
         if (certificateURL == null) {
             throw new SignatureException("parameter 'certificateURL' must not be null");
         }
 
-        this.rsaKey = this.readCertificate(certificateURL);
+        this.rsaKey = this.readCertificate(certificateURL, password);
     }
 
-    private T readCertificate(URL certificateURL) throws SignatureException {
+    private PKCS8Key readCertificate(URL certificateURL, String password) throws SignatureException
{
         URLConnection urlConnection = null;
         InputStream input = null;
 
+        if (password == null) {
+            password = "";
+        }
+
+        final char[] pwd = password.toCharArray();
+
         try {
             urlConnection = certificateURL.openConnection();
             input = urlConnection.getInputStream();
 
-            return this.readCertificate(input);
+            return new PKCS8Key(input, pwd);
         } catch (Exception e) {
             throw new SignatureException("Impossible to read the certificate from '"
                     + certificateURL
@@ -132,8 +143,8 @@ abstract class AbstractRsaSha1Key<T exte
         }
     }
 
-    public final T getRsaKey() {
-        return this.rsaKey;
+    protected PKCS8Key getRsaKey() {
+        return rsaKey;
     }
 
     @Override
@@ -141,8 +152,6 @@ abstract class AbstractRsaSha1Key<T exte
         return String.valueOf(this.rsaKey);
     }
 
-    protected abstract T readCertificate(InputStream input) throws Exception;
-
     /**
      * {@inheritDoc}
      */

Modified: incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1Method.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1Method.java?rev=1243343&r1=1243342&r2=1243343&view=diff
==============================================================================
--- incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1Method.java
(original)
+++ incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1Method.java
Sun Feb 12 22:21:11 2012
@@ -17,8 +17,6 @@
 package org.apache.amber.signature.rsa;
 
 import java.security.Signature;
-import java.security.interfaces.RSAPrivateKey;
-import java.security.interfaces.RSAPublicKey;
 
 import org.apache.amber.signature.AbstractMethod;
 import org.apache.amber.signature.SignatureException;
@@ -54,13 +52,12 @@ public final class RsaSha1Method extends
      * {@inheritDoc}
      */
     @Override
-    @SuppressWarnings("unchecked")
     protected String calculate(SigningKey signingKey,
             String tokenSecret,
             String baseString) throws SignatureException {
         try {
             Signature signer = Signature.getInstance(RSA_SHA1_ALGORITHM);
-            signer.initSign(((AbstractRsaSha1Key<RSAPrivateKey>) signingKey).getRsaKey());
+            signer.initSign(((RsaSha1SigningKey) signingKey).getPrivateKey());
             signer.update(toUTF8Bytes(baseString));
             byte[] signature = signer.sign();
 
@@ -75,14 +72,13 @@ public final class RsaSha1Method extends
      * {@inheritDoc}
      */
     @Override
-    @SuppressWarnings("unchecked")
     protected boolean verify(String signature,
             VerifyingKey verifyingKey,
             String tokenSecret,
             String baseString) throws SignatureException {
         try {
             Signature verifier = Signature.getInstance(RSA_SHA1_ALGORITHM);
-            verifier.initVerify(((AbstractRsaSha1Key<RSAPublicKey>) verifyingKey).getRsaKey());
+            verifier.initVerify(((RsaSha1VerifyingKey) verifyingKey).getPublicKey());
             verifier.update(toUTF8Bytes(baseString));
 
             return verifier.verify(decodeBase64(signature));

Copied: incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1SigningKey.java
(from r1233290, incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/PemRsaSha1SigningKey.java)
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1SigningKey.java?p2=incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1SigningKey.java&p1=incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/PemRsaSha1SigningKey.java&r1=1233290&r2=1243343&rev=1243343&view=diff
==============================================================================
--- incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/PemRsaSha1SigningKey.java
(original)
+++ incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1SigningKey.java
Sun Feb 12 22:21:11 2012
@@ -17,43 +17,37 @@
 package org.apache.amber.signature.rsa;
 
 import java.io.File;
-import java.io.InputStream;
 import java.net.URL;
-import java.security.interfaces.RSAPrivateKey;
+import java.security.PrivateKey;
 
 import org.apache.amber.signature.SignatureException;
 import org.apache.amber.signature.SigningKey;
 
 /**
- * 
+ *
  *
  * @version $Id$
  */
-public final class PemRsaSha1SigningKey
-        extends AbstractRsaSha1Key<RSAPrivateKey>
+public final class RsaSha1SigningKey
+        extends AbstractRsaSha1Key
         implements SigningKey {
 
-    public PemRsaSha1SigningKey(File certificateFileLocation)
+    public RsaSha1SigningKey(File certificateFileLocation, String password)
             throws SignatureException {
-        super(certificateFileLocation);
+        super(certificateFileLocation, password);
     }
 
-    public PemRsaSha1SigningKey(String certificateClasspathLocation)
+    public RsaSha1SigningKey(String certificateClasspathLocation, String password)
             throws SignatureException {
-        super(certificateClasspathLocation);
+        super(certificateClasspathLocation, password);
     }
 
-    public PemRsaSha1SigningKey(URL certificateURL) throws SignatureException {
-        super(certificateURL);
+    public RsaSha1SigningKey(URL certificateURL, String password) throws SignatureException
{
+        super(certificateURL, password);
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    protected RSAPrivateKey readCertificate(InputStream input) throws Exception {
-        PemCertificateParser pemCertificateParser = new PemCertificateParser(input);
-        return pemCertificateParser.parsePrivateKey();
+    public PrivateKey getPrivateKey() {
+        return getRsaKey().getPrivateKey();
     }
 
 }

Copied: incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1VerifyingKey.java
(from r1233290, incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/PemRsaSha1VerifyingKey.java)
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1VerifyingKey.java?p2=incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1VerifyingKey.java&p1=incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/PemRsaSha1VerifyingKey.java&r1=1233290&r2=1243343&rev=1243343&view=diff
==============================================================================
--- incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/PemRsaSha1VerifyingKey.java
(original)
+++ incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1VerifyingKey.java
Sun Feb 12 22:21:11 2012
@@ -17,43 +17,38 @@
 package org.apache.amber.signature.rsa;
 
 import java.io.File;
-import java.io.InputStream;
 import java.net.URL;
-import java.security.interfaces.RSAPublicKey;
+import java.security.GeneralSecurityException;
+import java.security.PublicKey;
 
 import org.apache.amber.signature.SignatureException;
 import org.apache.amber.signature.VerifyingKey;
 
 /**
- * 
+ *
  *
  * @version $Id$
  */
-public final class PemRsaSha1VerifyingKey
-        extends AbstractRsaSha1Key<RSAPublicKey>
+public final class RsaSha1VerifyingKey
+        extends AbstractRsaSha1Key
         implements VerifyingKey {
 
-    public PemRsaSha1VerifyingKey(File certificateFileLocation)
+    public RsaSha1VerifyingKey(File certificateFileLocation, String password)
             throws SignatureException {
-        super(certificateFileLocation);
+        super(certificateFileLocation, password);
     }
 
-    public PemRsaSha1VerifyingKey(String certificateClasspathLocation)
+    public RsaSha1VerifyingKey(String certificateClasspathLocation, String password)
             throws SignatureException {
-        super(certificateClasspathLocation);
+        super(certificateClasspathLocation, password);
     }
 
-    public PemRsaSha1VerifyingKey(URL certificateURL) throws SignatureException {
-        super(certificateURL);
+    public RsaSha1VerifyingKey(URL certificateURL, String password) throws SignatureException
{
+        super(certificateURL, password);
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    protected RSAPublicKey readCertificate(InputStream input) throws Exception {
-        PemCertificateParser pemCertificateParser = new PemCertificateParser(input);
-        return pemCertificateParser.parsePublicCertificate();
+    public PublicKey getPublicKey() throws GeneralSecurityException {
+        return getRsaKey().getPublicKey();
     }
 
 }

Modified: incubator/amber/trunk/signature-api/src/test/java/org/apache/amber/signature/rsa/RsaSha1MethodTestCase.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/signature-api/src/test/java/org/apache/amber/signature/rsa/RsaSha1MethodTestCase.java?rev=1243343&r1=1243342&r2=1243343&view=diff
==============================================================================
--- incubator/amber/trunk/signature-api/src/test/java/org/apache/amber/signature/rsa/RsaSha1MethodTestCase.java
(original)
+++ incubator/amber/trunk/signature-api/src/test/java/org/apache/amber/signature/rsa/RsaSha1MethodTestCase.java
Sun Feb 12 22:21:11 2012
@@ -17,24 +17,20 @@
 package org.apache.amber.signature.rsa;
 
 import org.apache.amber.signature.AbstractMethodTestCase;
+import org.junit.Ignore;
 import org.junit.Test;
 
 /**
- * 
+ *
  *
  * @version $Id$
  */
 public final class RsaSha1MethodTestCase extends AbstractMethodTestCase {
 
-    // TODO delete me once next test will be re-enabled
     @Test
-    public void doNothing() {
-        // do nothing
-    }
-
-    // TODO test disabled, expected signature has to be calculated
+    @Ignore
     public void verifyRsaSha1MethodAlgorithm() throws Exception {
-        this.verifySignature(new PemRsaSha1VerifyingKey("kd94hf93k423kf44"),
+        this.verifySignature(new RsaSha1VerifyingKey("org/apache/amber/signature/rsa/public.pem",
""),
                 new RsaSha1Method(),
                 "kd94hf93k423kf44&pfkkdhi9sl3r4s00");
     }



Mime
View raw message