-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: more logic parameters placement
- Loading branch information
Showing
1 changed file
with
16 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -677,8 +677,8 @@ public void build8021xSettingsShouldWorkWithTls() { | |
thenResultingMapContainsBytes("ca-cert", "binary ca cert"); | ||
thenResultingMapContainsBytes("client-cert", "binary client cert"); | ||
thenResultingMapContains("private-key-password", "sOPM6ph9zBENU0rrOiZhIAk8wn26W8qj0r+DBVu6Zbk="); | ||
thenResultingMapContainsEncrypted("private-key", PEM_PRIVATE_KEY, | ||
"sOPM6ph9zBENU0rrOiZhIAk8wn26W8qj0r+DBVu6Zbk="); | ||
thenResultingMapContainsEncryptedPrivateKey("private-key", "sOPM6ph9zBENU0rrOiZhIAk8wn26W8qj0r+DBVu6Zbk=", | ||
PEM_PRIVATE_KEY); | ||
|
||
thenResultingMapNotContains("ca-cert-password"); | ||
thenResultingMapNotContains("client-cert-password"); | ||
|
@@ -737,8 +737,8 @@ public void build8021xSettingsShouldWorkWithTlsWithNullCACert() { | |
thenResultingMapContains("identity", "[email protected]"); | ||
thenResultingMapContainsBytes("client-cert", "binary client cert"); | ||
thenResultingMapContains("private-key-password", "sOPM6ph9zBENU0rrOiZhIAk8wn26W8qj0r+DBVu6Zbk="); | ||
thenResultingMapContainsEncrypted("private-key", PEM_PRIVATE_KEY, | ||
"sOPM6ph9zBENU0rrOiZhIAk8wn26W8qj0r+DBVu6Zbk="); | ||
thenResultingMapContainsEncryptedPrivateKey("private-key", "sOPM6ph9zBENU0rrOiZhIAk8wn26W8qj0r+DBVu6Zbk=", | ||
PEM_PRIVATE_KEY); | ||
|
||
thenResultingMapNotContains("phase2-auth"); | ||
thenResultingMapNotContains("ca-cert"); | ||
|
@@ -766,8 +766,8 @@ public void build8021xSettingsShouldWorkWithTlsWithWrongTypeCACert() { | |
thenResultingMapContains("identity", "[email protected]"); | ||
thenResultingMapContainsBytes("client-cert", "binary client cert"); | ||
thenResultingMapContains("private-key-password", "sOPM6ph9zBENU0rrOiZhIAk8wn26W8qj0r+DBVu6Zbk="); | ||
thenResultingMapContainsEncrypted("private-key", PEM_PRIVATE_KEY, | ||
"sOPM6ph9zBENU0rrOiZhIAk8wn26W8qj0r+DBVu6Zbk="); | ||
thenResultingMapContainsEncryptedPrivateKey("private-key", "sOPM6ph9zBENU0rrOiZhIAk8wn26W8qj0r+DBVu6Zbk=", | ||
PEM_PRIVATE_KEY); | ||
|
||
thenResultingMapNotContains("phase2-auth"); | ||
thenResultingMapNotContains("ca-cert"); | ||
|
@@ -3179,24 +3179,24 @@ private void thenNoExceptionOccurred() { | |
assertNull(errorMessage, this.occurredException); | ||
} | ||
|
||
private void thenResultingMapContainsEncrypted(String key, String expectedPemPrivateKey, | ||
String privateKeyPassword) { | ||
private void thenResultingMapContainsEncryptedPrivateKey(String key, String expectedPrivateKeyPassword, | ||
String expectedPemPrivateKeyContent) { | ||
byte[] encryptedKey = (byte[]) this.resultMap.get(key).getValue(); | ||
byte[] decryptedKey = null; | ||
|
||
PBEKeySpec pbeSpec = new PBEKeySpec(privateKeyPassword.toCharArray()); | ||
PBEKeySpec pbeSpec = new PBEKeySpec(expectedPrivateKeyPassword.toCharArray()); | ||
try { | ||
EncryptedPrivateKeyInfo pkinfo = new EncryptedPrivateKeyInfo(convertToDer(encryptedKey)); | ||
SecretKeyFactory skf = SecretKeyFactory.getInstance(pkinfo.getAlgName()); | ||
SecretKey secret = skf.generateSecret(pbeSpec); | ||
PKCS8EncodedKeySpec keySpec = pkinfo.getKeySpec(secret); | ||
KeyFactory kf = KeyFactory.getInstance("RSA"); | ||
decryptedKey = kf.generatePrivate(keySpec).getEncoded(); | ||
EncryptedPrivateKeyInfo privateKeyInfo = new EncryptedPrivateKeyInfo(convertToDer(encryptedKey)); | ||
SecretKeyFactory secretKeyFact = SecretKeyFactory.getInstance(privateKeyInfo.getAlgName()); | ||
SecretKey secret = secretKeyFact.generateSecret(pbeSpec); | ||
PKCS8EncodedKeySpec keySpec = privateKeyInfo.getKeySpec(secret); | ||
KeyFactory keyFact = KeyFactory.getInstance("RSA"); | ||
decryptedKey = keyFact.generatePrivate(keySpec).getEncoded(); | ||
} catch (IOException | NoSuchAlgorithmException | InvalidKeyException | InvalidKeySpecException e) { | ||
fail("Failed to decrypt private key, caused by: " + e.getMessage()); | ||
} | ||
|
||
assertEquals(expectedPemPrivateKey, Base64.getEncoder().encodeToString(decryptedKey)); | ||
assertEquals(expectedPemPrivateKeyContent, Base64.getEncoder().encodeToString(decryptedKey)); | ||
} | ||
|
||
private byte[] convertToDer(byte[] privateKeyPem) { | ||
|