]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Added a small example on how to use the certificate selection callback in client...
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Thu, 20 Feb 2003 07:38:21 +0000 (07:38 +0000)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Thu, 20 Feb 2003 07:38:21 +0000 (07:38 +0000)
doc/examples/Makefile.am
doc/tex/Makefile.am
doc/tex/ex-cert-select.tex [new file with mode: 0644]
doc/tex/ex-info.tex
doc/tex/examples.tex

index b3597d023fa734ca409e279f8b24a861148b7457..6fc8dcca049f5f1e83eea82c2a0de4d24852da3a 100644 (file)
@@ -1,3 +1,3 @@
 EXTRA_DIST = ex-alert.c ex-client-resume.c ex-client-srp.c ex-client1.c \
        ex-client2.c ex-info.c ex-rfc2818.c ex-serv-export.c ex-serv-pgp.c \
-       ex-serv-srp.c ex-serv1.c ex-pgp-keyserver.c
+       ex-serv-srp.c ex-serv1.c ex-pgp-keyserver.c ex-cert-select.c
index 813e49dacf538e0ee745f4c094b531de80591def..dec2a362aa99df1283c4652253a9b8e680e88323 100644 (file)
@@ -7,7 +7,7 @@ EXTRA_DIST = gnutls.tex gnutls.ps \
 EXAMPLE_OBJECTS = ex-alert.tex ex-client-srp.tex ex-serv-export.tex \
        ex-client1.tex ex-client2.tex ex-info.tex ex-rfc2818.tex \
        ex-serv1.tex ex-client-resume.tex ex-serv-srp.tex \
-       ex-serv-pgp.tex ex-pgp-keyserver.tex
+       ex-serv-pgp.tex ex-pgp-keyserver.tex ex-cert-select.tex
 
 TEX_OBJECTS = gnutls.tex ../../lib/gnutls-api.tex fdl.tex ../../lib/x509/x509-api.tex \
        macros.tex cover.tex ciphersuites.tex handshake.tex translayer.tex \
diff --git a/doc/tex/ex-cert-select.tex b/doc/tex/ex-cert-select.tex
new file mode 100644 (file)
index 0000000..3be546b
--- /dev/null
@@ -0,0 +1,45 @@
+\begin{verbatim}
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <gnutls/gnutls.h>
+#include <gnutls/x509.h>
+
+/* This callback should be associated with a session by calling
+ * gnutls_certificate_client_set_select_function( session, cert_callback),
+ * before a handshake.
+ */
+
+static int cert_callback(gnutls_session session,
+                        const gnutls_datum * client_certs, int client_certs_num,
+                        const gnutls_datum * req_ca_rdn, int nreqs)
+{
+   char issuer_dn[256];
+   int len, i, ret;
+
+   /* Print the server's trusted CAs
+    */
+   if (nreqs > 0)
+      printf("- Server's trusted authorities:\n");
+   else
+      printf("- Server did not send us any trusted authorities names.\n");
+
+   /* print the names (if any) */
+   for (i = 0; i < nreqs; i++) {
+      len = sizeof(issuer_dn);
+      ret = gnutls_x509_rdn_get(&req_ca_rdn[i], issuer_dn, &len);
+      if (ret >= 0) {
+        printf("   [%d]: ", i);
+        printf("%s\n", issuer_dn);
+      }
+   }
+
+   /* Select a certificate from the client_certs and return it's
+    * index.
+    */
+
+   return -1;
+
+}
+
+\end{verbatim}
index 0616d22df44639a6ac7755afe5f3e3d44be85990..1dcfb6508bb5fce67c420505dbba0cd6e97b6cdd 100644 (file)
@@ -3,6 +3,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <gnutls/gnutls.h>
+#include <gnutls/x509.h>
 
 static void print_x509_certificate_info(gnutls_session);
 
index 4adbdbe254d68b066f2043907d73b5fde161c1a8..aca1cdbacfb0b3c7d80452f062246ada4834dad4 100644 (file)
@@ -35,6 +35,15 @@ This function should be called after a successful
 
 \input{ex-info}
 
+\subsection{Using a callback to select the certificate to use}
+There are cases where a client holds several certificate and key pairs,
+and may want to choose the appropriate to send in the current session.
+The following example demonstrates the use of the certificate selection callback
+to assist in this purpose.
+\par
+
+\input{ex-cert-select}
+
 
 \subsection{Client with Resume capability example}
 \label{resume-example}