summaryrefslogtreecommitdiff
path: root/lib/urls.c
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2014-11-23 09:11:38 +0100
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2014-11-23 10:08:03 +0100
commitb9dd3af9a17d0d4726df50515b176808ace69d18 (patch)
tree1daebd8c6d3cc12fb38eca22354a80b033ee7ea1 /lib/urls.c
parent54b0fb87f065320b42fe4b9fdd18f5348382b65b (diff)
downloadgnutls-b9dd3af9a17d0d4726df50515b176808ace69d18.tar.gz
Added the ability to register application specific URLs for keys and certs
Diffstat (limited to 'lib/urls.c')
-rw-r--r--lib/urls.c99
1 files changed, 99 insertions, 0 deletions
diff --git a/lib/urls.c b/lib/urls.c
index f68bec71cb..269a3236da 100644
--- a/lib/urls.c
+++ b/lib/urls.c
@@ -22,6 +22,12 @@
#include <gnutls_errors.h>
#include <gnutls_str.h>
#include "urls.h"
+#include "system-keys.h"
+
+#define MAX_CUSTOM_URLS 8
+
+gnutls_custom_url_st _gnutls_custom_urls[MAX_CUSTOM_URLS];
+unsigned _gnutls_custom_urls_size = 0;
static const char *_types[] =
{ "object-type=cert", "object-type=private", NULL };
@@ -90,3 +96,96 @@ char *_gnutls_sanitize_url(const char *url, unsigned type)
return gnutls_strdup(url);
}
}
+
+/**
+ * gnutls_url_is_supported:
+ * @url: A PKCS 11 url
+ *
+ * Check whether url is supported. Depending on the system libraries
+ * GnuTLS may support pkcs11 or tpmkey URLs.
+ *
+ * Returns: return non-zero if the given URL is supported, and zero if
+ * it is not known.
+ *
+ * Since: 3.1.0
+ **/
+int gnutls_url_is_supported(const char *url)
+{
+ unsigned i;
+#ifdef ENABLE_PKCS11
+ if (strncmp(url, PKCS11_URL, sizeof(PKCS11_URL)-1) == 0)
+ return 1;
+#endif
+#ifdef HAVE_TROUSERS
+ if (strncmp(url, TPMKEY_URL, sizeof(TPMKEY_URL)-1) == 0)
+ return 1;
+#endif
+ if (strncmp(url, SYSTEM_URL, sizeof(SYSTEM_URL)-1) == 0)
+ return _gnutls_system_url_is_supported(url);
+
+ for (i=0;i<_gnutls_custom_urls_size;i++) {
+ if (strncmp(url, _gnutls_custom_urls[i].name, _gnutls_custom_urls[i].name_size) == 0)
+ return 1;
+ }
+
+ return 0;
+}
+
+int _gnutls_url_is_known(const char *url)
+{
+ unsigned i;
+
+ if (strncmp(url, PKCS11_URL, sizeof(PKCS11_URL)-1) == 0)
+ return 1;
+ else if (strncmp(url, TPMKEY_URL, sizeof(TPMKEY_URL)-1) == 0)
+ return 1;
+ else if (strncmp(url, SYSTEM_URL, sizeof(SYSTEM_URL)-1) == 0)
+ return 1;
+ else {
+ for (i=0;i<_gnutls_custom_urls_size;i++) {
+ if (strncmp(url, _gnutls_custom_urls[i].name, _gnutls_custom_urls[i].name_size) == 0)
+ return 1;
+ }
+ return 0;
+ }
+}
+
+/**
+ * gnutls_register_custom_url:
+ * @st: A %gnutls_custom_url_st structure
+ *
+ * Register a custom URL. This will affect the following functions:
+ * gnutls_url_is_supported(), gnutls_privkey_import_url(),
+ * gnutls_pubkey_import_url, gnutls_x509_crt_import_url()
+ * and all functions that depend on
+ * them, e.g., gnutls_certificate_set_x509_key_file2().
+ *
+ * The provided structure and callback functions must be valid throughout
+ * the lifetime of the process. The registration of an existing URL type
+ * will fail with %GNUTLS_E_INVALID_REQUEST.
+ *
+ * This function is not thread safe.
+ *
+ * Returns: returns zero if the given structure was imported or a negative value otherwise.
+ *
+ * Since: 3.4.0
+ **/
+int gnutls_register_custom_url(const gnutls_custom_url_st *st)
+{
+ unsigned i;
+
+ for (i=0;i<_gnutls_custom_urls_size;i++) {
+ if (_gnutls_custom_urls[i].name_size == st->name_size &&
+ strcmp(_gnutls_custom_urls[i].name, st->name) == 0) {
+ return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
+ }
+ }
+
+ if (_gnutls_custom_urls_size < MAX_CUSTOM_URLS-1) {
+ memcpy(&_gnutls_custom_urls[_gnutls_custom_urls_size], st, sizeof(*st));
+ _gnutls_custom_urls_size++;
+ return 0;
+ } else {
+ return gnutls_assert_val(GNUTLS_E_UNIMPLEMENTED_FEATURE);
+ }
+}