security: Bug fixing
1. correct the error message for non-existing public key.
2. rename private key export/import methods to avoid confusion.
Refs: #1527
Change-Id: I3ea8378378a66e1fbec7f0d4f210057c8f9b969b
diff --git a/tests/security/test-sec-tpm-osx.cpp b/tests/security/test-sec-tpm-osx.cpp
index 435b2ce..eb4361a 100644
--- a/tests/security/test-sec-tpm-osx.cpp
+++ b/tests/security/test-sec-tpm-osx.cpp
@@ -19,8 +19,9 @@
{
SecTpmOsx tpm;
- Name keyName("/TestSecTpmOsx/Delete/ksk-" + boost::lexical_cast<string>(
- time::toUnixTimestamp(time::system_clock::now()).count()));
+ Name keyName("/TestSecTpmOsx/Delete/ksk-" +
+ boost::lexical_cast<string>(
+ time::toUnixTimestamp(time::system_clock::now()).count()));
BOOST_CHECK_NO_THROW(tpm.generateKeyPairInTpm(keyName, KEY_TYPE_RSA, 2048));
BOOST_REQUIRE_EQUAL(tpm.doesKeyExistInTpm(keyName, KEY_CLASS_PUBLIC), true);
@@ -36,15 +37,17 @@
{
SecTpmOsx tpm;
- Name keyName("/TestSecTpmOsx/SignVerify/ksk-" + boost::lexical_cast<string>(
- time::toUnixTimestamp(time::system_clock::now()).count()));
+ Name keyName("/TestSecTpmOsx/SignVerify/ksk-" +
+ boost::lexical_cast<string>(
+ time::toUnixTimestamp(time::system_clock::now()).count()));
BOOST_CHECK_NO_THROW(tpm.generateKeyPairInTpm(keyName, KEY_TYPE_RSA, 2048));
Data data("/TestSecTpmOsx/SignVaerify/Data/1");
const uint8_t content[] = {0x01, 0x02, 0x03, 0x04};
Block sigBlock;
- BOOST_CHECK_NO_THROW(sigBlock = tpm.signInTpm(content, sizeof(content), keyName, DIGEST_ALGORITHM_SHA256));
+ BOOST_CHECK_NO_THROW(sigBlock = tpm.signInTpm(content, sizeof(content),
+ keyName, DIGEST_ALGORITHM_SHA256));
shared_ptr<PublicKey> pubkeyPtr;
BOOST_CHECK_NO_THROW(pubkeyPtr = tpm.getPublicKeyFromTpm(keyName));
@@ -59,11 +62,11 @@
RSASS<PKCS1v15, SHA256>::Verifier verifier (publicKey);
bool result = verifier.VerifyMessage(content, sizeof(content),
- sigBlock.value(), sigBlock.value_size());
+ sigBlock.value(), sigBlock.value_size());
BOOST_CHECK_EQUAL(result, true);
}
- catch(CryptoPP::Exception& e)
+ catch (CryptoPP::Exception& e)
{
BOOST_CHECK(false);
}
@@ -98,8 +101,9 @@
SecTpmOsx tpm;
- Name keyName("/TestSecTpmOsx/ExportImportKey/ksk-" + boost::lexical_cast<string>(
- time::toUnixTimestamp(time::system_clock::now()).count()));
+ Name keyName("/TestSecTpmOsx/ExportImportKey/ksk-" +
+ boost::lexical_cast<string>(
+ time::toUnixTimestamp(time::system_clock::now()).count()));
BOOST_CHECK_NO_THROW(tpm.generateKeyPairInTpm(keyName, KEY_TYPE_RSA, 2048));
@@ -107,7 +111,7 @@
BOOST_REQUIRE(tpm.doesKeyExistInTpm(keyName, KEY_CLASS_PUBLIC) == true);
ConstBufferPtr exported;
- BOOST_CHECK_NO_THROW(exported = tpm.exportPrivateKeyPkcs8FromTpm(keyName, "1234"));
+ BOOST_CHECK_NO_THROW(exported = tpm.exportPrivateKeyPkcs5FromTpm(keyName, "1234"));
shared_ptr<PublicKey> pubkeyPtr;
BOOST_REQUIRE_NO_THROW(pubkeyPtr = tpm.getPublicKeyFromTpm(keyName));
@@ -116,14 +120,17 @@
BOOST_REQUIRE(tpm.doesKeyExistInTpm(keyName, KEY_CLASS_PRIVATE) == false);
BOOST_REQUIRE(tpm.doesKeyExistInTpm(keyName, KEY_CLASS_PUBLIC) == false);
- BOOST_REQUIRE(tpm.importPrivateKeyPkcs8IntoTpm(keyName, exported->buf(), exported->size(), "1234"));
+ BOOST_REQUIRE(tpm.importPrivateKeyPkcs5IntoTpm(keyName,
+ exported->buf(), exported->size(),
+ "1234"));
BOOST_REQUIRE(tpm.doesKeyExistInTpm(keyName, KEY_CLASS_PUBLIC) == true);
BOOST_REQUIRE(tpm.doesKeyExistInTpm(keyName, KEY_CLASS_PRIVATE) == true);
const uint8_t content[] = {0x01, 0x02, 0x03, 0x04};
Block sigBlock;
- BOOST_CHECK_NO_THROW(sigBlock = tpm.signInTpm(content, sizeof(content), keyName, DIGEST_ALGORITHM_SHA256));
+ BOOST_CHECK_NO_THROW(sigBlock = tpm.signInTpm(content, sizeof(content),
+ keyName, DIGEST_ALGORITHM_SHA256));
try
{
@@ -136,11 +143,11 @@
RSASS<PKCS1v15, SHA256>::Verifier verifier (publicKey);
bool result = verifier.VerifyMessage(content, sizeof(content),
- sigBlock.value(), sigBlock.value_size());
+ sigBlock.value(), sigBlock.value_size());
BOOST_CHECK_EQUAL(result, true);
}
- catch(CryptoPP::Exception& e)
+ catch (CryptoPP::Exception& e)
{
BOOST_CHECK(false);
}