Skip to content

Commit

Permalink
Add decryption of AES-encrypted keys
Browse files Browse the repository at this point in the history
  • Loading branch information
jrclark2 committed Dec 6, 2019
1 parent 97f21d6 commit 8427626
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
1 change: 0 additions & 1 deletion src/net/named_data/jndn/security/tpm/Tpm.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ public Error(String message)

if (key == null)
return new Blob();

else
return key.sign(digestAlgorithm, data);
}
Expand Down
12 changes: 5 additions & 7 deletions src/net/named_data/jndn/security/tpm/TpmPrivateKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public class TpmPrivateKey {
static {
Security.insertProviderAt(new org.spongycastle.jce.provider.BouncyCastleProvider(), 1);
}

/**
* A TpmPrivateKey.Error extends Exception and represents an error in private
* key processing.
Expand Down Expand Up @@ -156,11 +157,9 @@ else if (keyType == KeyType.RSA)
(ByteBuffer encoding, ByteBuffer password) throws TpmPrivateKey.Error {
//BouncyCastle classes expect a byte array and char array
byte[] encodingBytes = new byte[10];
encodingBytes = new byte[encoding.remaining()];
encoding.get(encodingBytes, 0, encodingBytes.length);
encoding.clear();
encodingBytes = new byte[encoding.capacity()];
encoding.get(encodingBytes, 0, encodingBytes.length);
encoding.clear();

CharBuffer charBuffer = Charset.forName("ISO-8859-1").decode(password);
char[] passwordBytes = charBuffer.array();
Expand All @@ -180,8 +179,8 @@ else if (keyType == KeyType.RSA)
("loadEncryptedPkcs8: Key type " + keyTypeString + " not supported");

} catch (IOException | OperatorCreationException | PKCSException ex) {
throw new TpmPrivateKey.Error
("loadEncryptedPkcs8: Error parsing PrivateKey info: " + ex);
throw new TpmPrivateKey.Error
("loadEncryptedPkcs8: Error parsing PrivateKey info: " + ex);
}

}
Expand Down Expand Up @@ -470,8 +469,7 @@ else if (keyType_ == KeyType.RSA) {

/**
* Get the encoded encrypted private key in PKCS #8.
* @param password The password for encrypting the private key, which should
* have characters in the range of 1 to 127.
* @param password The password for encrypting the private key.
* @return The encoding Blob of the EncryptedPrivateKeyInfo.
* @throws TpmPrivateKey.Error if no private key is loaded, or error encoding.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,15 @@ public class TestKeyChain {
);
Name testName = new Name("/ndn/test/");

try {
try {
SafeBag safebag = new SafeBag(testKey);
fixture_.keyChain_.importSafeBag(safebag, password.buf());
} catch (Throwable ex) {
fail("Unexpected exception: " + ex.getMessage());
}
assertTrue(fixture_.keyChain_.getPib().getIdentities_().getIdentities_().containsKey
(testName));
}
fail("Unexpected exception: " + ex.getMessage());
}
assertTrue(fixture_.keyChain_.getPib().getIdentities_().getIdentities_().containsKey
(testName));
}

@Test
public void
Expand Down

0 comments on commit 8427626

Please sign in to comment.