@@ -1011,54 +1011,62 @@ _httpTLSStart(http_t *http) // I - Connection to server
10111011 // Negotiate a TLS connection as a server
10121012 char crtfile [1024 ], // Certificate file
10131013 keyfile [1024 ]; // Private key file
1014- const char * cn , // Common name to lookup
1014+ const char * cn = NULL , // Common name to lookup
10151015 * cnptr ; // Pointer into common name
10161016 int have_creds = 0 ; // Have credentials?
10171017 int key_status , crt_status ; // Key and certificate load status
10181018
10191019 context = SSL_CTX_new (TLS_server_method ());
10201020
10211021 // Find the TLS certificate...
1022- if (http -> fields [HTTP_FIELD_HOST ])
1023- {
1024- // Use hostname for TLS upgrade...
1025- strlcpy (hostname , http -> fields [HTTP_FIELD_HOST ], sizeof (hostname ));
1026- }
1027- else
1022+ _cupsMutexLock (& tls_mutex );
1023+
1024+ if (!tls_common_name )
10281025 {
1029- // Resolve hostname from connection address...
1030- http_addr_t addr ; // Connection address
1031- socklen_t addrlen ; // Length of address
1026+ _cupsMutexUnlock (& tls_mutex );
10321027
1033- addrlen = sizeof (addr );
1034- if (getsockname (http -> fd , (struct sockaddr * )& addr , & addrlen ))
1028+ if (http -> fields [HTTP_FIELD_HOST ])
10351029 {
1036- // Unable to get local socket address so use default...
1037- DEBUG_printf (("4_httpTLSStart: Unable to get socket address: %s" , strerror (errno )));
1038- hostname [0 ] = '\0' ;
1039- }
1040- else if (httpAddrLocalhost (& addr ))
1041- {
1042- // Local access top use default...
1043- hostname [0 ] = '\0' ;
1030+ // Use hostname for TLS upgrade...
1031+ strlcpy (hostname , http -> fields [HTTP_FIELD_HOST ], sizeof (hostname ));
10441032 }
10451033 else
10461034 {
1047- // Lookup the socket address...
1048- httpAddrLookup (& addr , hostname , sizeof (hostname ));
1049- DEBUG_printf (("4_httpTLSStart: Resolved socket address to \"%s\"." , hostname ));
1035+ // Resolve hostname from connection address...
1036+ http_addr_t addr ; // Connection address
1037+ socklen_t addrlen ; // Length of address
1038+
1039+ addrlen = sizeof (addr );
1040+ if (getsockname (http -> fd , (struct sockaddr * )& addr , & addrlen ))
1041+ {
1042+ // Unable to get local socket address so use default...
1043+ DEBUG_printf (("4_httpTLSStart: Unable to get socket address: %s" , strerror (errno )));
1044+ hostname [0 ] = '\0' ;
1045+ }
1046+ else if (httpAddrLocalhost (& addr ))
1047+ {
1048+ // Local access top use default...
1049+ hostname [0 ] = '\0' ;
1050+ }
1051+ else
1052+ {
1053+ // Lookup the socket address...
1054+ httpAddrLookup (& addr , hostname , sizeof (hostname ));
1055+ DEBUG_printf (("4_httpTLSStart: Resolved socket address to \"%s\"." , hostname ));
1056+ }
10501057 }
1051- }
10521058
1053- if (isdigit (hostname [0 ] & 255 ) || hostname [0 ] == '[' )
1054- hostname [0 ] = '\0' ; // Don't allow numeric addresses
1059+ if (isdigit (hostname [0 ] & 255 ) || hostname [0 ] == '[' )
1060+ hostname [0 ] = '\0' ; // Don't allow numeric addresses
10551061
1056- if (hostname [0 ])
1057- cn = hostname ;
1058- else
1059- cn = tls_common_name ;
1062+ if (hostname [0 ])
1063+ cn = hostname ;
10601064
1061- _cupsMutexLock (& tls_mutex );
1065+ _cupsMutexLock (& tls_mutex );
1066+ }
1067+
1068+ if (!cn )
1069+ cn = tls_common_name ;
10621070
10631071 if (cn )
10641072 {
0 commit comments