@@ -75,7 +75,6 @@ be_tls_init(bool isServerStart)
7575{
7676 STACK_OF (X509_NAME ) * root_cert_list = NULL ;
7777 SSL_CTX * context ;
78- struct stat buf ;
7978
8079 /* This stuff need be done only once. */
8180 if (!SSL_initialized )
@@ -133,63 +132,8 @@ be_tls_init(bool isServerStart)
133132 goto error ;
134133 }
135134
136- if (stat (ssl_key_file , & buf ) != 0 )
137- {
138- ereport (isServerStart ? FATAL : LOG ,
139- (errcode_for_file_access (),
140- errmsg ("could not access private key file \"%s\": %m" ,
141- ssl_key_file )));
135+ if (!check_ssl_key_file_permissions (ssl_key_file , isServerStart ))
142136 goto error ;
143- }
144-
145- if (!S_ISREG (buf .st_mode ))
146- {
147- ereport (isServerStart ? FATAL : LOG ,
148- (errcode (ERRCODE_CONFIG_FILE_ERROR ),
149- errmsg ("private key file \"%s\" is not a regular file" ,
150- ssl_key_file )));
151- goto error ;
152- }
153-
154- /*
155- * Refuse to load key files owned by users other than us or root.
156- *
157- * XXX surely we can check this on Windows somehow, too.
158- */
159- #if !defined(WIN32 ) && !defined(__CYGWIN__ )
160- if (buf .st_uid != geteuid () && buf .st_uid != 0 )
161- {
162- ereport (isServerStart ? FATAL : LOG ,
163- (errcode (ERRCODE_CONFIG_FILE_ERROR ),
164- errmsg ("private key file \"%s\" must be owned by the database user or root" ,
165- ssl_key_file )));
166- goto error ;
167- }
168- #endif
169-
170- /*
171- * Require no public access to key file. If the file is owned by us,
172- * require mode 0600 or less. If owned by root, require 0640 or less to
173- * allow read access through our gid, or a supplementary gid that allows
174- * to read system-wide certificates.
175- *
176- * XXX temporarily suppress check when on Windows, because there may not
177- * be proper support for Unix-y file permissions. Need to think of a
178- * reasonable check to apply on Windows. (See also the data directory
179- * permission check in postmaster.c)
180- */
181- #if !defined(WIN32 ) && !defined(__CYGWIN__ )
182- if ((buf .st_uid == geteuid () && buf .st_mode & (S_IRWXG | S_IRWXO )) ||
183- (buf .st_uid == 0 && buf .st_mode & (S_IWGRP | S_IXGRP | S_IRWXO )))
184- {
185- ereport (isServerStart ? FATAL : LOG ,
186- (errcode (ERRCODE_CONFIG_FILE_ERROR ),
187- errmsg ("private key file \"%s\" has group or world access" ,
188- ssl_key_file ),
189- errdetail ("File must have permissions u=rw (0600) or less if owned by the database user, or permissions u=rw,g=r (0640) or less if owned by root." )));
190- goto error ;
191- }
192- #endif
193137
194138 /*
195139 * OK, try to load the private key file.
@@ -516,10 +460,6 @@ be_tls_open_server(Port *port)
516460 port -> peer_cert_valid = true;
517461 }
518462
519- ereport (DEBUG2 ,
520- (errmsg ("SSL connection from \"%s\"" ,
521- port -> peer_cn ? port -> peer_cn : "(anonymous)" )));
522-
523463 /* set up debugging/info callback */
524464 SSL_CTX_set_info_callback (SSL_context , info_cb );
525465
0 commit comments