http://git-wip-us.apache.org/repos/asf/cxf/blob/66a81773/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AesCbcHmacJweEncryption.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AesCbcHmacJweEncryption.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AesCbcHmacJweEncryption.java deleted file mode 100644 index 8f1e4bc..0000000 --- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AesCbcHmacJweEncryption.java +++ /dev/null @@ -1,175 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.rs.security.jose.jwe; - -import java.nio.ByteBuffer; -import java.security.spec.AlgorithmParameterSpec; -import java.util.HashMap; -import java.util.Map; - -import javax.crypto.Mac; -import javax.crypto.spec.IvParameterSpec; - -import org.apache.cxf.rs.security.jose.jwa.AlgorithmUtils; -import org.apache.cxf.rs.security.jose.jwa.ContentAlgorithm; -import org.apache.cxf.rt.security.crypto.HmacUtils; - -public class AesCbcHmacJweEncryption extends JweEncryption { - private static final Map<String, String> AES_HMAC_MAP; - private static final Map<String, Integer> AES_CEK_SIZE_MAP; - static { - AES_HMAC_MAP = new HashMap<String, String>(); - AES_HMAC_MAP.put(ContentAlgorithm.A128CBC_HS256.getJwaName(), AlgorithmUtils.HMAC_SHA_256_JAVA); - AES_HMAC_MAP.put(ContentAlgorithm.A192CBC_HS384.getJwaName(), AlgorithmUtils.HMAC_SHA_384_JAVA); - AES_HMAC_MAP.put(ContentAlgorithm.A256CBC_HS512.getJwaName(), AlgorithmUtils.HMAC_SHA_512_JAVA); - - AES_CEK_SIZE_MAP = new HashMap<String, Integer>(); - AES_CEK_SIZE_MAP.put(ContentAlgorithm.A128CBC_HS256.getJwaName(), 32); - AES_CEK_SIZE_MAP.put(ContentAlgorithm.A192CBC_HS384.getJwaName(), 48); - AES_CEK_SIZE_MAP.put(ContentAlgorithm.A256CBC_HS512.getJwaName(), 64); - } - public AesCbcHmacJweEncryption(String cekAlgo, - KeyEncryptionProvider keyEncryptionAlgorithm) { - this(ContentAlgorithm.getAlgorithm(cekAlgo), keyEncryptionAlgorithm); - } - public AesCbcHmacJweEncryption(ContentAlgorithm cekAlgoJwt, - KeyEncryptionProvider keyEncryptionAlgorithm) { - this(cekAlgoJwt, null, null, keyEncryptionAlgorithm); - } - public AesCbcHmacJweEncryption(ContentAlgorithm cekAlgoJwt, byte[] cek, - byte[] iv, KeyEncryptionProvider keyEncryptionAlgorithm) { - super(keyEncryptionAlgorithm, - new AesCbcContentEncryptionAlgorithm(cek, iv, - validateCekAlgorithm(cekAlgoJwt))); - - } - @Override - protected byte[] getActualCek(byte[] theCek, String algoJwt) { - return doGetActualCek(theCek, algoJwt); - } - @Override - protected int getCekSize(String algoJwt) { - return getFullCekKeySize(algoJwt) * 8; - } - protected static byte[] doGetActualCek(byte[] theCek, String algoJwt) { - int size = getFullCekKeySize(algoJwt) / 2; - byte[] actualCek = new byte[size]; - System.arraycopy(theCek, size, actualCek, 0, size); - return actualCek; - } - - protected static int getFullCekKeySize(String algoJwt) { - return AES_CEK_SIZE_MAP.get(algoJwt); - } - protected byte[] getActualCipher(byte[] cipher) { - return cipher; - } - protected byte[] getAuthenticationTag(JweEncryptionInternal state, byte[] cipher) { - final MacState macState = getInitializedMacState(state); - macState.mac.update(cipher); - return signAndGetTag(macState); - } - - protected static byte[] signAndGetTag(MacState macState) { - macState.mac.update(macState.al); - byte[] sig = macState.mac.doFinal(); - - int authTagLen = DEFAULT_AUTH_TAG_LENGTH / 8; - byte[] authTag = new byte[authTagLen]; - System.arraycopy(sig, 0, authTag, 0, authTagLen); - return authTag; - } - private MacState getInitializedMacState(final JweEncryptionInternal state) { - return getInitializedMacState(state.secretKey, state.theIv, state.aad, - state.theHeaders, state.protectedHeadersJson); - } - protected static MacState getInitializedMacState(byte[] secretKey, - byte[] theIv, - byte[] extraAad, - JweHeaders theHeaders, - String protectedHeadersJson) { - String algoJwt = theHeaders.getContentEncryptionAlgorithm().getJwaName(); - int size = getFullCekKeySize(algoJwt) / 2; - byte[] macKey = new byte[size]; - System.arraycopy(secretKey, 0, macKey, 0, size); - - String hmacAlgoJava = AES_HMAC_MAP.get(algoJwt); - Mac mac = HmacUtils.getInitializedMac(macKey, hmacAlgoJava, null); - - byte[] aad = JweUtils.getAdditionalAuthenticationData(protectedHeadersJson, extraAad); - ByteBuffer buf = ByteBuffer.allocate(8); - final byte[] al = buf.putInt(0).putInt(aad.length * 8).array(); - - mac.update(aad); - mac.update(theIv); - MacState macState = new MacState(); - macState.mac = mac; - macState.al = al; - return macState; - } - - protected AuthenticationTagProducer getAuthenticationTagProducer(final JweEncryptionInternal state) { - final MacState macState = getInitializedMacState(state); - - - return new AuthenticationTagProducer() { - - @Override - public void update(byte[] cipher, int off, int len) { - macState.mac.update(cipher, off, len); - } - - @Override - public byte[] getTag() { - return signAndGetTag(macState); - } - }; - } - @Override - protected byte[] getEncryptedContentEncryptionKey(JweHeaders headers, byte[] theCek) { - return getKeyEncryptionAlgo().getEncryptedContentEncryptionKey(headers, theCek); - } - - private static class AesCbcContentEncryptionAlgorithm extends AbstractContentEncryptionAlgorithm { - AesCbcContentEncryptionAlgorithm(byte[] cek, byte[] iv, ContentAlgorithm algo) { - super(cek, iv, algo); - } - @Override - public AlgorithmParameterSpec getAlgorithmParameterSpec(byte[] theIv) { - return new IvParameterSpec(theIv); - } - @Override - public byte[] getAdditionalAuthenticationData(String headersJson, byte[] aad) { - return null; - } - } - - protected static class MacState { - protected Mac mac; - private byte[] al; - } - - private static ContentAlgorithm validateCekAlgorithm(ContentAlgorithm cekAlgo) { - if (!AlgorithmUtils.isAesCbcHmac(cekAlgo.getJwaName())) { - LOG.warning("Invalid content encryption algorithm"); - throw new JweException(JweException.Error.INVALID_CONTENT_ALGORITHM); - } - return cekAlgo; - } -}
http://git-wip-us.apache.org/repos/asf/cxf/blob/66a81773/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AesGcmContentDecryptionAlgorithm.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AesGcmContentDecryptionAlgorithm.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AesGcmContentDecryptionAlgorithm.java deleted file mode 100644 index 64206b7..0000000 --- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AesGcmContentDecryptionAlgorithm.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.rs.security.jose.jwe; - -import org.apache.cxf.rs.security.jose.jwa.AlgorithmUtils; -import org.apache.cxf.rs.security.jose.jwa.ContentAlgorithm; - - - -public class AesGcmContentDecryptionAlgorithm extends AbstractContentEncryptionCipherProperties - implements ContentDecryptionProvider { - public AesGcmContentDecryptionAlgorithm(ContentAlgorithm supportedAlgo) { - super(supportedAlgo); - } - - @Override - public byte[] getEncryptedSequence(JweHeaders headers, byte[] cipher, byte[] authTag) { - String algo = headers.getContentEncryptionAlgorithm().getJwaName(); - if (!AlgorithmUtils.isAesGcm(algo) || !getAlgorithm().getJwaName().equals(algo)) { - LOG.warning("Invalid content encryption algorithm"); - throw new JweException(JweException.Error.INVALID_CONTENT_ALGORITHM); - } - return JweCompactConsumer.getCipherWithAuthTag(cipher, authTag); - } -} http://git-wip-us.apache.org/repos/asf/cxf/blob/66a81773/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AesGcmContentEncryptionAlgorithm.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AesGcmContentEncryptionAlgorithm.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AesGcmContentEncryptionAlgorithm.java deleted file mode 100644 index 4f87829..0000000 --- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AesGcmContentEncryptionAlgorithm.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.rs.security.jose.jwe; - -import javax.crypto.SecretKey; - -import org.apache.cxf.rs.security.jose.jwa.AlgorithmUtils; -import org.apache.cxf.rs.security.jose.jwa.ContentAlgorithm; -import org.apache.cxf.rt.security.crypto.CryptoUtils; - - -public class AesGcmContentEncryptionAlgorithm extends AbstractContentEncryptionAlgorithm { - private static final int DEFAULT_IV_SIZE = 96; - public AesGcmContentEncryptionAlgorithm(ContentAlgorithm algo) { - this((byte[])null, null, algo); - } - public AesGcmContentEncryptionAlgorithm(String encodedCek, String encodedIv, ContentAlgorithm algo) { - this((byte[])CryptoUtils.decodeSequence(encodedCek), CryptoUtils.decodeSequence(encodedIv), algo); - } - public AesGcmContentEncryptionAlgorithm(String encodedCek, ContentAlgorithm algo) { - this((byte[])CryptoUtils.decodeSequence(encodedCek), null, algo); - } - public AesGcmContentEncryptionAlgorithm(SecretKey key, byte[] iv, ContentAlgorithm algo) { - this(key.getEncoded(), iv, algo); - } - public AesGcmContentEncryptionAlgorithm(byte[] cek, byte[] iv, ContentAlgorithm algo) { - super(cek, iv, checkAlgorithm(algo)); - } - protected int getIvSize() { - return DEFAULT_IV_SIZE; - } - private static ContentAlgorithm checkAlgorithm(ContentAlgorithm algo) { - if (AlgorithmUtils.isAesGcm(algo.getJwaName())) { - return algo; - } - LOG.warning("Invalid content encryption algorithm"); - throw new JweException(JweException.Error.INVALID_CONTENT_ALGORITHM); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cxf/blob/66a81773/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AesGcmWrapKeyDecryptionAlgorithm.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AesGcmWrapKeyDecryptionAlgorithm.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AesGcmWrapKeyDecryptionAlgorithm.java deleted file mode 100644 index dda527e..0000000 --- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AesGcmWrapKeyDecryptionAlgorithm.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.rs.security.jose.jwe; - -import java.security.spec.AlgorithmParameterSpec; -import java.util.logging.Logger; - -import javax.crypto.SecretKey; - -import org.apache.cxf.common.logging.LogUtils; -import org.apache.cxf.common.util.Base64UrlUtility; -import org.apache.cxf.rs.security.jose.JoseException; -import org.apache.cxf.rs.security.jose.jwa.AlgorithmUtils; -import org.apache.cxf.rs.security.jose.jwa.KeyAlgorithm; -import org.apache.cxf.rt.security.crypto.CryptoUtils; - -public class AesGcmWrapKeyDecryptionAlgorithm extends WrappedKeyDecryptionAlgorithm { - protected static final Logger LOG = LogUtils.getL7dLogger(AesGcmWrapKeyDecryptionAlgorithm.class); - public AesGcmWrapKeyDecryptionAlgorithm(String encodedKey) { - this(encodedKey, null); - } - public AesGcmWrapKeyDecryptionAlgorithm(String encodedKey, KeyAlgorithm supportedAlgo) { - this(CryptoUtils.decodeSequence(encodedKey), supportedAlgo); - } - public AesGcmWrapKeyDecryptionAlgorithm(byte[] secretKey) { - this(secretKey, KeyAlgorithm.A128GCMKW); - } - public AesGcmWrapKeyDecryptionAlgorithm(byte[] secretKey, KeyAlgorithm supportedAlgo) { - this(CryptoUtils.createSecretKeySpec(secretKey, AlgorithmUtils.AES), supportedAlgo); - } - public AesGcmWrapKeyDecryptionAlgorithm(SecretKey secretKey) { - this(secretKey, null); - } - public AesGcmWrapKeyDecryptionAlgorithm(SecretKey secretKey, KeyAlgorithm supportedAlgo) { - super(secretKey, supportedAlgo); - } - @Override - protected byte[] getEncryptedContentEncryptionKey(JweDecryptionInput jweDecryptionInput) { - byte[] encryptedCekKey = super.getEncryptedContentEncryptionKey(jweDecryptionInput); - byte[] tag = getDecodedBytes(jweDecryptionInput, "tag"); - return JweCompactConsumer.getCipherWithAuthTag(encryptedCekKey, tag); - } - protected AlgorithmParameterSpec getAlgorithmParameterSpec(JweDecryptionInput jweDecryptionInput) { - byte[] iv = getDecodedBytes(jweDecryptionInput, "iv"); - return CryptoUtils.getContentEncryptionCipherSpec(128, iv); - } - private byte[] getDecodedBytes(JweDecryptionInput jweDecryptionInput, String headerName) { - try { - Object ivHeader = jweDecryptionInput.getJweHeaders().getHeader(headerName); - return Base64UrlUtility.decode(ivHeader.toString()); - } catch (Exception ex) { - throw new JoseException(ex); - } - } - protected void validateKeyEncryptionAlgorithm(String keyAlgo) { - super.validateKeyEncryptionAlgorithm(keyAlgo); - if (!AlgorithmUtils.isAesGcmKeyWrap(keyAlgo)) { - LOG.warning("Invalid key encryption algorithm"); - throw new JweException(JweException.Error.INVALID_KEY_ALGORITHM); - } - } -} http://git-wip-us.apache.org/repos/asf/cxf/blob/66a81773/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AesGcmWrapKeyEncryptionAlgorithm.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AesGcmWrapKeyEncryptionAlgorithm.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AesGcmWrapKeyEncryptionAlgorithm.java deleted file mode 100644 index 6349b7d..0000000 --- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AesGcmWrapKeyEncryptionAlgorithm.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.rs.security.jose.jwe; - -import java.security.spec.AlgorithmParameterSpec; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -import javax.crypto.SecretKey; - -import org.apache.cxf.common.util.Base64UrlUtility; -import org.apache.cxf.rs.security.jose.jwa.AlgorithmUtils; -import org.apache.cxf.rs.security.jose.jwa.KeyAlgorithm; -import org.apache.cxf.rt.security.crypto.CryptoUtils; - -public class AesGcmWrapKeyEncryptionAlgorithm extends AbstractWrapKeyEncryptionAlgorithm { - private static final Set<String> SUPPORTED_ALGORITHMS = new HashSet<String>( - Arrays.asList(KeyAlgorithm.A128GCMKW.getJwaName(), - KeyAlgorithm.A192GCMKW.getJwaName(), - KeyAlgorithm.A256GCMKW.getJwaName())); - public AesGcmWrapKeyEncryptionAlgorithm(String encodedKey, KeyAlgorithm keyAlgoJwt) { - this(CryptoUtils.decodeSequence(encodedKey), keyAlgoJwt); - } - public AesGcmWrapKeyEncryptionAlgorithm(byte[] keyBytes, KeyAlgorithm keyAlgoJwt) { - this(CryptoUtils.createSecretKeySpec(keyBytes, AlgorithmUtils.AES), - keyAlgoJwt); - } - public AesGcmWrapKeyEncryptionAlgorithm(SecretKey key, KeyAlgorithm keyAlgoJwt) { - super(key, keyAlgoJwt, true, SUPPORTED_ALGORITHMS); - } - - @Override - public byte[] getEncryptedContentEncryptionKey(JweHeaders headers, byte[] cek) { - byte[] wrappedKeyAndTag = super.getEncryptedContentEncryptionKey(headers, cek); - byte[] wrappedKey = new byte[wrappedKeyAndTag.length - 128 / 8]; - System.arraycopy(wrappedKeyAndTag, 0, wrappedKey, 0, wrappedKeyAndTag.length - 128 / 8); - String encodedTag = Base64UrlUtility.encodeChunk(wrappedKeyAndTag, - wrappedKeyAndTag.length - 128 / 8, 128 / 8); - headers.setHeader("tag", encodedTag); - return wrappedKey; - } - protected AlgorithmParameterSpec getAlgorithmParameterSpec(JweHeaders headers) { - byte[] iv = CryptoUtils.generateSecureRandomBytes(96 / 8); - String encodedIv = Base64UrlUtility.encode(iv); - headers.setHeader("iv", encodedIv); - return CryptoUtils.getContentEncryptionCipherSpec(128, iv); - } -} http://git-wip-us.apache.org/repos/asf/cxf/blob/66a81773/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AesWrapKeyDecryptionAlgorithm.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AesWrapKeyDecryptionAlgorithm.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AesWrapKeyDecryptionAlgorithm.java deleted file mode 100644 index 11350a2..0000000 --- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AesWrapKeyDecryptionAlgorithm.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.rs.security.jose.jwe; - -import javax.crypto.SecretKey; - -import org.apache.cxf.rs.security.jose.jwa.AlgorithmUtils; -import org.apache.cxf.rs.security.jose.jwa.KeyAlgorithm; -import org.apache.cxf.rt.security.crypto.CryptoUtils; - -public class AesWrapKeyDecryptionAlgorithm extends WrappedKeyDecryptionAlgorithm { - public AesWrapKeyDecryptionAlgorithm(String encodedKey) { - this(encodedKey, KeyAlgorithm.A128KW); - } - public AesWrapKeyDecryptionAlgorithm(String encodedKey, KeyAlgorithm supportedAlgo) { - this(CryptoUtils.decodeSequence(encodedKey), supportedAlgo); - } - public AesWrapKeyDecryptionAlgorithm(byte[] secretKey) { - this(secretKey, KeyAlgorithm.A128KW); - } - public AesWrapKeyDecryptionAlgorithm(byte[] secretKey, KeyAlgorithm supportedAlgo) { - this(CryptoUtils.createSecretKeySpec(secretKey, AlgorithmUtils.AES_WRAP_ALGO_JAVA), - supportedAlgo); - } - public AesWrapKeyDecryptionAlgorithm(SecretKey secretKey) { - this(secretKey, null); - } - public AesWrapKeyDecryptionAlgorithm(SecretKey secretKey, KeyAlgorithm supportedAlgo) { - super(secretKey, supportedAlgo); - } - @Override - protected void validateKeyEncryptionAlgorithm(String keyAlgo) { - super.validateKeyEncryptionAlgorithm(keyAlgo); - if (!isValidAlgorithmFamily(keyAlgo)) { - reportInvalidKeyAlgorithm(keyAlgo); - } - } - - protected boolean isValidAlgorithmFamily(String keyAlgo) { - return AlgorithmUtils.isAesKeyWrap(keyAlgo); - } - -} http://git-wip-us.apache.org/repos/asf/cxf/blob/66a81773/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AesWrapKeyEncryptionAlgorithm.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AesWrapKeyEncryptionAlgorithm.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AesWrapKeyEncryptionAlgorithm.java deleted file mode 100644 index 3fe85e3..0000000 --- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AesWrapKeyEncryptionAlgorithm.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.rs.security.jose.jwe; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -import javax.crypto.SecretKey; - -import org.apache.cxf.rs.security.jose.jwa.KeyAlgorithm; -import org.apache.cxf.rt.security.crypto.CryptoUtils; - -public class AesWrapKeyEncryptionAlgorithm extends AbstractWrapKeyEncryptionAlgorithm { - private static final Set<String> SUPPORTED_ALGORITHMS = new HashSet<String>( - Arrays.asList(KeyAlgorithm.A128KW.getJwaName(), - KeyAlgorithm.A192KW.getJwaName(), - KeyAlgorithm.A256KW.getJwaName())); - public AesWrapKeyEncryptionAlgorithm(String encodedKey, KeyAlgorithm keyAlgoJwt) { - this(CryptoUtils.decodeSequence(encodedKey), keyAlgoJwt); - } - public AesWrapKeyEncryptionAlgorithm(byte[] keyBytes, KeyAlgorithm keyAlgoJwt) { - this(CryptoUtils.createSecretKeySpec(keyBytes, keyAlgoJwt.getJavaName()), - keyAlgoJwt); - } - public AesWrapKeyEncryptionAlgorithm(SecretKey key, KeyAlgorithm keyAlgoJwt) { - super(key, keyAlgoJwt, SUPPORTED_ALGORITHMS); - } - - - -} http://git-wip-us.apache.org/repos/asf/cxf/blob/66a81773/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AuthenticationTagProducer.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AuthenticationTagProducer.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AuthenticationTagProducer.java deleted file mode 100644 index 897e68c..0000000 --- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/AuthenticationTagProducer.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.rs.security.jose.jwe; - -public interface AuthenticationTagProducer { - void update(byte[] cipher, int off, int len); - byte[] getTag(); -} http://git-wip-us.apache.org/repos/asf/cxf/blob/66a81773/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/ContentDecryptionProvider.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/ContentDecryptionProvider.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/ContentDecryptionProvider.java deleted file mode 100644 index 6c79019..0000000 --- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/ContentDecryptionProvider.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.rs.security.jose.jwe; - - -public interface ContentDecryptionProvider extends ContentEncryptionCipherProperties { - byte[] getEncryptedSequence(JweHeaders headers, byte[] cipher, byte[] authTag); -} http://git-wip-us.apache.org/repos/asf/cxf/blob/66a81773/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/ContentEncryptionCipherProperties.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/ContentEncryptionCipherProperties.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/ContentEncryptionCipherProperties.java deleted file mode 100644 index 055d602..0000000 --- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/ContentEncryptionCipherProperties.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.rs.security.jose.jwe; - -import java.security.spec.AlgorithmParameterSpec; - -import org.apache.cxf.rs.security.jose.jwa.ContentAlgorithm; - - -public interface ContentEncryptionCipherProperties { - ContentAlgorithm getAlgorithm(); - byte[] getAdditionalAuthenticationData(String headersJson, byte[] aad); - AlgorithmParameterSpec getAlgorithmParameterSpec(byte[] iv); -} http://git-wip-us.apache.org/repos/asf/cxf/blob/66a81773/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/ContentEncryptionProvider.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/ContentEncryptionProvider.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/ContentEncryptionProvider.java deleted file mode 100644 index 940455a..0000000 --- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/ContentEncryptionProvider.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.rs.security.jose.jwe; - - - -public interface ContentEncryptionProvider extends ContentEncryptionCipherProperties { - byte[] getInitVector(); - byte[] getContentEncryptionKey(JweHeaders headers); -} http://git-wip-us.apache.org/repos/asf/cxf/blob/66a81773/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/DirectKeyDecryptionAlgorithm.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/DirectKeyDecryptionAlgorithm.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/DirectKeyDecryptionAlgorithm.java deleted file mode 100644 index 3883dcd..0000000 --- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/DirectKeyDecryptionAlgorithm.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.rs.security.jose.jwe; - -import java.security.Key; -import java.util.logging.Logger; - -import org.apache.cxf.common.logging.LogUtils; -import org.apache.cxf.rs.security.jose.jwa.KeyAlgorithm; -import org.apache.cxf.rt.security.crypto.CryptoUtils; - -public class DirectKeyDecryptionAlgorithm implements KeyDecryptionProvider { - private static final Logger LOG = LogUtils.getL7dLogger(DirectKeyDecryptionAlgorithm.class); - private byte[] contentDecryptionKey; - public DirectKeyDecryptionAlgorithm(Key contentDecryptionKey) { - this(contentDecryptionKey.getEncoded()); - } - public DirectKeyDecryptionAlgorithm(String encodedContentDecryptionKey) { - this(CryptoUtils.decodeSequence(encodedContentDecryptionKey)); - } - public DirectKeyDecryptionAlgorithm(byte[] contentDecryptionKey) { - this.contentDecryptionKey = contentDecryptionKey; - } - @Override - public byte[] getDecryptedContentEncryptionKey(JweDecryptionInput jweDecryptionInput) { - validateKeyEncryptionKey(jweDecryptionInput); - return contentDecryptionKey; - } - @Override - public KeyAlgorithm getAlgorithm() { - return null; - } - protected void validateKeyEncryptionKey(JweDecryptionInput jweDecryptionInput) { - byte[] encryptedCEK = jweDecryptionInput.getEncryptedCEK(); - if (encryptedCEK != null && encryptedCEK.length > 0) { - LOG.warning("Unexpected content encryption key"); - throw new JweException(JweException.Error.INVALID_KEY_ALGORITHM); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cxf/blob/66a81773/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/DirectKeyEncryptionAlgorithm.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/DirectKeyEncryptionAlgorithm.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/DirectKeyEncryptionAlgorithm.java deleted file mode 100644 index 2f038a9..0000000 --- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/DirectKeyEncryptionAlgorithm.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.rs.security.jose.jwe; - -import java.util.logging.Logger; - -import org.apache.cxf.common.logging.LogUtils; -import org.apache.cxf.rs.security.jose.jwa.KeyAlgorithm; - -public class DirectKeyEncryptionAlgorithm implements KeyEncryptionProvider { - private static final Logger LOG = LogUtils.getL7dLogger(DirectKeyEncryptionAlgorithm.class); - public byte[] getEncryptedContentEncryptionKey(JweHeaders headers, byte[] theCek) { - checkKeyEncryptionAlgorithm(headers); - return new byte[0]; - } - protected void checkKeyEncryptionAlgorithm(JweHeaders headers) { - if (headers.getKeyEncryptionAlgorithm() != null) { - LOG.warning("Key encryption algorithm header is set"); - throw new JweException(JweException.Error.INVALID_KEY_ALGORITHM); - } - } - @Override - public KeyAlgorithm getAlgorithm() { - return null; - } -} http://git-wip-us.apache.org/repos/asf/cxf/blob/66a81773/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/DirectKeyJweDecryption.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/DirectKeyJweDecryption.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/DirectKeyJweDecryption.java deleted file mode 100644 index 7434acf..0000000 --- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/DirectKeyJweDecryption.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.rs.security.jose.jwe; - - - -public class DirectKeyJweDecryption extends JweDecryption { - public DirectKeyJweDecryption(String encodedKey, ContentDecryptionProvider ctAlgo) { - super(new DirectKeyDecryptionAlgorithm(encodedKey), - ctAlgo); - } - public DirectKeyJweDecryption(byte[] key, ContentDecryptionProvider ctAlgo) { - super(new DirectKeyDecryptionAlgorithm(key), - ctAlgo); - } -} http://git-wip-us.apache.org/repos/asf/cxf/blob/66a81773/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/DirectKeyJweEncryption.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/DirectKeyJweEncryption.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/DirectKeyJweEncryption.java deleted file mode 100644 index 3c83466..0000000 --- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/DirectKeyJweEncryption.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.rs.security.jose.jwe; - - - -public class DirectKeyJweEncryption extends JweEncryption { - public DirectKeyJweEncryption(ContentEncryptionProvider contentEncryptionAlgo) { - super(new DirectKeyEncryptionAlgorithm(), contentEncryptionAlgo); - } -} http://git-wip-us.apache.org/repos/asf/cxf/blob/66a81773/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/EcdhAesWrapKeyDecryptionAlgorithm.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/EcdhAesWrapKeyDecryptionAlgorithm.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/EcdhAesWrapKeyDecryptionAlgorithm.java deleted file mode 100644 index 4860904..0000000 --- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/EcdhAesWrapKeyDecryptionAlgorithm.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.rs.security.jose.jwe; - -import java.security.interfaces.ECPrivateKey; - -import org.apache.cxf.rs.security.jose.jwa.AlgorithmUtils; -import org.apache.cxf.rs.security.jose.jwa.KeyAlgorithm; - -public class EcdhAesWrapKeyDecryptionAlgorithm implements KeyDecryptionProvider { - private ECPrivateKey key; - private KeyAlgorithm algo; - public EcdhAesWrapKeyDecryptionAlgorithm(ECPrivateKey key) { - this(key, KeyAlgorithm.ECDH_ES_A128KW); - } - public EcdhAesWrapKeyDecryptionAlgorithm(ECPrivateKey key, KeyAlgorithm algo) { - this.key = key; - this.algo = algo; - } - @Override - public byte[] getDecryptedContentEncryptionKey(JweDecryptionInput jweDecryptionInput) { - byte[] derivedKey = - EcdhDirectKeyJweDecryption.getDecryptedContentEncryptionKeyFromHeaders( - jweDecryptionInput.getJweHeaders(), key); - KeyDecryptionProvider aesWrap = new AesWrapKeyDecryptionAlgorithm(derivedKey) { - protected boolean isValidAlgorithmFamily(String wrapAlgo) { - return AlgorithmUtils.isEcdhEsWrap(wrapAlgo); - } - }; - return aesWrap.getDecryptedContentEncryptionKey(jweDecryptionInput); - } - - @Override - public KeyAlgorithm getAlgorithm() { - return algo; - } - -} http://git-wip-us.apache.org/repos/asf/cxf/blob/66a81773/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/EcdhAesWrapKeyEncryptionAlgorithm.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/EcdhAesWrapKeyEncryptionAlgorithm.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/EcdhAesWrapKeyEncryptionAlgorithm.java deleted file mode 100644 index 2c19541..0000000 --- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/EcdhAesWrapKeyEncryptionAlgorithm.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.rs.security.jose.jwe; - -import java.security.interfaces.ECPublicKey; -import java.util.HashMap; -import java.util.Map; - -import org.apache.cxf.rs.security.jose.jwa.AlgorithmUtils; -import org.apache.cxf.rs.security.jose.jwa.KeyAlgorithm; -import org.apache.cxf.rs.security.jose.jwe.EcdhDirectKeyJweEncryption.EcdhHelper; -import org.apache.cxf.rs.security.jose.jwk.JsonWebKey; - -public class EcdhAesWrapKeyEncryptionAlgorithm implements KeyEncryptionProvider { - - private static final Map<String, String> ECDH_AES_MAP; - static { - ECDH_AES_MAP = new HashMap<String, String>(); - ECDH_AES_MAP.put(KeyAlgorithm.ECDH_ES_A128KW.getJwaName(), KeyAlgorithm.A128KW.getJwaName()); - ECDH_AES_MAP.put(KeyAlgorithm.ECDH_ES_A192KW.getJwaName(), KeyAlgorithm.A192KW.getJwaName()); - ECDH_AES_MAP.put(KeyAlgorithm.ECDH_ES_A256KW.getJwaName(), KeyAlgorithm.A256KW.getJwaName()); - } - private KeyAlgorithm keyAlgo; - private EcdhHelper helper; - - public EcdhAesWrapKeyEncryptionAlgorithm(ECPublicKey peerPublicKey, - KeyAlgorithm keyAlgo) { - //TODO: figure out the curve *name* given ECPublicKey - this(peerPublicKey, JsonWebKey.EC_CURVE_P256, null, null, keyAlgo); - } - public EcdhAesWrapKeyEncryptionAlgorithm(ECPublicKey peerPublicKey, - String curve, - KeyAlgorithm keyAlgo) { - - this(peerPublicKey, curve, null, null, keyAlgo); - } - public EcdhAesWrapKeyEncryptionAlgorithm(ECPublicKey peerPublicKey, - String curve, - String apuString, - String apvString, - KeyAlgorithm keyAlgo) { - - this.keyAlgo = keyAlgo; - helper = new EcdhHelper(peerPublicKey, curve, apuString, apvString, keyAlgo.getJwaName()); - } - - @Override - public byte[] getEncryptedContentEncryptionKey(JweHeaders headers, byte[] cek) { - final byte[] derivedKey = helper.getDerivedKey(headers); - KeyEncryptionProvider aesWrap = new AesWrapKeyEncryptionAlgorithm(derivedKey, - keyAlgo) { - protected void checkAlgorithms(JweHeaders headers) { - // complete - } - protected String getKeyEncryptionAlgoJava(JweHeaders headers) { - return AlgorithmUtils.AES_WRAP_ALGO_JAVA; - } - }; - return aesWrap.getEncryptedContentEncryptionKey(headers, cek); - } - - @Override - public KeyAlgorithm getAlgorithm() { - return keyAlgo; - } -} http://git-wip-us.apache.org/repos/asf/cxf/blob/66a81773/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/EcdhDirectKeyJweDecryption.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/EcdhDirectKeyJweDecryption.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/EcdhDirectKeyJweDecryption.java deleted file mode 100644 index 64cb7e5..0000000 --- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/EcdhDirectKeyJweDecryption.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.rs.security.jose.jwe; - -import java.security.interfaces.ECPrivateKey; - -import org.apache.cxf.rs.security.jose.JoseUtils; -import org.apache.cxf.rs.security.jose.jwa.ContentAlgorithm; -import org.apache.cxf.rs.security.jose.jwk.JsonWebKey; -import org.apache.cxf.rs.security.jose.jwk.JwkUtils; - - -public class EcdhDirectKeyJweDecryption extends JweDecryption { - public EcdhDirectKeyJweDecryption(ECPrivateKey privateKey, ContentAlgorithm supportedCtAlgo) { - super(new EcdhDirectKeyDecryptionAlgorithm(privateKey), - new AesGcmContentDecryptionAlgorithm(supportedCtAlgo)); - } - protected static byte[] getDecryptedContentEncryptionKeyFromHeaders(JweHeaders headers, - ECPrivateKey privateKey) { - ContentAlgorithm jwtAlgo = headers.getContentEncryptionAlgorithm(); - JsonWebKey publicJwk = headers.getJsonWebKey("epv"); - String apuHeader = (String)headers.getHeader("apu"); - byte[] apuBytes = apuHeader == null ? null : JoseUtils.decode(apuHeader); - String apvHeader = (String)headers.getHeader("apv"); - byte[] apvBytes = apvHeader == null ? null : JoseUtils.decode(apvHeader); - return JweUtils.getECDHKey(privateKey, JwkUtils.toECPublicKey(publicJwk), - apuBytes, apvBytes, jwtAlgo.getJwaName(), jwtAlgo.getKeySizeBits()); - } - protected static class EcdhDirectKeyDecryptionAlgorithm extends DirectKeyDecryptionAlgorithm { - private ECPrivateKey privateKey; - public EcdhDirectKeyDecryptionAlgorithm(ECPrivateKey privateKey) { - super((byte[])null); - this.privateKey = privateKey; - } - @Override - public byte[] getDecryptedContentEncryptionKey(JweDecryptionInput jweDecryptionInput) { - super.validateKeyEncryptionKey(jweDecryptionInput); - - return getDecryptedContentEncryptionKeyFromHeaders(jweDecryptionInput.getJweHeaders(), privateKey); - } - } -} http://git-wip-us.apache.org/repos/asf/cxf/blob/66a81773/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/EcdhDirectKeyJweEncryption.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/EcdhDirectKeyJweEncryption.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/EcdhDirectKeyJweEncryption.java deleted file mode 100644 index 39b6928..0000000 --- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/EcdhDirectKeyJweEncryption.java +++ /dev/null @@ -1,118 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.rs.security.jose.jwe; - -import java.security.KeyPair; -import java.security.interfaces.ECPrivateKey; -import java.security.interfaces.ECPublicKey; - -import org.apache.cxf.common.util.Base64UrlUtility; -import org.apache.cxf.common.util.StringUtils; -import org.apache.cxf.rs.security.jose.jwa.ContentAlgorithm; -import org.apache.cxf.rs.security.jose.jwa.KeyAlgorithm; -import org.apache.cxf.rs.security.jose.jwk.JwkUtils; -import org.apache.cxf.rt.security.crypto.CryptoUtils; - - -public class EcdhDirectKeyJweEncryption extends JweEncryption { - public EcdhDirectKeyJweEncryption(ECPublicKey peerPublicKey, - String curve, - ContentAlgorithm ctAlgo) { - this(peerPublicKey, curve, null, null, ctAlgo); - } - public EcdhDirectKeyJweEncryption(ECPublicKey peerPublicKey, - String curve, - String apuString, - String apvString, - ContentAlgorithm ctAlgo) { - super(new EcdhDirectKeyEncryptionAlgorithm(), - new EcdhAesGcmContentEncryptionAlgorithm(peerPublicKey, - curve, - apuString, - apvString, - ctAlgo)); - } - protected static class EcdhDirectKeyEncryptionAlgorithm extends DirectKeyEncryptionAlgorithm { - protected void checkKeyEncryptionAlgorithm(JweHeaders headers) { - headers.setKeyEncryptionAlgorithm(KeyAlgorithm.ECDH_ES_DIRECT); - } - } - protected static class EcdhAesGcmContentEncryptionAlgorithm extends AesGcmContentEncryptionAlgorithm { - private EcdhHelper helper; - public EcdhAesGcmContentEncryptionAlgorithm(ECPublicKey peerPublicKey, - String curve, - String apuString, - String apvString, - ContentAlgorithm ctAlgo) { - super(ctAlgo); - helper = new EcdhHelper(peerPublicKey, curve, apuString, apvString, ctAlgo.getJwaName()); - } - public byte[] getContentEncryptionKey(JweHeaders headers) { - return helper.getDerivedKey(headers); - } - } - - protected static class EcdhHelper { - private ECPublicKey peerPublicKey; - private String ecurve; - private byte[] apuBytes; - private byte[] apvBytes; - private String ctAlgo; - public EcdhHelper(ECPublicKey peerPublicKey, - String curve, - String apuString, - String apvString, - String ctAlgo) { - this.ctAlgo = ctAlgo; - this.peerPublicKey = peerPublicKey; - this.ecurve = curve; - // JWA spec suggests the "apu" field MAY either be omitted or - // represent a random 512-bit value (...) and the "apv" field SHOULD NOT be present." - this.apuBytes = toApuBytes(apuString); - this.apvBytes = toBytes(apvString); - } - public byte[] getDerivedKey(JweHeaders headers) { - KeyPair pair = CryptoUtils.generateECKeyPair(ecurve); - ECPublicKey publicKey = (ECPublicKey)pair.getPublic(); - ECPrivateKey privateKey = (ECPrivateKey)pair.getPrivate(); - ContentAlgorithm jwtAlgo = ContentAlgorithm.valueOf(ctAlgo); - - headers.setHeader("apu", Base64UrlUtility.encode(apuBytes)); - headers.setHeader("apv", Base64UrlUtility.encode(apvBytes)); - headers.setJsonWebKey("epv", JwkUtils.fromECPublicKey(publicKey, ecurve)); - - return JweUtils.getECDHKey(privateKey, peerPublicKey, apuBytes, apvBytes, - jwtAlgo.getJwaName(), jwtAlgo.getKeySizeBits()); - - } - private byte[] toApuBytes(String apuString) { - if (apuString != null) { - return toBytes(apuString); - } else { - return CryptoUtils.generateSecureRandomBytes(512 / 8); - } - - } - private byte[] toBytes(String str) { - return str == null ? null : StringUtils.toBytesUTF8(str); - } - - } - -} http://git-wip-us.apache.org/repos/asf/cxf/blob/66a81773/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweCompactConsumer.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweCompactConsumer.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweCompactConsumer.java deleted file mode 100644 index 9371726..0000000 --- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweCompactConsumer.java +++ /dev/null @@ -1,125 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.cxf.rs.security.jose.jwe; - -import java.io.UnsupportedEncodingException; -import java.util.logging.Logger; - -import org.apache.cxf.common.logging.LogUtils; -import org.apache.cxf.common.util.Base64Exception; -import org.apache.cxf.common.util.Base64UrlUtility; -import org.apache.cxf.jaxrs.provider.json.JsonMapObject; -import org.apache.cxf.jaxrs.provider.json.JsonMapObjectReaderWriter; -import org.apache.cxf.rs.security.jose.JoseException; -import org.apache.cxf.rs.security.jose.JoseUtils; - - -public class JweCompactConsumer { - protected static final Logger LOG = LogUtils.getL7dLogger(JweCompactConsumer.class); - private JweDecryptionInput jweDecryptionInput; - public JweCompactConsumer(String jweContent) { - String[] parts = JoseUtils.getCompactParts(jweContent); - if (parts.length != 5) { - LOG.warning("5 JWE parts are expected"); - throw new JweException(JweException.Error.INVALID_COMPACT_JWE); - } - try { - String headersJson = new String(Base64UrlUtility.decode(parts[0])); - byte[] encryptedCEK = Base64UrlUtility.decode(parts[1]); - byte[] initVector = Base64UrlUtility.decode(parts[2]); - byte[] encryptedContent = Base64UrlUtility.decode(parts[3]); - byte[] authTag = Base64UrlUtility.decode(parts[4]); - JsonMapObjectReaderWriter reader = new JsonMapObjectReaderWriter(); - JsonMapObject joseHeaders = reader.fromJsonToJsonObject(headersJson); - if (joseHeaders.getUpdateCount() != null) { - LOG.warning("Duplicate headers have been detected"); - throw new JweException(JweException.Error.INVALID_COMPACT_JWE); - } - JweHeaders jweHeaders = new JweHeaders(joseHeaders.asMap()); - jweDecryptionInput = new JweDecryptionInput(encryptedCEK, - initVector, - encryptedContent, - authTag, - null, - headersJson, - jweHeaders); - - } catch (Base64Exception ex) { - LOG.warning("Incorrect Base64 URL encoding"); - throw new JweException(JweException.Error.INVALID_COMPACT_JWE); - } - } - - public String getDecodedJsonHeaders() { - return jweDecryptionInput.getDecodedJsonHeaders(); - } - - public JweHeaders getJweHeaders() { - return jweDecryptionInput.getJweHeaders(); - } - - public byte[] getEncryptedContentEncryptionKey() { - return jweDecryptionInput.getEncryptedCEK(); - } - - public byte[] getContentDecryptionCipherInitVector() { - return jweDecryptionInput.getInitVector(); - } - - public byte[] getContentEncryptionCipherAAD() { - return JweHeaders.toCipherAdditionalAuthData(jweDecryptionInput.getDecodedJsonHeaders()); - } - - public byte[] getEncryptionAuthenticationTag() { - return jweDecryptionInput.getAuthTag(); - } - - public byte[] getEncryptedContent() { - return jweDecryptionInput.getEncryptedContent(); - } - - public byte[] getEncryptedContentWithAuthTag() { - return getCipherWithAuthTag(getEncryptedContent(), getEncryptionAuthenticationTag()); - } - public JweDecryptionInput getJweDecryptionInput() { - return jweDecryptionInput; - } - public static byte[] getCipherWithAuthTag(byte[] cipher, byte[] authTag) { - byte[] encryptedContentWithTag = new byte[cipher.length + authTag.length]; - System.arraycopy(cipher, 0, encryptedContentWithTag, 0, cipher.length); - System.arraycopy(authTag, 0, encryptedContentWithTag, cipher.length, authTag.length); - return encryptedContentWithTag; - } - - public byte[] getDecryptedContent(JweDecryptionProvider decryption) { - // temp workaround - return decryption.decrypt(jweDecryptionInput); - } - public String getDecryptedContentText(JweDecryptionProvider decryption) { - try { - return new String(getDecryptedContent(decryption), "UTF-8"); - } catch (UnsupportedEncodingException ex) { - throw new JoseException(ex); - } - } - public boolean validateCriticalHeaders() { - return JweUtils.validateCriticalHeaders(getJweHeaders()); - } -} http://git-wip-us.apache.org/repos/asf/cxf/blob/66a81773/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweCompactProducer.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweCompactProducer.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweCompactProducer.java deleted file mode 100644 index 53e7ec3..0000000 --- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweCompactProducer.java +++ /dev/null @@ -1,129 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.cxf.rs.security.jose.jwe; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.cxf.common.util.Base64UrlUtility; -import org.apache.cxf.common.util.StringUtils; -import org.apache.cxf.jaxrs.provider.json.JsonMapObjectReaderWriter; - - -public class JweCompactProducer { - private StringBuilder jweContentBuilder; - private String encodedEncryptedContent; - private String encodedAuthTag; - public JweCompactProducer(JweHeaders headers, - byte[] encryptedContentEncryptionKey, - byte[] cipherInitVector, - byte[] encryptedContentNoTag, - byte[] authenticationTag) { - this(getHeadersJson(headers), encryptedContentEncryptionKey, - cipherInitVector, encryptedContentNoTag, authenticationTag); - } - - public JweCompactProducer(String headersJson, - byte[] encryptedContentEncryptionKey, - byte[] cipherInitVector, - byte[] encryptedContentNoTag, - byte[] authenticationTag) { - jweContentBuilder = startJweContent(new StringBuilder(), headersJson, - encryptedContentEncryptionKey, cipherInitVector); - this.encodedEncryptedContent = Base64UrlUtility.encode(encryptedContentNoTag); - this.encodedAuthTag = Base64UrlUtility.encode(authenticationTag); - - } - - public JweCompactProducer(JweHeaders headers, - byte[] encryptedContentEncryptionKey, - byte[] cipherInitVector, - byte[] encryptedContentWithTag, - int authTagLengthBits) { - jweContentBuilder = startJweContent(new StringBuilder(), headers, - encryptedContentEncryptionKey, cipherInitVector); - this.encodedEncryptedContent = Base64UrlUtility.encodeChunk( - encryptedContentWithTag, - 0, - encryptedContentWithTag.length - authTagLengthBits / 8); - this.encodedAuthTag = Base64UrlUtility.encodeChunk( - encryptedContentWithTag, - encryptedContentWithTag.length - authTagLengthBits / 8, - authTagLengthBits / 8); - - } - public static String startJweContent(JweHeaders headers, - byte[] encryptedContentEncryptionKey, - byte[] cipherInitVector) { - return startJweContent(new StringBuilder(), - headers, encryptedContentEncryptionKey, cipherInitVector).toString(); - } - public static StringBuilder startJweContent(StringBuilder sb, - JweHeaders headers, - byte[] encryptedContentEncryptionKey, - byte[] cipherInitVector) { - return startJweContent(sb, - getHeadersJson(headers), - encryptedContentEncryptionKey, - cipherInitVector); - } - private static String getHeadersJson(JweHeaders headers) { - return new JsonMapObjectReaderWriter().toJson(headers); - - } - public static StringBuilder startJweContent(StringBuilder sb, - String headersJson, - byte[] encryptedContentEncryptionKey, - byte[] cipherInitVector) { - String encodedHeaders = Base64UrlUtility.encode(headersJson); - String encodedContentEncryptionKey = Base64UrlUtility.encode(encryptedContentEncryptionKey); - String encodedInitVector = Base64UrlUtility.encode(cipherInitVector); - sb.append(encodedHeaders) - .append('.') - .append(encodedContentEncryptionKey == null ? "" : encodedContentEncryptionKey) - .append('.') - .append(encodedInitVector == null ? "" : encodedInitVector) - .append('.'); - return sb; - } - - public static void startJweContent(OutputStream os, - JweHeaders headers, - byte[] encryptedContentEncryptionKey, - byte[] cipherInitVector) throws IOException { - byte[] jsonBytes = StringUtils.toBytesUTF8(getHeadersJson(headers)); - Base64UrlUtility.encodeAndStream(jsonBytes, 0, jsonBytes.length, os); - byte[] dotBytes = new byte[]{'.'}; - os.write(dotBytes); - Base64UrlUtility.encodeAndStream(encryptedContentEncryptionKey, 0, - encryptedContentEncryptionKey.length, os); - os.write(dotBytes); - Base64UrlUtility.encodeAndStream(cipherInitVector, 0, cipherInitVector.length, os); - os.write(dotBytes); - os.flush(); - } - - public String getJweContent() { - return jweContentBuilder.append(encodedEncryptedContent) - .append('.') - .append(encodedAuthTag) - .toString(); - } -} http://git-wip-us.apache.org/repos/asf/cxf/blob/66a81773/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweDecryption.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweDecryption.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweDecryption.java deleted file mode 100644 index 4b5b4bf..0000000 --- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweDecryption.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.rs.security.jose.jwe; - - -public class JweDecryption extends AbstractJweDecryption { - - public JweDecryption(KeyDecryptionProvider keyDecryptionAlgo, - ContentDecryptionProvider cipherProps) { - super(keyDecryptionAlgo, cipherProps); - } -} http://git-wip-us.apache.org/repos/asf/cxf/blob/66a81773/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweDecryptionInput.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweDecryptionInput.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweDecryptionInput.java deleted file mode 100644 index 8d7f00f..0000000 --- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweDecryptionInput.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.rs.security.jose.jwe; - - -public class JweDecryptionInput { - private String headersJson; - private byte[] encryptedCEK; - private byte[] initVector; - private byte[] encryptedContent; - private byte[] authTag; - private byte[] aad; - private JweHeaders jweHeaders; - - public JweDecryptionInput(byte[] encryptedCEK, - byte[] initVector, - byte[] encryptedContent, - byte[] authTag, - byte[] aad, - String headersJson, - JweHeaders jweHeaders) { - this.encryptedCEK = encryptedCEK; - this.initVector = initVector; - this.encryptedContent = encryptedContent; - this.aad = aad; - this.authTag = authTag; - this.headersJson = headersJson; - this.jweHeaders = jweHeaders; - } - - public byte[] getEncryptedCEK() { - return encryptedCEK; - } - public byte[] getInitVector() { - return initVector; - } - public byte[] getEncryptedContent() { - return encryptedContent; - } - public byte[] getAuthTag() { - return authTag; - } - public byte[] getAad() { - return aad; - } - public String getDecodedJsonHeaders() { - return headersJson; - } - public JweHeaders getJweHeaders() { - return jweHeaders; - } -} http://git-wip-us.apache.org/repos/asf/cxf/blob/66a81773/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweDecryptionOutput.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweDecryptionOutput.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweDecryptionOutput.java deleted file mode 100644 index 7e2b290..0000000 --- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweDecryptionOutput.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.rs.security.jose.jwe; - -import java.io.UnsupportedEncodingException; - -import org.apache.cxf.rs.security.jose.JoseException; - -public class JweDecryptionOutput { - private JweHeaders headers; - private byte[] content; - public JweDecryptionOutput(JweHeaders headers, byte[] content) { - this.headers = headers; - this.content = content; - } - public JweHeaders getHeaders() { - return headers; - } - public byte[] getContent() { - return content; - } - public String getContentText() { - try { - return new String(getContent(), "UTF-8"); - } catch (UnsupportedEncodingException ex) { - throw new JoseException(ex); - } - } -} http://git-wip-us.apache.org/repos/asf/cxf/blob/66a81773/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweDecryptionProvider.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweDecryptionProvider.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweDecryptionProvider.java deleted file mode 100644 index 1f4861a..0000000 --- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweDecryptionProvider.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.rs.security.jose.jwe; - - - -public interface JweDecryptionProvider extends JweKeyProperties { - JweDecryptionOutput decrypt(String jweContent); - byte[] decrypt(JweDecryptionInput jweInput); -} http://git-wip-us.apache.org/repos/asf/cxf/blob/66a81773/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweEncryption.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweEncryption.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweEncryption.java deleted file mode 100644 index e314515..0000000 --- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweEncryption.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.rs.security.jose.jwe; - - -public class JweEncryption extends AbstractJweEncryption { - public JweEncryption(KeyEncryptionProvider keyEncryptionAlgorithm, - ContentEncryptionProvider contentEncryptionAlgo) { - super(contentEncryptionAlgo, keyEncryptionAlgorithm); - } - - -} http://git-wip-us.apache.org/repos/asf/cxf/blob/66a81773/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweEncryptionInput.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweEncryptionInput.java b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweEncryptionInput.java deleted file mode 100644 index a1336ca..0000000 --- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweEncryptionInput.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.rs.security.jose.jwe; - -public class JweEncryptionInput { - private JweHeaders jweHeaders; - private byte[] cek; - private byte[] iv; - private byte[] aad; - private byte[] content; - public JweEncryptionInput() { - - } - public JweEncryptionInput(JweHeaders jweHeaders) { - this(jweHeaders, null); - } - public JweEncryptionInput(JweHeaders jweHeaders, - byte[] content) { - this(jweHeaders, content, null); - } - public JweEncryptionInput(JweHeaders jweHeaders, - byte[] content, - byte[] aad) { - this(jweHeaders, content, aad, null, null); - - } - public JweEncryptionInput(JweHeaders jweHeaders, - byte[] content, - byte[] cek, - byte[] iv) { - this(jweHeaders, content, null, cek, iv); - } - public JweEncryptionInput(JweHeaders jweHeaders, - byte[] content, - byte[] aad, - byte[] cek, - byte[] iv) { - this.jweHeaders = jweHeaders; - this.content = content; - this.cek = cek; - this.iv = iv; - this.aad = aad; - } - public JweHeaders getJweHeaders() { - return jweHeaders; - } - public void setJweHeaders(JweHeaders jweHeaders) { - this.jweHeaders = jweHeaders; - } - public byte[] getCek() { - return cek; - } - public void setCek(byte[] cek) { - this.cek = cek; - } - public byte[] getIv() { - return iv; - } - public void setIv(byte[] iv) { - this.iv = iv; - } - public byte[] getAad() { - return aad; - } - public void setAad(byte[] aad) { - this.aad = aad; - } - public byte[] getContent() { - return content; - } - public void setContent(byte[] content) { - this.content = content; - } -}
