Skip to content

Commit 36ddfe7

Browse files
Log a warning when an unsupported asym algorithm is used with JceMasterKey
1 parent 7d5ab6e commit 36ddfe7

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/main/java/com/amazonaws/encryptionsdk/jce/JceMasterKey.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import java.util.Collection;
3030
import java.util.List;
3131
import java.util.Map;
32+
import java.util.logging.Logger;
33+
import java.util.regex.Pattern;
3234

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

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

236239
private static class Rsa extends JceMasterKey {
240+
private static final Pattern SUPPORTED_TRANSFORMATIONS =
241+
Pattern.compile("RSA/ECB/(?:PKCS1Padding|OAEPWithSHA-(?:1|256|384|512)AndMGF1Padding)");
237242
private final String transformation_;
238243

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

245253
@Override

0 commit comments

Comments
 (0)