File: libpq-ssl.html

package info (click to toggle)
postgresql-9.1 9.1.15-0%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 109,092 kB
  • sloc: ansic: 575,877; sql: 43,887; yacc: 26,399; perl: 6,352; lex: 6,171; sh: 5,282; makefile: 3,772; asm: 65; sed: 15; python: 12
file content (1052 lines) | stat: -rw-r--r-- 19,972 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>SSL Support</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REV="MADE"
HREF="mailto:pgsql-docs@postgresql.org"><LINK
REL="HOME"
TITLE="PostgreSQL 9.1.15 Documentation"
HREF="index.html"><LINK
REL="UP"
TITLE="libpq - C Library"
HREF="libpq.html"><LINK
REL="PREVIOUS"
TITLE="LDAP Lookup of Connection Parameters"
HREF="libpq-ldap.html"><LINK
REL="NEXT"
TITLE="Behavior in Threaded Programs"
HREF="libpq-threading.html"><LINK
REL="STYLESHEET"
TYPE="text/css"
HREF="stylesheet.css"><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=ISO-8859-1"><META
NAME="creation"
CONTENT="2015-02-02T21:03:01"></HEAD
><BODY
CLASS="SECT1"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="5"
ALIGN="center"
VALIGN="bottom"
><A
HREF="index.html"
>PostgreSQL 9.1.15 Documentation</A
></TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
TITLE="LDAP Lookup of Connection Parameters"
HREF="libpq-ldap.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="libpq.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
>Chapter 31. <SPAN
CLASS="APPLICATION"
>libpq</SPAN
> - C Library</TD
><TD
WIDTH="20%"
ALIGN="right"
VALIGN="top"
><A
TITLE="Behavior in Threaded Programs"
HREF="libpq-threading.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="LIBPQ-SSL"
>31.17. SSL Support</A
></H1
><P
>   <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> has native support for using <ACRONYM
CLASS="ACRONYM"
>SSL</ACRONYM
>
   connections to encrypt client/server communications for increased
   security. See <A
HREF="ssl-tcp.html"
>Section 17.9</A
> for details about the server-side
   <ACRONYM
CLASS="ACRONYM"
>SSL</ACRONYM
> functionality.
  </P
><P
>   <SPAN
CLASS="APPLICATION"
>libpq</SPAN
> reads the system-wide
   <SPAN
CLASS="PRODUCTNAME"
>OpenSSL</SPAN
> configuration file. By default, this
   file is named <TT
CLASS="FILENAME"
>openssl.cnf</TT
> and is located in the
   directory reported by <TT
CLASS="LITERAL"
>openssl version -d</TT
>.  This default
   can be overridden by setting environment variable
   <TT
CLASS="ENVAR"
>OPENSSL_CONF</TT
> to the name of the desired configuration
   file.
  </P
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="LIBQ-SSL-CERTIFICATES"
>31.17.1. Client Verification of Server Certificates</A
></H2
><P
>   By default, <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> will not perform any verification of
   the server certificate. This means that it is possible to spoof the server
   identity (for example by modifying a DNS record or by taking over the server
   IP address) without the client knowing. In order to prevent spoofing,
   <ACRONYM
CLASS="ACRONYM"
>SSL</ACRONYM
> certificate verification must be used.
  </P
><P
>   If the parameter <TT
CLASS="LITERAL"
>sslmode</TT
> is set to <TT
CLASS="LITERAL"
>verify-ca</TT
>,
   libpq will verify that the server is trustworthy by checking the
   certificate chain up to a trusted certificate authority
   (<ACRONYM
CLASS="ACRONYM"
>CA</ACRONYM
>). If <TT
CLASS="LITERAL"
>sslmode</TT
> is set to <TT
CLASS="LITERAL"
>verify-full</TT
>,
   libpq will <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>also</I
></SPAN
> verify that the server host name matches its
   certificate. The SSL connection will fail if the server certificate cannot
   be verified. <TT
CLASS="LITERAL"
>verify-full</TT
> is recommended in most
   security-sensitive environments.
  </P
><P
>   In <TT
CLASS="LITERAL"
>verify-full</TT
> mode, the <TT
CLASS="LITERAL"
>cn</TT
> (Common Name) attribute
   of the certificate is matched against the host name. If the <TT
CLASS="LITERAL"
>cn</TT
>
   attribute starts with an asterisk (<TT
CLASS="LITERAL"
>*</TT
>), it will be treated as
   a wildcard, and will match all characters <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>except</I
></SPAN
> a dot
   (<TT
CLASS="LITERAL"
>.</TT
>). This means the certificate will not match subdomains.
   If the connection is made using an IP address instead of a host name, the
   IP address will be matched (without doing any DNS lookups).
  </P
><P
>   To allow server certificate verification, the certificate(s) of one or more
   trusted <ACRONYM
CLASS="ACRONYM"
>CA</ACRONYM
>s must be
   placed in the file <TT
CLASS="FILENAME"
>~/.postgresql/root.crt</TT
> in the user's home
   directory. (On Microsoft Windows the file is named
   <TT
CLASS="FILENAME"
>%APPDATA%\postgresql\root.crt</TT
>.)
  </P
><P
>   Certificate Revocation List (CRL) entries are also checked
   if the file <TT
CLASS="FILENAME"
>~/.postgresql/root.crl</TT
> exists
   (<TT
CLASS="FILENAME"
>%APPDATA%\postgresql\root.crl</TT
> on Microsoft
   Windows).
  </P
><P
>   The location of the root certificate file and the CRL can be changed by
   setting
   the connection parameters <TT
CLASS="LITERAL"
>sslrootcert</TT
> and <TT
CLASS="LITERAL"
>sslcrl</TT
>
   or the environment variables <TT
CLASS="ENVAR"
>PGSSLROOTCERT</TT
> and <TT
CLASS="ENVAR"
>PGSSLCRL</TT
>.
  </P
><DIV
CLASS="NOTE"
><BLOCKQUOTE
CLASS="NOTE"
><P
><B
>Note: </B
>    For backwards compatibility with earlier versions of PostgreSQL, if a
    root CA file exists, the behavior of
    <TT
CLASS="LITERAL"
>sslmode</TT
>=<TT
CLASS="LITERAL"
>require</TT
> will be the same
    as that of <TT
CLASS="LITERAL"
>verify-ca</TT
>, meaning the server certificate
    is validated against the CA. Relying on this behavior is discouraged,
    and applications that need certificate validation should always use
    <TT
CLASS="LITERAL"
>verify-ca</TT
> or <TT
CLASS="LITERAL"
>verify-full</TT
>.
   </P
></BLOCKQUOTE
></DIV
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="LIBPQ-SSL-CLIENTCERT"
>31.17.2. Client Certificates</A
></H2
><P
>   If the server requests a trusted client certificate,
   <SPAN
CLASS="APPLICATION"
>libpq</SPAN
> will send the certificate stored in
   file <TT
CLASS="FILENAME"
>~/.postgresql/postgresql.crt</TT
> in the user's home
   directory.  The certificate must be signed by one of the certificate
   authorities (<ACRONYM
CLASS="ACRONYM"
>CA</ACRONYM
>) trusted by the server.  A matching
   private key file <TT
CLASS="FILENAME"
>~/.postgresql/postgresql.key</TT
> must also
   be present. The private
   key file must not allow any access to world or group; achieve this by the
   command <TT
CLASS="COMMAND"
>chmod 0600 ~/.postgresql/postgresql.key</TT
>.
   On Microsoft Windows these files are named
   <TT
CLASS="FILENAME"
>%APPDATA%\postgresql\postgresql.crt</TT
> and
   <TT
CLASS="FILENAME"
>%APPDATA%\postgresql\postgresql.key</TT
>, and there
   is no special permissions check since the directory is presumed secure.
   The location of the certificate and key files can be overridden by the
   connection parameters <TT
CLASS="LITERAL"
>sslcert</TT
> and <TT
CLASS="LITERAL"
>sslkey</TT
> or the
   environment variables <TT
CLASS="ENVAR"
>PGSSLCERT</TT
> and <TT
CLASS="ENVAR"
>PGSSLKEY</TT
>.
  </P
><P
>   In some cases, the client certificate might be signed by an
   <SPAN
CLASS="QUOTE"
>"intermediate"</SPAN
> certificate authority, rather than one that is
   directly trusted by the server.  To use such a certificate, append the
   certificate of the signing authority to the <TT
CLASS="FILENAME"
>postgresql.crt</TT
>
   file, then its parent authority's certificate, and so on up to a
   <SPAN
CLASS="QUOTE"
>"root"</SPAN
> authority that is trusted by the server.  The root
   certificate should be included in every case where
   <TT
CLASS="FILENAME"
>postgresql.crt</TT
> contains more than one certificate.
  </P
><P
>   Note that <TT
CLASS="FILENAME"
>root.crt</TT
> lists the top-level CAs that are
   considered trusted for signing server certificates.  In principle it need
   not list the CA that signed the client's certificate, though in most cases
   that CA would also be trusted for server certificates.
  </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="LIBPQ-SSL-PROTECTION"
>31.17.3. Protection Provided in Different Modes</A
></H2
><P
>   The different values for the <TT
CLASS="LITERAL"
>sslmode</TT
> parameter provide different
   levels of protection. SSL can provide
   protection against three types of attacks:

   <P
></P
></P><DIV
CLASS="VARIABLELIST"
><DL
><DT
>Eavesdropping</DT
><DD
><P
>If a third party can examine the network traffic between the
       client and the server, it can read both connection information (including
       the user name and password) and the data that is passed. <ACRONYM
CLASS="ACRONYM"
>SSL</ACRONYM
>
       uses encryption to prevent this.
      </P
></DD
><DT
>Man in the middle (<ACRONYM
CLASS="ACRONYM"
>MITM</ACRONYM
>)</DT
><DD
><P
>If a third party can modify the data while passing between the
       client and server, it can pretend to be the server and therefore see and
       modify data <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>even if it is encrypted</I
></SPAN
>. The third party can then
       forward the connection information and data to the original server,
       making it impossible to detect this attack. Common vectors to do this
       include DNS poisoning and address hijacking, whereby the client is directed
       to a different server than intended. There are also several other
       attack methods that can accomplish this. <ACRONYM
CLASS="ACRONYM"
>SSL</ACRONYM
> uses certificate
       verification to prevent this, by authenticating the server to the client.
      </P
></DD
><DT
>Impersonation</DT
><DD
><P
>If a third party can pretend to be an authorized client, it can
       simply access data it should not have access to. Typically this can
       happen through insecure password management. <ACRONYM
CLASS="ACRONYM"
>SSL</ACRONYM
> uses
       client certificates to prevent this, by making sure that only holders
       of valid certificates can access the server.
      </P
></DD
></DL
></DIV
><P>
  </P
><P
>   For a connection to be known secure, SSL usage must be configured
   on <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>both the client and the server</I
></SPAN
> before the connection
   is made. If it is only configured on the server, the client may end up
   sending sensitive information (e.g. passwords) before
   it knows that the server requires high security. In libpq, secure
   connections can be ensured
   by setting the <TT
CLASS="LITERAL"
>sslmode</TT
> parameter to <TT
CLASS="LITERAL"
>verify-full</TT
> or
   <TT
CLASS="LITERAL"
>verify-ca</TT
>, and providing the system with a root certificate to
   verify against. This is analogous to using an <TT
CLASS="LITERAL"
>https</TT
>
   <ACRONYM
CLASS="ACRONYM"
>URL</ACRONYM
> for encrypted web browsing.
  </P
><P
>   Once the server has been authenticated, the client can pass sensitive data.
   This means that up until this point, the client does not need to know if
   certificates will be used for authentication, making it safe to specify that
   only in the server configuration.
  </P
><P
>   All <ACRONYM
CLASS="ACRONYM"
>SSL</ACRONYM
> options carry overhead in the form of encryption and
   key-exchange, so there is a tradeoff that has to be made between performance
   and security. <A
HREF="libpq-ssl.html#LIBPQ-SSL-SSLMODE-STATEMENTS"
>Table 31-1</A
>
   illustrates the risks the different <TT
CLASS="LITERAL"
>sslmode</TT
> values
   protect against, and what statement they make about security and overhead.
  </P
><DIV
CLASS="TABLE"
><A
NAME="LIBPQ-SSL-SSLMODE-STATEMENTS"
></A
><P
><B
>Table 31-1. SSL Mode Descriptions</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><COL><COL><THEAD
><TR
><TH
><TT
CLASS="LITERAL"
>sslmode</TT
></TH
><TH
>Eavesdropping protection</TH
><TH
><ACRONYM
CLASS="ACRONYM"
>MITM</ACRONYM
> protection</TH
><TH
>Statement</TH
></TR
></THEAD
><TBODY
><TR
><TD
><TT
CLASS="LITERAL"
>disable</TT
></TD
><TD
>No</TD
><TD
>No</TD
><TD
>I don't care about security, and I don't want to pay the overhead
       of encryption.
      </TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>allow</TT
></TD
><TD
>Maybe</TD
><TD
>No</TD
><TD
>I don't care about security, but I will pay the overhead of
       encryption if the server insists on it.
      </TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>prefer</TT
></TD
><TD
>Maybe</TD
><TD
>No</TD
><TD
>I don't care about encryption, but I wish to pay the overhead of
       encryption if the server supports it.
      </TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>require</TT
></TD
><TD
>Yes</TD
><TD
>No</TD
><TD
>I want my data to be encrypted, and I accept the overhead. I trust
       that the network will make sure I always connect to the server I want.
      </TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>verify-ca</TT
></TD
><TD
>Yes</TD
><TD
><TT
CLASS="LITERAL"
>Depends on CA</TT
>-policy</TD
><TD
>I want my data encrypted, and I accept the overhead. I want to be
       sure that I connect to a server that I trust.
      </TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>verify-full</TT
></TD
><TD
>Yes</TD
><TD
>Yes</TD
><TD
>I want my data encrypted, and I accept the overhead. I want to be
        sure that I connect to a server I trust, and that it's the one I
        specify.
       </TD
></TR
></TBODY
></TABLE
></DIV
><P
>   The difference between <TT
CLASS="LITERAL"
>verify-ca</TT
> and <TT
CLASS="LITERAL"
>verify-full</TT
>
   depends on the policy of the root <ACRONYM
CLASS="ACRONYM"
>CA</ACRONYM
>. If a public
   <ACRONYM
CLASS="ACRONYM"
>CA</ACRONYM
> is used, <TT
CLASS="LITERAL"
>verify-ca</TT
> allows connections to a server
   that <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>somebody else</I
></SPAN
> may have registered with the <ACRONYM
CLASS="ACRONYM"
>CA</ACRONYM
>.
   In this case, <TT
CLASS="LITERAL"
>verify-full</TT
> should always be used. If
   a local <ACRONYM
CLASS="ACRONYM"
>CA</ACRONYM
> is used, or even a self-signed certificate, using
   <TT
CLASS="LITERAL"
>verify-ca</TT
> often provides enough protection.
  </P
><P
>   The default value for <TT
CLASS="LITERAL"
>sslmode</TT
> is <TT
CLASS="LITERAL"
>prefer</TT
>. As is shown
   in the table, this makes no sense from a security point of view, and it only
   promises performance overhead if possible. It is only provided as the default
   for backward compatibility, and is not recommended in secure deployments.
  </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="LIBPQ-SSL-FILEUSAGE"
>31.17.4. SSL Client File Usage</A
></H2
><P
>   <A
HREF="libpq-ssl.html#LIBPQ-SSL-FILE-USAGE"
>Table 31-2</A
> summarizes the files that are
   relevant to the SSL setup on the client.
  </P
><DIV
CLASS="TABLE"
><A
NAME="LIBPQ-SSL-FILE-USAGE"
></A
><P
><B
>Table 31-2. Libpq/Client SSL File Usage</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><COL><THEAD
><TR
><TH
>File</TH
><TH
>Contents</TH
><TH
>Effect</TH
></TR
></THEAD
><TBODY
><TR
><TD
><TT
CLASS="FILENAME"
>~/.postgresql/postgresql.crt</TT
></TD
><TD
>client certificate</TD
><TD
>requested by server</TD
></TR
><TR
><TD
><TT
CLASS="FILENAME"
>~/.postgresql/postgresql.key</TT
></TD
><TD
>client private key</TD
><TD
>proves client certificate sent by owner; does not indicate
      certificate owner is trustworthy</TD
></TR
><TR
><TD
><TT
CLASS="FILENAME"
>~/.postgresql/root.crt</TT
></TD
><TD
>trusted certificate authorities</TD
><TD
>checks that server certificate is signed by a trusted certificate
      authority</TD
></TR
><TR
><TD
><TT
CLASS="FILENAME"
>~/.postgresql/root.crl</TT
></TD
><TD
>certificates revoked by certificate authorities</TD
><TD
>server certificate must not be on this list</TD
></TR
></TBODY
></TABLE
></DIV
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="LIBPQ-SSL-INITIALIZE"
>31.17.5. SSL Library Initialization</A
></H2
><P
>   If your application initializes <TT
CLASS="LITERAL"
>libssl</TT
> and/or
   <TT
CLASS="LITERAL"
>libcrypto</TT
> libraries and <SPAN
CLASS="APPLICATION"
>libpq</SPAN
>
   is built with <ACRONYM
CLASS="ACRONYM"
>SSL</ACRONYM
> support, you should call
   <CODE
CLASS="FUNCTION"
>PQinitOpenSSL</CODE
> to tell <SPAN
CLASS="APPLICATION"
>libpq</SPAN
>
   that the <TT
CLASS="LITERAL"
>libssl</TT
> and/or <TT
CLASS="LITERAL"
>libcrypto</TT
> libraries
   have been initialized by your application, so that
   <SPAN
CLASS="APPLICATION"
>libpq</SPAN
> will not also initialize those libraries.
   
   See <A
HREF="http://h71000.www7.hp.com/doc/83final/BA554_90007/ch04.html"
TARGET="_top"
>http://h71000.www7.hp.com/doc/83final/BA554_90007/ch04.html</A
>
   for details on the SSL API.
  </P
><P
>   <P
></P
></P><DIV
CLASS="VARIABLELIST"
><DL
><DT
><A
NAME="LIBPQ-PQINITOPENSSL"
></A
><CODE
CLASS="FUNCTION"
>PQinitOpenSSL</CODE
>
      </DT
><DD
><P
>       Allows applications to select which security libraries to initialize.
</P><PRE
CLASS="SYNOPSIS"
>void PQinitOpenSSL(int do_ssl, int do_crypto);</PRE
><P>
      </P
><P
>       When <TT
CLASS="PARAMETER"
>do_ssl</TT
> is non-zero, <SPAN
CLASS="APPLICATION"
>libpq</SPAN
>
       will initialize the <SPAN
CLASS="APPLICATION"
>OpenSSL</SPAN
> library before first
       opening a database connection.  When <TT
CLASS="PARAMETER"
>do_crypto</TT
> is
       non-zero, the <TT
CLASS="LITERAL"
>libcrypto</TT
> library will be initialized.  By
       default (if <CODE
CLASS="FUNCTION"
>PQinitOpenSSL</CODE
> is not called), both libraries
       are initialized.  When SSL support is not compiled in, this function is
       present but does nothing.
      </P
><P
>       If your application uses and initializes either <SPAN
CLASS="APPLICATION"
>OpenSSL</SPAN
>
       or its underlying <TT
CLASS="LITERAL"
>libcrypto</TT
> library, you <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>must</I
></SPAN
>
       call this function with zeroes for the appropriate parameter(s)
       before first opening a database connection.  Also be sure that you
       have done that initialization before opening a database connection.
      </P
></DD
><DT
><A
NAME="LIBPQ-PQINITSSL"
></A
><CODE
CLASS="FUNCTION"
>PQinitSSL</CODE
>
      </DT
><DD
><P
>       Allows applications to select which security libraries to initialize.
</P><PRE
CLASS="SYNOPSIS"
>void PQinitSSL(int do_ssl);</PRE
><P>
      </P
><P
>       This function is equivalent to
       <TT
CLASS="LITERAL"
>PQinitOpenSSL(do_ssl, do_ssl)</TT
>.
       It is sufficient for applications that initialize both or neither
       of <SPAN
CLASS="APPLICATION"
>OpenSSL</SPAN
> and <TT
CLASS="LITERAL"
>libcrypto</TT
>.
      </P
><P
>       <CODE
CLASS="FUNCTION"
>PQinitSSL</CODE
> has been present since
       <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> 8.0, while <CODE
CLASS="FUNCTION"
>PQinitOpenSSL</CODE
>
       was added in <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> 8.4, so <CODE
CLASS="FUNCTION"
>PQinitSSL</CODE
>
       might be preferable for applications that need to work with older
       versions of <SPAN
CLASS="APPLICATION"
>libpq</SPAN
>.
      </P
></DD
></DL
></DIV
><P>
  </P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="libpq-ldap.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="libpq-threading.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>LDAP Lookup of Connection Parameters</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="libpq.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Behavior in Threaded Programs</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>