} else if (ret < 0) {
fprintf(stderr, "*** Error: %s\n", gnutls_strerror(ret));
goto end;
- } else if (ret > 0) {
- printf("- Received %d bytes: ", ret);
- for (ii = 0; ii < ret; ii++) {
- fputc(buffer[ii], stdout);
- }
- fputs("\n", stdout);
}
+
+ printf("- Received %d bytes: ", ret);
+ for (ii = 0; ii < ret; ii++) {
+ fputc(buffer[ii], stdout);
+ }
+ fputs("\n", stdout);
+
gnutls_bye( session, GNUTLS_SHUT_RDWR);
end:
/* Set the priorities.
*/
gnutls_set_default_priority(session);
-
- /* use GNUTLS_KX_SRP
- */
gnutls_kx_set_priority(session, kx_priority);
} else if (ret < 0) {
fprintf(stderr, "*** Error: %s\n", gnutls_strerror(ret));
goto end;
- } else if (ret > 0) {
- printf("- Received %d bytes: ", ret);
- for (ii = 0; ii < ret; ii++) {
- fputc(buffer[ii], stdout);
- }
- fputs("\n", stdout);
}
+
+ printf("- Received %d bytes: ", ret);
+ for (ii = 0; ii < ret; ii++) {
+ fputc(buffer[ii], stdout);
+ }
+ fputs("\n", stdout);
+
gnutls_bye( session, GNUTLS_SHUT_RDWR);
end:
int cert_list_size;
gnutls_x509_crt cert;
- /* This function only works with X.509 certificates.
- */
- if ( gnutls_certificate_type_get(session) != GNUTLS_CRT_X509)
- return;
/* This verification function uses the trusted CAs in the credentials
* structure. So you must have installed one or more CA certificates.
printf("The certificate has been revoked.\n");
+ /* Up to here the process is the same for X.509 certificates and
+ * OpenPGP keys. From now on X.509 certificates are assumed. This can
+ * be easily extended to work with openpgp keys as well.
+ */
+ if ( gnutls_certificate_type_get(session) != GNUTLS_CRT_X509)
+ return;
+
if ( gnutls_x509_crt_init( &cert) < 0) {
printf("error in initialization\n");
return;
}
if ( !gnutls_x509_crt_check_hostname( cert, hostname)) {
- printf("The certificate does not match hostname\n");
+ printf("The certificate's owner does not match hostname '%s'\n", hostname);
return;
}
\subsection{Obtaining session information}
The following function prints information about the current \tls{} session.
-\par
This function should be called after a successful
\printfunc{gnutls_handshake}{gnutls\_handshake}
\input{ex-session-info}
\subsection{Verifying peer's certificate}
-\par A TLS connection is not secure just after the handshake has finished.
-It must be considered secure, after the peer's identity has been
-verified. That is, you usually have to verify not only the peer's
+A TLS connection is not secure just after the handshake has finished.
+It must be considered secure, after the peer's certificate and identity have been
+verified. That is, you usually have to verify not only the signature in peer's
certificate, but also the hostname in the certificate, expiration dates etc.
After this step you should treat the connection as being a secure one.