
// Load the trusted CA certificates.
gnutls_certificate_credentials_t cred = NULL;
int ret = gnutls_certificate_allocate_credentials (&cred);
if (ret != GNUTLS_E_SUCCESS) {
  fprintf(stderr, "error: gnutls_certificate_allocate_credentials: %s\n",
	    gnutls_strerror(ret));
  exit(1);
}

ret = gnutls_certificate_set_x509_system_trust(cred);
if (ret == 0) {
  fprintf(stderr, "error: no certificates found in system trust store\n");
  exit(1);
}
if (ret < 0) {
  fprintf(stderr, "error: gnutls_certificate_set_x509_system_trust: %s\n",
	    gnutls_strerror(ret));
  exit(1);
}

