Skip to content
ssluse.c 30.9 KiB
Newer Older
    failf(data, "SSL: couldn't get peer certificate!");
  }
  infof (data, "Server certificate:\n");
Daniel Stenberg's avatar
Daniel Stenberg committed
  
  str = X509_NAME_oneline (X509_get_subject_name (conn->ssl.server_cert),
                           NULL, 0);
  if(!str) {
    failf(data, "SSL: couldn't get X509-subject!");
  }
  infof(data, "\t subject: %s\n", str);
  CRYPTO_free(str);

  certdate = X509_get_notBefore(conn->ssl.server_cert);
  Curl_ASN1_UTCTIME_output(conn, "\t start date: ", certdate);

  certdate = X509_get_notAfter(conn->ssl.server_cert);
  Curl_ASN1_UTCTIME_output(conn, "\t expire date: ", certdate);

    if (X509_NAME_get_text_by_NID(X509_get_subject_name(conn->ssl.server_cert),
                                  NID_commonName,
                                  peer_CN,
                                  sizeof(peer_CN)) < 0) {
      /* Failed to get the CN field from the server's certificate */
        failf(data, "SSL: unable to obtain common name from peer certificate");
        X509_free(conn->ssl.server_cert);
        return CURLE_SSL_PEER_CERTIFICATE;
      }
      else
        /* Consider verifyhost == 1 as an "OK" for a missing CN field, but we
           output a note about the situation */
        infof(data, "\t common name: WARNING couldn't obtain\n");
    }
    else {
      /* Compare the CN field with the remote host name */
      if (!cert_hostcheck(peer_CN, conn->hostname)) {
        if (data->set.ssl.verifyhost > 1) {
          failf(data, "SSL: certificate subject name '%s' does not match "
                "target host name '%s'",
                peer_CN, conn->hostname);
          X509_free(conn->ssl.server_cert);
          return CURLE_SSL_PEER_CERTIFICATE;
        }
        else
          infof(data,
                "\t common name: %s (does not match '%s')\n",
                peer_CN, conn->hostname);
      }
      else
        infof(data, "\t common name: %s (matched)\n", peer_CN);
  str = X509_NAME_oneline (X509_get_issuer_name  (conn->ssl.server_cert),
                           NULL, 0);
  if(!str) {
    failf(data, "SSL: couldn't get X509-issuer name!");
  }
  infof(data, "\t issuer: %s\n", str);
  CRYPTO_free(str);
Daniel Stenberg's avatar
Daniel Stenberg committed

  /* We could do all sorts of certificate verification stuff here before
     deallocating the certificate. */
Daniel Stenberg's avatar
Daniel Stenberg committed

  if(data->set.ssl.verifypeer) {
    data->set.ssl.certverifyresult=SSL_get_verify_result(conn->ssl.handle);
    if (data->set.ssl.certverifyresult != X509_V_OK) {
      failf(data, "SSL certificate verify result: %d",
Daniel Stenberg's avatar
Daniel Stenberg committed

  X509_free(conn->ssl.server_cert);
Daniel Stenberg's avatar
Daniel Stenberg committed
#else /* USE_SSLEAY */
  /* this is for "-ansi -Wall -pedantic" to stop complaining!   (rabe) */
Daniel Stenberg's avatar
Daniel Stenberg committed
#endif
Daniel Stenberg's avatar
Daniel Stenberg committed
}