Show
Ignore:
Timestamp:
2008-06-28 20:33:01 (5 months ago)
Author:
Brendan Cully <brendan@…>
Branch:
HEAD
Message:

Extract CN from client certificate in gnutls.
Nothing currently uses it, but I suspect we should be using it as the
external auth name in mutt_sasl_client_new.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • mutt_ssl_gnutls.c

    r5431 r5432  
    170170} 
    171171 
     172static void tls_get_client_cert (CONNECTION* conn) 
     173{ 
     174  tlssockdata *data = conn->sockdata; 
     175  const gnutls_datum_t* crtdata; 
     176  gnutls_x509_crt_t clientcrt; 
     177  char* dn; 
     178  char* cn; 
     179  char* cnend; 
     180  size_t dnlen; 
     181 
     182  /* get our cert CN if we have one */ 
     183  if (!(crtdata = gnutls_certificate_get_ours (data->state))) 
     184    return; 
     185 
     186  if (gnutls_x509_crt_init (&clientcrt) < 0) 
     187  { 
     188    dprint (1, (debugfile, "Failed to init gnutls crt\n")); 
     189    return; 
     190  } 
     191  if (gnutls_x509_crt_import (clientcrt, crtdata, GNUTLS_X509_FMT_DER) < 0) 
     192  { 
     193    dprint (1, (debugfile, "Failed to import gnutls client crt\n")); 
     194    goto err_crt; 
     195  } 
     196  /* get length of DN */ 
     197  dnlen = 0; 
     198  gnutls_x509_crt_get_dn (clientcrt, NULL, &dnlen); 
     199  if (!(dn = calloc (1, dnlen))) 
     200  { 
     201    dprint (1, (debugfile, "could not allocate DN\n")); 
     202    goto err_crt; 
     203  } 
     204  gnutls_x509_crt_get_dn (clientcrt, dn, &dnlen); 
     205  dprint (2, (debugfile, "client certificate DN: %s\n", dn)); 
     206 
     207  /* extract CN to use as external user name */ 
     208  if (!(cn = strstr (dn, "CN="))) 
     209  { 
     210    dprint (1, (debugfile, "no CN found in DN\n")); 
     211    goto err_dn; 
     212  } 
     213  cn += 3; 
     214 
     215  if ((cnend = strstr (dn, ",EMAIL="))) 
     216    *cnend = '\0'; 
     217 
     218  dprint (2, (debugfile, "client CN: %s\n", cn)); 
     219 
     220err_dn: 
     221  FREE (&dn); 
     222err_crt: 
     223  gnutls_x509_crt_deinit (clientcrt); 
     224} 
     225 
    172226static int protocol_priority[] = {GNUTLS_TLS1, GNUTLS_SSL3, 0}; 
    173227 
     
    275329  /* NB: gnutls_cipher_get_key_size() returns key length in bytes */ 
    276330  conn->ssf = gnutls_cipher_get_key_size (gnutls_cipher_get (data->state)) * 8; 
     331 
     332  tls_get_client_cert (conn); 
    277333 
    278334  mutt_message (_("SSL/TLS connection using %s (%s/%s/%s)"),