oltu-commits mailing list archives

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

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

added a shortcut method to verify current JWS

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=1524737&r1=1524736&r2=1524737&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 19 13:26:33
2013
@@ -58,6 +58,30 @@ public class JWS {
         return signature;
     }
 
+    public <SK extends SigningKey, VK extends VerifyingKey> boolean validate(SignatureMethod<SK,
VK> method,
+                                                                             VK verifyingKey)
{
+        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 (!header.getAlgorithm().equalsIgnoreCase(method.getAlgorithm())) {
+            throw new IllegalArgumentException("Impossible to verify current JWS signature
with algorithm '"
+                                               + method.getAlgorithm()
+                                               + "', JWS header specifies message has been
signed with '"
+                                               + header.getAlgorithm()
+                                               + "' algorithm.");
+        }
+
+        return method.verify(signature, payload, verifyingKey);
+    }
+
     public static final class Builder {
 
         /**



Mime
View raw message