Skip to content

Log a warning when an unsupported asym algorithm is used with JceMasterKey #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import java.util.regex.Pattern;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
Expand All @@ -49,6 +51,7 @@
* {@link #getInstance(PublicKey, PrivateKey, String, String, String)}.
*/
public abstract class JceMasterKey extends MasterKey<JceMasterKey> {
private static final Logger LOGGER = Logger.getLogger(JceMasterKey.class.getName());
private static final byte[] EMPTY_ARRAY = new byte[0];

private final SecureRandom rnd = new SecureRandom();
Expand Down Expand Up @@ -234,12 +237,17 @@ public WrappingData(final Cipher cipher, final byte[] extraInfo) {
}

private static class Rsa extends JceMasterKey {
private static final Pattern SUPPORTED_TRANSFORMATIONS =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be nice to have some kind of test coverage for this in general in the future to make sure we warn / don't warn as intended

Pattern.compile("RSA/ECB/(?:PKCS1Padding|OAEPWithSHA-(?:1|256|384|512)AndMGF1Padding)");
private final String transformation_;

private Rsa(PublicKey wrappingKey, PrivateKey unwrappingKey, String providerName, String keyId,
String transformation) {
super(wrappingKey, unwrappingKey, providerName, keyId);
transformation_ = transformation;
if (!SUPPORTED_TRANSFORMATIONS.matcher(transformation_).matches()) {
LOGGER.warning(transformation_ + " is not officially supported by the JceMasterKey");
}
}

@Override
Expand Down