You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
3.6 KiB

  1. From c3f68d987c00284d91ad6599a013b7111662545b Mon Sep 17 00:00:00 2001
  2. From: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
  3. Date: Fri, 2 Sep 2016 21:33:33 +0000
  4. Subject: [PATCH] uw-imap: compile against openssl 1.1.0
  5. I *think* I replaced access to cert->name with certificate's subject name. I
  6. assume that the re-aranged C-code is doing the same thing. A double check
  7. wouldn't hurt :)
  8. Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
  9. ---
  10. src/osdep/unix/ssl_unix.c | 28 +++++++++++++++++-----------
  11. 1 file changed, 17 insertions(+), 11 deletions(-)
  12. diff --git a/src/osdep/unix/ssl_unix.c b/src/osdep/unix/ssl_unix.c
  13. index 3bfdff3..836e9fa 100644
  14. --- a/src/osdep/unix/ssl_unix.c
  15. +++ b/src/osdep/unix/ssl_unix.c
  16. @@ -59,7 +59,7 @@ typedef struct ssl_stream {
  17. static SSLSTREAM *ssl_start(TCPSTREAM *tstream,char *host,unsigned long flags);
  18. static char *ssl_start_work (SSLSTREAM *stream,char *host,unsigned long flags);
  19. static int ssl_open_verify (int ok,X509_STORE_CTX *ctx);
  20. -static char *ssl_validate_cert (X509 *cert,char *host);
  21. +static char *ssl_validate_cert (X509 *cert,char *host, char *cert_subj);
  22. static long ssl_compare_hostnames (unsigned char *s,unsigned char *pat);
  23. static char *ssl_getline_work (SSLSTREAM *stream,unsigned long *size,
  24. long *contd);
  25. @@ -210,6 +210,7 @@ static char *ssl_start_work (SSLSTREAM *stream,char *host,unsigned long flags)
  26. BIO *bio;
  27. X509 *cert;
  28. unsigned long sl,tl;
  29. + char cert_subj[250];
  30. char *s,*t,*err,tmp[MAILTMPLEN];
  31. sslcertificatequery_t scq =
  32. (sslcertificatequery_t) mail_parameters (NIL,GET_SSLCERTIFICATEQUERY,NIL);
  33. @@ -266,14 +267,19 @@ static char *ssl_start_work (SSLSTREAM *stream,char *host,unsigned long flags)
  34. if (SSL_write (stream->con,"",0) < 0)
  35. return ssl_last_error ? ssl_last_error : "SSL negotiation failed";
  36. /* need to validate host names? */
  37. - if (!(flags & NET_NOVALIDATECERT) &&
  38. - (err = ssl_validate_cert (cert = SSL_get_peer_certificate (stream->con),
  39. - host))) {
  40. - /* application callback */
  41. - if (scq) return (*scq) (err,host,cert ? cert->name : "???") ? NIL : "";
  42. + if (!(flags & NET_NOVALIDATECERT)) {
  43. +
  44. + cert_subj[0] = '\0';
  45. + cert = SSL_get_peer_certificate(stream->con);
  46. + if (cert)
  47. + X509_NAME_oneline(X509_get_subject_name(cert), cert_subj, sizeof(cert_subj));
  48. + err = ssl_validate_cert (cert, host, cert_subj);
  49. + if (err)
  50. + /* application callback */
  51. + if (scq) return (*scq) (err,host,cert ? cert_subj : "???") ? NIL : "";
  52. /* error message to return via mm_log() */
  53. - sprintf (tmp,"*%.128s: %.255s",err,cert ? cert->name : "???");
  54. - return ssl_last_error = cpystr (tmp);
  55. + sprintf (tmp,"*%.128s: %.255s",err,cert ? cert_subj : "???");
  56. + return ssl_last_error = cpystr (tmp);
  57. }
  58. return NIL;
  59. }
  60. @@ -313,7 +319,7 @@ static int ssl_open_verify (int ok,X509_STORE_CTX *ctx)
  61. * Returns: NIL if validated, else string of error message
  62. */
  63. -static char *ssl_validate_cert (X509 *cert,char *host)
  64. +static char *ssl_validate_cert (X509 *cert,char *host, char *cert_subj)
  65. {
  66. int i,n;
  67. char *s,*t,*ret;
  68. @@ -322,9 +328,9 @@ static char *ssl_validate_cert (X509 *cert,char *host)
  69. /* make sure have a certificate */
  70. if (!cert) ret = "No certificate from server";
  71. /* and that it has a name */
  72. - else if (!cert->name) ret = "No name in certificate";
  73. + else if (cert_subj[0] == '\0') ret = "No name in certificate";
  74. /* locate CN */
  75. - else if (s = strstr (cert->name,"/CN=")) {
  76. + else if (s = strstr (cert_subj,"/CN=")) {
  77. if (t = strchr (s += 4,'/')) *t = '\0';
  78. /* host name matches pattern? */
  79. ret = ssl_compare_hostnames (host,s) ? NIL :
  80. --
  81. 2.9.3