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
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 \
--- /dev/null
+\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}
\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}