Skip to content

Commit a3e9bd6

Browse files
authored
Remove key size requirement for certificates (#749)
* Remove key size requirement for client credentials * Remove key size test
1 parent 1d81ee5 commit a3e9bd6

File tree

2 files changed

+0
-37
lines changed

2 files changed

+0
-37
lines changed

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ClientCertificate.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
final class ClientCertificate implements IClientCertificate {
3232

33-
private final static int MIN_KEY_SIZE_IN_BITS = 2048;
3433
public static final String DEFAULT_PKCS12_PASSWORD = "";
3534

3635
@Accessors(fluent = true)
@@ -47,30 +46,6 @@ final class ClientCertificate implements IClientCertificate {
4746

4847
this.privateKey = privateKey;
4948

50-
if (privateKey instanceof RSAPrivateKey) {
51-
if (((RSAPrivateKey) privateKey).getModulus().bitLength() < MIN_KEY_SIZE_IN_BITS) {
52-
throw new IllegalArgumentException(
53-
"certificate key size must be at least " + MIN_KEY_SIZE_IN_BITS);
54-
}
55-
} else if ("sun.security.mscapi.RSAPrivateKey".equals(privateKey.getClass().getName()) ||
56-
"sun.security.mscapi.CPrivateKey".equals(privateKey.getClass().getName())) {
57-
try {
58-
Method method = privateKey.getClass().getMethod("length");
59-
method.setAccessible(true);
60-
if ((int) method.invoke(privateKey) < MIN_KEY_SIZE_IN_BITS) {
61-
throw new IllegalArgumentException(
62-
"certificate key size must be at least " + MIN_KEY_SIZE_IN_BITS);
63-
}
64-
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
65-
throw new RuntimeException("error accessing sun.security.mscapi.RSAPrivateKey length: "
66-
+ ex.getMessage());
67-
}
68-
} else {
69-
throw new IllegalArgumentException(
70-
"certificate key must be an instance of java.security.interfaces.RSAPrivateKey or" +
71-
" sun.security.mscapi.RSAPrivateKey");
72-
}
73-
7449
this.publicKeyCertificateChain = publicKeyCertificateChain;
7550
}
7651

msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ClientCertificateTest.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,6 @@ void testNullKey() {
2626
assertEquals("PrivateKey is null or empty", ex.getMessage());
2727
}
2828

29-
@Test
30-
void testInvalidKeysize() {
31-
final RSAPrivateKey key = mock(RSAPrivateKey.class);
32-
final BigInteger modulus = mock(BigInteger.class);
33-
doReturn(2047).when(modulus).bitLength();
34-
doReturn(modulus).when(key).getModulus();
35-
36-
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> ClientCertificate.create(key, null));
37-
38-
assertEquals("certificate key size must be at least 2048", ex.getMessage());
39-
}
40-
4129
@Test
4230
void testGetClient() {
4331
final RSAPrivateKey key = mock(RSAPrivateKey.class);

0 commit comments

Comments
 (0)