openldap-nss-regex-search-hashed-cacert-dir.patch 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. MozNSS: better file name matching for hashed CA certificate directory
  2. CA certificate files in OpenSSL compatible CACERTDIR were loaded if the file extension was '.0'. However the file name
  3. should be 8 letters long certificate hash of the certificate subject name, followed by a numeric suffix which is used
  4. to differentiate between two certificates with the same subject name.
  5. Wit this patch, certificate file names are matched correctly (using regular expressions).
  6. Author: Jan Vcelak <jvcelak@redhat.com>
  7. Upstream ITS: #7374
  8. Resolves: #852786
  9. diff --git a/libraries/libldap/tls_m.c b/libraries/libldap/tls_m.c
  10. index 5e49fc5..61d71d4 100644
  11. --- a/libraries/libldap/tls_m.c
  12. +++ b/libraries/libldap/tls_m.c
  13. @@ -38,6 +38,7 @@
  14. #include <ac/unistd.h>
  15. #include <ac/param.h>
  16. #include <ac/dirent.h>
  17. +#include <ac/regex.h>
  18. #include "ldap-int.h"
  19. #include "ldap-tls.h"
  20. @@ -118,9 +119,7 @@ static const PRIOMethods tlsm_PR_methods;
  21. #define PEM_LIBRARY "nsspem"
  22. #define PEM_MODULE "PEM"
  23. -/* hash files for use with cacertdir have this file name suffix */
  24. -#define PEM_CA_HASH_FILE_SUFFIX ".0"
  25. -#define PEM_CA_HASH_FILE_SUFFIX_LEN 2
  26. +#define PEM_CA_HASH_FILE_REGEX "^[0-9a-f]{8}\\.[0-9]+$"
  27. static SECMODModule *pem_module;
  28. @@ -1541,6 +1540,7 @@ tlsm_init_ca_certs( tlsm_ctx *ctx, const char *cacertfile, const char *cacertdir
  29. PRDir *dir;
  30. PRDirEntry *entry;
  31. PRStatus fistatus = PR_FAILURE;
  32. + regex_t hashfile_re;
  33. memset( &fi, 0, sizeof(fi) );
  34. fistatus = PR_GetFileInfo( cacertdir, &fi );
  35. @@ -1570,20 +1570,30 @@ tlsm_init_ca_certs( tlsm_ctx *ctx, const char *cacertfile, const char *cacertdir
  36. goto done;
  37. }
  38. + if ( regcomp( &hashfile_re, PEM_CA_HASH_FILE_REGEX, REG_NOSUB|REG_EXTENDED ) != 0 ) {
  39. + Debug( LDAP_DEBUG_ANY, "TLS: cannot compile regex for CA hash files matching\n", 0, 0, 0 );
  40. + goto done;
  41. + }
  42. +
  43. do {
  44. entry = PR_ReadDir( dir, PR_SKIP_BOTH | PR_SKIP_HIDDEN );
  45. if ( ( NULL != entry ) && ( NULL != entry->name ) ) {
  46. char *fullpath = NULL;
  47. - char *ptr;
  48. + int match;
  49. - ptr = PL_strrstr( entry->name, PEM_CA_HASH_FILE_SUFFIX );
  50. - if ( ( ptr == NULL ) || ( *(ptr + PEM_CA_HASH_FILE_SUFFIX_LEN) != '\0' ) ) {
  51. + match = regexec( &hashfile_re, entry->name, 0, NULL, 0 );
  52. + if ( match == REG_NOMATCH ) {
  53. Debug( LDAP_DEBUG_TRACE,
  54. - "TLS: file %s does not end in [%s] - does not appear to be a CA certificate "
  55. - "directory file with a properly hashed file name - skipping.\n",
  56. - entry->name, PEM_CA_HASH_FILE_SUFFIX, 0 );
  57. + "TLS: skipping '%s' - filename does not have expected format "
  58. + "(certificate hash with numeric suffix)\n", entry->name, 0, 0 );
  59. + continue;
  60. + } else if ( match != 0 ) {
  61. + Debug( LDAP_DEBUG_ANY,
  62. + "TLS: cannot execute regex for CA hash file matching (%d).\n",
  63. + match, 0, 0 );
  64. continue;
  65. }
  66. +
  67. fullpath = PR_smprintf( "%s/%s", cacertdir, entry->name );
  68. if ( !tlsm_add_cert_from_file( ctx, fullpath, isca ) ) {
  69. Debug( LDAP_DEBUG_TRACE,
  70. @@ -1599,6 +1609,7 @@ tlsm_init_ca_certs( tlsm_ctx *ctx, const char *cacertfile, const char *cacertdir
  71. PR_smprintf_free( fullpath );
  72. }
  73. } while ( NULL != entry );
  74. + regfree ( &hashfile_re );
  75. PR_CloseDir( dir );
  76. }
  77. done:
  78. --
  79. 1.7.11.4