]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Several changes to openpgp code:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Wed, 24 Oct 2007 20:44:45 +0000 (23:44 +0300)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Wed, 24 Oct 2007 20:44:45 +0000 (23:44 +0300)
* gnutls_certificate_set_openpgp_* functions were modified to include format
* KEYRING_HACK is defined to overcome a bug in opencdk which makes keyrings reentrant.
Once fixed, the KEYRING_HACK code should be removed.

15 files changed:
NEWS
includes/gnutls/extra.h
includes/gnutls/gnutls.h.in
includes/gnutls/gnutlsxx.h
includes/gnutls/openpgp.h
lib/auth_cert.h
lib/gnutls_cert.c
lib/gnutls_int.h
lib/gnutlsxx.cpp
libextra/gnutls_openpgp.c
libextra/openpgp/compat.c
libextra/openpgp/gnutls_openpgp.h
libextra/openpgp/openpgp.h
src/cli.c
src/serv.c

diff --git a/NEWS b/NEWS
index 4ffe4c4c232a86765ae6c9c8169bdf811fad8934..9d7d6980db8271b644a724d7f8c176b1f1c665c9 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -23,7 +23,15 @@ used.
 ** Introduced gnutls_session_enable_compatibility_mode() to allow enabling
 all supported compatibility options (like disabling padding).
 
+** The gnutls_certificate_set_openpgp_* functions were modified to include
+the format. This makes the interface consistent with the x509 functions.
+
+
 ** API and ABI modifications:
+gnutls_certificate_set_openpgp_key_mem: MODIFIED
+gnutls_certificate_set_openpgp_key_file: MODIFIED
+gnutls_certificate_set_openpgp_keyring_mem: MODIFIED
+gnutls_certificate_set_openpgp_keyring_file: MODIFIED
 gnutls_set_default_priority: DEPRECATED
 gnutls_set_default_priority_export: DEPRECATED
 gnutls_set_default_priority2: ADDED
index f7c7bd998bc44175183a01c3086ccf5be320c08d..888bd605f3841861194f10d1c50a0693baa5b20e 100644 (file)
@@ -41,6 +41,12 @@ extern "C"
 /* Openpgp certificate stuff 
  */
 
+  typedef enum gnutls_openpgp_crt_fmt
+  { GNUTLS_OPENPGP_FMT_RAW,
+    GNUTLS_OPENPGP_FMT_BASE64
+  } gnutls_openpgp_crt_fmt_t;
+#define gnutls_openpgp_key_fmt_t gnutls_openpgp_crt_fmt_t
+
 /**
  * gnutls_openpgp_recv_key_func - Callback prototype to get OpenPGP keys
  * @session: a TLS session
@@ -66,25 +72,20 @@ extern "C"
   int
     gnutls_certificate_set_openpgp_key_file (gnutls_certificate_credentials_t
                                             res, const char *CERTFILE,
-                                            const char *KEYFILE);
+                                            const char *KEYFILE, gnutls_openpgp_crt_fmt_t);
   int gnutls_certificate_set_openpgp_key_mem (gnutls_certificate_credentials_t
                                              res,
                                              const gnutls_datum_t * CERT,
-                                             const gnutls_datum_t * KEY);
-
-  int
-    gnutls_certificate_set_openpgp_keyserver (gnutls_certificate_credentials_t
-                                             res, const char *keyserver,
-                                             int port);
+                                             const gnutls_datum_t * KEY, gnutls_openpgp_crt_fmt_t);
 
   int
     gnutls_certificate_set_openpgp_keyring_mem
     (gnutls_certificate_credentials_t c, const unsigned char *data,
-     size_t dlen);
+     size_t dlen, gnutls_openpgp_crt_fmt_t);
 
   int
     gnutls_certificate_set_openpgp_keyring_file
-    (gnutls_certificate_credentials_t c, const char *file);
+    (gnutls_certificate_credentials_t c, const char *file, gnutls_openpgp_crt_fmt_t);
 
   /* TLS/IA stuff
    */
index 062cffd6df7c120b9a02bdb89fdf21b4d8ca2cab..f282b54fbe27fee578c627c4ce02b6dec14c577e 100644 (file)
@@ -542,7 +542,7 @@ extern "C"
 /* if you just want some defaults, use the following.
  */
   void gnutls_set_default_priority2 (gnutls_session_t session, gnutls_priority_flag_t flag);
-  #define gnutls_set_default_priority(x) gnutls_set_default_priority2( x, GNUTLS_PRIORITIES_SECURITY)
+  #define gnutls_set_default_priority(x) gnutls_set_default_priority2( x, GNUTLS_PRIORITIES_SECURITY_NORMAL)
   #define gnutls_set_default_export_priority(x) gnutls_set_default_priority2( x, GNUTLS_PRIORITIES_EXPORT)
 
 /* Returns the name of a cipher suite */
index be1fe5a0e3188d0c5f910edeef3bb0847dda09c6..521764f970f7ce66620e20bd32065a997a065e12 100644 (file)
@@ -64,7 +64,7 @@ class rsa_params
         gnutls_rsa_params_t params;
 };
 
-enum priority_flag { ALL_CIPHERS, EXPORT_CIPHERS };
+typedef gnutls_priority_flag_t priority_flag;
 
 class session
 {
index 6657951aea7772d85ea007a4a7db2f458600e384..d1a27fbe898114425a5de69f344f8c9a2683db68 100644 (file)
@@ -40,12 +40,6 @@ extern "C"
 /* gnutls_openpgp_cert_t should be defined in gnutls.h
  */
 
-  typedef enum gnutls_openpgp_crt_fmt
-  { GNUTLS_OPENPGP_FMT_RAW,
-    GNUTLS_OPENPGP_FMT_BASE64
-  } gnutls_openpgp_crt_fmt_t;
-#define gnutls_openpgp_key_fmt_t gnutls_openpgp_crt_fmt_t
-
 #define gnutls_openpgp_key_init gnutls_openpgp_crt_init
 #define gnutls_openpgp_key_deinit gnutls_openpgp_crt_deinit
 #define gnutls_openpgp_key_import gnutls_openpgp_crt_import
index c38582218266e2c0626bf48ef7aa8b0b146cc2f2..4d36bd19c7364ac419956a89c450c77872bebaea 100644 (file)
@@ -64,7 +64,12 @@ typedef struct gnutls_certificate_credentials_st
 
   /* OpenPGP specific stuff */
 
+#ifndef KEYRING_HACK
   gnutls_openpgp_keyring_t keyring;
+#else
+  gnutls_datum keyring;
+  int keyring_format;
+#endif
 
   /* X509 specific stuff */
 
index cbfb4f35c87675c3855048f957a2ff434fe218c9..12ec1f5e47e8d2dd8792f072d52ed691a002feb8 100644 (file)
@@ -190,8 +190,13 @@ gnutls_certificate_free_credentials (gnutls_certificate_credentials_t sc)
 #ifdef ENABLE_PKI
   gnutls_certificate_free_crls (sc);
 #endif
+
+#ifndef KEYRING_HACK
   if (_E_gnutls_openpgp_keyring_deinit)
     _E_gnutls_openpgp_keyring_deinit( sc->keyring);
+#else
+  _gnutls_free_datum( &sc->keyring);
+#endif
 
   gnutls_free (sc);
 }
index fa401403fcf2ba7b2d3b3428cfe2965fe4c7aa60..1d6f724e1ed884845be490e4aedd4ac8e6358890 100644 (file)
 #include <gnutls/gnutls.h>
 #include <gnutls/extra.h>
 
+/* FIXME: delete this once opencdk has reentrant keyring functions
+ */
+#define KEYRING_HACK
+
 /*
  * They are not needed any more. You can simply enable
  * the gnutls_log callback to get error descriptions.
index 9680dbb45243e98076cc068021aed2f2b79baf33..79b629a4d19893800a1335e4553b1da87ca25efd 100644 (file)
@@ -189,10 +189,7 @@ void session::set_certificate_type_priority (const int *list)
  */
 void session::set_default_priority(priority_flag flag)
 {
-    if (flag == EXPORT_CIPHERS)
-        RETWRAP( gnutls_set_default_export_priority( this->s));
-    else
-        RETWRAP( gnutls_set_default_priority( this->s));
+    gnutls_set_default_priority2( this->s, flag);
 }
 
 gnutls_protocol_t session::get_protocol_version() const
index 8151deed0489222e5f3de1f8fd8c4604a2bb54f4..36b54077b4aa4747b20a44eb7be70aee1e6811e6 100644 (file)
@@ -28,7 +28,7 @@
 #include "gnutls_cert.h"
 #include "gnutls_datum.h"
 #include "gnutls_global.h"
-#include <openpgp/gnutls_openpgp.h>
+#include "openpgp/gnutls_openpgp.h"
 #include "read-file.h"
 #include <gnutls_str.h>
 #include <gnutls_sig.h>
@@ -123,7 +123,7 @@ kbx_blob_new (keybox_blob ** r_ctx)
 }
 
 
-void
+static void
 kbx_blob_release (keybox_blob * ctx)
 {
   if (!ctx)
@@ -133,7 +133,7 @@ kbx_blob_release (keybox_blob * ctx)
 }
 
 
-cdk_keydb_hd_t
+static cdk_keydb_hd_t
 kbx_to_keydb (keybox_blob * blob)
 {
   cdk_keydb_hd_t db;
@@ -166,7 +166,7 @@ kbx_to_keydb (keybox_blob * blob)
 
 
 /* Extract a keybox blob from the given position. */
-keybox_blob *
+static keybox_blob *
 kbx_read_blob (const gnutls_datum_t * keyring, size_t pos)
 {
   keybox_blob *blob = NULL;
@@ -441,6 +441,85 @@ _gnutls_openpgp_raw_key_to_gcert (gnutls_cert * cert,
   return rc;
 }
 
+/**
+  * gnutls_certificate_set_openpgp_key - Used to set keys in a gnutls_certificate_credentials_t structure
+  * @res: is an #gnutls_certificate_credentials_t structure.
+  * @key: contains an openpgp public key
+  * @pkey: is an openpgp private key
+  *
+  * This function sets a certificate/private key pair in the 
+  * gnutls_certificate_credentials_t structure. This function may be called
+  * more than once (in case multiple keys/certificates exist for the
+  * server).
+  *
+  **/
+int
+gnutls_certificate_set_openpgp_key (gnutls_certificate_credentials_t
+                                   res, gnutls_openpgp_crt_t crt,
+                                   gnutls_openpgp_privkey_t pkey)
+{
+  int ret;
+
+  /* this should be first */
+
+  res->pkey = gnutls_realloc_fast (res->pkey,
+                                  (res->ncerts + 1) * 
+                                  sizeof (gnutls_privkey));
+  if (res->pkey == NULL)
+    {
+      gnutls_assert ();
+      return GNUTLS_E_MEMORY_ERROR;
+    }
+
+  ret = _gnutls_openpgp_privkey_to_gkey (&res->pkey[res->ncerts], pkey);
+  if (ret < 0)
+    {
+      gnutls_assert ();
+      return ret;
+    }
+
+  res->cert_list = gnutls_realloc_fast (res->cert_list,
+                                       (1 +
+                                        res->ncerts) *
+                                       sizeof (gnutls_cert *));
+  if (res->cert_list == NULL)
+    {
+      gnutls_assert ();
+      return GNUTLS_E_MEMORY_ERROR;
+    }
+
+  res->cert_list_length = gnutls_realloc_fast (res->cert_list_length,
+                                              (1 +
+                                               res->ncerts) * sizeof (int));
+  if (res->cert_list_length == NULL)
+    {
+      gnutls_assert ();
+      return GNUTLS_E_MEMORY_ERROR;
+    }
+
+  res->cert_list[res->ncerts] = gnutls_calloc (1, sizeof (gnutls_cert));
+  if (res->cert_list[res->ncerts] == NULL)
+    {
+      gnutls_assert ();
+      return GNUTLS_E_MEMORY_ERROR;
+    }
+
+  res->cert_list_length[res->ncerts] = 1;
+
+  ret = _gnutls_openpgp_crt_to_gcert (res->cert_list[res->ncerts], crt);
+  if (ret < 0)
+    {
+      gnutls_assert ();
+      return ret;
+    }
+
+  res->ncerts++;
+
+  /* FIXME: Check if the keys match. */
+
+  return 0;
+}
+
 
 /*-
  * gnutls_openpgp_get_key - Retrieve a key from the keyring.
@@ -555,148 +634,49 @@ stream_to_datum (cdk_stream_t inp, gnutls_datum_t * raw)
  **/
 int
 gnutls_certificate_set_openpgp_key_mem (gnutls_certificate_credentials_t
-                                       res, const gnutls_datum_t * cert,
-                                       const gnutls_datum_t * key)
+                                       res, const gnutls_datum_t * icert,
+                                       const gnutls_datum_t * ikey,
+                                       gnutls_openpgp_crt_fmt_t format)
 {
-  gnutls_datum_t raw;
-  cdk_kbnode_t knode = NULL, ctx = NULL, p;
-  cdk_packet_t pkt;
-  int i = 0;
-  int rc = 0;
-  cdk_stream_t inp = NULL;
-
-  if (!res || !key || !cert)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_INVALID_REQUEST;
-    }
-
-  rc = cdk_stream_tmp_from_mem (cert->data, cert->size, &inp);
-  if (rc)
-    {
-      rc = _gnutls_map_cdk_rc (rc);
-      gnutls_assert ();
-      return rc;
-    }
-
-  if (cdk_armor_filter_use (inp))
-    cdk_stream_set_armor_flag (inp, 0);
-
-  res->cert_list = gnutls_realloc_fast (res->cert_list,
-                                       (1 + res->ncerts) *
-                                       sizeof (gnutls_cert *));
-  if (res->cert_list == NULL)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_MEMORY_ERROR;
-    }
-
-  res->cert_list_length = gnutls_realloc_fast (res->cert_list_length,
-                                              (1 +
-                                               res->ncerts) * sizeof (int));
-  if (res->cert_list_length == NULL)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_MEMORY_ERROR;
-    }
-
-  res->cert_list[res->ncerts] = gnutls_calloc (1, sizeof (gnutls_cert));
-  if (res->cert_list[res->ncerts] == NULL)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_MEMORY_ERROR;
-    }
-
-  i = 1;
-  rc = cdk_keydb_get_keyblock (inp, &knode);
-
-  while (knode && (p = cdk_kbnode_walk (knode, &ctx, 0)))
-    {
-      pkt = cdk_kbnode_get_packet (p);
-      if (i > MAX_PUBLIC_PARAMS_SIZE)
-       {
-         gnutls_assert ();
-         break;
-       }
-      if (pkt->pkttype == CDK_PKT_PUBLIC_KEY)
-       {
-         int n = res->ncerts;
-
-         cdk_pkt_pubkey_t pk = pkt->pkt.public_key;
-         res->cert_list_length[n] = 1;
-
-         if (stream_to_datum (inp, &res->cert_list[n][0].raw))
-           {
-             gnutls_assert ();
-             return GNUTLS_E_MEMORY_ERROR;
-           }
-         rc = openpgp_pk_to_gnutls_cert (&res->cert_list[n][0], pk);
-         if (rc < 0)
-           {
-             gnutls_assert ();
-             return rc;
-           }
-         i++;
-       }
-    }
-
-  if (rc == CDK_EOF && i > 1)
-    rc = 0;
-
-  cdk_stream_close (inp);
-
-  if (rc)
-    {
-      cdk_kbnode_release (knode);
-      gnutls_assert ();
-      rc = _gnutls_map_cdk_rc (rc);
-      goto leave;
-    }
-
-  res->ncerts++;
-  res->pkey = gnutls_realloc_fast (res->pkey,
-                                  (res->ncerts) * sizeof (gnutls_privkey));
-  if (!res->pkey)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_MEMORY_ERROR;
-    }
-
-  /* ncerts has been incremented before */
-
-  rc = cdk_stream_tmp_from_mem (key->data, key->size, &inp);
-  if (rc)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_INTERNAL_ERROR;
-    }
-
-  if (cdk_armor_filter_use (inp))
-    cdk_stream_set_armor_flag (inp, 0);
+  gnutls_openpgp_privkey_t key;
+  gnutls_openpgp_crt_t cert;
+  int ret;
+  
+  ret = gnutls_openpgp_privkey_init( &key);
+  if (ret < 0) {
+    gnutls_assert();
+    return ret;
+  }
 
-  memset (&raw, 0, sizeof raw);
+  ret = gnutls_openpgp_privkey_import( key, ikey, format, NULL, 0);
+  if (ret < 0) {
+    gnutls_assert();
+    gnutls_openpgp_privkey_deinit( key);
+    return ret;
+  }
 
-  if (stream_to_datum (inp, &raw))
-    {
-      gnutls_assert ();
-      return GNUTLS_E_INTERNAL_ERROR;
-    }
-  cdk_stream_close (inp);
+  ret = gnutls_openpgp_crt_init( &cert);
+  if (ret < 0) {
+    gnutls_assert();
+    gnutls_openpgp_privkey_deinit( key);
+    return ret;
+  }
 
-  rc = _gnutls_openpgp_raw_privkey_to_gkey (&res->pkey[res->ncerts - 1],
-                                           &raw,
-                                           GNUTLS_OPENPGP_FMT_RAW);
-  if (rc)
-    {
-      gnutls_assert ();
-    }
+  ret = gnutls_openpgp_crt_import( cert, icert, format);
+  if (ret < 0) {
+    gnutls_assert();
+    gnutls_openpgp_privkey_deinit( key);
+    gnutls_openpgp_crt_deinit( cert);
+    return ret;
+  }
 
-  _gnutls_free_datum (&raw);
 
-leave:
-  cdk_kbnode_release (knode);
+  ret = gnutls_certificate_set_openpgp_key( res, cert, key);
 
-  return rc;
+  gnutls_openpgp_privkey_deinit( key);
+  gnutls_openpgp_crt_deinit( cert);
+  
+  return ret;
 }
 
 
@@ -713,7 +693,8 @@ leave:
 int
 gnutls_certificate_set_openpgp_key_file (gnutls_certificate_credentials_t
                                         res, const char *certfile,
-                                        const char *keyfile)
+                                        const char *keyfile,
+                                        gnutls_openpgp_crt_fmt_t format)
 {
   struct stat statbuf;
   gnutls_datum_t key, cert;
@@ -749,7 +730,7 @@ gnutls_certificate_set_openpgp_key_file (gnutls_certificate_credentials_t
       return GNUTLS_E_FILE_ERROR;
     }
 
-  rc = gnutls_certificate_set_openpgp_key_mem (res, &cert, &key);
+  rc = gnutls_certificate_set_openpgp_key_mem (res, &cert, &key, format);
 
   free (cert.data);
   free (key.data);
@@ -812,7 +793,7 @@ gnutls_openpgp_count_key_names (const gnutls_datum_t * cert)
  **/
 int
   gnutls_certificate_set_openpgp_keyring_file
-  (gnutls_certificate_credentials_t c, const char *file)
+  (gnutls_certificate_credentials_t c, const char *file, gnutls_openpgp_crt_fmt_t format)
 {
 gnutls_datum ring;
 size_t size;
@@ -832,7 +813,7 @@ int rc;
       return GNUTLS_E_FILE_ERROR;
     }
 
-  rc = gnutls_certificate_set_openpgp_keyring_mem (c, ring.data, ring.size);
+  rc = gnutls_certificate_set_openpgp_keyring_mem (c, ring.data, ring.size, format);
   
   free( ring.data);
   
@@ -854,8 +835,9 @@ int rc;
 int
 gnutls_certificate_set_openpgp_keyring_mem (gnutls_certificate_credentials_t
                                            c, const opaque * data,
-                                           size_t dlen)
+                                           size_t dlen, gnutls_openpgp_crt_fmt_t format)
 {
+#ifndef KEYRING_HACK
   cdk_stream_t inp;
   size_t count;
   uint8_t *buf;
@@ -877,7 +859,7 @@ gnutls_certificate_set_openpgp_keyring_mem (gnutls_certificate_credentials_t
     return rc;
   }
   
-  rc = gnutls_openpgp_keyring_import( c->keyring, &ddata, GNUTLS_OPENPGP_FMT_BASE64);
+  rc = gnutls_openpgp_keyring_import( c->keyring, &ddata, format);
   if ( rc < 0) {
     gnutls_assert();
     gnutls_openpgp_keyring_deinit( c->keyring);
@@ -885,6 +867,21 @@ gnutls_certificate_set_openpgp_keyring_mem (gnutls_certificate_credentials_t
   }
   
   return 0;
+#else
+
+  c->keyring_format = format;
+
+  c->keyring.data = gnutls_malloc( dlen+1);
+  if (c->keyring.data == NULL)
+  {
+    gnutls_assert();
+    return GNUTLS_E_MEMORY_ERROR;
+  }
+  memcpy(c->keyring.data, data, dlen);
+  c->keyring.data[dlen]=0;
+  c->keyring.size = dlen;
+
+#endif
 }
 
 /*-
@@ -904,6 +901,9 @@ _gnutls_openpgp_request_key (gnutls_session_t session, gnutls_datum_t * ret,
                             opaque * key_fpr, int key_fpr_size)
 {
   int rc = 0;
+#ifdef KEYRING_HACK
+  gnutls_openpgp_keyring_t kring;
+#endif
 
   if (!ret || !cred || !key_fpr)
     {
@@ -914,9 +914,27 @@ _gnutls_openpgp_request_key (gnutls_session_t session, gnutls_datum_t * ret,
   if (key_fpr_size != 16 && key_fpr_size != 20)
     return GNUTLS_E_HASH_FAILED; /* only MD5 and SHA1 are supported */
 
+#ifndef KEYRING_HACK
   rc = gnutls_openpgp_get_key (ret, cred->keyring, KEY_ATTR_FPR, key_fpr);
-  if (rc >= 0)                 /* key was found */
+#else
+  rc = gnutls_openpgp_keyring_init( &kring);
+  if ( rc < 0) {
+    gnutls_assert();
     return rc;
+  }
+  
+  rc = gnutls_openpgp_keyring_import( kring, &cred->keyring, cred->keyring_format);
+  if ( rc < 0) {
+    gnutls_assert();
+    gnutls_openpgp_keyring_deinit( kring);
+    return rc;
+  }
+#endif
+  if (rc >= 0) /* key was found */
+    {
+      rc = 0;
+      goto error;
+    }
   else
     rc = GNUTLS_E_OPENPGP_GETKEY_FAILED;
 
@@ -929,10 +947,15 @@ _gnutls_openpgp_request_key (gnutls_session_t session, gnutls_datum_t * ret,
       if (rc < 0)
        {
          gnutls_assert ();
-         return GNUTLS_E_OPENPGP_GETKEY_FAILED;
+         rc = GNUTLS_E_OPENPGP_GETKEY_FAILED;
+         goto error;
        }
     }
 
+  error:
+#ifdef KEYRING_HACK
+  gnutls_openpgp_keyring_deinit( kring);
+#endif
   return rc;
 }
 
@@ -1040,84 +1063,6 @@ _gnutls_openpgp_crt_to_gcert (gnutls_cert * gcert, gnutls_openpgp_crt_t cert)
 
 }
 
-/**
-  * gnutls_certificate_set_openpgp_key - Used to set keys in a gnutls_certificate_credentials_t structure
-  * @res: is an #gnutls_certificate_credentials_t structure.
-  * @key: contains an openpgp public key
-  * @pkey: is an openpgp private key
-  *
-  * This function sets a certificate/private key pair in the 
-  * gnutls_certificate_credentials_t structure. This function may be called
-  * more than once (in case multiple keys/certificates exist for the
-  * server).
-  *
-  **/
-int
-gnutls_certificate_set_openpgp_key (gnutls_certificate_credentials_t
-                                   res, gnutls_openpgp_crt_t key,
-                                   gnutls_openpgp_privkey_t pkey)
-{
-  int ret;
-
-  /* this should be first */
-
-  res->pkey = gnutls_realloc_fast (res->pkey,
-                                  (res->ncerts + 1) * 
-                                  sizeof (gnutls_privkey));
-  if (res->pkey == NULL)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_MEMORY_ERROR;
-    }
-
-  ret = _gnutls_openpgp_privkey_to_gkey (&res->pkey[res->ncerts], pkey);
-  if (ret < 0)
-    {
-      gnutls_assert ();
-      return ret;
-    }
-
-  res->cert_list = gnutls_realloc_fast (res->cert_list,
-                                       (1 +
-                                        res->ncerts) *
-                                       sizeof (gnutls_cert *));
-  if (res->cert_list == NULL)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_MEMORY_ERROR;
-    }
-
-  res->cert_list_length = gnutls_realloc_fast (res->cert_list_length,
-                                              (1 +
-                                               res->ncerts) * sizeof (int));
-  if (res->cert_list_length == NULL)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_MEMORY_ERROR;
-    }
-
-  res->cert_list[res->ncerts] = gnutls_calloc (1, sizeof (gnutls_cert));
-  if (res->cert_list[res->ncerts] == NULL)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_MEMORY_ERROR;
-    }
-
-  res->cert_list_length[res->ncerts] = 1;
-
-  ret = _gnutls_openpgp_crt_to_gcert (res->cert_list[res->ncerts], key);
-  if (ret < 0)
-    {
-      gnutls_assert ();
-      return ret;
-    }
-
-  res->ncerts++;
-
-  /* FIXME: Check if the keys match. */
-
-  return 0;
-}
 
 /**
  * gnutls_openpgp_privkey_sign_hash - This function will sign the given data using the private key params
index 4f7e78410810cbf76e52366dd5238587fa16fb4c..02385db6f99f08b6480dc506902d451c04dfa4b7 100644 (file)
@@ -73,6 +73,7 @@ _gnutls_openpgp_verify_key (const gnutls_certificate_credentials_t cred,
       goto leave;
     }
 
+#ifndef KEYRING_HACK
   if (cred->keyring != NULL)
     {
       ret = gnutls_openpgp_crt_verify_ring (key, cred->keyring, 0, &verify);
@@ -82,6 +83,33 @@ _gnutls_openpgp_verify_key (const gnutls_certificate_credentials_t cred,
          goto leave;
        }
     }
+#else
+  {
+  gnutls_openpgp_keyring_t kring;
+  
+  ret = gnutls_openpgp_keyring_init( &kring);
+  if ( ret < 0) {
+    gnutls_assert();
+    return ret;
+  }
+
+  ret = gnutls_openpgp_keyring_import( kring, &cred->keyring, cred->keyring_format);
+  if ( ret < 0) {
+    gnutls_assert();
+    gnutls_openpgp_keyring_deinit( kring);
+    return ret;
+  }
+
+  ret = gnutls_openpgp_crt_verify_ring (key, kring, 0, &verify);
+  if (ret < 0)
+  {
+    gnutls_assert ();
+    gnutls_openpgp_keyring_deinit( kring);
+    return ret;
+  }
+  gnutls_openpgp_keyring_deinit( kring);
+  }
+#endif
 
   /* Now try the self signature. */
   ret = gnutls_openpgp_crt_verify_self (key, 0, &verify_self);
@@ -93,10 +121,15 @@ _gnutls_openpgp_verify_key (const gnutls_certificate_credentials_t cred,
 
   *status = verify_self | verify;
 
+#ifndef KEYRING_HACK
   /* If we only checked the self signature. */
   if (!cred->keyring)
+#else
+  if (!cred->keyring.data || !cred->keyring.size)
+#endif
     *status |= GNUTLS_CERT_SIGNER_NOT_FOUND;
 
+
   ret = 0;
 
 leave:
index 9c4124dbac9864a37242cb1ce99c8887720902e1..9894b084bab2798f11b274c6bf406a0cbba30d18 100644 (file)
@@ -33,23 +33,17 @@ typedef enum
 int
 gnutls_certificate_set_openpgp_key_file (gnutls_certificate_credentials_t
                                         res, const char *CERTFILE,
-                                        const char *KEYFILE);
+                                        const char *KEYFILE, gnutls_openpgp_crt_fmt_t);
 
 int gnutls_openpgp_count_key_names (const gnutls_datum_t * cert);
 
-int gnutls_openpgp_add_keyring_mem (gnutls_datum_t * keyring,
-                                   const void *data, size_t len);
-
-int gnutls_openpgp_add_keyring_file (gnutls_datum_t * keyring,
-                                    const char *name);
-
 int gnutls_certificate_set_openpgp_keyring_file
-  (gnutls_certificate_credentials_t c, const char *file);
+  (gnutls_certificate_credentials_t c, const char *file, gnutls_openpgp_crt_fmt_t);
 
 int
 gnutls_certificate_set_openpgp_keyring_mem (gnutls_certificate_credentials_t
                                            c, const opaque * data,
-                                           size_t dlen);
+                                           size_t dlen, gnutls_openpgp_crt_fmt_t);
 
 int gnutls_openpgp_get_key (gnutls_datum_t * key,
                            gnutls_openpgp_keyring_t keyring,
@@ -74,10 +68,6 @@ _gnutls_openpgp_request_key (gnutls_session_t,
                             const gnutls_certificate_credentials_t cred,
                             opaque * key_fpr, int key_fpr_size);
 
-keybox_blob *kbx_read_blob (const gnutls_datum_t * keyring, size_t pos);
-cdk_keydb_hd_t kbx_to_keydb (keybox_blob * blob);
-void kbx_blob_release (keybox_blob * ctx);
-
 int _gnutls_openpgp_verify_key (const gnutls_certificate_credentials_t,
                                const gnutls_datum_t * cert_list,
                                int cert_list_length, unsigned int *status);
@@ -88,6 +78,21 @@ time_t _gnutls_openpgp_get_raw_key_creation_time (const gnutls_datum_t *
 time_t _gnutls_openpgp_get_raw_key_expiration_time (const gnutls_datum_t *
                                                    cert);
 
+int
+gnutls_openpgp_privkey_init (gnutls_openpgp_privkey_t * key);
+
+int
+gnutls_openpgp_privkey_init (gnutls_openpgp_privkey_t * key);
+
+void
+gnutls_openpgp_privkey_deinit (gnutls_openpgp_privkey_t key);
+
+int
+gnutls_openpgp_privkey_import (gnutls_openpgp_privkey_t key,
+                              const gnutls_datum_t * data,
+                              gnutls_openpgp_crt_fmt_t format,
+                              const char *pass, unsigned int flags);
+
 #endif /*GNUTLS_OPENPGP_H */
 
 #endif /*ENABLE_OPENPGP */
index 84a1ad762595f0c09232566fecdb68c14ac3ea3a..ecdee694ccefec5f5343706473cef366ee620ba3 100644 (file)
@@ -5,13 +5,6 @@
 # include <config.h>
 #endif
 
-/* The format the OpenPGP key is stored in. */
-typedef enum gnutls_openpgp_crt_fmt_t
-{
-  GNUTLS_OPENPGP_FMT_RAW, 
-  GNUTLS_OPENPGP_FMT_BASE64
-} gnutls_openpgp_crt_fmt_t;
-
 #ifdef ENABLE_OPENPGP
 
 #include <opencdk.h>
index 5640030ddbda74b6c107c48348cf734c7f70faa8..f04a6aeee4bfa7cc09876739ff301ddd219ff831 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -966,7 +966,7 @@ init_global_tls_stuff (void)
 #ifdef ENABLE_OPENPGP
   if (pgp_keyring != NULL)
     {
-      ret = gnutls_certificate_set_openpgp_keyring_file (xcred, pgp_keyring);
+      ret = gnutls_certificate_set_openpgp_keyring_file (xcred, pgp_keyring, GNUTLS_OPENPGP_FMT_BASE64);
       if (ret < 0)
        {
          fprintf (stderr, "Error setting the OpenPGP keyring file\n");
index 9ab93d475546f6a17b6735c8f1b07cb210775a97..27959d253cbabebf7d0211e4ab13644740899c95 100644 (file)
@@ -898,7 +898,7 @@ main (int argc, char **argv)
   if (pgp_keyring != NULL)
     {
       ret =
-       gnutls_certificate_set_openpgp_keyring_file (cert_cred, pgp_keyring);
+       gnutls_certificate_set_openpgp_keyring_file (cert_cred, pgp_keyring, GNUTLS_OPENPGP_FMT_BASE64);
       if (ret < 0)
        {
          fprintf (stderr, "Error setting the OpenPGP keyring file\n");
@@ -908,7 +908,7 @@ main (int argc, char **argv)
 
   if (pgp_certfile != NULL)
     if ((ret = gnutls_certificate_set_openpgp_key_file
-        (cert_cred, pgp_certfile, pgp_keyfile)) < 0)
+        (cert_cred, pgp_certfile, pgp_keyfile, GNUTLS_OPENPGP_FMT_BASE64)) < 0)
       {
        fprintf (stderr,
                 "Error[%d] while reading the OpenPGP key pair ('%s', '%s')\n",