Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-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 4692B11147 for ; Mon, 22 Sep 2014 09:00:29 +0000 (UTC) Received: (qmail 70243 invoked by uid 500); 22 Sep 2014 09:00:29 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 70187 invoked by uid 500); 22 Sep 2014 09:00:29 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 70178 invoked by uid 99); 22 Sep 2014 09:00:29 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 22 Sep 2014 09:00:29 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id BE130948561; Mon, 22 Sep 2014 09:00:28 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sergeyb@apache.org To: commits@cxf.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: git commit: [CXF-5944] Adding few more JWK utility methods Date: Mon, 22 Sep 2014 09:00:28 +0000 (UTC) Repository: cxf Updated Branches: refs/heads/master 9fe4c04a1 -> 669bd557f [CXF-5944] Adding few more JWK utility methods Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/669bd557 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/669bd557 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/669bd557 Branch: refs/heads/master Commit: 669bd557f38288fac54204478d8dc31cf82e8e94 Parents: 9fe4c04 Author: Sergey Beryozkin Authored: Mon Sep 22 10:00:12 2014 +0100 Committer: Sergey Beryozkin Committed: Mon Sep 22 10:00:12 2014 +0100 ---------------------------------------------------------------------- .../cxf/rs/security/jose/jwk/JwkUtils.java | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/669bd557/rt/rs/security/oauth-parent/oauth2-jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JwkUtils.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/oauth-parent/oauth2-jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JwkUtils.java b/rt/rs/security/oauth-parent/oauth2-jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JwkUtils.java index 3e61fd4..bf255b9 100644 --- a/rt/rs/security/oauth-parent/oauth2-jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JwkUtils.java +++ b/rt/rs/security/oauth-parent/oauth2-jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JwkUtils.java @@ -18,6 +18,7 @@ */ package org.apache.cxf.rs.security.jose.jwk; +import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.security.interfaces.ECPrivateKey; @@ -53,6 +54,12 @@ public final class JwkUtils { private JwkUtils() { } + public static JsonWebKey readJwkKey(InputStream is) throws IOException { + return new DefaultJwkReaderWriter().jsonToJwk(IOUtils.readStringFromStream(is)); + } + public static JsonWebKeys readJwkSet(InputStream is) throws IOException { + return new DefaultJwkReaderWriter().jsonToJwkSet(IOUtils.readStringFromStream(is)); + } public static JsonWebKey readJwkKey(String jwkJson) { return new DefaultJwkReaderWriter().jsonToJwk(jwkJson); } @@ -83,6 +90,17 @@ public final class JwkUtils { public static JsonWebKeys decryptJwkSet(String jsonJwkSet, JweDecryptionProvider jwe, JwkReaderWriter reader) { return reader.jsonToJwkSet(jwe.decrypt(jsonJwkSet).getContentText()); } + public static JsonWebKeys decryptJwkSet(InputStream is, char[] password) throws IOException { + return decryptJwkSet(is, password, new DefaultJwkReaderWriter()); + } + public static JsonWebKeys decryptJwkSet(InputStream is, char[] password, JwkReaderWriter reader) + throws IOException { + return decryptJwkSet(is, createDefaultDecryption(password), reader); + } + public static JsonWebKeys decryptJwkSet(InputStream is, JweDecryptionProvider jwe, JwkReaderWriter reader) + throws IOException { + return reader.jsonToJwkSet(jwe.decrypt(IOUtils.readStringFromStream(is)).getContentText()); + } public static String encryptJwkKey(JsonWebKey jwk, char[] password) { return encryptJwkKey(jwk, password, new DefaultJwkReaderWriter()); } @@ -101,6 +119,17 @@ public final class JwkUtils { public static JsonWebKey decryptJwkKey(String jsonJwkKey, JweDecryptionProvider jwe, JwkReaderWriter reader) { return reader.jsonToJwk(jwe.decrypt(jsonJwkKey).getContentText()); } + public static JsonWebKey decryptJwkKey(InputStream is, char[] password) throws IOException { + return decryptJwkKey(is, password, new DefaultJwkReaderWriter()); + } + public static JsonWebKey decryptJwkKey(InputStream is, char[] password, JwkReaderWriter reader) + throws IOException { + return decryptJwkKey(is, createDefaultDecryption(password), reader); + } + public static JsonWebKey decryptJwkKey(InputStream is, JweDecryptionProvider jwe, JwkReaderWriter reader) + throws IOException { + return reader.jsonToJwk(jwe.decrypt(IOUtils.readStringFromStream(is)).getContentText()); + } private static JweEncryptionProvider createDefaultEncryption(char[] password) { KeyEncryptionAlgorithm keyEncryption = new PbesHmacAesWrapKeyEncryptionAlgorithm(password, Algorithm.PBES2_HS256_A128KW.getJwtName());