[gmime] Added encapsulated pgp signing test
- From: Jeffrey Stedfast <fejj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gmime] Added encapsulated pgp signing test
- Date: Sat, 11 Mar 2017 15:20:02 +0000 (UTC)
commit 1954c71de9c1bec56e83cf32fab1f56e114b3321
Author: Jeffrey Stedfast <jestedfa microsoft com>
Date: Sat Mar 11 10:19:09 2017 -0500
Added encapsulated pgp signing test
.../{pkcs7 => smime}/certificate-authority.crt | 0
.../{pkcs7 => smime}/certificate-authority.key | 0
tests/data/{pkcs7 => smime}/smime.crt | Bin 1412 -> 1412 bytes
tests/data/{pkcs7 => smime}/smime.csr | 0
tests/data/{pkcs7 => smime}/smime.key | 0
tests/data/{pkcs7 => smime}/smime.p12 | Bin 4173 -> 4173 bytes
tests/test-pgp.c | 72 ++++++++++++++++++-
tests/test-pkcs7.c | 2 +-
8 files changed, 69 insertions(+), 5 deletions(-)
---
diff --git a/tests/data/pkcs7/certificate-authority.crt b/tests/data/smime/certificate-authority.crt
similarity index 100%
rename from tests/data/pkcs7/certificate-authority.crt
rename to tests/data/smime/certificate-authority.crt
diff --git a/tests/data/pkcs7/certificate-authority.key b/tests/data/smime/certificate-authority.key
similarity index 100%
rename from tests/data/pkcs7/certificate-authority.key
rename to tests/data/smime/certificate-authority.key
diff --git a/tests/data/pkcs7/smime.csr b/tests/data/smime/smime.csr
similarity index 100%
rename from tests/data/pkcs7/smime.csr
rename to tests/data/smime/smime.csr
diff --git a/tests/data/pkcs7/smime.key b/tests/data/smime/smime.key
similarity index 100%
rename from tests/data/pkcs7/smime.key
rename to tests/data/smime/smime.key
diff --git a/tests/test-pgp.c b/tests/test-pgp.c
index b1beb3a..41b89f4 100644
--- a/tests/test-pgp.c
+++ b/tests/test-pgp.c
@@ -65,13 +65,13 @@ get_sig_status (GMimeSignatureList *signatures)
}
static void
-test_sign (GMimeCryptoContext *ctx, GMimeStream *cleartext, GMimeStream *ciphertext)
+test_sign (GMimeCryptoContext *ctx, gboolean detached, GMimeStream *cleartext, GMimeStream *ciphertext)
{
GError *err = NULL;
Exception *ex;
int rv;
- rv = g_mime_crypto_context_sign (ctx, TRUE, "no.user@no.domain",
+ rv = g_mime_crypto_context_sign (ctx, detached, "no.user@no.domain",
GMIME_DIGEST_ALGO_SHA256,
cleartext, ciphertext, &err);
@@ -88,7 +88,7 @@ test_sign (GMimeCryptoContext *ctx, GMimeStream *cleartext, GMimeStream *ciphert
}
static void
-test_verify (GMimeCryptoContext *ctx, GMimeStream *cleartext, GMimeStream *ciphertext)
+test_verify_detached (GMimeCryptoContext *ctx, GMimeStream *cleartext, GMimeStream *ciphertext)
{
GMimeSignatureList *signatures;
GMimeSignatureStatus status;
@@ -114,6 +114,50 @@ test_verify (GMimeCryptoContext *ctx, GMimeStream *cleartext, GMimeStream *ciphe
}
static void
+test_verify (GMimeCryptoContext *ctx, GMimeStream *cleartext, GMimeStream *ciphertext)
+{
+ GMimeSignatureList *signatures;
+ GMimeSignatureStatus status;
+ Exception *ex = NULL;
+ GMimeStream *stream;
+ GError *err = NULL;
+ GByteArray *buf[2];
+
+ stream = g_mime_stream_mem_new ();
+
+ signatures = g_mime_crypto_context_verify (ctx, 0, ciphertext, NULL, stream, &err);
+
+ if (signatures == NULL) {
+ ex = exception_new ("%s", err->message);
+ g_object_unref (stream);
+ g_error_free (err);
+ throw (ex);
+ }
+
+ status = get_sig_status (signatures);
+
+ if ((status & GMIME_SIGNATURE_STATUS_RED) != 0) {
+ g_object_unref (signatures);
+ g_object_unref (stream);
+
+ throw (exception_new ("signature BAD"));
+ }
+
+ g_object_unref (signatures);
+
+ buf[0] = GMIME_STREAM_MEM (cleartext)->buffer;
+ buf[1] = GMIME_STREAM_MEM (stream)->buffer;
+
+ if (buf[0]->len != buf[1]->len || memcmp (buf[0]->data, buf[1]->data, buf[0]->len) != 0)
+ ex = exception_new ("extracted data does not match original cleartext");
+
+ g_object_unref (stream);
+
+ if (ex != NULL)
+ throw (ex);
+}
+
+static void
test_encrypt (GMimeCryptoContext *ctx, gboolean sign, GMimeStream *cleartext, GMimeStream *ciphertext)
{
GPtrArray *recipients;
@@ -360,7 +404,7 @@ int main (int argc, char **argv)
what = "GMimeGpgContext::sign";
testsuite_check (what);
try {
- test_sign (ctx, istream, ostream);
+ test_sign (ctx, FALSE, istream, ostream);
testsuite_check_passed ();
what = "GMimeGpgContext::verify";
@@ -377,6 +421,26 @@ int main (int argc, char **argv)
g_mime_stream_reset (istream);
ostream = g_mime_stream_mem_new ();
+ what = "GMimeGpgContext::sign (detached)";
+ testsuite_check (what);
+ try {
+ test_sign (ctx, TRUE, istream, ostream);
+ testsuite_check_passed ();
+
+ what = "GMimeGpgContext::verify (detached)";
+ testsuite_check (what);
+ g_mime_stream_reset (istream);
+ g_mime_stream_reset (ostream);
+ test_verify_detached (ctx, istream, ostream);
+ testsuite_check_passed ();
+ } catch (ex) {
+ testsuite_check_failed ("%s failed: %s", what, ex->message);
+ } finally;
+
+ g_object_unref (ostream);
+ g_mime_stream_reset (istream);
+ ostream = g_mime_stream_mem_new ();
+
what = "GMimeGpgContext::encrypt";
testsuite_check (what);
try {
diff --git a/tests/test-pkcs7.c b/tests/test-pkcs7.c
index 475d20a..eb63cbd 100644
--- a/tests/test-pkcs7.c
+++ b/tests/test-pkcs7.c
@@ -311,7 +311,7 @@ import_key (GMimeCryptoContext *ctx, const char *path)
int main (int argc, char **argv)
{
- const char *datadir = "data/pkcs7";
+ const char *datadir = "data/smime";
GMimeStream *istream, *ostream;
GMimeCryptoContext *ctx;
const char *what;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]