Browse Source

Merge branch 'master' into Release_3.1

master
Krista Bennett 3 months ago
parent
commit
dd3f226ed5
3 changed files with 197 additions and 4 deletions
  1. +13
    -4
      src/pgp_sequoia.c
  2. +102
    -0
      test/src/EncryptSignDirectLoopTest.cc
  3. +82
    -0
      test/test_files/just_the_mimetext_maam.txt

+ 13
- 4
src/pgp_sequoia.c View File

@ -3092,7 +3092,7 @@ PEP_STATUS pgp_import_keydata(PEP_SESSION session, const char *key_data,
// Because we also import binary keys we have to be careful with this.
//
if (strlen(key_data + prefix_len) > prefix_len) {
if ((size - prefix_len) > 0) {
const char* subtract_junk = strnstr(key_data, pgp_begin, size);
// If it's not in there, we just try to import it as is...
if (subtract_junk) {
@ -3101,6 +3101,9 @@ PEP_STATUS pgp_import_keydata(PEP_SESSION session, const char *key_data,
}
}
// This will only be greater than 1 IF we are importing ASCII keys
// and those keys are in a concatenated keyfile with ASCII armour around each key.
// However, see caveat below.
unsigned int keycount = count_keydata_parts(key_data, size);
if (keycount < 2) {
retval = _pgp_import_keydata(session, key_data, size, private_idents,
@ -3115,15 +3118,21 @@ PEP_STATUS pgp_import_keydata(PEP_SESSION session, const char *key_data,
identity_list* collected_idents = NULL;
retval = PEP_KEY_IMPORTED;
// Binary keys should never get here. HOWEVER, someone could be sinister
// and create a binary key file and add the string from the armor
// somewhere in there, which could fool us above. Thus, we're still
// not safe with a strlen.
for (i = 0, curr_begin = key_data; i < keycount; i++) {
const char* next_begin = NULL;
size_t size_remaining = size - (curr_begin - key_data);
// This is assured to be OK because the count function above
// made sure that THIS round contains at least prefix_len chars
// We used strnstr to count, so we know that strstr will be ok.
if (strlen(curr_begin + prefix_len) > prefix_len)
next_begin = strstr(curr_begin + prefix_len, pgp_begin);
if ((size_remaining - prefix_len) > 0)
next_begin = strnstr(curr_begin + prefix_len, pgp_begin, size_remaining);
if (next_begin)
curr_size = next_begin - curr_begin;


+ 102
- 0
test/src/EncryptSignDirectLoopTest.cc View File

@ -0,0 +1,102 @@
#include <stdlib.h>
#include <string>
#include <cstring>
#include "pEpEngine.h"
#include "TestUtilities.h"
#include "TestConstants.h"
#include "Engine.h"
#include "pgp_sequoia.h"
#include <gtest/gtest.h>
#if 0
namespace {
//The fixture for EncryptSignDirectLoopTest
class EncryptSignDirectLoopTest : public ::testing::Test {
public:
Engine* engine;
PEP_SESSION session;
protected:
// You can remove any or all of the following functions if its body
// is empty.
EncryptSignDirectLoopTest() {
// You can do set-up work for each test here.
test_suite_name = ::testing::UnitTest::GetInstance()->current_test_info()->GTEST_SUITE_SYM();
test_name = ::testing::UnitTest::GetInstance()->current_test_info()->name();
test_path = get_main_test_home_dir() + "/" + test_suite_name + "/" + test_name;
}
~EncryptSignDirectLoopTest() override {
// You can do clean-up work that doesn't throw exceptions here.
}
// If the constructor and destructor are not enough for setting up
// and cleaning up each test, you can define the following methods:
void SetUp() override {
// Code here will be called immediately after the constructor (right
// before each test).
// Leave this empty if there are no files to copy to the home directory path
std::vector<std::pair<std::string, std::string>> init_files = std::vector<std::pair<std::string, std::string>>();
// Get a new test Engine.
engine = new Engine(test_path);
ASSERT_NE(engine, nullptr);
// Ok, let's initialize test directories etc.
engine->prep(NULL, NULL, NULL, init_files);
// Ok, try to start this bugger.
engine->start();
ASSERT_NE(engine->session, nullptr);
session = engine->session;
// Engine is up. Keep on truckin'
}
void TearDown() override {
// Code here will be called immediately after each test (right
// before the destructor).
engine->shut_down();
delete engine;
engine = NULL;
session = NULL;
}
private:
const char* test_suite_name;
const char* test_name;
string test_path;
// Objects declared here can be used by all tests in the EncryptSignDirectLoopTest suite.
};
} // namespace
TEST_F(EncryptSignDirectLoopTest, check_encrypt_sign_optional_loop) {
ASSERT_TRUE(slurp_and_import_key(session, "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc"));
ASSERT_TRUE(slurp_and_import_key(session, "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc"));
ASSERT_TRUE(slurp_and_import_key(session, "test_keys/pub/pep-test-carol-0x42A85A42_pub.asc"));
string plaintext = slurp("test_files/just_the_mimetext_maam.txt");
const char* ptext = plaintext.c_str();
size_t psize = plaintext.size();
stringlist_t* keylist = new_stringlist("4ABE3AAF59AC32CFE4F86500A9411D176FF00E97");
stringlist_add(keylist, "8DD4F5827B45839E9ACCA94687BDDFFB42A85A42");
for (int i = 0; i < 1000; i++) {
char* ctext = NULL;
size_t csize = 0;
PEP_STATUS status = encrypt_and_sign(session, keylist, ptext, psize, &ctext, &csize);
ASSERT_OK;
if (i % 10 == 0)
cout << i << endl;
free(ctext);
}
free_stringlist(keylist);
}
#endif

+ 82
- 0
test/test_files/just_the_mimetext_maam.txt View File

@ -0,0 +1,82 @@
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="6f47e8af358911342c968a5c60624f4b"
--6f47e8af358911342c968a5c60624f4b
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
This message was encrypted with p=E2=89=A1p (https://pep.software). If yo=
u are seeing this message,
your client does not support raising message attachments. Please click on=
the message attachment
to view it, or better yet, consider using p=E2=89=A1p=21
--6f47e8af358911342c968a5c60624f4b
Content-Type: message/rfc822; forwarded="no"
Message-ID: <pEp.QVEC7D.0DNYNIXZV0OD0.493CE2D4-E460-4581-9CCC-B291417B03F8@pep-project.org>
From: Alice Spivak Hyatt <pep.test.alice@pep-project.org>
To: Carol Burnett <pep-test-carol@pep-project.org>
Subject: Boom shaka laka
X-pEp-Version: 2.1
X-pEp-Wrapped-Message-Info: INNER
X-pEp-Sender-FPR: 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97
MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Don't you get sick of these?
--6f47e8af358911342c968a5c60624f4b
Content-Type: application/pgp-keys
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="sender_key.asc"
LS0tLS1CRUdJTiBQR1AgUFVCTElDIEtFWSBCTE9DSy0tLS0tCgp4c0JOQkZWNFBiRUJDQURUbWpH
RHNvdGkvVlBvWjN3Mm9Dakx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