]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Added helper functions gnutls_pubkey_import_openpgp_raw() and gnutls_pubkey_import_x5...
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Sun, 7 Oct 2012 09:01:29 +0000 (11:01 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Sun, 7 Oct 2012 09:07:25 +0000 (11:07 +0200)
NEWS
doc/cha-tokens.texi
lib/gnutls_privkey.c
lib/gnutls_pubkey.c
lib/includes/gnutls/abstract.h
lib/libgnutls.map

diff --git a/NEWS b/NEWS
index a7f8d3f8a0a786b4b59886d13a233138e77f5492..f22d2ca5699bc1653a9c156d815639f26ea52c73 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -40,6 +40,8 @@ gnutls_openpgp_crt_export2: Added
 gnutls_openpgp_privkey_export2: Added
 gnutls_pkcs11_obj_export2: Added
 gnutls_pkcs12_export2: Added
+gnutls_pubkey_import_openpgp_raw: Added
+gnutls_pubkey_import_x509_raw: Added
 dane_query_init: Added
 dane_query_deinit: Added
 dane_query_resolve_tlsa: Added
index b290ff52c75bad91fb20fbbadf3a3e77bf66c305..ad61b152b9272aeac21979bfb8e68c233b4b3088 100644 (file)
@@ -73,6 +73,11 @@ sequence.
 
 @showfuncB{gnutls_pubkey_export,gnutls_pubkey_export2}
 
+Other helper functions that allow directly importing from raw X.509 or
+OpenPGP structures are shown below. 
+
+@showfuncB{gnutls_pubkey_import_x509_raw,gnutls_pubkey_import_openpgp_raw}
+
 An important function is @funcref{gnutls_pubkey_import_url} which will import
 public keys from URLs that identify objects stored in tokens (see @ref{Smart cards and HSMs} and @ref{Trusted Platform Module}).
 A function to check for a supported by GnuTLS URL is @funcref{gnutls_url_is_supported}.
index 00187a5cd6f9a9b9f1e20573671f55f11e638f9d..f718b7cf691f827726fd1c817af20b61a16c1bfa 100644 (file)
@@ -947,8 +947,6 @@ cleanup:
   return ret;
 }
 
-
-
 /**
  * gnutls_privkey_import_url:
  * @key: A key of type #gnutls_privkey_t
index 21bea55ed96d4472cd3037c5059146293a78e2be..36e9cee0da17e294a999b03fd9101b4411629467 100644 (file)
@@ -467,6 +467,67 @@ gnutls_pubkey_get_openpgp_key_id (gnutls_pubkey_t key, unsigned int flags,
   return 0;
 }
 
+/**
+ * gnutls_pubkey_import_openpgp_raw:
+ * @pkey: The public key
+ * @data: The public key data to be imported
+ * @format: The format of the public key
+ * @keyid: The key id to use (optional)
+ * @flags: Should be zero
+ *
+ * This function will import the given public key to the abstract
+ * #gnutls_pubkey_t structure. 
+ *
+ * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
+ *   negative error value.
+ *
+ * Since: 3.1.3
+ **/
+int gnutls_pubkey_import_openpgp_raw (gnutls_pubkey_t pkey,
+                                      const gnutls_datum_t * data,
+                                      gnutls_openpgp_crt_fmt_t format,
+                                      const gnutls_openpgp_keyid_t keyid,
+                                      unsigned int flags)
+{
+  gnutls_openpgp_crt_t xpriv;
+  int ret;
+  
+  ret = gnutls_openpgp_crt_init(&xpriv);
+  if (ret < 0)
+    return gnutls_assert_val(ret);
+
+  ret = gnutls_openpgp_crt_import(xpriv, data, format);
+  if (ret < 0)
+    {
+      gnutls_assert();
+      goto cleanup;
+    }
+
+  if(keyid)
+    {
+      ret = gnutls_openpgp_crt_set_preferred_key_id(xpriv, keyid);
+      if (ret < 0)
+        {
+          gnutls_assert();
+          goto cleanup;
+        }
+    }
+
+  ret = gnutls_pubkey_import_openpgp(pkey, xpriv, flags);
+  if (ret < 0)
+    {
+      gnutls_assert();
+      goto cleanup;
+    }
+    
+  ret = 0;
+  
+cleanup:
+  gnutls_openpgp_crt_deinit(xpriv);
+  
+  return ret;
+}
+
 #endif
 
 /**
@@ -1951,3 +2012,53 @@ void gnutls_pubkey_set_pin_function (gnutls_pubkey_t key,
   key->pin.cb = fn;
   key->pin.data = userdata;
 }
+
+/**
+ * gnutls_pubkey_import_x509_raw:
+ * @pkey: The public key
+ * @data: The public key data to be imported
+ * @format: The format of the public key
+ * @flags: should be zero
+ *
+ * This function will import the given public key to the abstract
+ * #gnutls_pubkey_t structure. 
+ *
+ * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
+ *   negative error value.
+ *
+ * Since: 3.1.0
+ **/
+int gnutls_pubkey_import_x509_raw (gnutls_pubkey_t pkey,
+                                    const gnutls_datum_t * data,
+                                    gnutls_x509_crt_fmt_t format,
+                                    unsigned int flags)
+{
+  gnutls_x509_crt_t xpriv;
+  int ret;
+  
+  ret = gnutls_x509_crt_init(&xpriv);
+  if (ret < 0)
+    return gnutls_assert_val(ret);
+
+  ret = gnutls_x509_crt_import(xpriv, data, format);
+  if (ret < 0)
+    {
+      gnutls_assert();
+      goto cleanup;
+    }
+
+  ret = gnutls_pubkey_import_x509(pkey, xpriv, flags);
+  if (ret < 0)
+    {
+      gnutls_assert();
+      goto cleanup;
+    }
+
+  return 0;
+  
+cleanup:
+  gnutls_x509_crt_deinit(xpriv);
+
+  return ret;
+}
+
index b96d6305e894b515ee3b9ac7747ec8c92fd05c8d..36aa89cb74f0ac2038d17032247b0bc8d39c7b28 100644 (file)
@@ -69,6 +69,17 @@ int gnutls_pubkey_import_pkcs11 (gnutls_pubkey_t key,
 int gnutls_pubkey_import_openpgp (gnutls_pubkey_t key,
                                   gnutls_openpgp_crt_t crt,
                                   unsigned int flags);
+
+int gnutls_pubkey_import_openpgp_raw (gnutls_pubkey_t pkey,
+                                      const gnutls_datum_t * data,
+                                      gnutls_openpgp_crt_fmt_t format,
+                                      const gnutls_openpgp_keyid_t keyid,
+                                      unsigned int flags);
+int gnutls_pubkey_import_x509_raw (gnutls_pubkey_t pkey,
+                                    const gnutls_datum_t * data,
+                                    gnutls_x509_crt_fmt_t format,
+                                    unsigned int flags);
+
 int
 gnutls_pubkey_import_privkey (gnutls_pubkey_t key, gnutls_privkey_t pkey,
                               unsigned int usage, unsigned int flags);
index 578e159f17bfc3d6f9794b431eb0403b0b4cd932..c795ab18438834a1f30779db19ba753d206c534a 100644 (file)
@@ -854,6 +854,8 @@ GNUTLS_3_1_0 {
        gnutls_openpgp_privkey_export2;
        gnutls_pkcs11_obj_export2;
        gnutls_pkcs12_export2;
+       gnutls_pubkey_import_openpgp_raw;
+       gnutls_pubkey_import_x509_raw;
 } GNUTLS_3_0_0;
 
 GNUTLS_PRIVATE {