~ubuntu-branches/ubuntu/trusty/postgresql-8.4/trusty

« back to all changes in this revision

Viewing changes to src/backend/libpq/be-secure.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-11 16:59:35 UTC
  • mfrom: (5.1.1 karmic)
  • Revision ID: james.westby@ubuntu.com-20090711165935-jfwin6gfrxf0gfsi
Tags: 8.4.0-2
* debian/libpq-dev.install: Ship catalog/genbki.h. (Closes: #536139)
* debian/rules: Drop --enable-cassert for final release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 *
12
12
 *
13
13
 * IDENTIFICATION
14
 
 *        $PostgreSQL: pgsql/src/backend/libpq/be-secure.c,v 1.91 2009/05/11 08:06:21 mha Exp $
 
14
 *        $PostgreSQL: pgsql/src/backend/libpq/be-secure.c,v 1.92 2009/06/11 14:48:58 momjian 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
730
730
                 * Load and verify certificate and private key
731
731
                 */
732
732
                if (SSL_CTX_use_certificate_chain_file(SSL_context,
733
 
                                                                                  SERVER_CERT_FILE) != 1)
 
733
                                                                                           SERVER_CERT_FILE) != 1)
734
734
                        ereport(FATAL,
735
735
                                        (errcode(ERRCODE_CONFIG_FILE_ERROR),
736
736
                                  errmsg("could not load server certificate file \"%s\": %s",
754
754
                if (!S_ISREG(buf.st_mode) || buf.st_mode & (S_IRWXG | S_IRWXO))
755
755
                        ereport(FATAL,
756
756
                                        (errcode(ERRCODE_CONFIG_FILE_ERROR),
757
 
                                         errmsg("private key file \"%s\" has group or world access",
758
 
                                                        SERVER_PRIVATE_KEY_FILE),
759
 
                                         errdetail("Permissions should be u=rw (0600) or less.")));
 
757
                                  errmsg("private key file \"%s\" has group or world access",
 
758
                                                 SERVER_PRIVATE_KEY_FILE),
 
759
                                   errdetail("Permissions should be u=rw (0600) or less.")));
760
760
#endif
761
761
 
762
762
                if (SSL_CTX_use_PrivateKey_file(SSL_context,
763
 
                                                                                 SERVER_PRIVATE_KEY_FILE,
764
 
                                                                                 SSL_FILETYPE_PEM) != 1)
 
763
                                                                                SERVER_PRIVATE_KEY_FILE,
 
764
                                                                                SSL_FILETYPE_PEM) != 1)
765
765
                        ereport(FATAL,
766
766
                                        (errmsg("could not load private key file \"%s\": %s",
767
767
                                                        SERVER_PRIVATE_KEY_FILE, SSLerrmessage())));
781
781
                elog(FATAL, "could not set the cipher list (no valid ciphers available)");
782
782
 
783
783
        /*
784
 
         * Attempt to load CA store, so we can verify client certificates if needed.
 
784
         * Attempt to load CA store, so we can verify client certificates if
 
785
         * needed.
785
786
         */
786
787
        if (access(ROOT_CERT_FILE, R_OK))
787
788
        {
788
789
                ssl_loaded_verify_locations = false;
789
790
 
790
791
                /*
791
 
                 * If root certificate file simply not found. Don't log an error here, because
792
 
                 * it's quite likely the user isn't planning on using client certificates.
793
 
                 * If we can't access it for other reasons, it is an error.
 
792
                 * If root certificate file simply not found. Don't log an error here,
 
793
                 * because it's quite likely the user isn't planning on using client
 
794
                 * certificates. If we can't access it for other reasons, it is an
 
795
                 * error.
794
796
                 */
795
797
                if (errno != ENOENT)
796
798
                {
797
799
                        ereport(FATAL,
798
 
                                        (errmsg("could not access root certificate file \"%s\": %m",
799
 
                                                        ROOT_CERT_FILE)));
 
800
                                 (errmsg("could not access root certificate file \"%s\": %m",
 
801
                                                 ROOT_CERT_FILE)));
800
802
                }
801
803
        }
802
804
        else if (SSL_CTX_load_verify_locations(SSL_context, ROOT_CERT_FILE, NULL) != 1)
803
805
        {
804
806
                /*
805
 
                 * File was there, but we could not load it. This means the file is somehow
806
 
                 * broken, and we cannot do verification at all - so abort here.
 
807
                 * File was there, but we could not load it. This means the file is
 
808
                 * somehow broken, and we cannot do verification at all - so abort
 
809
                 * here.
807
810
                 */
808
811
                ssl_loaded_verify_locations = false;
809
812
                ereport(FATAL,
843
846
                        }
844
847
 
845
848
                        /*
846
 
                         * Always ask for SSL client cert, but don't fail if it's not presented. We'll fail later in this case,
847
 
                         * based on what we find in pg_hba.conf.
 
849
                         * Always ask for SSL client cert, but don't fail if it's not
 
850
                         * presented. We'll fail later in this case, based on what we find
 
851
                         * in pg_hba.conf.
848
852
                         */
849
853
                        SSL_CTX_set_verify(SSL_context,
850
854
                                                           (SSL_VERIFY_PEER |