[gnome-keyring] egg: Make OpenSSL PEM routines return outer block as well.
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-keyring] egg: Make OpenSSL PEM routines return outer block as well.
- Date: Thu, 1 Sep 2011 10:16:19 +0000 (UTC)
commit c80fcdeb016e197be54ad7ebbefeeb9823d76155
Author: Stef Walter <stefw collabora co uk>
Date: Wed Aug 31 21:06:00 2011 +0200
egg: Make OpenSSL PEM routines return outer block as well.
* We expose this in GcrParser so that we can reparse a block that needs
a password.
egg/egg-openssl.c | 40 +++++++++++++++++++++++++-------
egg/egg-openssl.h | 9 +++++-
egg/tests/test-openssl.c | 9 +++++-
gcr/gcr-parser.c | 9 +++++-
pkcs11/gkm/tests/test-data-der.c | 9 +++++-
pkcs11/roots-store/gkm-roots-module.c | 9 +++++-
pkcs11/ssh-store/gkm-ssh-openssh.c | 18 +++++++++++---
7 files changed, 80 insertions(+), 23 deletions(-)
---
diff --git a/egg/egg-openssl.c b/egg/egg-openssl.c
index f22a2bd..63d92ab 100644
--- a/egg/egg-openssl.c
+++ b/egg/egg-openssl.c
@@ -92,7 +92,10 @@ parse_header_lines (const gchar *hbeg, const gchar *hend, GHashTable **result)
}
static const gchar*
-pem_find_begin (const gchar *data, gsize n_data, GQuark *type)
+pem_find_begin (const gchar *data,
+ gsize n_data,
+ GQuark *type,
+ const gchar **outer)
{
const gchar *pref, *suff;
gchar *stype;
@@ -113,7 +116,10 @@ pem_find_begin (const gchar *data, gsize n_data, GQuark *type)
/* Make sure on the same line */
if (memchr (pref, '\n', suff - pref))
return NULL;
-
+
+ if (outer)
+ *outer = pref;
+
if (type) {
*type = 0;
pref += PEM_PREF_BEGIN_L;
@@ -122,14 +128,17 @@ pem_find_begin (const gchar *data, gsize n_data, GQuark *type)
memcpy (stype, pref, suff - pref);
stype[suff - pref] = 0;
*type = g_quark_from_string (stype);
- }
-
+ }
+
/* The byte after this ---BEGIN--- */
return suff + PEM_SUFF_L;
}
static const gchar*
-pem_find_end (const gchar *data, gsize n_data, GQuark type)
+pem_find_end (const gchar *data,
+ gsize n_data,
+ GQuark type,
+ const gchar **outer)
{
const gchar *stype;
const gchar *pref;
@@ -155,7 +164,14 @@ pem_find_end (const gchar *data, gsize n_data, GQuark type)
/* Next comes the suffix */
if (strncmp ((gchar*)data, PEM_SUFF, PEM_SUFF_L) != 0)
return NULL;
-
+
+ if (outer != NULL) {
+ data += PEM_SUFF_L;
+ if (isspace (data[0]))
+ data++;
+ *outer = data;
+ }
+
/* The beginning of this ---END--- */
return pref;
}
@@ -238,6 +254,7 @@ egg_openssl_pem_parse (gconstpointer data, gsize n_data,
EggOpensslPemCallback callback, gpointer user_data)
{
const gchar *beg, *end;
+ const gchar *outer_beg, *outer_end;
guint nfound = 0;
guchar *decoded = NULL;
gsize n_decoded = 0;
@@ -251,20 +268,25 @@ egg_openssl_pem_parse (gconstpointer data, gsize n_data,
while (n_data > 0) {
/* This returns the first character after the PEM BEGIN header */
- beg = pem_find_begin ((const gchar*)data, n_data, &type);
+ beg = pem_find_begin ((const gchar*)data, n_data, &type, &outer_beg);
if (!beg)
break;
g_assert (type);
/* This returns the character position before the PEM END header */
- end = pem_find_end ((const gchar*)beg, n_data - ((const gchar*)beg - (const gchar *)data), type);
+ end = pem_find_end ((const gchar*)beg, n_data - ((const gchar*)beg - (const gchar *)data),
+ type, &outer_end);
if (!end)
break;
if (beg != end) {
if (pem_parse_block (beg, end - beg, &decoded, &n_decoded, &headers)) {
- (callback) (type, decoded, n_decoded, headers, user_data);
+ g_assert (outer_end > outer_beg);
+ (callback) (type,
+ decoded, n_decoded,
+ outer_beg, outer_end - outer_beg,
+ headers, user_data);
++nfound;
egg_secure_free (decoded);
if (headers)
diff --git a/egg/egg-openssl.h b/egg/egg-openssl.h
index 3253d73..49716dd 100644
--- a/egg/egg-openssl.h
+++ b/egg/egg-openssl.h
@@ -26,8 +26,13 @@
#include <glib.h>
-typedef void (*EggOpensslPemCallback) (GQuark type, const guchar *data, gsize n_data,
- GHashTable *headers, gpointer user_data);
+typedef void (*EggOpensslPemCallback) (GQuark type,
+ const guchar *data,
+ gsize n_data,
+ const gchar *outer,
+ gsize n_outer,
+ GHashTable *headers,
+ gpointer user_data);
GHashTable* egg_openssl_headers_new (void);
diff --git a/egg/tests/test-openssl.c b/egg/tests/test-openssl.c
index e80c1b1..6721f74 100644
--- a/egg/tests/test-openssl.c
+++ b/egg/tests/test-openssl.c
@@ -71,8 +71,13 @@ copy_each_key_value (gpointer key, gpointer value, gpointer user_data)
}
static void
-parse_reference (GQuark type, const guchar *data, gsize n_data,
- GHashTable *headers, gpointer user_data)
+parse_reference (GQuark type,
+ const guchar *data,
+ gsize n_data,
+ const gchar *outer,
+ gsize n_outer,
+ GHashTable *headers,
+ gpointer user_data)
{
Test *test = user_data;
gboolean res;
diff --git a/gcr/gcr-parser.c b/gcr/gcr-parser.c
index 00c7e39..5874e9b 100644
--- a/gcr/gcr-parser.c
+++ b/gcr/gcr-parser.c
@@ -1288,8 +1288,13 @@ typedef struct {
} HandlePemArgs;
static void
-handle_pem_data (GQuark type, const guchar *data, gsize n_data,
- GHashTable *headers, gpointer user_data)
+handle_pem_data (GQuark type,
+ const guchar *data,
+ gsize n_data,
+ const gchar *outer,
+ gsize n_outer,
+ GHashTable *headers,
+ gpointer user_data)
{
HandlePemArgs *args = (HandlePemArgs*)user_data;
gint res = GCR_ERROR_FAILURE;
diff --git a/pkcs11/gkm/tests/test-data-der.c b/pkcs11/gkm/tests/test-data-der.c
index ac1ac48..6b5531d 100644
--- a/pkcs11/gkm/tests/test-data-der.c
+++ b/pkcs11/gkm/tests/test-data-der.c
@@ -297,8 +297,13 @@ test_write_certificate (Test *test, gconstpointer unused)
}
static void
-on_ca_certificate_public_key_info (GQuark type, const guchar *data, gsize n_data,
- GHashTable *headers, gpointer user_data)
+on_ca_certificate_public_key_info (GQuark type,
+ const guchar *data,
+ gsize n_data,
+ const gchar *outer,
+ gsize n_outer,
+ GHashTable *headers,
+ gpointer user_data)
{
GNode *asn1 = NULL;
GkmDataResult res;
diff --git a/pkcs11/roots-store/gkm-roots-module.c b/pkcs11/roots-store/gkm-roots-module.c
index 8f97895..32569f4 100644
--- a/pkcs11/roots-store/gkm-roots-module.c
+++ b/pkcs11/roots-store/gkm-roots-module.c
@@ -136,8 +136,13 @@ add_certificate_for_data (GkmRootsModule *self, const guchar *data,
}
static void
-parsed_pem_block (GQuark type, const guchar *data, gsize n_data,
- GHashTable *headers, gpointer user_data)
+parsed_pem_block (GQuark type,
+ const guchar *data,
+ gsize n_data,
+ const gchar *outer,
+ gsize n_outer,
+ GHashTable *headers,
+ gpointer user_data)
{
static GQuark PEM_CERTIFICATE;
static volatile gsize quarks_inited = 0;
diff --git a/pkcs11/ssh-store/gkm-ssh-openssh.c b/pkcs11/ssh-store/gkm-ssh-openssh.c
index 46e8660..a20ce92 100644
--- a/pkcs11/ssh-store/gkm-ssh-openssh.c
+++ b/pkcs11/ssh-store/gkm-ssh-openssh.c
@@ -205,8 +205,13 @@ is_private_key_type (GQuark type)
}
static void
-parsed_pem_block (GQuark type, const guchar *data, gsize n_data,
- GHashTable *headers, gpointer user_data)
+parsed_pem_block (GQuark type,
+ const guchar *data,
+ gsize n_data,
+ const gchar *outer,
+ gsize n_outer,
+ GHashTable *headers,
+ gpointer user_data)
{
ParsePrivate *ctx = (ParsePrivate*)user_data;
const gchar *dekinfo;
@@ -233,8 +238,13 @@ parsed_pem_block (GQuark type, const guchar *data, gsize n_data,
}
static void
-digest_pem_block (GQuark type, const guchar *data, gsize n_data,
- GHashTable *headers, gpointer user_data)
+digest_pem_block (GQuark type,
+ const guchar *data,
+ gsize n_data,
+ const gchar *outer,
+ gsize n_outer,
+ GHashTable *headers,
+ gpointer user_data)
{
gchar **result = (gchar**)user_data;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]