src/lib/tls.c
bool tls_postconnect_verify_cn(JCR *jcr, TLS_CONNECTION *tls, alist *verify_list)
{
   SSL *ssl = tls->openssl;
   X509 *cert;
   X509_NAME *subject;
   bool auth_success = false;
   char data[256];

   /* Check if peer provided a certificate */
   if (!(cert = SSL_get_peer_certificate(ssl))) {
      Qmsg0(jcr, M_ERROR, 0, _("Peer failed to present a TLS certificate\n"));
      return false;
   }

   if ((subject = X509_get_subject_name(cert)) != NULL) {
      if (X509_NAME_get_text_by_NID(subject, NID_commonName, data, sizeof(data)) > 0) {
         char *cn;
         /* NULL terminate data */
         data[255] = 0;

         /* Try all the CNs in the list */
         foreach_alist(cn, verify_list) {
            if (strcasecmp(data, cn) == 0) {
               auth_success = true;
            }
         }
      }
   }

   X509_free(cert);
   return auth_success;
}
/*
 * Verifies a list of common names against the certificate
 * commonName attribute.
 *  Returns: true on success
 *           false on failure
 */
Verifies a list of common names against the certificate
commonName attribute.
Returns: true on success
false on failure
Verifies a list of common names against the certificate commonName attribute . Returns : true on success false on failure
bool tls_postconnect_verify_cn(JCR *jcr, TLS_CONNECTION *tls, alist *verify_list)
{
   SSL *ssl = tls->openssl;
   X509 *cert;
   X509_NAME *subject;
   bool auth_success = false;
   char data[256];
   if (!(cert = SSL_get_peer_certificate(ssl))) {
      Qmsg0(jcr, M_ERROR, 0, _("Peer failed to present a TLS certificate\n"));
      return false;
   }
   if ((subject = X509_get_subject_name(cert)) != NULL) {
      if (X509_NAME_get_text_by_NID(subject, NID_commonName, data, sizeof(data)) > 0) {
         char *cn;
         data[255] = 0;
         foreach_alist(cn, verify_list) {
            if (strcasecmp(data, cn) == 0) {
               auth_success = true;
            }
         }
      }
   }
   X509_free(cert);
   return auth_success;
}
bool tls_postconnect_verify_cn ( JCR * jcr , TLS_CONNECTION * tls , alist * verify_list ) { SSL * ssl = tls -> openssl ; X509 * cert ; X509_NAME * subject ; bool auth_success = false ; char data [ 256 ] ; if ( ! ( cert = SSL_get_peer_certificate ( ssl ) ) ) { Qmsg0 ( jcr , M_ERROR , 0 , _ ( " \n " ) ) ; return false ; } if ( ( subject = X509_get_subject_name ( cert ) ) != NULL ) { if ( X509_NAME_get_text_by_NID ( subject , NID_commonName , data , sizeof ( data ) ) > 0 ) { char * cn ; data [ 255 ] = 0 ; foreach_alist ( cn , verify_list ) { if ( strcasecmp ( data , cn ) == 0 ) { auth_success = true ; } } } } X509_free ( cert ) ; return auth_success ; }
Verifies a list of common names against the certificate
 commonName attribute.
Verifies a list of common names against the certificate commonName attribute .
/* Check if peer provided a certificate */ /* NULL terminate data */ /* Try all the CNs in the list */