oltu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1526416 - /oltu/trunk/jose/jws/src/main/java/org/apache/oltu/jose/jws/JWS.java
Date Thu, 26 Sep 2013 08:34:04 GMT
Author: simonetripodi
Date: Thu Sep 26 08:34:03 2013
New Revision: 1526416

URL: http://svn.apache.org/r1526416
Log:
OLTU-118 - Implement JWS of the JOSE working group

added a public method in JWT entity to check if the current JWT accepts an signature method
for the verification

Modified:
    oltu/trunk/jose/jws/src/main/java/org/apache/oltu/jose/jws/JWS.java

Modified: oltu/trunk/jose/jws/src/main/java/org/apache/oltu/jose/jws/JWS.java
URL: http://svn.apache.org/viewvc/oltu/trunk/jose/jws/src/main/java/org/apache/oltu/jose/jws/JWS.java?rev=1526416&r1=1526415&r2=1526416&view=diff
==============================================================================
--- oltu/trunk/jose/jws/src/main/java/org/apache/oltu/jose/jws/JWS.java (original)
+++ oltu/trunk/jose/jws/src/main/java/org/apache/oltu/jose/jws/JWS.java Thu Sep 26 08:34:03
2013
@@ -58,26 +58,20 @@ public class JWS {
         return signature;
     }
 
-    public <SK extends SigningKey, VK extends VerifyingKey> boolean validate(SignatureMethod<SK,
VK> method,
-                                                                             VK verifyingKey)
{
+    public <SK extends SigningKey, VK extends VerifyingKey> boolean acceptAlgorithm(SignatureMethod<SK,
VK> method) {
         if (method == null) {
             throw new IllegalArgumentException("A signature method is required in order to
verify the signature.");
         }
-        if (verifyingKey == null) {
-            throw new IllegalArgumentException("A verifying key is required in order to verify
the signature.");
-        }
-
         if (header == null || header.getAlgorithm() == null) {
             throw new IllegalStateException("JWS token must have a valid JSON header with
specified algorithm.");
         }
-        if (payload == null) {
-            throw new IllegalStateException("JWS token must have a payload.");
-        }
-        if (signature == null) {
-            throw new IllegalStateException("JWS token must have a signature to be verified.");
-        }
 
-        if (!header.getAlgorithm().equalsIgnoreCase(method.getAlgorithm())) {
+        return header.getAlgorithm().equalsIgnoreCase(method.getAlgorithm());
+    }
+
+    public <SK extends SigningKey, VK extends VerifyingKey> boolean validate(SignatureMethod<SK,
VK> method,
+                                                                             VK verifyingKey)
{
+        if (!acceptAlgorithm(method)) {
             throw new IllegalArgumentException("Impossible to verify current JWS signature
with algorithm '"
                                                + method.getAlgorithm()
                                                + "', JWS header specifies message has been
signed with '"
@@ -85,6 +79,17 @@ public class JWS {
                                                + "' algorithm.");
         }
 
+        if (verifyingKey == null) {
+            throw new IllegalArgumentException("A verifying key is required in order to verify
the signature.");
+        }
+
+        if (payload == null) {
+            throw new IllegalStateException("JWS token must have a payload.");
+        }
+        if (signature == null) {
+            throw new IllegalStateException("JWS token must have a signature to be verified.");
+        }
+
         return method.verify(signature, payload, verifyingKey);
     }
 



Mime
View raw message