[gmime-devel] [PATCH 5/5] test the use of session keys
- From: Daniel Kahn Gillmor <dkg fifthhorseman net>
- To: Gmime Development <gmime-devel-list gnome org>
- Subject: [gmime-devel] [PATCH 5/5] test the use of session keys
- Date: Mon, 5 Dec 2016 02:05:07 -0500
---
tests/test-pgpmime.c | 34 ++++++++++++++++++++++++++++------
1 file changed, 28 insertions(+), 6 deletions(-)
diff --git a/tests/test-pgpmime.c b/tests/test-pgpmime.c
index 95d5c71..c671c9b 100644
--- a/tests/test-pgpmime.c
+++ b/tests/test-pgpmime.c
@@ -327,9 +327,10 @@ _construct_example (GMimeCryptoContext *ctx, gboolean sign,
*cleartext_out = cleartext;
}
-static void
+static char *
test_multipart_encrypted (GMimeCryptoContext *ctx, gboolean sign,
- GMimeStream *cleartext, GMimeStream *stream)
+ GMimeStream *cleartext, GMimeStream *stream,
+ const char *session_key)
{
GMimeStream *test_stream;
GMimeMultipartEncrypted *mpe;
@@ -342,6 +343,7 @@ test_multipart_encrypted (GMimeCryptoContext *ctx, gboolean sign,
GByteArray *buf[2];
GError *err = NULL;
GMimePart *part;
+ char *ret = NULL;
g_mime_stream_reset (stream);
g_mime_stream_reset (cleartext);
@@ -360,7 +362,7 @@ test_multipart_encrypted (GMimeCryptoContext *ctx, gboolean sign,
mpe = (GMimeMultipartEncrypted *) message->mime_part;
/* okay, now to test our decrypt function... */
- decrypted = g_mime_multipart_encrypted_decrypt (mpe, ctx, &result, &err);
+ decrypted = g_mime_multipart_encrypted_decrypt_session (mpe, ctx, session_key, &result, &err);
if (!decrypted || err != NULL) {
ex = exception_new ("decryption failed: %s", err->message);
g_error_free (err);
@@ -371,6 +373,7 @@ test_multipart_encrypted (GMimeCryptoContext *ctx, gboolean sign,
ex = exception_new ("No session key returned!");
throw (ex);
}
+ ret = g_strdup (result->session_key);
if (result->signatures)
v(print_verify_results (result->signatures));
@@ -386,6 +389,8 @@ test_multipart_encrypted (GMimeCryptoContext *ctx, gboolean sign,
g_object_unref (result);
if (ex != NULL) {
+ g_free (ret);
+ ret = 0;
throw (ex);
}
@@ -400,8 +405,12 @@ test_multipart_encrypted (GMimeCryptoContext *ctx, gboolean sign,
g_object_unref (test_stream);
- if (ex != NULL)
+ if (ex != NULL) {
+ g_free (ret);
+ ret = 0;
throw (ex);
+ }
+ return ret;
}
static void
@@ -434,6 +443,7 @@ int main (int argc, char *argv[])
char *key;
int i;
GMimeStream *stream = NULL, *cleartext = NULL;
+ char *session_key;
g_mime_init (0);
@@ -485,7 +495,8 @@ int main (int argc, char *argv[])
testsuite_check ("multipart/encrypted");
try {
_construct_example (ctx, FALSE, &cleartext, &stream);
- test_multipart_encrypted (ctx, FALSE, cleartext, stream);
+ session_key = test_multipart_encrypted (ctx, FALSE, cleartext, stream, NULL);
+ g_free (test_multipart_encrypted (ctx, FALSE, cleartext, stream, session_key));
testsuite_check_passed ();
} catch (ex) {
testsuite_check_failed ("multipart/encrypted failed: %s", ex->message);
@@ -493,11 +504,17 @@ int main (int argc, char *argv[])
g_object_unref (cleartext);
g_object_unref (stream);
cleartext = stream = NULL;
+ if (session_key) {
+ memset (session_key, 0, strlen (session_key));
+ g_free (session_key);
+ session_key = NULL;
+ }
testsuite_check ("multipart/encrypted+sign");
try {
_construct_example (ctx, TRUE, &cleartext, &stream);
- test_multipart_encrypted (ctx, TRUE, cleartext, stream);
+ session_key = test_multipart_encrypted (ctx, TRUE, cleartext, stream, NULL);
+ g_free (test_multipart_encrypted (ctx, TRUE, cleartext, stream, session_key));
testsuite_check_passed ();
} catch (ex) {
testsuite_check_failed ("multipart/encrypted+sign failed: %s", ex->message);
@@ -505,6 +522,11 @@ int main (int argc, char *argv[])
g_object_unref (cleartext);
g_object_unref (stream);
cleartext = stream = NULL;
+ if (session_key) {
+ memset (session_key, 0, strlen (session_key));
+ g_free (session_key);
+ session_key = NULL;
+ }
g_object_unref (ctx);
--
2.10.2
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]