summaryrefslogtreecommitdiffstats
path: root/OpenSSL/SSL/SSLContext.html
blob: eaeea8fe59e1aaf229885917bff4666f2ccd9912 (plain)
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
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">

<title>class OpenSSL::SSL::SSLContext - RDoc Documentation</title>

<script type="text/javascript">
  var rdoc_rel_prefix = "../../";
  var index_rel_prefix = "../../";
</script>

<script src="../../js/jquery.js"></script>
<script src="../../js/darkfish.js"></script>

<link href="../../css/fonts.css" rel="stylesheet">
<link href="../../css/rdoc.css" rel="stylesheet">



<body id="top" role="document" class="class">
<nav role="navigation">
  <div id="project-navigation">
    <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2>
    <a href="../../index.html" rel="home">Home</a>
  </h2>

  <div id="table-of-contents-navigation">
    <a href="../../table_of_contents.html#pages">Pages</a>
    <a href="../../table_of_contents.html#classes">Classes</a>
    <a href="../../table_of_contents.html#methods">Methods</a>
  </div>
</div>

    <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

  </div>

  

  <div id="class-metadata">
    
    <div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  
  <p class="link">Object
  
</div>

    
    
    <!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    
    <li ><a href="#method-c-new">::new</a>
    
    <li ><a href="#method-i-ciphers">#ciphers</a>
    
    <li ><a href="#method-i-ciphers-3D">#ciphers=</a>
    
    <li ><a href="#method-i-ecdh_curves-3D">#ecdh_curves=</a>
    
    <li ><a href="#method-i-flush_sessions">#flush_sessions</a>
    
    <li ><a href="#method-i-options">#options</a>
    
    <li ><a href="#method-i-options-3D">#options=</a>
    
    <li ><a href="#method-i-security_level">#security_level</a>
    
    <li ><a href="#method-i-security_level-3D">#security_level=</a>
    
    <li ><a href="#method-i-session_add">#session_add</a>
    
    <li ><a href="#method-i-session_cache_mode">#session_cache_mode</a>
    
    <li ><a href="#method-i-session_cache_mode-3D">#session_cache_mode=</a>
    
    <li ><a href="#method-i-session_cache_size">#session_cache_size</a>
    
    <li ><a href="#method-i-session_cache_size-3D">#session_cache_size=</a>
    
    <li ><a href="#method-i-session_cache_stats">#session_cache_stats</a>
    
    <li ><a href="#method-i-session_remove">#session_remove</a>
    
    <li ><a href="#method-i-set_params">#set_params</a>
    
    <li ><a href="#method-i-setup">#setup</a>
    
    <li ><a href="#method-i-ssl_version-3D">#ssl_version=</a>
    
  </ul>
</div>

  </div>
</nav>

<main role="main" aria-labelledby="class-OpenSSL::SSL::SSLContext">
  <h1 id="class-OpenSSL::SSL::SSLContext" class="class">
    class OpenSSL::SSL::SSLContext
  </h1>

  <section class="description">
    
<p>An <a href="SSLContext.html">SSLContext</a> is used to set various options
regarding certificates, algorithms, verification, session caching, etc. 
The <a href="SSLContext.html">SSLContext</a> is used to create an <a
href="SSLSocket.html">SSLSocket</a>.</p>

<p>All attributes must be set before creating an <a
href="SSLSocket.html">SSLSocket</a> as the <a
href="SSLContext.html">SSLContext</a> will be frozen afterward.</p>

  </section>

  
  
  
  <section id="5Buntitled-5D" class="documentation-section">
    

    

    
    <section class="constants-list">
      <header>
        <h3>Constants</h3>
      </header>
      <dl>
      
        <dt id="METHODS">METHODS
        
        <dd><p>The list of available SSL/TLS methods</p>
        
      
        <dt id="SESSION_CACHE_BOTH">SESSION_CACHE_BOTH
        
        <dd><p>Both client and server sessions are added to the session cache</p>
        
      
        <dt id="SESSION_CACHE_CLIENT">SESSION_CACHE_CLIENT
        
        <dd><p>Client sessions are added to the session cache</p>
        
      
        <dt id="SESSION_CACHE_NO_AUTO_CLEAR">SESSION_CACHE_NO_AUTO_CLEAR
        
        <dd><p>Normally the session cache is checked for expired sessions every 255
connections.  Since this may lead to a delay that cannot be controlled, the
automatic flushing may be disabled and <a
href="SSLContext.html#method-i-flush_sessions">flush_sessions</a> can be
called explicitly.</p>
        
      
        <dt id="SESSION_CACHE_NO_INTERNAL">SESSION_CACHE_NO_INTERNAL
        
        <dd><p>Enables both <a
href="SSLContext.html#SESSION_CACHE_NO_INTERNAL_LOOKUP">SESSION_CACHE_NO_INTERNAL_LOOKUP</a>
and <a
href="SSLContext.html#SESSION_CACHE_NO_INTERNAL_STORE">SESSION_CACHE_NO_INTERNAL_STORE</a>.</p>
        
      
        <dt id="SESSION_CACHE_NO_INTERNAL_LOOKUP">SESSION_CACHE_NO_INTERNAL_LOOKUP
        
        <dd><p>Always perform external lookups of sessions even if they are in the
internal cache.</p>

<p>This flag has no effect on clients</p>
        
      
        <dt id="SESSION_CACHE_NO_INTERNAL_STORE">SESSION_CACHE_NO_INTERNAL_STORE
        
        <dd><p>Never automatically store sessions in the internal store.</p>
        
      
        <dt id="SESSION_CACHE_OFF">SESSION_CACHE_OFF
        
        <dd><p>No session caching for client or server</p>
        
      
        <dt id="SESSION_CACHE_SERVER">SESSION_CACHE_SERVER
        
        <dd><p>Server sessions are added to the session cache</p>
        
      
      </dl>
    </section>
    

    
    <section class="attribute-method-details" class="method-section">
      <header>
        <h3>Attributes</h3>
      </header>

      
      <div id="attribute-i-alpn_protocols" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">alpn_protocols</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>An Enumerable of Strings. Each String represents a protocol to be
advertised as the list of supported protocols for Application-Layer
Protocol Negotiation. Supported in <a href="../../OpenSSL.html">OpenSSL</a>
1.0.2 and higher. Has no effect on the server side. If not set explicitly,
the ALPN extension will not be included in the handshake.</p>

<h3 id="attribute-i-alpn_protocols-label-Example">Example<span><a href="#attribute-i-alpn_protocols-label-Example">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">alpn_protocols</span> = [<span class="ruby-string">&quot;http/1.1&quot;</span>, <span class="ruby-string">&quot;spdy/2&quot;</span>, <span class="ruby-string">&quot;h2&quot;</span>]
</pre>
        
        </div>
      </div>
      
      <div id="attribute-i-alpn_select_cb" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">alpn_select_cb</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>A callback invoked on the server side when the server needs to select a
protocol from the list sent by the client. Supported in <a
href="../../OpenSSL.html">OpenSSL</a> 1.0.2 and higher. The callback must
return a protocol of those advertised by the client. If none is acceptable,
raising an error in the callback will cause the handshake to fail. Not
setting this callback explicitly means not supporting the ALPN extension on
the server - any protocols advertised by the client will be ignored.</p>

<h3 id="attribute-i-alpn_select_cb-label-Example">Example<span><a href="#attribute-i-alpn_select_cb-label-Example">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">alpn_select_cb</span> = <span class="ruby-identifier">lambda</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">protocols</span><span class="ruby-operator">|</span>
  <span class="ruby-comment"># inspect the protocols and select one</span>
  <span class="ruby-identifier">protocols</span>.<span class="ruby-identifier">first</span>
<span class="ruby-keyword">end</span>
</pre>
        
        </div>
      </div>
      
      <div id="attribute-i-ca_file" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">ca_file</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>The path to a file containing a PEM-format CA certificate</p>
        
        </div>
      </div>
      
      <div id="attribute-i-ca_path" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">ca_path</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>The path to a directory containing CA certificates in PEM format.</p>

<p>Files are looked up by subject&#39;s <a href="../X509.html">X509</a>
name&#39;s hash value.</p>
        
        </div>
      </div>
      
      <div id="attribute-i-cert" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">cert</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>Context certificate</p>
        
        </div>
      </div>
      
      <div id="attribute-i-cert_store" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">cert_store</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>An <a href="../X509/Store.html">OpenSSL::X509::Store</a> used for
certificate verification.</p>
        
        </div>
      </div>
      
      <div id="attribute-i-client_ca" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">client_ca</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>A certificate or Array of certificates that will be sent to the client.</p>
        
        </div>
      </div>
      
      <div id="attribute-i-client_cert_cb" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">client_cert_cb</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>A callback invoked when a client certificate is requested by a server and
no certificate has been set.</p>

<p>The callback is invoked with a <a href="Session.html">Session</a> and must
return an Array containing an <a
href="../X509/Certificate.html">OpenSSL::X509::Certificate</a> and an <a
href="../PKey.html">OpenSSL::PKey</a>.  If any other value is returned the
handshake is suspended.</p>
        
        </div>
      </div>
      
      <div id="attribute-i-extra_chain_cert" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">extra_chain_cert</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>An Array of extra <a href="../X509.html">X509</a> certificates to be added
to the certificate chain.</p>
        
        </div>
      </div>
      
      <div id="attribute-i-key" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">key</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>Context private key</p>
        
        </div>
      </div>
      
      <div id="attribute-i-npn_protocols" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">npn_protocols</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>An Enumerable of Strings. Each String represents a protocol to be
advertised as the list of supported protocols for Next Protocol
Negotiation. Supported in <a href="../../OpenSSL.html">OpenSSL</a> 1.0.1
and higher. Has no effect on the client side. If not set explicitly, the
NPN extension will not be sent by the server in the handshake.</p>

<h3 id="attribute-i-npn_protocols-label-Example">Example<span><a href="#attribute-i-npn_protocols-label-Example">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">npn_protocols</span> = [<span class="ruby-string">&quot;http/1.1&quot;</span>, <span class="ruby-string">&quot;spdy/2&quot;</span>]
</pre>
        
        </div>
      </div>
      
      <div id="attribute-i-npn_select_cb" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">npn_select_cb</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>A callback invoked on the client side when the client needs to select a
protocol from the list sent by the server. Supported in <a
href="../../OpenSSL.html">OpenSSL</a> 1.0.1 and higher. The client MUST
select a protocol of those advertised by the server. If none is acceptable,
raising an error in the callback will cause the handshake to fail. Not
setting this callback explicitly means not supporting the NPN extension on
the client - any protocols advertised by the server will be ignored.</p>

<h3 id="attribute-i-npn_select_cb-label-Example">Example<span><a href="#attribute-i-npn_select_cb-label-Example">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">npn_select_cb</span> = <span class="ruby-identifier">lambda</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">protocols</span><span class="ruby-operator">|</span>
  <span class="ruby-comment"># inspect the protocols and select one</span>
  <span class="ruby-identifier">protocols</span>.<span class="ruby-identifier">first</span>
<span class="ruby-keyword">end</span>
</pre>
        
        </div>
      </div>
      
      <div id="attribute-i-renegotiation_cb" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">renegotiation_cb</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>A callback invoked whenever a new handshake is initiated. May be used to
disable renegotiation entirely.</p>

<p>The callback is invoked with the active <a
href="SSLSocket.html">SSLSocket</a>. The callback&#39;s return value is
irrelevant, normal return indicates “approval” of the renegotiation and
will continue the process. To forbid renegotiation and to cancel the
process, an Error may be raised within the callback.</p>

<h3 id="attribute-i-renegotiation_cb-label-Disable+client+renegotiation">Disable client renegotiation<span><a href="#attribute-i-renegotiation_cb-label-Disable+client+renegotiation">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>When running a server, it is often desirable to disable client
renegotiation entirely. You may use a callback as follows to implement this
feature:</p>

<pre class="ruby"><span class="ruby-identifier">num_handshakes</span> = <span class="ruby-value">0</span>
<span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">renegotiation_cb</span> = <span class="ruby-identifier">lambda</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">ssl</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">num_handshakes</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">RuntimeError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Client renegotiation disabled&quot;</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">num_handshakes</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span>
<span class="ruby-keyword">end</span>
</pre>
        
        </div>
      </div>
      
      <div id="attribute-i-servername_cb" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">servername_cb</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>A callback invoked at connect time to distinguish between multiple server
names.</p>

<p>The callback is invoked with an <a href="SSLSocket.html">SSLSocket</a> and
a server name.  The callback must return an <a
href="SSLContext.html">SSLContext</a> for the server name or nil.</p>
        
        </div>
      </div>
      
      <div id="attribute-i-session_get_cb" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">session_get_cb</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>A callback invoked on a server when a session is proposed by the client but
the session could not be found in the server&#39;s internal cache.</p>

<p>The callback is invoked with the <a href="SSLSocket.html">SSLSocket</a> and
session id.  The callback may return a <a href="Session.html">Session</a>
from an external cache.</p>
        
        </div>
      </div>
      
      <div id="attribute-i-session_id_context" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">session_id_context</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>Sets the context in which a session can be reused.  This allows sessions
for multiple applications to be distinguished, for example, by name.</p>
        
        </div>
      </div>
      
      <div id="attribute-i-session_new_cb" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">session_new_cb</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>A callback invoked when a new session was negotiated.</p>

<p>The callback is invoked with an <a href="SSLSocket.html">SSLSocket</a>.  If
false is returned the session will be removed from the internal cache.</p>
        
        </div>
      </div>
      
      <div id="attribute-i-session_remove_cb" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">session_remove_cb</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>A callback invoked when a session is removed from the internal cache.</p>

<p>The callback is invoked with an <a href="SSLContext.html">SSLContext</a>
and a <a href="Session.html">Session</a>.</p>
        
        </div>
      </div>
      
      <div id="attribute-i-ssl_timeout" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">ssl_timeout</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>Maximum session lifetime in seconds.</p>
        
        </div>
      </div>
      
      <div id="attribute-i-timeout" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">timeout</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>Maximum session lifetime in seconds.</p>
        
        </div>
      </div>
      
      <div id="attribute-i-tmp_dh_callback" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">tmp_dh_callback</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>A callback invoked when DH parameters are required.</p>

<p>The callback is invoked with the <a href="Session.html">Session</a> for the
key exchange, an flag indicating the use of an export cipher and the
keylength required.</p>

<p>The callback must return an <a href="../PKey/DH.html">OpenSSL::PKey::DH</a>
instance of the correct key length.</p>
        
        </div>
      </div>
      
      <div id="attribute-i-tmp_ecdh_callback" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">tmp_ecdh_callback</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>A callback invoked when ECDH parameters are required.</p>

<p>The callback is invoked with the <a href="Session.html">Session</a> for the
key exchange, an flag indicating the use of an export cipher and the
keylength required.</p>

<p>The callback is deprecated. This does not work with recent versions of <a
href="../../OpenSSL.html">OpenSSL</a>. Use <a
href="SSLContext.html#method-i-ecdh_curves-3D">#ecdh_curves=</a> instead.</p>
        
        </div>
      </div>
      
      <div id="attribute-i-verify_callback" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">verify_callback</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>A callback for additional certificate verification.  The callback is
invoked for each certificate in the chain.</p>

<p>The callback is invoked with two values.  <code>preverify_ok</code>
indicates indicates if the verification was passed (true) or not (false).
<code>store_context</code> is an <a
href="../X509/StoreContext.html">OpenSSL::X509::StoreContext</a> containing
the context used for certificate verification.</p>

<p>If the callback returns false, the chain verification is immediately
stopped and a bad_certificate alert is then sent.</p>
        
        </div>
      </div>
      
      <div id="attribute-i-verify_depth" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">verify_depth</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>Number of CA certificates to walk when verifying a certificate chain.</p>
        
        </div>
      </div>
      
      <div id="attribute-i-verify_hostname" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">verify_hostname</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>Whether to check the server certificate is valid for the hostname.</p>

<p>In order to make this work, <a
href="SSLContext.html#attribute-i-verify_mode">#verify_mode</a> must be set
to VERIFY_PEER and the server hostname must be given by <a
href="SSLSocket.html#method-i-hostname-3D">OpenSSL::SSL::SSLSocket#hostname=</a>.</p>
        
        </div>
      </div>
      
      <div id="attribute-i-verify_mode" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">verify_mode</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p><a href="Session.html">Session</a> verification mode.</p>

<p>Valid modes are VERIFY_NONE, VERIFY_PEER, VERIFY_CLIENT_ONCE,
VERIFY_FAIL_IF_NO_PEER_CERT and defined on <a
href="../SSL.html">OpenSSL::SSL</a></p>

<p>The default mode is VERIFY_NONE, which does not perform any verification at
all.</p>

<p>See SSL_CTX_set_verify(3) for details.</p>
        
        </div>
      </div>
      
    </section>
    

    
     <section id="public-class-5Buntitled-5D-method-details" class="method-section">
       <header>
         <h3>Public Class Methods</h3>
       </header>

    
      <div id="method-c-new" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            new &rarr; ctx
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            new(:TLSv1) &rarr; ctx
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            new(&quot;SSLv23_client&quot;) &rarr; ctx
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>You can get a list of valid methods with <a
href="SSLContext.html#METHODS">OpenSSL::SSL::SSLContext::METHODS</a></p>
          
          

          
          <div class="method-source-code" id="new-source">
            <pre><span class="ruby-comment"># File lib/openssl/ssl.rb, line 97</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">version</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">options</span> <span class="ruby-operator">|=</span> <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">SSL</span><span class="ruby-operator">::</span><span class="ruby-constant">OP_ALL</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">ssl_version</span> = <span class="ruby-identifier">version</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">version</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
    </section>
  
     <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
       <header>
         <h3>Public Instance Methods</h3>
       </header>

    
      <div id="method-i-ciphers" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            ciphers &rarr; [[name, version, bits, alg_bits], ...]
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>The list of cipher suites configured for this context.</p>
          
          

          
          <div class="method-source-code" id="ciphers-source">
            <pre>static VALUE
ossl_sslctx_get_ciphers(VALUE self)
{
    SSL_CTX *ctx;
    STACK_OF(SSL_CIPHER) *ciphers;
    const SSL_CIPHER *cipher;
    VALUE ary;
    int i, num;

    GetSSLCTX(self, ctx);
    if(!ctx){
        rb_warning(&quot;SSL_CTX is not initialized.&quot;);
        return Qnil;
    }
    ciphers = SSL_CTX_get_ciphers(ctx);

    if (!ciphers)
        return rb_ary_new();

    num = sk_SSL_CIPHER_num(ciphers);
    ary = rb_ary_new2(num);
    for(i = 0; i &lt; num; i++){
        cipher = sk_SSL_CIPHER_value(ciphers, i);
        rb_ary_push(ary, ossl_ssl_cipher_to_ary(cipher));
    }
    return ary;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-ciphers-3D" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            ciphers = &quot;cipher1:cipher2:...&quot;
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            ciphers = [name, ...]
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            ciphers = [[name, version, bits, alg_bits], ...]
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Sets the list of available cipher suites for this context.  Note in a
server context some ciphers require the appropriate certificates.  For
example, an RSA cipher suite can only be chosen when an RSA certificate is
available.</p>
          
          

          
          <div class="method-source-code" id="ciphers-3D-source">
            <pre>static VALUE
ossl_sslctx_set_ciphers(VALUE self, VALUE v)
{
    SSL_CTX *ctx;
    VALUE str, elem;
    int i;

    rb_check_frozen(self);
    if (NIL_P(v))
        return v;
    else if (RB_TYPE_P(v, T_ARRAY)) {
        str = rb_str_new(0, 0);
        for (i = 0; i &lt; RARRAY_LEN(v); i++) {
            elem = rb_ary_entry(v, i);
            if (RB_TYPE_P(elem, T_ARRAY)) elem = rb_ary_entry(elem, 0);
            elem = rb_String(elem);
            rb_str_append(str, elem);
            if (i &lt; RARRAY_LEN(v)-1) rb_str_cat2(str, &quot;:&quot;);
        }
    } else {
        str = v;
        StringValue(str);
    }

    GetSSLCTX(self, ctx);
    if(!ctx){
        ossl_raise(eSSLError, &quot;SSL_CTX is not initialized.&quot;);
        return Qnil;
    }
    if (!SSL_CTX_set_cipher_list(ctx, StringValueCStr(str))) {
        ossl_raise(eSSLError, &quot;SSL_CTX_set_cipher_list&quot;);
    }

    return v;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-ecdh_curves-3D" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            ecdh_curves = curve_list &rarr; curve_list
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Sets the list of “supported elliptic curves” for this context.</p>

<p>For a TLS client, the list is directly used in the Supported Elliptic
Curves Extension. For a server, the list is used by <a
href="../../OpenSSL.html">OpenSSL</a> to determine the set of shared
curves. <a href="../../OpenSSL.html">OpenSSL</a> will pick the most
appropriate one from it.</p>

<p>Note that this works differently with old <a
href="../../OpenSSL.html">OpenSSL</a> (&lt;= 1.0.1). Only one curve can be
set, and this has no effect for TLS clients.</p>

<h3 id="method-i-ecdh_curves-3D-label-Example">Example<span><a href="#method-i-ecdh_curves-3D-label-Example">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">ctx1</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">SSL</span><span class="ruby-operator">::</span><span class="ruby-constant">SSLContext</span>.<span class="ruby-identifier">new</span>
<span class="ruby-identifier">ctx1</span>.<span class="ruby-identifier">ecdh_curves</span> = <span class="ruby-string">&quot;X25519:P-256:P-224&quot;</span>
<span class="ruby-identifier">svr</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">SSL</span><span class="ruby-operator">::</span><span class="ruby-constant">SSLServer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">tcp_svr</span>, <span class="ruby-identifier">ctx1</span>)
<span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span> { <span class="ruby-identifier">svr</span>.<span class="ruby-identifier">accept</span> }

<span class="ruby-identifier">ctx2</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">SSL</span><span class="ruby-operator">::</span><span class="ruby-constant">SSLContext</span>.<span class="ruby-identifier">new</span>
<span class="ruby-identifier">ctx2</span>.<span class="ruby-identifier">ecdh_curves</span> = <span class="ruby-string">&quot;P-256&quot;</span>
<span class="ruby-identifier">cli</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">SSL</span><span class="ruby-operator">::</span><span class="ruby-constant">SSLSocket</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">tcp_sock</span>, <span class="ruby-identifier">ctx2</span>)
<span class="ruby-identifier">cli</span>.<span class="ruby-identifier">connect</span>

<span class="ruby-identifier">p</span> <span class="ruby-identifier">cli</span>.<span class="ruby-identifier">tmp_key</span>.<span class="ruby-identifier">group</span>.<span class="ruby-identifier">curve_name</span>
<span class="ruby-comment"># =&gt; &quot;prime256v1&quot; (is an alias for NIST P-256)</span>
</pre>
          
          

          
          <div class="method-source-code" id="ecdh_curves-3D-source">
            <pre>static VALUE
ossl_sslctx_set_ecdh_curves(VALUE self, VALUE arg)
{
    SSL_CTX *ctx;

    rb_check_frozen(self);
    GetSSLCTX(self, ctx);
    StringValueCStr(arg);

#if defined(HAVE_SSL_CTX_SET1_CURVES_LIST)
    if (!SSL_CTX_set1_curves_list(ctx, RSTRING_PTR(arg)))
        ossl_raise(eSSLError, NULL);
#else
    /* OpenSSL does not have SSL_CTX_set1_curves_list()... Fallback to
     * SSL_CTX_set_tmp_ecdh(). So only the first curve is used. */
    {
        VALUE curve, splitted;
        EC_KEY *ec;
        int nid;

        splitted = rb_str_split(arg, &quot;:&quot;);
        if (!RARRAY_LEN(splitted))
            ossl_raise(eSSLError, &quot;invalid input format&quot;);
        curve = RARRAY_AREF(splitted, 0);
        StringValueCStr(curve);

        /* SSL_CTX_set1_curves_list() accepts NIST names */
        nid = EC_curve_nist2nid(RSTRING_PTR(curve));
        if (nid == NID_undef)
            nid = OBJ_txt2nid(RSTRING_PTR(curve));
        if (nid == NID_undef)
            ossl_raise(eSSLError, &quot;unknown curve name&quot;);

        ec = EC_KEY_new_by_curve_name(nid);
        if (!ec)
            ossl_raise(eSSLError, NULL);
        EC_KEY_set_asn1_flag(ec, OPENSSL_EC_NAMED_CURVE);
        if (!SSL_CTX_set_tmp_ecdh(ctx, ec)) {
            EC_KEY_free(ec);
            ossl_raise(eSSLError, &quot;SSL_CTX_set_tmp_ecdh&quot;);
        }
        EC_KEY_free(ec);
# if defined(HAVE_SSL_CTX_SET_ECDH_AUTO)
        /* tmp_ecdh and ecdh_auto conflict. tmp_ecdh is ignored when ecdh_auto
         * is enabled. So disable ecdh_auto. */
        if (!SSL_CTX_set_ecdh_auto(ctx, 0))
            ossl_raise(eSSLError, &quot;SSL_CTX_set_ecdh_auto&quot;);
# endif
    }
#endif

    return arg;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-flush_sessions" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            flush_sessions(time | nil) &rarr; self
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Removes sessions in the internal cache that have expired at
<code>time</code>.</p>
          
          

          
          <div class="method-source-code" id="flush_sessions-source">
            <pre>static VALUE
ossl_sslctx_flush_sessions(int argc, VALUE *argv, VALUE self)
{
    VALUE arg1;
    SSL_CTX *ctx;
    time_t tm = 0;

    rb_scan_args(argc, argv, &quot;01&quot;, &amp;arg1);

    GetSSLCTX(self, ctx);

    if (NIL_P(arg1)) {
        tm = time(0);
    } else if (rb_obj_is_instance_of(arg1, rb_cTime)) {
        tm = NUM2LONG(rb_funcall(arg1, rb_intern(&quot;to_i&quot;), 0));
    } else {
        ossl_raise(rb_eArgError, &quot;arg must be Time or nil&quot;);
    }

    SSL_CTX_flush_sessions(ctx, (long)tm);

    return self;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-options" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">options</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Gets various <a href="../../OpenSSL.html">OpenSSL</a> options.</p>
          
          

          
          <div class="method-source-code" id="options-source">
            <pre>static VALUE
ossl_sslctx_get_options(VALUE self)
{
    SSL_CTX *ctx;
    GetSSLCTX(self, ctx);
    return LONG2NUM(SSL_CTX_get_options(ctx));
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-options-3D" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">options=</span><span
            class="method-args">(p1)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Sets various <a href="../../OpenSSL.html">OpenSSL</a> options.</p>
          
          

          
          <div class="method-source-code" id="options-3D-source">
            <pre>static VALUE
ossl_sslctx_set_options(VALUE self, VALUE options)
{
    SSL_CTX *ctx;

    rb_check_frozen(self);
    GetSSLCTX(self, ctx);

    SSL_CTX_clear_options(ctx, SSL_CTX_get_options(ctx));

    if (NIL_P(options)) {
        SSL_CTX_set_options(ctx, SSL_OP_ALL);
    } else {
        SSL_CTX_set_options(ctx, NUM2LONG(options));
    }

    return self;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-security_level" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            security_level &rarr; Integer
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns the security level for the context.</p>

<p>See also <a
href="SSLContext.html#method-i-security_level-3D">#security_level=</a>.</p>
          
          

          
          <div class="method-source-code" id="security_level-source">
            <pre>static VALUE
ossl_sslctx_get_security_level(VALUE self)
{
    SSL_CTX *ctx;

    GetSSLCTX(self, ctx);

#if defined(HAVE_SSL_CTX_GET_SECURITY_LEVEL)
    return INT2NUM(SSL_CTX_get_security_level(ctx));
#else
    (void)ctx;
    return INT2FIX(0);
#endif
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-security_level-3D" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            security_level = integer
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Sets the security level for the context. <a
href="../../OpenSSL.html">OpenSSL</a> limits parameters according to the
level. The “parameters” include: ciphersuites, curves, key sizes,
certificate signature algorithms, protocol version and so on. For example,
level 1 rejects parameters offering below 80 bits of security, such as
ciphersuites using MD5 for the MAC or RSA keys shorter than 1024 bits.</p>

<p>Note that attempts to set such parameters with insufficient security are
also blocked. You need to lower the level first.</p>

<p>This feature is not supported in <a href="../../OpenSSL.html">OpenSSL</a>
&lt; 1.1.0, and setting the level to other than 0 will raise
NotImplementedError. Level 0 means everything is permitted, the same
behavior as previous versions of <a href="../../OpenSSL.html">OpenSSL</a>.</p>

<p>See the manpage of SSL_CTX_set_security_level(3) for details.</p>
          
          

          
          <div class="method-source-code" id="security_level-3D-source">
            <pre>static VALUE
ossl_sslctx_set_security_level(VALUE self, VALUE value)
{
    SSL_CTX *ctx;

    rb_check_frozen(self);
    GetSSLCTX(self, ctx);

#if defined(HAVE_SSL_CTX_GET_SECURITY_LEVEL)
    SSL_CTX_set_security_level(ctx, NUM2INT(value));
#else
    (void)ctx;
    if (NUM2INT(value) != 0)
        ossl_raise(rb_eNotImpError, &quot;setting security level to other than 0 is &quot;
                   &quot;not supported in this version of OpenSSL&quot;);
#endif

    return value;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-session_add" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            session_add(session) &rarr; true | false
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Adds <code>session</code> to the session cache.</p>
          
          

          
          <div class="method-source-code" id="session_add-source">
            <pre>static VALUE
ossl_sslctx_session_add(VALUE self, VALUE arg)
{
    SSL_CTX *ctx;
    SSL_SESSION *sess;

    GetSSLCTX(self, ctx);
    SafeGetSSLSession(arg, sess);

    return SSL_CTX_add_session(ctx, sess) == 1 ? Qtrue : Qfalse;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-session_cache_mode" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            session_cache_mode &rarr; Integer
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>The current session cache mode.</p>
          
          

          
          <div class="method-source-code" id="session_cache_mode-source">
            <pre>static VALUE
ossl_sslctx_get_session_cache_mode(VALUE self)
{
    SSL_CTX *ctx;

    GetSSLCTX(self, ctx);

    return LONG2NUM(SSL_CTX_get_session_cache_mode(ctx));
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-session_cache_mode-3D" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            session_cache_mode=(integer) &rarr; Integer
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Sets the <a href="../SSL.html">SSL</a> session cache mode.  Bitwise-or
together the desired SESSION_CACHE_* constants to set.  See
SSL_CTX_set_session_cache_mode(3) for details.</p>
          
          

          
          <div class="method-source-code" id="session_cache_mode-3D-source">
            <pre>static VALUE
ossl_sslctx_set_session_cache_mode(VALUE self, VALUE arg)
{
    SSL_CTX *ctx;

    GetSSLCTX(self, ctx);

    SSL_CTX_set_session_cache_mode(ctx, NUM2LONG(arg));

    return arg;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-session_cache_size" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            session_cache_size &rarr; Integer
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns the current session cache size.  Zero is used to represent an
unlimited cache size.</p>
          
          

          
          <div class="method-source-code" id="session_cache_size-source">
            <pre>static VALUE
ossl_sslctx_get_session_cache_size(VALUE self)
{
    SSL_CTX *ctx;

    GetSSLCTX(self, ctx);

    return LONG2NUM(SSL_CTX_sess_get_cache_size(ctx));
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-session_cache_size-3D" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            session_cache_size=(integer) &rarr; Integer
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Sets the session cache size.  Returns the previously valid session cache
size.  Zero is used to represent an unlimited session cache size.</p>
          
          

          
          <div class="method-source-code" id="session_cache_size-3D-source">
            <pre>static VALUE
ossl_sslctx_set_session_cache_size(VALUE self, VALUE arg)
{
    SSL_CTX *ctx;

    GetSSLCTX(self, ctx);

    SSL_CTX_sess_set_cache_size(ctx, NUM2LONG(arg));

    return arg;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-session_cache_stats" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            session_cache_stats &rarr; Hash
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns a Hash containing the following keys:</p>
<dl class="rdoc-list note-list"><dt>:accept
<dd>
<p>Number of started SSL/TLS handshakes in server mode</p>
</dd><dt>:accept_good
<dd>
<p>Number of established SSL/TLS sessions in server mode</p>
</dd><dt>:accept_renegotiate
<dd>
<p>Number of start renegotiations in server mode</p>
</dd><dt>:cache_full
<dd>
<p>Number of sessions that were removed due to cache overflow</p>
</dd><dt>:cache_hits
<dd>
<p>Number of successfully reused connections</p>
</dd><dt>:cache_misses
<dd>
<p>Number of sessions proposed by clients that were not found in the cache</p>
</dd><dt>:cache_num
<dd>
<p>Number of sessions in the internal session cache</p>
</dd><dt>:cb_hits
<dd>
<p>Number of sessions retrieved from the external cache in server mode</p>
</dd><dt>:connect
<dd>
<p>Number of started SSL/TLS handshakes in client mode</p>
</dd><dt>:connect_good
<dd>
<p>Number of established SSL/TLS sessions in client mode</p>
</dd><dt>:connect_renegotiate
<dd>
<p>Number of start renegotiations in client mode</p>
</dd><dt>:timeouts
<dd>
<p>Number of sessions proposed by clients that were found in the cache but had
expired due to timeouts</p>
</dd></dl>
          
          

          
          <div class="method-source-code" id="session_cache_stats-source">
            <pre>static VALUE
ossl_sslctx_get_session_cache_stats(VALUE self)
{
    SSL_CTX *ctx;
    VALUE hash;

    GetSSLCTX(self, ctx);

    hash = rb_hash_new();
    rb_hash_aset(hash, ID2SYM(rb_intern(&quot;cache_num&quot;)), LONG2NUM(SSL_CTX_sess_number(ctx)));
    rb_hash_aset(hash, ID2SYM(rb_intern(&quot;connect&quot;)), LONG2NUM(SSL_CTX_sess_connect(ctx)));
    rb_hash_aset(hash, ID2SYM(rb_intern(&quot;connect_good&quot;)), LONG2NUM(SSL_CTX_sess_connect_good(ctx)));
    rb_hash_aset(hash, ID2SYM(rb_intern(&quot;connect_renegotiate&quot;)), LONG2NUM(SSL_CTX_sess_connect_renegotiate(ctx)));
    rb_hash_aset(hash, ID2SYM(rb_intern(&quot;accept&quot;)), LONG2NUM(SSL_CTX_sess_accept(ctx)));
    rb_hash_aset(hash, ID2SYM(rb_intern(&quot;accept_good&quot;)), LONG2NUM(SSL_CTX_sess_accept_good(ctx)));
    rb_hash_aset(hash, ID2SYM(rb_intern(&quot;accept_renegotiate&quot;)), LONG2NUM(SSL_CTX_sess_accept_renegotiate(ctx)));
    rb_hash_aset(hash, ID2SYM(rb_intern(&quot;cache_hits&quot;)), LONG2NUM(SSL_CTX_sess_hits(ctx)));
    rb_hash_aset(hash, ID2SYM(rb_intern(&quot;cb_hits&quot;)), LONG2NUM(SSL_CTX_sess_cb_hits(ctx)));
    rb_hash_aset(hash, ID2SYM(rb_intern(&quot;cache_misses&quot;)), LONG2NUM(SSL_CTX_sess_misses(ctx)));
    rb_hash_aset(hash, ID2SYM(rb_intern(&quot;cache_full&quot;)), LONG2NUM(SSL_CTX_sess_cache_full(ctx)));
    rb_hash_aset(hash, ID2SYM(rb_intern(&quot;timeouts&quot;)), LONG2NUM(SSL_CTX_sess_timeouts(ctx)));

    return hash;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-session_remove" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            session_remove(session) &rarr; true | false
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Removes <code>session</code> from the session cache.</p>
          
          

          
          <div class="method-source-code" id="session_remove-source">
            <pre>static VALUE
ossl_sslctx_session_remove(VALUE self, VALUE arg)
{
    SSL_CTX *ctx;
    SSL_SESSION *sess;

    GetSSLCTX(self, ctx);
    SafeGetSSLSession(arg, sess);

    return SSL_CTX_remove_session(ctx, sess) == 1 ? Qtrue : Qfalse;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-set_params" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            set_params(params = {}) &rarr; params
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Sets saner defaults optimized for the use with HTTP-like protocols.</p>

<p>If a Hash <code>params</code> is given, the parameters are overridden with
it. The keys in <code>params</code> must be assignment methods on <a
href="SSLContext.html">SSLContext</a>.</p>

<p>If the <a href="SSLContext.html#attribute-i-verify_mode">#verify_mode</a>
is not VERIFY_NONE and <a
href="SSLContext.html#attribute-i-ca_file">#ca_file</a>, <a
href="SSLContext.html#attribute-i-ca_path">#ca_path</a> and <a
href="SSLContext.html#attribute-i-cert_store">#cert_store</a> are not set
then the system default certificate store is used.</p>
          
          

          
          <div class="method-source-code" id="set_params-source">
            <pre><span class="ruby-comment"># File lib/openssl/ssl.rb, line 114</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">set_params</span>(<span class="ruby-identifier">params</span>={})
  <span class="ruby-identifier">params</span> = <span class="ruby-constant">DEFAULT_PARAMS</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">params</span>)
  <span class="ruby-identifier">params</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">name</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">__send__</span>(<span class="ruby-node">&quot;#{name}=&quot;</span>, <span class="ruby-identifier">value</span>) }
  <span class="ruby-keyword">if</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">verify_mode</span> <span class="ruby-operator">!=</span> <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">SSL</span><span class="ruby-operator">::</span><span class="ruby-constant">VERIFY_NONE</span>
    <span class="ruby-keyword">unless</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">ca_file</span> <span class="ruby-keyword">or</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">ca_path</span> <span class="ruby-keyword">or</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">cert_store</span>
      <span class="ruby-keyword">self</span>.<span class="ruby-identifier">cert_store</span> = <span class="ruby-constant">DEFAULT_CERT_STORE</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">params</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-setup" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            setup &rarr; Qtrue # first time
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            setup &rarr; nil # thereafter
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>This method is called automatically when a new <a
href="SSLSocket.html">SSLSocket</a> is created. However, it is not
thread-safe and must be called before creating <a
href="SSLSocket.html">SSLSocket</a> objects in a multi-threaded program.</p>
          
          

          
          <div class="method-source-code" id="setup-source">
            <pre>static VALUE
ossl_sslctx_setup(VALUE self)
{
    SSL_CTX *ctx;
    X509 *cert = NULL, *client_ca = NULL;
    EVP_PKEY *key = NULL;
    char *ca_path = NULL, *ca_file = NULL;
    int verify_mode;
    long i;
    VALUE val;

    if(OBJ_FROZEN(self)) return Qnil;
    GetSSLCTX(self, ctx);

#if !defined(OPENSSL_NO_DH)
    SSL_CTX_set_tmp_dh_callback(ctx, ossl_tmp_dh_callback);
#endif

#if !defined(OPENSSL_NO_EC)
    /* We added SSLContext#tmp_ecdh_callback= in Ruby 2.3.0,
     * but SSL_CTX_set_tmp_ecdh_callback() was removed in OpenSSL 1.1.0. */
    if (RTEST(rb_attr_get(self, id_i_tmp_ecdh_callback))) {
# if defined(HAVE_SSL_CTX_SET_TMP_ECDH_CALLBACK)
        rb_warn(&quot;#tmp_ecdh_callback= is deprecated; use #ecdh_curves= instead&quot;);
        SSL_CTX_set_tmp_ecdh_callback(ctx, ossl_tmp_ecdh_callback);
#  if defined(HAVE_SSL_CTX_SET_ECDH_AUTO)
        /* tmp_ecdh_callback and ecdh_auto conflict; OpenSSL ignores
         * tmp_ecdh_callback. So disable ecdh_auto. */
        if (!SSL_CTX_set_ecdh_auto(ctx, 0))
            ossl_raise(eSSLError, &quot;SSL_CTX_set_ecdh_auto&quot;);
#  endif
# else
        ossl_raise(eSSLError, &quot;OpenSSL does not support tmp_ecdh_callback; &quot;
                   &quot;use #ecdh_curves= instead&quot;);
# endif
    }
#endif /* OPENSSL_NO_EC */

    val = rb_attr_get(self, id_i_cert_store);
    if (!NIL_P(val)) {
        X509_STORE *store = GetX509StorePtr(val); /* NO NEED TO DUP */
        SSL_CTX_set_cert_store(ctx, store);
#if !defined(HAVE_X509_STORE_UP_REF)
        /*
         * WORKAROUND:
         *   X509_STORE can count references, but
         *   X509_STORE_free() doesn&#39;t care it.
         *   So we won&#39;t increment it but mark it by ex_data.
         */
        SSL_CTX_set_ex_data(ctx, ossl_ssl_ex_store_p, (void *)1);
#else /* Fixed in OpenSSL 1.0.2; bff9ce4db38b (master), 5b4b9ce976fc (1.0.2) */
        X509_STORE_up_ref(store);
#endif
    }

    val = rb_attr_get(self, id_i_extra_chain_cert);
    if(!NIL_P(val)){
        rb_block_call(val, rb_intern(&quot;each&quot;), 0, 0, ossl_sslctx_add_extra_chain_cert_i, self);
    }

    /* private key may be bundled in certificate file. */
    val = rb_attr_get(self, id_i_cert);
    cert = NIL_P(val) ? NULL : GetX509CertPtr(val); /* NO DUP NEEDED */
    val = rb_attr_get(self, id_i_key);
    key = NIL_P(val) ? NULL : GetPrivPKeyPtr(val); /* NO DUP NEEDED */
    if (cert &amp;&amp; key) {
        if (!SSL_CTX_use_certificate(ctx, cert)) {
            /* Adds a ref =&gt; Safe to FREE */
            ossl_raise(eSSLError, &quot;SSL_CTX_use_certificate&quot;);
        }
        if (!SSL_CTX_use_PrivateKey(ctx, key)) {
            /* Adds a ref =&gt; Safe to FREE */
            ossl_raise(eSSLError, &quot;SSL_CTX_use_PrivateKey&quot;);
        }
        if (!SSL_CTX_check_private_key(ctx)) {
            ossl_raise(eSSLError, &quot;SSL_CTX_check_private_key&quot;);
        }
    }

    val = rb_attr_get(self, id_i_client_ca);
    if(!NIL_P(val)){
        if (RB_TYPE_P(val, T_ARRAY)) {
            for(i = 0; i &lt; RARRAY_LEN(val); i++){
                client_ca = GetX509CertPtr(RARRAY_AREF(val, i));
                if (!SSL_CTX_add_client_CA(ctx, client_ca)){
                    /* Copies X509_NAME =&gt; FREE it. */
                    ossl_raise(eSSLError, &quot;SSL_CTX_add_client_CA&quot;);
                }
            }
        }
        else{
            client_ca = GetX509CertPtr(val); /* NO DUP NEEDED. */
            if (!SSL_CTX_add_client_CA(ctx, client_ca)){
                /* Copies X509_NAME =&gt; FREE it. */
                ossl_raise(eSSLError, &quot;SSL_CTX_add_client_CA&quot;);
            }
        }
    }

    val = rb_attr_get(self, id_i_ca_file);
    ca_file = NIL_P(val) ? NULL : StringValueCStr(val);
    val = rb_attr_get(self, id_i_ca_path);
    ca_path = NIL_P(val) ? NULL : StringValueCStr(val);
    if(ca_file || ca_path){
        if (!SSL_CTX_load_verify_locations(ctx, ca_file, ca_path))
            rb_warning(&quot;can&#39;t set verify locations&quot;);
    }

    val = rb_attr_get(self, id_i_verify_mode);
    verify_mode = NIL_P(val) ? SSL_VERIFY_NONE : NUM2INT(val);
    SSL_CTX_set_verify(ctx, verify_mode, ossl_ssl_verify_callback);
    if (RTEST(rb_attr_get(self, id_i_client_cert_cb)))
        SSL_CTX_set_client_cert_cb(ctx, ossl_client_cert_cb);

    val = rb_attr_get(self, id_i_timeout);
    if(!NIL_P(val)) SSL_CTX_set_timeout(ctx, NUM2LONG(val));

    val = rb_attr_get(self, id_i_verify_depth);
    if(!NIL_P(val)) SSL_CTX_set_verify_depth(ctx, NUM2INT(val));

#ifdef HAVE_SSL_CTX_SET_NEXT_PROTO_SELECT_CB
    val = rb_attr_get(self, id_i_npn_protocols);
    if (!NIL_P(val)) {
        VALUE encoded = ssl_encode_npn_protocols(val);
        SSL_CTX_set_next_protos_advertised_cb(ctx, ssl_npn_advertise_cb, (void *)encoded);
        OSSL_Debug(&quot;SSL NPN advertise callback added&quot;);
    }
    if (RTEST(rb_attr_get(self, id_i_npn_select_cb))) {
        SSL_CTX_set_next_proto_select_cb(ctx, ssl_npn_select_cb, (void *) self);
        OSSL_Debug(&quot;SSL NPN select callback added&quot;);
    }
#endif

#ifdef HAVE_SSL_CTX_SET_ALPN_SELECT_CB
    val = rb_attr_get(self, id_i_alpn_protocols);
    if (!NIL_P(val)) {
        VALUE rprotos = ssl_encode_npn_protocols(val);

        /* returns 0 on success */
        if (SSL_CTX_set_alpn_protos(ctx, (unsigned char *)RSTRING_PTR(rprotos),
                                    RSTRING_LENINT(rprotos)))
            ossl_raise(eSSLError, &quot;SSL_CTX_set_alpn_protos&quot;);
        OSSL_Debug(&quot;SSL ALPN values added&quot;);
    }
    if (RTEST(rb_attr_get(self, id_i_alpn_select_cb))) {
        SSL_CTX_set_alpn_select_cb(ctx, ssl_alpn_select_cb, (void *) self);
        OSSL_Debug(&quot;SSL ALPN select callback added&quot;);
    }
#endif

    rb_obj_freeze(self);

    val = rb_attr_get(self, id_i_session_id_context);
    if (!NIL_P(val)){
        StringValue(val);
        if (!SSL_CTX_set_session_id_context(ctx, (unsigned char *)RSTRING_PTR(val),
                                            RSTRING_LENINT(val))){
            ossl_raise(eSSLError, &quot;SSL_CTX_set_session_id_context&quot;);
        }
    }

    if (RTEST(rb_attr_get(self, id_i_session_get_cb))) {
        SSL_CTX_sess_set_get_cb(ctx, ossl_sslctx_session_get_cb);
        OSSL_Debug(&quot;SSL SESSION get callback added&quot;);
    }
    if (RTEST(rb_attr_get(self, id_i_session_new_cb))) {
        SSL_CTX_sess_set_new_cb(ctx, ossl_sslctx_session_new_cb);
        OSSL_Debug(&quot;SSL SESSION new callback added&quot;);
    }
    if (RTEST(rb_attr_get(self, id_i_session_remove_cb))) {
        SSL_CTX_sess_set_remove_cb(ctx, ossl_sslctx_session_remove_cb);
        OSSL_Debug(&quot;SSL SESSION remove callback added&quot;);
    }

#ifdef HAVE_SSL_SET_TLSEXT_HOST_NAME
    val = rb_attr_get(self, id_i_servername_cb);
    if (!NIL_P(val)) {
        SSL_CTX_set_tlsext_servername_callback(ctx, ssl_servername_cb);
        OSSL_Debug(&quot;SSL TLSEXT servername callback added&quot;);
    }
#endif

    return Qtrue;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-ssl_version-3D" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            ssl_version = :TLSv1
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            ssl_version = &quot;SSLv23_client&quot;
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Sets the SSL/TLS protocol version for the context. This forces connections
to use only the specified protocol version.</p>

<p>You can get a list of valid versions with <a
href="SSLContext.html#METHODS">OpenSSL::SSL::SSLContext::METHODS</a></p>
          
          

          
          <div class="method-source-code" id="ssl_version-3D-source">
            <pre>static VALUE
ossl_sslctx_set_ssl_version(VALUE self, VALUE ssl_method)
{
    SSL_CTX *ctx;
    const char *s;
    VALUE m = ssl_method;
    int i;

    GetSSLCTX(self, ctx);
    if (RB_TYPE_P(ssl_method, T_SYMBOL))
        m = rb_sym2str(ssl_method);
    s = StringValueCStr(m);
    for (i = 0; i &lt; numberof(ossl_ssl_method_tab); i++) {
        if (strcmp(ossl_ssl_method_tab[i].name, s) == 0) {
#if defined(HAVE_SSL_CTX_SET_MIN_PROTO_VERSION)
            int version = ossl_ssl_method_tab[i].version;
#endif
            SSL_METHOD *method = ossl_ssl_method_tab[i].func();

            if (SSL_CTX_set_ssl_version(ctx, method) != 1)
                ossl_raise(eSSLError, &quot;SSL_CTX_set_ssl_version&quot;);

#if defined(HAVE_SSL_CTX_SET_MIN_PROTO_VERSION)
            if (!SSL_CTX_set_min_proto_version(ctx, version))
                ossl_raise(eSSLError, &quot;SSL_CTX_set_min_proto_version&quot;);
            if (!SSL_CTX_set_max_proto_version(ctx, version))
                ossl_raise(eSSLError, &quot;SSL_CTX_set_max_proto_version&quot;);
#endif
            return ssl_method;
        }
    }

    ossl_raise(rb_eArgError, &quot;unknown SSL method `%&quot;PRIsVALUE&quot;&#39;.&quot;, m);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
    </section>
  
  </section>
</main>


<footer id="validator-badges" role="contentinfo">
  <p><a href="http://validator.w3.org/check/referer">Validate</a>
  <p>Generated by <a href="http://docs.seattlerb.org/rdoc/">RDoc</a> 4.2.3.
  <p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
</footer>