11
11
*
12
12
*
13
13
* IDENTIFICATION
14
- * $PostgreSQL: pgsql/src/backend/libpq/be-secure.c,v 1.100 2010/05/26 15:52:37 tgl Exp $
14
+ * $PostgreSQL: pgsql/src/backend/libpq/be-secure.c,v 1.101 2010/05/26 16: 15:57 tgl Exp $
15
15
*
16
16
* Since the server static private key ($DataDir/server.key)
17
17
* will normally be stored unencrypted so that the database
18
18
* backend can restart automatically, it is important that
19
19
* we select an algorithm that continues to provide confidentiality
20
- * even if the attacker has the server's private key. Empheral
20
+ * even if the attacker has the server's private key. Ephemeral
21
21
* DH (EDH) keys provide this, and in fact provide Perfect Forward
22
22
* Secrecy (PFS) except for situations where the session can
23
23
* be hijacked during a periodic handshake/renegotiation.
@@ -113,7 +113,7 @@ char *SSLCipherSuites = NULL;
113
113
/* ------------------------------------------------------------ */
114
114
115
115
/*
116
- * Hardcoded DH parameters, used in empheral DH keying.
116
+ * Hardcoded DH parameters, used in ephemeral DH keying.
117
117
* As discussed above, EDH protects the confidentiality of
118
118
* sessions even if the static private key is compromised,
119
119
* so we are *highly* motivated to ensure that we can use
@@ -411,7 +411,6 @@ secure_write(Port *port, void *ptr, size_t len)
411
411
* directly so it gets passed through the socket/signals layer on Win32.
412
412
*
413
413
* They are closely modelled on the original socket implementations in OpenSSL.
414
- *
415
414
*/
416
415
417
416
static bool my_bio_initialized = false;
@@ -501,7 +500,7 @@ my_SSL_set_fd(SSL *s, int fd)
501
500
* to verify that the DBA-generated DH parameters file contains
502
501
* what we expect it to contain.
503
502
*/
504
- static DH *
503
+ static DH *
505
504
load_dh_file (int keylength )
506
505
{
507
506
FILE * fp ;
@@ -559,7 +558,7 @@ load_dh_file(int keylength)
559
558
* To prevent problems if the DH parameters files don't even
560
559
* exist, we can load DH parameters hardcoded into this file.
561
560
*/
562
- static DH *
561
+ static DH *
563
562
load_dh_buffer (const char * buffer , size_t len )
564
563
{
565
564
BIO * bio ;
@@ -579,7 +578,7 @@ load_dh_buffer(const char *buffer, size_t len)
579
578
}
580
579
581
580
/*
582
- * Generate an empheral DH key. Because this can take a long
581
+ * Generate an ephemeral DH key. Because this can take a long
583
582
* time to compute, we can use precomputed parameters of the
584
583
* common key sizes.
585
584
*
@@ -591,7 +590,7 @@ load_dh_buffer(const char *buffer, size_t len)
591
590
* the OpenSSL library can efficiently generate random keys from
592
591
* the information provided.
593
592
*/
594
- static DH *
593
+ static DH *
595
594
tmp_dh_cb (SSL * s , int is_export , int keylength )
596
595
{
597
596
DH * r = NULL ;
@@ -737,7 +736,7 @@ initialize_SSL(void)
737
736
SSLerrmessage ())));
738
737
739
738
/*
740
- * Load and verify certificate and private key
739
+ * Load and verify server's certificate and private key
741
740
*/
742
741
if (SSL_CTX_use_certificate_chain_file (SSL_context ,
743
742
SERVER_CERT_FILE ) != 1 )
@@ -782,62 +781,59 @@ initialize_SSL(void)
782
781
SSLerrmessage ())));
783
782
}
784
783
785
- /* set up empheral DH keys */
784
+ /* set up ephemeral DH keys, and disallow SSL v2 while at it */
786
785
SSL_CTX_set_tmp_dh_callback (SSL_context , tmp_dh_cb );
787
786
SSL_CTX_set_options (SSL_context , SSL_OP_SINGLE_DH_USE | SSL_OP_NO_SSLv2 );
788
787
789
- /* setup the allowed cipher list */
788
+ /* set up the allowed cipher list */
790
789
if (SSL_CTX_set_cipher_list (SSL_context , SSLCipherSuites ) != 1 )
791
790
elog (FATAL , "could not set the cipher list (no valid ciphers available)" );
792
791
793
792
/*
794
793
* Attempt to load CA store, so we can verify client certificates if
795
794
* needed.
796
795
*/
797
- if (access (ROOT_CERT_FILE , R_OK ))
798
- {
799
- ssl_loaded_verify_locations = false;
796
+ ssl_loaded_verify_locations = false;
800
797
798
+ if (access (ROOT_CERT_FILE , R_OK ) != 0 )
799
+ {
801
800
/*
802
- * If root certificate file simply not found. Don 't log an error here,
801
+ * If root certificate file simply not found, don 't log an error here,
803
802
* because it's quite likely the user isn't planning on using client
804
803
* certificates. If we can't access it for other reasons, it is an
805
804
* error.
806
805
*/
807
806
if (errno != ENOENT )
808
- {
809
807
ereport (FATAL ,
810
808
(errmsg ("could not access root certificate file \"%s\": %m" ,
811
809
ROOT_CERT_FILE )));
812
- }
813
810
}
814
811
else if (SSL_CTX_load_verify_locations (SSL_context , ROOT_CERT_FILE , NULL ) != 1 ||
815
812
(root_cert_list = SSL_load_client_CA_file (ROOT_CERT_FILE )) == NULL )
816
813
{
817
814
/*
818
815
* File was there, but we could not load it. This means the file is
819
- * somehow broken, and we cannot do verification at all - so abort
820
- * here.
816
+ * somehow broken, and we cannot do verification at all - so fail.
821
817
*/
822
- ssl_loaded_verify_locations = false;
823
818
ereport (FATAL ,
824
819
(errmsg ("could not load root certificate file \"%s\": %s" ,
825
820
ROOT_CERT_FILE , SSLerrmessage ())));
826
821
}
827
822
else
828
823
{
829
- /*
830
- * Check the Certificate Revocation List (CRL) if file exists.
831
- * http://searchsecurity.techtarget.com/sDefinition/0,,sid14_gci803160,
832
- * 00.html
824
+ /*----------
825
+ * Load the Certificate Revocation List (CRL) if file exists.
826
+ * http://searchsecurity.techtarget.com/sDefinition/0,,sid14_gci803160,00.html
827
+ *----------
833
828
*/
834
829
X509_STORE * cvstore = SSL_CTX_get_cert_store (SSL_context );
835
830
836
831
if (cvstore )
837
832
{
838
833
/* Set the flags to check against the complete CRL chain */
839
834
if (X509_STORE_load_locations (cvstore , ROOT_CRL_FILE , NULL ) == 1 )
840
- /* OpenSSL 0.96 does not support X509_V_FLAG_CRL_CHECK */
835
+ {
836
+ /* OpenSSL 0.96 does not support X509_V_FLAG_CRL_CHECK */
841
837
#ifdef X509_V_FLAG_CRL_CHECK
842
838
X509_STORE_set_flags (cvstore ,
843
839
X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL );
@@ -847,6 +843,7 @@ initialize_SSL(void)
847
843
ROOT_CRL_FILE ),
848
844
errdetail ("SSL library does not support certificate revocation lists." )));
849
845
#endif
846
+ }
850
847
else
851
848
{
852
849
/* Not fatal - we do not require CRL */
@@ -858,14 +855,15 @@ initialize_SSL(void)
858
855
859
856
/*
860
857
* Always ask for SSL client cert, but don't fail if it's not
861
- * presented. We'll fail later in this case, based on what we find
862
- * in pg_hba.conf.
858
+ * presented. We might fail such connections later, depending on
859
+ * what we find in pg_hba.conf.
863
860
*/
864
861
SSL_CTX_set_verify (SSL_context ,
865
862
(SSL_VERIFY_PEER |
866
863
SSL_VERIFY_CLIENT_ONCE ),
867
864
verify_cb );
868
865
866
+ /* Set flag to remember CA store is successfully loaded */
869
867
ssl_loaded_verify_locations = true;
870
868
}
871
869
0 commit comments