@@ -75,7 +75,6 @@ be_tls_init(bool isServerStart)
75
75
{
76
76
STACK_OF (X509_NAME ) * root_cert_list = NULL ;
77
77
SSL_CTX * context ;
78
- struct stat buf ;
79
78
80
79
/* This stuff need be done only once. */
81
80
if (!SSL_initialized )
@@ -133,63 +132,8 @@ be_tls_init(bool isServerStart)
133
132
goto error ;
134
133
}
135
134
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 ))
142
136
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
193
137
194
138
/*
195
139
* OK, try to load the private key file.
@@ -516,10 +460,6 @@ be_tls_open_server(Port *port)
516
460
port -> peer_cert_valid = true;
517
461
}
518
462
519
- ereport (DEBUG2 ,
520
- (errmsg ("SSL connection from \"%s\"" ,
521
- port -> peer_cn ? port -> peer_cn : "(anonymous)" )));
522
-
523
463
/* set up debugging/info callback */
524
464
SSL_CTX_set_info_callback (SSL_context , info_cb );
525
465
0 commit comments