Return-Path: X-Original-To: apmail-oltu-commits-archive@www.apache.org Delivered-To: apmail-oltu-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7335E10914 for ; Thu, 26 Sep 2013 08:35:28 +0000 (UTC) Received: (qmail 17307 invoked by uid 500); 26 Sep 2013 08:34:33 -0000 Delivered-To: apmail-oltu-commits-archive@oltu.apache.org Received: (qmail 16049 invoked by uid 500); 26 Sep 2013 08:34:29 -0000 Mailing-List: contact commits-help@oltu.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@oltu.apache.org Delivered-To: mailing list commits@oltu.apache.org Received: (qmail 15974 invoked by uid 99); 26 Sep 2013 08:34:25 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 Sep 2013 08:34:25 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 Sep 2013 08:34:24 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 50E9D23889D5; Thu, 26 Sep 2013 08:34:04 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@oltu.apache.org From: simonetripodi@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130926083404.50E9D23889D5@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 boolean validate(SignatureMethod method, - VK verifyingKey) { + public boolean acceptAlgorithm(SignatureMethod 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 boolean validate(SignatureMethod 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); }