Browse Source

Merge with sync

pEpMIME_windows
Thomas 3 years ago
parent
commit
9497a0a52a
4 changed files with 86 additions and 9 deletions
  1. +14
    -5
      src/pgp_sequoia.c
  2. +2
    -1
      test/include/KeyringImportTests.h
  3. +70
    -3
      test/src/engine_tests/KeyringImportTests.cc
  4. BIN
      test/test_keys/pub/pep-test-android-keyring.pgp

+ 14
- 5
src/pgp_sequoia.c View File

@ -124,12 +124,21 @@ PEP_STATUS pgp_init(PEP_SESSION session, bool in_first)
PEP_STATUS status = PEP_STATUS_OK;
// Create the home directory.
char *home_env = NULL;
#ifndef NDEBUG
home_env = getenv("PEP_HOME");
#endif
#ifdef _WIN32
#define PATH "\\pEp\\.pEp_keys.db"
char *home_env = getenv("LOCALAPPDATA");
#define PATH "\\pEp\\.pEp_keys.db"
if (!home_env)
home_env = getenv("LOCALAPPDATA");
#else
#define PATH "/.pEp_keys.db"
char *home_env = getenv("HOME");
if (!home_env)
home_env = getenv("HOME");
#endif
if (!home_env)
@ -143,9 +152,9 @@ PEP_STATUS pgp_init(PEP_SESSION session, bool in_first)
ERROR_OUT(NULL, PEP_OUT_OF_MEMORY, "out of memory");
#ifdef _WIN32
int r = snprintf(path, path_size, "%s\\pEp\\.pEp_keys.db", home_env);
int r = snprintf(path, path_size, "%s\\pEp\\.pEp_keys.db", home_env);
#else
int r = snprintf(path, path_size, "%s/.pEp_keys.db", home_env);
int r = snprintf(path, path_size, "%s/.pEp_keys.db", home_env);
#endif
assert(r >= 0 && r < path_size);
if (r < 0)


+ 2
- 1
test/include/KeyringImportTests.h View File

@ -16,7 +16,8 @@ class KeyringImportTests : public EngineTestSessionSuite {
void setup();
void tear_down();
private:
void import();
void import1();
void import2();
};
#endif

+ 70
- 3
test/src/engine_tests/KeyringImportTests.cc View File

@ -21,8 +21,10 @@ using namespace std;
KeyringImportTests::KeyringImportTests(string suitename, string test_home_dir) :
EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("KeyringImportTests::import"),
static_cast<Func>(&KeyringImportTests::import)));
add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("KeyringImportTests::import1"),
static_cast<Func>(&KeyringImportTests::import1)));
add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("KeyringImportTests::import2"),
static_cast<Func>(&KeyringImportTests::import2)));
}
void KeyringImportTests::setup() {
@ -33,7 +35,7 @@ void KeyringImportTests::tear_down() {
EngineTestSessionSuite::tear_down();
}
void KeyringImportTests::import() {
void KeyringImportTests::import1() {
const string pub_key = slurp("test_keys/pub/pep-test-keyring.asc");
PEP_STATUS statuspub = import_key(session, pub_key.c_str(), pub_key.length(), NULL);
@ -82,3 +84,68 @@ void KeyringImportTests::import() {
free_identity(id);
}
}
void KeyringImportTests::import2() {
const string pub_key = slurp("test_keys/pub/pep-test-android-keyring.pgp");
PEP_STATUS statuspub = import_key(session, pub_key.c_str(), pub_key.length(), NULL);
TEST_ASSERT_MSG((statuspub == PEP_TEST_KEY_IMPORT_SUCCESS), "statuspub == PEP_STATUS_OK");
struct entry {
const char *fingerprint;
const char *address;
};
// Several addresses appear multiple times in the keyring. To
// avoid teaching this function how key election works, we just
// don't test those.
struct entry entries[] = {
// { "1D600EA0BD575C846E0A8C1008BE097B1F15FB26",
// "android01@peptest.ch" },
// { "51FBBE53E9643A69D6D1F60E74E8073E2DD1F4AC",
// "test010@peptest.ch" },
{ "DB92DA58C7F6D6A48F7EF9DC4EBB4CED0E93C7B3",
"thomas@o365.peptest.ch" },
{ "667A749BEC0C6F844D499D57851E58B37BD4B02E",
"iostest009@peptest.ch" },
{ "7FCCC380455A9C2F1B080E18CEFBF78746423688",
"iostest006@peptest.ch" },
// { "447C595819EDB241",
// "android02@peptest.ch" },
// { "474D7DE519248C2A2EFD45A2148BBDB8A9C68A1C",
// "test010@peptest.ch" },
{ "DBA0A1A1001396838E3A3269DF2ED8AA4A3144AA",
"sva@pep-security.net" },
{ "DBA0A1A1001396838E3A3269DF2ED8AA4A3144AA",
"bernadette@pep-security.net" },
{ "DBA0A1A1001396838E3A3269DF2ED8AA4A3144AA",
"bernadette.laengle@pep.foundation" },
{ "DBA0A1A1001396838E3A3269DF2ED8AA4A3144AA",
"sva@pep.foundation" },
{ "1E02952E9E2048ABD510261AF43CDF9D0F14C2DB",
"pepegrillodev@gmail.com" },
// { "E3549B2DCD26832F4F30D8D051716A5DF1F4C2BF",
// "android01@peptest.ch" },
{ "5CC67646D67A33D8A2E4FF849E61B9BC790E6B02",
"huss@pep-project.org" },
// { "911BD458F82249F0",
// "android02@peptest.ch" },
};
for (int i = 0; i < sizeof(entries) / sizeof(entries[0]); i ++) {
const char *address = entries[i].address;
const char *fpr = entries[i].fingerprint;
cout << "Looking up: " << address << ", should have fingerprint: " << fpr << endl;
pEp_identity *id = new_identity(address, NULL, NULL, NULL);
PEP_STATUS status = update_identity(session, id);
TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
cout << "Got: " << (id->fpr ?: "NULL") << " (expected: " << fpr << ") -> " << (id->address ?: "NULL") << endl;
// We should always get the same fingerprint.
TEST_ASSERT_MSG((id->fpr), "id->fpr");
TEST_ASSERT_MSG((strcmp(id->fpr, fpr) == 0), "strcmp(id->fpr, fpr) == 0");
free_identity(id);
}
}

BIN
test/test_keys/pub/pep-test-android-keyring.pgp View File


Loading…
Cancel
Save