oltu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r963008 - /incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/AbstractMethod.java
Date Sun, 11 Jul 2010 08:04:01 GMT
Author: simonetripodi
Date: Sun Jul 11 08:04:01 2010
New Revision: 963008

URL: http://svn.apache.org/viewvc?rev=963008&view=rev
Log:
added method to block sign/verify operations with unsupported keys

Modified:
    incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/AbstractMethod.java

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=963008&r1=963007&r2=963008&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 Jul 11 08:04:01 2010
@@ -19,6 +19,7 @@ package org.apache.amber.signature;
 import java.net.URL;
 import java.nio.charset.Charset;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.BitSet;
 import java.util.Collections;
 import java.util.List;
@@ -131,6 +132,7 @@ public abstract class AbstractMethod imp
         if (request == null) {
             throw new IllegalArgumentException("parameter 'request' must not be null");
         }
+        this.checkKey(signingKey);
 
         String baseString = this.createBaseString(request);
         String tokenSecret = extractTokenSecret(token);
@@ -164,6 +166,7 @@ public abstract class AbstractMethod imp
         if (request == null) {
             throw new IllegalArgumentException("parameter 'request' must not be null");
         }
+        this.checkKey(verifyingKey);
 
         String baseString = this.createBaseString(request);
         String tokenSecret = extractTokenSecret(token);
@@ -183,6 +186,27 @@ public abstract class AbstractMethod imp
     protected abstract boolean verify(String signature, VerifyingKey verifyingKey, String
tokenSecret, String baseString) throws SignatureException;
 
     /**
+     * 
+     *
+     * @param key
+     * @throws SignatureException
+     */
+    private void checkKey(Key key) throws SignatureException {
+        for (String method : key.getAlgorithmMethods()) {
+            if (this.getAlgorithm().equals(method)) {
+                return;
+            }
+        }
+        throw new SignatureException("Required '"
+                + this.getAlgorithm()
+                + "', key of type '"
+                + key.getClass().getName()
+                + "' only supports "
+                + Arrays.toString(key.getAlgorithmMethods())
+                + " methods");
+    }
+
+    /**
      * Calculates the OAuth base string.
      *
      * @param request



Mime
View raw message