aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/core/GpgCoreTestSubkeygen.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/core/GpgCoreTestSubkeygen.cpp')
-rw-r--r--src/test/core/GpgCoreTestSubkeygen.cpp173
1 files changed, 125 insertions, 48 deletions
diff --git a/src/test/core/GpgCoreTestSubkeygen.cpp b/src/test/core/GpgCoreTestSubkeygen.cpp
index 7c826c24..c4fe92b0 100644
--- a/src/test/core/GpgCoreTestSubkeygen.cpp
+++ b/src/test/core/GpgCoreTestSubkeygen.cpp
@@ -43,13 +43,8 @@ TEST_F(GpgCoreTest, GenerateSubkeyRSA2048Test) {
ASSERT_TRUE(main_key.IsGood());
auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
- subkeygen_info->SetAlgo(
- std::get<2>(subkeygen_info->GetSupportedSubkeyAlgo()[0]));
+ subkeygen_info->SetAlgo("rsa");
subkeygen_info->SetKeyLength(2048);
- subkeygen_info->SetAllowAuthentication(true);
- subkeygen_info->SetAllowCertification(true);
- subkeygen_info->SetAllowEncryption(true);
- subkeygen_info->SetAllowSigning(true);
subkeygen_info->SetNonExpired(true);
subkeygen_info->SetNonPassPhrase(true);
@@ -87,13 +82,8 @@ TEST_F(GpgCoreTest, GenerateSubkeyDSA2048Test) {
ASSERT_TRUE(main_key.IsGood());
auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
- subkeygen_info->SetAlgo(
- std::get<2>(subkeygen_info->GetSupportedSubkeyAlgo()[1]));
+ subkeygen_info->SetAlgo("dsa");
subkeygen_info->SetKeyLength(2048);
- subkeygen_info->SetAllowAuthentication(true);
- subkeygen_info->SetAllowCertification(true);
- subkeygen_info->SetAllowEncryption(true);
- subkeygen_info->SetAllowSigning(true);
subkeygen_info->SetNonExpired(true);
subkeygen_info->SetNonPassPhrase(true);
@@ -125,19 +115,52 @@ TEST_F(GpgCoreTest, GenerateSubkeyDSA2048Test) {
ASSERT_TRUE(subkey.IsHasSigningCapability());
}
-TEST_F(GpgCoreTest, GenerateSubkeyED25519Test) {
+TEST_F(GpgCoreTest, GenerateSubkeyELG2048Test) {
auto main_key = GpgKeyGetter::GetInstance().GetKey(
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
ASSERT_TRUE(main_key.IsGood());
auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
- subkeygen_info->SetAlgo(
- std::get<2>(subkeygen_info->GetSupportedSubkeyAlgo()[2]));
+ subkeygen_info->SetAlgo("elg");
subkeygen_info->SetKeyLength(2048);
- subkeygen_info->SetAllowAuthentication(true);
- subkeygen_info->SetAllowCertification(true);
- subkeygen_info->SetAllowEncryption(true);
- subkeygen_info->SetAllowSigning(true);
+ subkeygen_info->SetNonExpired(true);
+ subkeygen_info->SetNonPassPhrase(true);
+
+ auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
+ .GenerateSubkeySync(main_key, subkeygen_info);
+
+ ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
+ ASSERT_EQ(data_object->GetObjectSize(), 1);
+ ASSERT_TRUE(data_object->Check<GpgGenerateKeyResult>());
+
+ auto result = ExtractParams<GpgGenerateKeyResult>(data_object, 0);
+ ASSERT_TRUE(result.IsGood());
+ ASSERT_FALSE(result.GetFingerprint().isEmpty());
+ auto key = GpgKeyGetter::GetInstance(kGpgFrontendDefaultChannel)
+ .GetKey(result.GetFingerprint());
+ ASSERT_TRUE(key.IsGood());
+
+ auto subkeys = key.GetSubKeys();
+ auto& subkey = subkeys->back();
+
+ ASSERT_EQ(subkey.GetPubkeyAlgo(), "ELG-E");
+ ASSERT_EQ(subkey.GetKeyAlgo(), "ELG2048");
+ ASSERT_EQ(subkey.GetKeyLength(), 2048);
+ ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
+
+ ASSERT_FALSE(subkey.IsHasCertificationCapability());
+ ASSERT_FALSE(subkey.IsHasAuthenticationCapability());
+ ASSERT_TRUE(subkey.IsHasEncryptionCapability());
+ ASSERT_FALSE(subkey.IsHasSigningCapability());
+}
+
+TEST_F(GpgCoreTest, GenerateSubkeyED25519Test) {
+ auto main_key = GpgKeyGetter::GetInstance().GetKey(
+ "E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
+ ASSERT_TRUE(main_key.IsGood());
+
+ auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
+ subkeygen_info->SetAlgo("ed25519");
subkeygen_info->SetNonExpired(true);
subkeygen_info->SetNonPassPhrase(true);
@@ -175,13 +198,7 @@ TEST_F(GpgCoreTest, GenerateSubkeyCV25519Test) {
ASSERT_TRUE(main_key.IsGood());
auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
- subkeygen_info->SetAlgo(
- std::get<2>(subkeygen_info->GetSupportedSubkeyAlgo()[3]));
- subkeygen_info->SetKeyLength(2048);
- subkeygen_info->SetAllowAuthentication(true);
- subkeygen_info->SetAllowCertification(true);
- subkeygen_info->SetAllowEncryption(true);
- subkeygen_info->SetAllowSigning(true);
+ subkeygen_info->SetAlgo("cv25519");
subkeygen_info->SetNonExpired(true);
subkeygen_info->SetNonPassPhrase(true);
@@ -202,8 +219,8 @@ TEST_F(GpgCoreTest, GenerateSubkeyCV25519Test) {
auto subkeys = key.GetSubKeys();
auto& subkey = subkeys->back();
- ASSERT_EQ(subkey.GetPubkeyAlgo(), "ECDH");
- ASSERT_EQ(subkey.GetKeyAlgo(), "CV25519");
+ ASSERT_EQ(subkey.GetPubkeyAlgo(), QString("ECDH"));
+ ASSERT_EQ(subkey.GetKeyAlgo(), QString("CV25519"));
ASSERT_EQ(subkey.GetKeyLength(), 255);
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
@@ -219,15 +236,8 @@ TEST_F(GpgCoreTest, GenerateSubkeyNISTP256Test) {
ASSERT_TRUE(main_key.IsGood());
auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
- subkeygen_info->SetAlgo(
- std::get<2>(subkeygen_info->GetSupportedSubkeyAlgo()[4]));
- subkeygen_info->SetKeyLength(2048);
- subkeygen_info->SetAllowAuthentication(true);
- subkeygen_info->SetAllowCertification(true);
- subkeygen_info->SetAllowEncryption(true);
- subkeygen_info->SetAllowSigning(true);
+ subkeygen_info->SetAlgo("nistp256");
subkeygen_info->SetNonExpired(true);
- subkeygen_info->SetNonPassPhrase(true);
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
.GenerateSubkeySync(main_key, subkeygen_info);
@@ -246,8 +256,8 @@ TEST_F(GpgCoreTest, GenerateSubkeyNISTP256Test) {
auto subkeys = key.GetSubKeys();
auto& subkey = subkeys->back();
- ASSERT_EQ(subkey.GetPubkeyAlgo(), "ECDH");
- ASSERT_EQ(subkey.GetKeyAlgo(), "NISTP256");
+ ASSERT_EQ(subkey.GetPubkeyAlgo(), QString("ECDH"));
+ ASSERT_EQ(subkey.GetKeyAlgo(), QString("NISTP256"));
ASSERT_EQ(subkey.GetKeyLength(), 256);
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
@@ -263,15 +273,82 @@ TEST_F(GpgCoreTest, GenerateSubkeyBRAINPOOLP256R1Test) {
ASSERT_TRUE(main_key.IsGood());
auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
- subkeygen_info->SetAlgo(
- std::get<2>(subkeygen_info->GetSupportedSubkeyAlgo()[7]));
- subkeygen_info->SetKeyLength(2048);
- subkeygen_info->SetAllowAuthentication(true);
- subkeygen_info->SetAllowCertification(true);
- subkeygen_info->SetAllowEncryption(true);
- subkeygen_info->SetAllowSigning(true);
+ subkeygen_info->SetAlgo("brainpoolp256r1");
+ subkeygen_info->SetNonExpired(true);
+
+ auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
+ .GenerateSubkeySync(main_key, subkeygen_info);
+
+ ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
+ ASSERT_EQ(data_object->GetObjectSize(), 1);
+ ASSERT_TRUE(data_object->Check<GpgGenerateKeyResult>());
+
+ auto result = ExtractParams<GpgGenerateKeyResult>(data_object, 0);
+ ASSERT_TRUE(result.IsGood());
+ ASSERT_FALSE(result.GetFingerprint().isEmpty());
+ auto key = GpgKeyGetter::GetInstance(kGpgFrontendDefaultChannel)
+ .GetKey(result.GetFingerprint());
+ ASSERT_TRUE(key.IsGood());
+
+ auto subkeys = key.GetSubKeys();
+ auto& subkey = subkeys->back();
+
+ ASSERT_EQ(subkey.GetPubkeyAlgo(), QString("ECDH"));
+ ASSERT_EQ(subkey.GetKeyAlgo(), QString("BRAINPOOLP256R1"));
+ ASSERT_EQ(subkey.GetKeyLength(), 256);
+ ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
+
+ ASSERT_FALSE(subkey.IsHasCertificationCapability());
+ ASSERT_FALSE(subkey.IsHasAuthenticationCapability());
+ ASSERT_TRUE(subkey.IsHasEncryptionCapability());
+ ASSERT_FALSE(subkey.IsHasSigningCapability());
+}
+
+TEST_F(GpgCoreTest, GenerateSubkeyX448Test) {
+ auto main_key = GpgKeyGetter::GetInstance().GetKey(
+ "E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
+ ASSERT_TRUE(main_key.IsGood());
+
+ auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
+ subkeygen_info->SetAlgo("x448");
+ subkeygen_info->SetNonExpired(true);
+
+ auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
+ .GenerateSubkeySync(main_key, subkeygen_info);
+
+ ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
+ ASSERT_EQ(data_object->GetObjectSize(), 1);
+ ASSERT_TRUE(data_object->Check<GpgGenerateKeyResult>());
+
+ auto result = ExtractParams<GpgGenerateKeyResult>(data_object, 0);
+ ASSERT_TRUE(result.IsGood());
+ ASSERT_FALSE(result.GetFingerprint().isEmpty());
+ auto key = GpgKeyGetter::GetInstance(kGpgFrontendDefaultChannel)
+ .GetKey(result.GetFingerprint());
+ ASSERT_TRUE(key.IsGood());
+
+ auto subkeys = key.GetSubKeys();
+ auto& subkey = subkeys->back();
+
+ ASSERT_EQ(subkey.GetPubkeyAlgo(), QString("ECDH"));
+ ASSERT_EQ(subkey.GetKeyAlgo(), QString("CV448"));
+ ASSERT_EQ(subkey.GetKeyLength(), 448);
+ ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
+
+ ASSERT_FALSE(subkey.IsHasCertificationCapability());
+ ASSERT_FALSE(subkey.IsHasAuthenticationCapability());
+ ASSERT_TRUE(subkey.IsHasEncryptionCapability());
+ ASSERT_FALSE(subkey.IsHasSigningCapability());
+}
+
+TEST_F(GpgCoreTest, GenerateSubkeySECP256K1Test) {
+ auto main_key = GpgKeyGetter::GetInstance().GetKey(
+ "E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
+ ASSERT_TRUE(main_key.IsGood());
+
+ auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
+ subkeygen_info->SetAlgo("secp256k1");
subkeygen_info->SetNonExpired(true);
- subkeygen_info->SetNonPassPhrase(true);
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
.GenerateSubkeySync(main_key, subkeygen_info);
@@ -290,8 +367,8 @@ TEST_F(GpgCoreTest, GenerateSubkeyBRAINPOOLP256R1Test) {
auto subkeys = key.GetSubKeys();
auto& subkey = subkeys->back();
- ASSERT_EQ(subkey.GetPubkeyAlgo(), "ECDH");
- ASSERT_EQ(subkey.GetKeyAlgo(), "BRAINPOOLP256R1");
+ ASSERT_EQ(subkey.GetPubkeyAlgo(), QString("ECDH"));
+ ASSERT_EQ(subkey.GetKeyAlgo(), QString("SECP256K1"));
ASSERT_EQ(subkey.GetKeyLength(), 256);
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));