Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 2675 lines (2179 sloc) 51.931 kb
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 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674
/* SSLeay.xs - Perl module for using Eric Young's implementation of SSL
*
* Copyright (c) 1996-2002 Sampo Kellomaki <sampo@iki.fi>
* Copyright (C) 2005 Florian Ragwitz <rafl@debian.org>
* Copyright (C) 2005 Mike McCauley <mikem@open.com.au>
*
* All Rights Reserved.
*
* 19.6.1998, Maintenance release to sync with SSLeay-0.9.0, --Sampo
* 24.6.1998, added write_partial to support ssl_write_all in more
* memory efficient way. --Sampo
* 8.7.1998, Added SSL_(CTX)?_set_options and associated constants.
* 31.3.1999, Tracking OpenSSL-0.9.2b changes, dropping support for
* earlier versions
* 30.7.1999, Tracking OpenSSL-0.9.3a changes, --Sampo
* 7.4.2001, OpenSSL-0.9.6a update, --Sampo
* 18.4.2001, added TLSv1 support by Stephen C. Koehler
* <koehler@securecomputing.com>, version 1.07, --Sampo
* 25.4.2001, applied 64 bit fixes by Marko Asplund <aspa@kronodoc.fi> --Sampo
* 16.7.2001, applied Win filehandle patch from aspa, added
* SSL_*_methods --Sampo
* 25.9.2001, added a big pile of methods by automatically grepping and diffing
* openssl headers and my module --Sampo
* 17.4.2002, applied patch to fix CTX_set_default_passwd_cb() contributed
* by Timo Kujala <timo.kujala@@intellitel_.com>, --Sampo
* 17.5.2002, Added BIO_s_mem, BIO_new, BIO_free, BIO_write, BIO_read ,
* BIO_eof, BIO_pending, BIO_wpending, X509_NAME_get_text_by_NID,
* RSA_generate_key, BIO_new_file
* Fixed problem with return value from verify callback being
* ignored.
* Fixed a problem with CTX_set_tmp_rsa and CTX_set_tmp_dh
* args incorrect
* --mikem@open.com_.au
* 10.8.2002, Added SSL_peek patch to ssl_read_until from
* Peter Behroozi <peter@@fhpwireless_.com> --Sampo
* 21.8.2002, Added SESSION_get_master_key, SSL_get_client_random, SSL_get_server_random
* --mikem@open.com_.au
* 2.9.2002, Added SSL_CTX_get_cert_store, X509_STORE_add_cert, X509_STORE_add_crl
* X509_STORE_set_flags, X509_load_cert_file, X509_load_crl_file
* X509_load_cert_crl_file, PEM_read_bio_X509_CRL
* constants for X509_V_FLAG_*
* --mikem@open.com_.au
* 6.9.2002, applied Mike's patch and fixed X509_STORE_* to X509_STORE_CTX_*
* --Sampo
* 18.2.2003, RAND patch from Toni Andjelkovic <toni@soth._at>
* 13.6.2003, applied SSL_X509_LOOKUP patch by Marian Jancar <mjancar@suse._cz>
* 18.8.2003, fixed some const char pointer warnings --Sampo
* 01.12.2005 fixed a thread safety problem with SvSetSV that could cause crashes
* if SSL_CTX_set_default_passwd_cb and friends were called multiple
* times in different threads.
* Reintroduced X509_STORE_set_flags, also added
* X509_STORE_set_purpose and X509_STORE_set_trust
* Added X509_get_subjectAltNames and a number of other openssl
* X509 functions: X509_get_ext_by_NID X509_get_ext
* X509V3_EXT_d2i
* X509_verify_cert_error_string
* --mikem@open.com_.au
* 13.12.2005 Reinstated the thread safety fix from 01.12.2005 due memory leaks
* It is better to reset the callback with undef after use to prevent
* leaks and thread safety problems.
* 28.7.2006 Use New and Safefree insted of malloc/free. Use OPENSSL_free
* instead of free to release memory allocated by X509_NAME_oneline.
* These changes to deal with thread safety issues.
* 01.08.2006 set_*fd nw woork with filehandles as well as filenos on Windows
*
* $Id$
*
* The distribution and use of this module are subject to the conditions
* listed in LICENSE file at the root of OpenSSL-0.9.6b
* distribution (i.e. free, but mandatory attribution and NO WARRANTY).
*/

/* Prevent warnings about strncpy from Windows compilers */
#define _CRT_SECURE_NO_DEPRECATE

#ifdef __cplusplus
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
#ifdef __cplusplus
}
#endif

/* OpenSSL-0.9.3a has some strange warning about this in
* openssl/des.h
*/
#undef _

#include <openssl/err.h>
#include <openssl/lhash.h>
#include <openssl/rand.h>
#include <openssl/buffer.h>
#include <openssl/ssl.h>
#include <openssl/comp.h> /* openssl-0.9.6a forgets to include this */
#include <openssl/md2.h>
#include <openssl/md4.h>
#include <openssl/md5.h> /* openssl-SNAP-20020227 does not automatically include this */
#include <openssl/x509.h>
#include <openssl/x509v3.h>
#include <openssl/engine.h>

/* Debugging output */

#if 0
#define PR(s) printf(s);
#define PRN(s,n) printf("'%s' (%d)\n",s,n);
#define SEX_DEBUG 1
#else
#define PR(s)
#define PRN(s,n)
#undef SEX_DEBUG
#endif

#include "constants.c"

/* ============= typedefs to agument TYPEMAP ============== */

typedef void callback_no_ret(void);
typedef void cb_ssl_int_int_ret_void(const SSL *ssl,int,int);
typedef RSA * cb_ssl_int_int_ret_RSA(SSL * ssl,int is_export, int keylength);
typedef DH * cb_ssl_int_int_ret_DH(SSL * ssl,int is_export, int keylength);

typedef STACK_OF(X509_NAME) X509_NAME_STACK;

typedef int perl_filehandle_t;

/* ============= callback stuff ============== */

static HV* ssleay_ctx_verify_callbacks = (HV*)NULL;

static int
ssleay_verify_callback_invoke (int ok, X509_STORE_CTX* x509_store) {
SSL* ssl;
SV* key;
char* key_str;
STRLEN key_len;
SV** callback;
int count, res;
dSP;

ssl = X509_STORE_CTX_get_ex_data( x509_store, SSL_get_ex_data_X509_STORE_CTX_idx() );
key = sv_2mortal(newSViv( (IV)ssl ));
key_str = SvPV(key, key_len);

callback = hv_fetch( ssleay_ctx_verify_callbacks, key_str, key_len, 0 );

if (callback == NULL) {
SSL_CTX* ssl_ctx = SSL_get_SSL_CTX(ssl);
key = sv_2mortal(newSViv( (IV)ssl_ctx ));
key_str = SvPV(key, key_len);

callback = hv_fetch( ssleay_ctx_verify_callbacks, key_str, key_len, 0 );

if (callback == NULL) {
croak ("Net::SSLeay: verify_callback called, but not "
"set to point to any perl function.\n");
}
}


ENTER;
SAVETMPS;

PRN("verify callback glue", ok);

PUSHMARK(sp);
EXTEND( sp, 2 );
PUSHs( sv_2mortal(newSViv(ok)) );
PUSHs( sv_2mortal(newSViv((unsigned long int)x509_store)) );
PUTBACK;

PR("About to call verify callback.\n");
count = call_sv(*callback, G_SCALAR);
PR("Returned from verify callback.\n");

SPAGAIN;

if (count != 1) {
croak ( "Net::SSLeay: verify_callback "
"perl function did not return a scalar.\n");
}

res = POPi;

PUTBACK;
FREETMPS;
LEAVE;

return res;
}

static HV* ssleay_ctx_passwd_cbs = (HV*)NULL;

struct _ssleay_cb_t {
SV* func;
SV* data;
};
typedef struct _ssleay_cb_t ssleay_ctx_passwd_cb_t;
typedef struct _ssleay_cb_t ssleay_ctx_cert_verify_cb_t;
typedef struct _ssleay_cb_t ssleay_session_secret_cb_t;
typedef struct _ssleay_cb_t ssleay_RSA_generate_key_cb_t;

ssleay_ctx_passwd_cb_t*
ssleay_ctx_passwd_cb_new(SSL_CTX* ctx) {
ssleay_ctx_passwd_cb_t* cb;
SV* hash_value;
SV* key;
char* key_str;
STRLEN key_len;

New(0, cb, 1, ssleay_ctx_passwd_cb_t);
cb->func = NULL;
cb->data = NULL;

if (ctx == NULL)
croak( "Net::SSLeay: ctx == NULL in ssleay_ctx_passwd_cb_new" );

hash_value = sv_2mortal(newSViv( (IV)cb ));

key = sv_2mortal(newSViv( (IV)ctx ));
key_str = SvPV(key, key_len);

if (ssleay_ctx_passwd_cbs == (HV*)NULL)
ssleay_ctx_passwd_cbs = newHV();

SvREFCNT_inc(hash_value);
hv_store( ssleay_ctx_passwd_cbs, key_str, key_len, hash_value, 0 );

return cb;
}

ssleay_ctx_passwd_cb_t*
ssleay_ctx_passwd_cb_get(SSL_CTX* ctx) {
SV* key;
char* key_str;
STRLEN key_len;
SV** hash_value;
ssleay_ctx_passwd_cb_t* cb;

key = sv_2mortal(newSViv( (IV)ctx ));
key_str = SvPV(key, key_len);

hash_value = hv_fetch( ssleay_ctx_passwd_cbs, key_str, key_len, 0 );

if (hash_value == NULL || *hash_value == NULL) {
cb = ssleay_ctx_passwd_cb_new(ctx);
} else {
cb = (ssleay_ctx_passwd_cb_t*)SvIV( *hash_value );
}

return cb;
}

void
ssleay_ctx_passwd_cb_func_set(SSL_CTX* ctx, SV* func) {
ssleay_ctx_passwd_cb_t* cb;

cb = ssleay_ctx_passwd_cb_get(ctx);

if (cb->func)
SvREFCNT_dec(cb->func);

SvREFCNT_inc(func);
cb->func = func;
}

void
ssleay_ctx_passwd_cb_userdata_set(SSL_CTX* ctx, SV* data) {
ssleay_ctx_passwd_cb_t* cb;

cb = ssleay_ctx_passwd_cb_get(ctx);

if (cb->data)
SvREFCNT_dec(cb->data);

SvREFCNT_inc(data);
cb->data = data;
}

void
ssleay_ctx_passwd_cb_free_func(SSL_CTX* ctx) {
ssleay_ctx_passwd_cb_t* cb;

cb = ssleay_ctx_passwd_cb_get(ctx);

if (cb && cb->func) {
SvREFCNT_dec(cb->func);
cb->func = NULL;
}
}

void
ssleay_ctx_passwd_cb_free_userdata(SSL_CTX* ctx) {
ssleay_ctx_passwd_cb_t* cb;

cb = ssleay_ctx_passwd_cb_get(ctx);

if (cb && cb->data) {
SvREFCNT_dec(cb->data);
cb->data = NULL;
}
}

/* pem_password_cb function */

static int
ssleay_ctx_passwd_cb_invoke(char *buf, int size, int rwflag, void *userdata) {
dSP;

int count;
char *res;
ssleay_ctx_passwd_cb_t* cb = (ssleay_ctx_passwd_cb_t*)userdata;

ENTER;
SAVETMPS;

PUSHMARK(sp);
XPUSHs( sv_2mortal( newSViv(rwflag)) );
if (cb->data)
XPUSHs( cb->data );
PUTBACK;

if (cb->func == NULL)
croak ("Net::SSLeay: ssleay_ctx_passwd_cb_invoke called, but not "
"set to point to any perl function.\n");

count = call_sv( cb->func, G_SCALAR );

SPAGAIN;

if (count != 1)
croak ("Net::SSLeay: ssleay_ctx_passwd_cb_invoke "
"perl function did not return a scalar.\n");

res = POPp;

if (res == NULL) {
*buf = '\0';
} else {
strncpy(buf, res, size);
buf[size - 1] = '\0';
}

PUTBACK;
FREETMPS;
LEAVE;

return strlen(buf);
}

static HV* ssleay_ctx_cert_verify_cbs = (HV*)NULL;

ssleay_ctx_cert_verify_cb_t*
ssleay_ctx_cert_verify_cb_new(SSL_CTX* ctx, SV* func, SV* data) {
ssleay_ctx_cert_verify_cb_t* cb;
SV* hash_value;
SV* key;
char* key_str;
STRLEN key_len;

cb = New(0, cb, 1, ssleay_ctx_cert_verify_cb_t);

SvREFCNT_inc(func);
SvREFCNT_inc(data);
cb->func = func;
cb->data = data;

if (ctx == NULL) {
croak( "Net::SSLeay: ctx == NULL in ssleay_ctx_cert_verify_cb_new" );
}

hash_value = sv_2mortal(newSViv( (IV)cb ));

key = sv_2mortal(newSViv( (IV)ctx ));
key_str = SvPV(key, key_len);

if (ssleay_ctx_cert_verify_cbs == (HV*)NULL)
ssleay_ctx_cert_verify_cbs = newHV();

SvREFCNT_inc(hash_value);
hv_store( ssleay_ctx_cert_verify_cbs, key_str, key_len, hash_value, 0 );

return cb;
}

ssleay_ctx_cert_verify_cb_t*
ssleay_ctx_cert_verify_cb_get(SSL_CTX* ctx) {
SV* key;
char* key_str;
STRLEN key_len;
SV** hash_value;
ssleay_ctx_cert_verify_cb_t* cb;

key = sv_2mortal(newSViv( (IV)ctx ));
key_str = SvPV(key, key_len);

hash_value = hv_fetch( ssleay_ctx_cert_verify_cbs, key_str, key_len, 0 );

if (hash_value == NULL || *hash_value == NULL) {
cb = NULL;
} else {
cb = (ssleay_ctx_cert_verify_cb_t*)SvIV( *hash_value );
}

return cb;
}

void
ssleay_ctx_cert_verify_cb_free(SSL_CTX* ctx) {
ssleay_ctx_passwd_cb_t* cb;

cb = ssleay_ctx_cert_verify_cb_get(ctx);

if (cb) {
if (cb->func) {
SvREFCNT_dec(cb->func);
cb->func = NULL;
}

if (cb->data) {
SvREFCNT_dec(cb->data);
cb->data = NULL;
}
}

Safefree(cb);
}

int
ssleay_ctx_cert_verify_cb_invoke(X509_STORE_CTX* x509_store_ctx, void* data) {
dSP;

int count;
int res;
ssleay_ctx_cert_verify_cb_t* cb = (ssleay_ctx_cert_verify_cb_t*)data;

ENTER;
SAVETMPS;

PUSHMARK(SP);
XPUSHs(sv_2mortal(newSViv( (IV)x509_store_ctx )));
if (cb->data) {
XPUSHs( cb->data );
}
PUTBACK;

if (cb->func == NULL) {
croak ("Net::SSLeay: ssleay_ctx_cert_verify_cb_invoke called, but not "
"set to point to any perl function.\n");
}

count = call_sv( cb->func, G_SCALAR );

SPAGAIN;

if (count != 1) {
croak ("Net::SSLeay: ssleay_ctx_cert_verify_cb_invoke "
"perl function did not return a scalar.\n");
}

res = POPi;

PUTBACK;
FREETMPS;
LEAVE;

return res;
}

#ifdef SSL_F_SSL_SET_HELLO_EXTENSION
static HV* ssleay_session_secret_cbs = (HV*)NULL;

ssleay_session_secret_cb_t*
ssleay_session_secret_cb_new(SSL* s, SV* func, SV* data) {
ssleay_session_secret_cb_t* cb;
SV* hash_value;
SV* key;
char* key_str;
STRLEN key_len;

cb = New(0, cb, 1, ssleay_session_secret_cb_t);

SvREFCNT_inc(func);
SvREFCNT_inc(data);
cb->func = func;
cb->data = data;

if (s == NULL) {
croak( "Net::SSLeay: s == NULL in ssleay_session_secret_cb_new" );
}

hash_value = sv_2mortal(newSViv( (IV)cb ));

key = sv_2mortal(newSViv( (IV)s ));
key_str = SvPV(key, key_len);

if (ssleay_session_secret_cbs == (HV*)NULL)
ssleay_session_secret_cbs = newHV();

SvREFCNT_inc(hash_value);
hv_store( ssleay_session_secret_cbs, key_str, key_len, hash_value, 0 );

return cb;
}

ssleay_session_secret_cb_t*
ssleay_session_secret_cb_get(SSL* s) {
SV* key;
char* key_str;
STRLEN key_len;
SV** hash_value;
ssleay_session_secret_cb_t* cb;

key = sv_2mortal(newSViv( (IV)s ));
key_str = SvPV(key, key_len);

hash_value = hv_fetch( ssleay_session_secret_cbs, key_str, key_len, 0 );

if (hash_value == NULL || *hash_value == NULL) {
cb = NULL;
} else {
cb = (ssleay_session_secret_cb_t*)SvIV( *hash_value );
}

return cb;
}

void
ssleay_session_secret_cb_free(SSL* s) {
ssleay_session_secret_cb_t* cb;

cb = ssleay_session_secret_cb_get(s);

if (cb) {
if (cb->func) {
SvREFCNT_dec(cb->func);
cb->func = NULL;
}

if (cb->data) {
SvREFCNT_dec(cb->data);
cb->data = NULL;
}
}

Safefree(cb);
}

int
ssleay_session_secret_cb_invoke(SSL* s, void* secret, int *secret_len,
STACK_OF(SSL_CIPHER) *peer_ciphers,
SSL_CIPHER **cipher, void *arg)
{
dSP;

int count;
int res;
int i;
AV *ciphers = newAV();
SV *pref_cipher = sv_newmortal();
ssleay_session_secret_cb_t* cb = (ssleay_session_secret_cb_t*)arg;

ENTER;
SAVETMPS;

PUSHMARK(SP);
XPUSHs( sv_2mortal( newSVpv(secret, *secret_len)) );
for (i=0; i<sk_SSL_CIPHER_num(peer_ciphers); i++)
{
SSL_CIPHER *c = sk_SSL_CIPHER_value(peer_ciphers,i);
av_store(ciphers, i, sv_2mortal(newSVpv(SSL_CIPHER_get_name(c), 0)));
}
XPUSHs(sv_2mortal(newRV((SV*)ciphers)));
XPUSHs(sv_2mortal(newRV(pref_cipher)));
if (cb->data) {
XPUSHs( cb->data );
}
PUTBACK;

if (cb->func == NULL) {
croak ("Net::SSLeay: ssleay_session_secret_cb_invoke called, but not "
"set to point to any perl function.\n");
}

count = call_sv( cb->func, G_SCALAR );

SPAGAIN;

if (count != 1) {
croak ("Net::SSLeay: ssleay_session_secret_cb_invoke "
"perl function did not return a scalar.\n");
}

res = POPi;
if (res)
{
/* See if there is a preferred cipher selected, if so
it is an index into the stack */
if (SvIOK(pref_cipher))
{
*cipher = sk_SSL_CIPHER_value(peer_ciphers, SvIV(pref_cipher));
}
}

PUTBACK;
FREETMPS;
LEAVE;

return res;
}

#endif

ssleay_RSA_generate_key_cb_t*
ssleay_RSA_generate_key_cb_new(SV* func, SV* data) {
ssleay_RSA_generate_key_cb_t* cb;

New(0, cb, 1, ssleay_RSA_generate_key_cb_t);
cb->func = NULL;
cb->data = NULL;

if (func) {
SvREFCNT_inc(func);
cb->func = func;
}

if (data) {
SvREFCNT_inc(data);
cb->data = data;
}

return cb;
}

void
ssleay_RSA_generate_key_cb_free(ssleay_RSA_generate_key_cb_t* cb) {
if (cb) {
if (cb->func) {
SvREFCNT_dec(cb->func);
cb->func = NULL;
}

if (cb->data) {
SvREFCNT_dec(cb->data);
cb->data = NULL;
}
}

Safefree(cb);
}

void
ssleay_RSA_generate_key_cb_invoke(int i, int n, void* data) {
dSP;

ssleay_RSA_generate_key_cb_t* cb = (ssleay_RSA_generate_key_cb_t*)data;

if (cb->func) {
int count;

ENTER;
SAVETMPS;

PUSHMARK(sp);

XPUSHs(sv_2mortal( newSViv(i) ));
XPUSHs(sv_2mortal( newSViv(n) ));

if (cb->data)
XPUSHs( cb->data );

PUTBACK;

count = call_sv( cb->func, G_VOID|G_DISCARD );

if (count != 0)
croak ("Net::SSLeay: ssleay_RSA_generate_key_cb_invoke "
"perl function did return something in void context.\n");

PUTBACK;
FREETMPS;
LEAVE;
}
}


MODULE = Net::SSLeay PACKAGE = Net::SSLeay PREFIX = SSL_

PROTOTYPES: ENABLE

double
constant(name)
     char * name

int
hello()
        CODE:
        PR("\tSSLeay Hello World!\n");
        RETVAL = 1;
        OUTPUT:
        RETVAL

#define REM1 "============= SSL CONTEXT functions =============="

SSL_CTX *
SSL_CTX_new()
     CODE:
     RETVAL = SSL_CTX_new (SSLv23_method());
     OUTPUT:
     RETVAL

SSL_CTX *
SSL_CTX_v2_new()
     CODE:
     RETVAL = SSL_CTX_new (SSLv2_method());
     OUTPUT:
     RETVAL

SSL_CTX *
SSL_CTX_v3_new()
     CODE:
     RETVAL = SSL_CTX_new (SSLv3_method());
     OUTPUT:
     RETVAL

SSL_CTX *
SSL_CTX_v23_new()
     CODE:
     RETVAL = SSL_CTX_new (SSLv23_method());
     OUTPUT:
     RETVAL

SSL_CTX *
SSL_CTX_tlsv1_new()
     CODE:
     RETVAL = SSL_CTX_new (TLSv1_method());
     OUTPUT:
     RETVAL

SSL_CTX *
SSL_CTX_new_with_method(meth)
     CODE:
     RETVAL = SSL_CTX_new (SSLv23_method());
     OUTPUT:
     RETVAL

void
SSL_CTX_free(ctx)
     SSL_CTX * ctx

int
SSL_CTX_add_session(ctx,ses)
     SSL_CTX * ctx
     SSL_SESSION * ses

int
SSL_CTX_remove_session(ctx,ses)
     SSL_CTX * ctx
     SSL_SESSION * ses

void
SSL_CTX_flush_sessions(ctx,tm)
     SSL_CTX * ctx
     long tm

int
SSL_CTX_set_default_verify_paths(ctx)
     SSL_CTX * ctx

int
SSL_CTX_load_verify_locations(ctx,CAfile,CApath)
     SSL_CTX * ctx
     char * CAfile
     char * CApath
     CODE:
     RETVAL = SSL_CTX_load_verify_locations (ctx,
CAfile?(*CAfile?CAfile:NULL):NULL,
CApath?(*CApath?CApath:NULL):NULL
);
     OUTPUT:
     RETVAL

void
SSL_CTX_set_verify(ctx,mode,callback=NULL)
SSL_CTX * ctx
int mode
SV * callback
PREINIT:
SV* key;
char* key_str;
STRLEN key_len;
CODE:

if (ssleay_ctx_verify_callbacks == (HV*)NULL)
ssleay_ctx_verify_callbacks = newHV();

key = sv_2mortal(newSViv( (IV)ctx ));
key_str = SvPV(key, key_len);

/* Former versions of SSLeay checked if the callback was a true boolean value
* and didn't call it if it was false. Therefor some people set the callback
* to '0' if they don't want to use it (IO::Socket::SSL for example). Therefor
* we don't execute the callback if it's value isn't something true to retain
* backwards compatibility.
*/

if (callback == NULL || !SvTRUE(callback)) {
hv_delete( ssleay_ctx_verify_callbacks, key_str, key_len, G_DISCARD );
SSL_CTX_set_verify( ctx, mode, NULL );
} else {
hv_store( ssleay_ctx_verify_callbacks, key_str, key_len, newSVsv(callback), 0 );
SSL_CTX_set_verify( ctx, mode, &ssleay_verify_callback_invoke );
}

int
SSL_get_error(s,ret)
     SSL * s
     int ret

#define REM10 "============= SSL functions =============="

SSL *
SSL_new(ctx)
     SSL_CTX * ctx

void
SSL_free(s)
     SSL * s

#if 0 /* this seems to be gone in 0.9.0 */
void
SSL_debug(file)
       char * file

#endif

int
SSL_accept(s)
     SSL * s

void
SSL_clear(s)
     SSL * s

int
SSL_connect(s)
     SSL * s


#if defined(WIN32)

int
SSL_set_fd(s,fd)
     SSL * s
     perl_filehandle_t fd
     CODE:
     RETVAL = SSL_set_fd(s,_get_osfhandle(fd));
     OUTPUT:
     RETVAL

int
SSL_set_rfd(s,fd)
     SSL * s
     perl_filehandle_t fd
     CODE:
     RETVAL = SSL_set_rfd(s,_get_osfhandle(fd));
     OUTPUT:
     RETVAL

int
SSL_set_wfd(s,fd)
     SSL * s
     perl_filehandle_t fd
     CODE:
     RETVAL = SSL_set_wfd(s,_get_osfhandle(fd));
     OUTPUT:
     RETVAL

#else

int
SSL_set_fd(s,fd)
     SSL * s
     perl_filehandle_t fd

int
SSL_set_rfd(s,fd)
     SSL * s
     perl_filehandle_t fd

int
SSL_set_wfd(s,fd)
     SSL * s
     perl_filehandle_t fd

#endif

int
SSL_get_fd(s)
     SSL * s

void
SSL_read(s,max=32768)
SSL * s
int max
PREINIT:
char *buf;
int got;
CODE:
New(0, buf, max, char);
ST(0) = sv_newmortal(); /* Undefined to start with */
if ((got = SSL_read(s, buf, max)) >= 0)
sv_setpvn( ST(0), buf, got);
Safefree(buf);

void
SSL_peek(s,max=32768)
SSL * s
int max
PREINIT:
char *buf;
int got;
CODE:
New(0, buf, max, char);
ST(0) = sv_newmortal(); /* Undefined to start with */
if ((got = SSL_peek(s, buf, max)) >= 0)
sv_setpvn( ST(0), buf, got);
Safefree(buf);

int
SSL_write(s,buf)
     SSL * s
     PREINIT:
     STRLEN len;
     INPUT:
     char * buf = SvPV( ST(1), len);
     CODE:
     RETVAL = SSL_write (s, buf, (int)len);
     OUTPUT:
     RETVAL

int
SSL_write_partial(s,from,count,buf)
     SSL * s
     int from
     int count
     PREINIT:
     STRLEN len;
     INPUT:
     char * buf = SvPV( ST(3), len);
     CODE:
      /*
if (SvROK( ST(3) )) {
SV* t = SvRV( ST(3) );
buf = SvPV( t, len);
} else
buf = SvPV( ST(3), len);
*/
     PRN("write_partial from",from);
     PRN(&buf[from],len);
     PRN("write_partial count",count);
     len -= from;
     if (len < 0) {
       croak("from beyound end of buffer");
       RETVAL = -1;
     } else
       RETVAL = SSL_write (s, &(buf[from]), ((STRLEN)count<=len)?count:len);
     OUTPUT:
     RETVAL

int
SSL_use_RSAPrivateKey(s,rsa)
     SSL * s
     RSA * rsa

int
SSL_use_RSAPrivateKey_ASN1(s,d,len)
     SSL * s
     unsigned char * d
     long len

int
SSL_use_RSAPrivateKey_file(s,file,type)
     SSL * s
     char * file
     int type

int
SSL_CTX_use_RSAPrivateKey_file(ctx,file,type)
     SSL_CTX * ctx
     char * file
     int type

int
SSL_use_PrivateKey(s,pkey)
     SSL * s
     EVP_PKEY * pkey

int
SSL_use_PrivateKey_ASN1(pk,s,d,len)
     int pk
     SSL * s
     unsigned char * d
     long len

int
SSL_use_PrivateKey_file(s,file,type)
     SSL * s
     char * file
     int type

int
SSL_CTX_use_PrivateKey_file(ctx,file,type)
     SSL_CTX * ctx
     char * file
     int type

int
SSL_use_certificate(s,x)
     SSL * s
     X509 * x

int
SSL_use_certificate_ASN1(s,d,len)
     SSL * s
     unsigned char * d
     long len

int
SSL_use_certificate_file(s,file,type)
     SSL * s
     char * file
     int type

int
SSL_CTX_use_certificate_file(ctx,file,type)
     SSL_CTX * ctx
     char * file
     int type

const char *
SSL_state_string(s)
     SSL * s

const char *
SSL_rstate_string(s)
     SSL * s

const char *
SSL_state_string_long(s)
     SSL * s

const char *
SSL_rstate_string_long(s)
     SSL * s


long
SSL_get_time(ses)
     SSL_SESSION * ses

long
SSL_set_time(ses,t)
     SSL_SESSION * ses
     long t

long
SSL_get_timeout(ses)
     SSL_SESSION * ses

long
SSL_set_timeout(ses,t)
     SSL_SESSION * ses
     long t

void
SSL_copy_session_id(to,from)
     SSL * to
     SSL * from

void
SSL_set_read_ahead(s,yes=1)
     SSL * s
     int yes

int
SSL_get_read_ahead(s)
     SSL * s

int
SSL_pending(s)
     SSL * s

int
SSL_CTX_set_cipher_list(s,str)
     SSL_CTX * s
     char * str

const char *
SSL_get_cipher_list(s,n)
     SSL * s
     int n

int
SSL_set_cipher_list(s,str)
     SSL * s
     char * str

const char *
SSL_get_cipher(s)
     SSL * s

char *
SSL_get_shared_ciphers(s,buf,len)
     SSL * s
     char * buf
     int len

X509 *
SSL_get_peer_certificate(s)
     SSL * s

void
SSL_set_verify(s,mode,callback)
    SSL * s
    int mode
    SV * callback
PREINIT:
SV* key;
char* key_str;
STRLEN key_len;
    CODE:

if (ssleay_ctx_verify_callbacks == (HV*)NULL)
ssleay_ctx_verify_callbacks = newHV();

key = sv_2mortal(newSViv( (IV)s ));
key_str = SvPV(key, key_len);

if (callback == NULL) {
hv_delete( ssleay_ctx_verify_callbacks, key_str, key_len, G_DISCARD );
SSL_set_verify( s, mode, NULL );
} else {
hv_store( ssleay_ctx_verify_callbacks, key_str, key_len, newSVsv(callback), 0 );
SSL_set_verify( s, mode, &ssleay_verify_callback_invoke );
}

void
SSL_set_bio(s,rbio,wbio)
     SSL * s
     BIO * rbio
     BIO * wbio

BIO *
SSL_get_rbio(s)
     SSL * s

BIO *
SSL_get_wbio(s)
     SSL * s


SSL_SESSION *
SSL_SESSION_new()

int
SSL_SESSION_print(fp,ses)
     BIO * fp
     SSL_SESSION * ses

void
SSL_SESSION_free(ses)
     SSL_SESSION * ses

int
i2d_SSL_SESSION(in,pp)
     SSL_SESSION * in
     unsigned char * &pp

int
SSL_set_session(to,ses)
     SSL * to
     SSL_SESSION * ses

SSL_SESSION *
d2i_SSL_SESSION(a,pp,length)
     SSL_SESSION * &a
     const unsigned char * &pp
     long length

#define REM30 "SSLeay-0.9.0 defines these as macros. I expand them here for safety's sake"

SSL_SESSION *
SSL_get_session(s)
SSL * s
ALIAS:
SSL_get0_session = 1

SSL_SESSION *
SSL_get1_session(s)
     SSL * s

X509 *
SSL_get_certificate(s)
     SSL * s

SSL_CTX *
SSL_get_SSL_CTX(s)
     SSL * s

long
SSL_ctrl(ssl,cmd,larg,parg)
SSL * ssl
int cmd
long larg
char * parg

long
SSL_CTX_ctrl(ctx,cmd,larg,parg)
    SSL_CTX * ctx
    int cmd
    long larg
    char * parg

long
SSL_get_options(ssl)
     SSL * ssl

void
SSL_set_options(ssl,op)
     SSL * ssl
     long op

long
SSL_CTX_get_options(ctx)
     SSL_CTX * ctx

void
SSL_CTX_set_options(ctx,op)
     SSL_CTX * ctx
     long op

LHASH *
SSL_CTX_sessions(ctx)
     SSL_CTX * ctx
     CODE:
    /* NOTE: This should be deprecated. Corresponding macro was removed from ssl.h as of 0.9.2 */
     if (ctx == NULL) croak("NULL SSL context passed as argument.");
     RETVAL = ctx -> sessions;
     OUTPUT:
     RETVAL

unsigned long
SSL_CTX_sess_number(ctx)
     SSL_CTX * ctx

int
SSL_CTX_sess_connect(ctx)
     SSL_CTX * ctx

int
SSL_CTX_sess_connect_good(ctx)
     SSL_CTX * ctx

int
SSL_CTX_sess_connect_renegotiate(ctx)
     SSL_CTX * ctx

int
SSL_CTX_sess_accept(ctx)
     SSL_CTX * ctx

int
SSL_CTX_sess_accept_renegotiate(ctx)
     SSL_CTX * ctx

int
SSL_CTX_sess_accept_good(ctx)
     SSL_CTX * ctx

int
SSL_CTX_sess_hits(ctx)
     SSL_CTX * ctx

int
SSL_CTX_sess_cb_hits(ctx)
     SSL_CTX * ctx

int
SSL_CTX_sess_misses(ctx)
     SSL_CTX * ctx

int
SSL_CTX_sess_timeouts(ctx)
     SSL_CTX * ctx

int
SSL_CTX_sess_cache_full(ctx)
     SSL_CTX * ctx

int
SSL_CTX_sess_get_cache_size(ctx)
     SSL_CTX * ctx

void
SSL_CTX_sess_set_cache_size(ctx,size)
     SSL_CTX * ctx
     int size

int
SSL_want(s)
     SSL * s

int
SSL_state(s)
     SSL * s

BIO_METHOD *
BIO_f_ssl()

BIO_METHOD *
BIO_s_mem()

unsigned long
ERR_get_error()

unsigned long
ERR_peek_error()

void
ERR_put_error(lib,func,reason,file,line)
     int lib
     int func
     int reason
     char * file
     int line

void
ERR_clear_error()

char *
ERR_error_string(error,buf=NULL)
     unsigned long error
     char * buf
     CODE:
     RETVAL = ERR_error_string(error,buf);
     OUTPUT:
     RETVAL

void
SSL_load_error_strings()

void
ERR_load_crypto_strings()

int
SSL_library_init()
ALIAS:
SSLeay_add_ssl_algorithms = 1
OpenSSL_add_ssl_algorithms = 2
add_ssl_algorithms = 3

void
ENGINE_load_builtin_engines()

void
ENGINE_register_all_complete()

ENGINE*
ENGINE_by_id(id)
char * id

int
ENGINE_set_default(e, flags)
        ENGINE * e
        int flags

void
ERR_load_SSL_strings()

void
ERR_load_RAND_strings()

int
RAND_bytes(buf, num)
    SV *buf
    int num
    PREINIT:
        int rc;
        unsigned char *random;
    CODE:
        New(0, random, num, unsigned char);
        rc = RAND_bytes(random, num);
        sv_setpvn(buf, (const char*)random, num);
        Safefree(random);
        RETVAL = rc;
    OUTPUT:
        RETVAL

int
RAND_pseudo_bytes(buf, num)
    SV *buf
    int num
    PREINIT:
        int rc;
        unsigned char *random;
    CODE:
        New(0, random, num, unsigned char);
        rc = RAND_pseudo_bytes(random, num);
        sv_setpvn(buf, (const char*)random, num);
        Safefree(random);
        RETVAL = rc;
    OUTPUT:
        RETVAL

void
RAND_add(buf, num, entropy)
    SV *buf
    int num
    double entropy
    PREINIT:
        STRLEN len;
    CODE:
        RAND_add((const void *)SvPV(buf, len), num, entropy);

int
RAND_poll()

int
RAND_status()

int
RAND_egd_bytes(path, bytes)
    const char *path
    int bytes

SV *
RAND_file_name(num)
    size_t num
    PREINIT:
        char *buf;
    CODE:
        New(0, buf, num, char);
        if (!RAND_file_name(buf, num)) {
            Safefree(buf);
            XSRETURN_UNDEF;
        }
        RETVAL = newSVpv(buf, 0);
        Safefree(buf);
    OUTPUT:
        RETVAL

void
RAND_seed(buf)
     PREINIT:
     STRLEN len;
     INPUT:
     char * buf = SvPV( ST(1), len);
     CODE:
     RAND_seed (buf, (int)len);

void
RAND_cleanup()

int
RAND_load_file(file_name, how_much)
     char * file_name
     int how_much

int
RAND_write_file(file_name)
     char * file_name

int
RAND_egd(path)
     char * path

#define REM40 "Minimal X509 stuff..., this is a bit ugly and should be put in its own modules Net::SSLeay::X509.pm"

X509_NAME*
X509_get_issuer_name(cert)
     X509 * cert

X509_NAME*
X509_get_subject_name(cert)
     X509 * cert

void
X509_NAME_oneline(name)
X509_NAME * name
PREINIT:
char * buf;
CODE:
ST(0) = sv_newmortal(); /* Undefined to start with */
if (buf = X509_NAME_oneline(name, NULL, 0))
sv_setpvn( ST(0), buf, strlen(buf));
OPENSSL_free(buf); /* mem was allocated by openssl */

# WTF is the point of this function?
# The NID_* constants aren't bound anyway and no one can remember
# those undocumented numbers anyway.
void
X509_NAME_get_text_by_NID(name,nid)
X509_NAME * name
int nid
PREINIT:
char* buf;
int length;
CODE:
ST(0) = sv_newmortal(); /* Undefined to start with */
length = X509_NAME_get_text_by_NID(name, nid, NULL, 0);

New(0, buf, length+1, char);
if (X509_NAME_get_text_by_NID(name, nid, buf, length + 1))
sv_setpvn( ST(0), buf, length + 1);
Safefree(buf);

X509 *
X509_STORE_CTX_get_current_cert(x509_store_ctx)
     X509_STORE_CTX * x509_store_ctx

void *
X509_STORE_CTX_get_ex_data(x509_store_ctx,idx)
     X509_STORE_CTX * x509_store_ctx
     int idx

void
X509_get_subjectAltNames(cert)
X509 * cert
PPCODE:
int i, j, count = 0;
X509_EXTENSION *subjAltNameExt = NULL;
STACK_OF(GENERAL_NAME) *subjAltNameDNs = NULL;
GENERAL_NAME *subjAltNameDN = NULL;
int num_gnames;
if ( (i = X509_get_ext_by_NID(cert, NID_subject_alt_name, -1)) >= 0
&& (subjAltNameExt = X509_get_ext(cert, i))
&& (subjAltNameDNs = X509V3_EXT_d2i(subjAltNameExt)))
{
num_gnames = sk_GENERAL_NAME_num(subjAltNameDNs);

for (j = 0; j < num_gnames; j++)
                {
subjAltNameDN = sk_GENERAL_NAME_value(subjAltNameDNs, j);

                     switch (subjAltNameDN->type)
                     {
                     case GEN_OTHERNAME:
                         EXTEND(SP, 2);
                         count++;
                         PUSHs(sv_2mortal(newSViv(subjAltNameDN->type)));
                         PUSHs(sv_2mortal(newSVpv((const char*)ASN1_STRING_data(subjAltNameDN->d.otherName->value->value.utf8string), ASN1_STRING_length(subjAltNameDN->d.otherName->value->value.utf8string))));
                         break;
                     
                     case GEN_EMAIL:
                     case GEN_DNS:
                     case GEN_URI:
                         EXTEND(SP, 2);
                         count++;
                         PUSHs(sv_2mortal(newSViv(subjAltNameDN->type)));
                         PUSHs(sv_2mortal(newSVpv((const char*)ASN1_STRING_data(subjAltNameDN->d.ia5), ASN1_STRING_length(subjAltNameDN->d.ia5))));
                         break;

                     case GEN_DIRNAME:
                         {
                         char * buf = X509_NAME_oneline(subjAltNameDN->d.dirn, NULL, 0);
                         EXTEND(SP, 2);
                         count++;
                         PUSHs(sv_2mortal(newSViv(subjAltNameDN->type)));
                         PUSHs(sv_2mortal(newSVpv((buf), strlen((buf)))));
                         break;
                         }

                     case GEN_IPADD:
                         EXTEND(SP, 2);
                         count++;
                         PUSHs(sv_2mortal(newSViv(subjAltNameDN->type)));
                         PUSHs(sv_2mortal(newSVpv((const char*)subjAltNameDN->d.ip->data, subjAltNameDN->d.ip->length)));
                         break;
                        
                     }
}
}
XSRETURN(count * 2);

int
X509_get_ext_by_NID(x,nid,loc)
X509* x
int nid
int loc

X509_EXTENSION *
X509_get_ext(x,loc)
X509* x
int loc

void *
X509V3_EXT_d2i(ext)
X509_EXTENSION *ext

int
X509_STORE_CTX_get_error(x509_store_ctx)
     X509_STORE_CTX * x509_store_ctx

int
X509_STORE_CTX_get_error_depth(x509_store_ctx)
     X509_STORE_CTX * x509_store_ctx

int
X509_STORE_CTX_set_ex_data(x509_store_ctx,idx,data)
     X509_STORE_CTX * x509_store_ctx
     int idx
     void * data

void
X509_STORE_CTX_set_error(x509_store_ctx,s)
     X509_STORE_CTX * x509_store_ctx
     int s

void
X509_STORE_CTX_set_cert(x509_store_ctx,x)
     X509_STORE_CTX * x509_store_ctx
     X509 * x

int
X509_STORE_add_cert(ctx, x)
    X509_STORE *ctx
    X509 *x

int
X509_STORE_add_crl(ctx, x)
    X509_STORE *ctx
    X509_CRL *x

void
X509_STORE_CTX_set_flags(ctx, flags)
    X509_STORE_CTX *ctx
    long flags

#if OPENSSL_VERSION_NUMBER >= 0x0090800fL

void
X509_STORE_set_flags(ctx, flags)
    X509_STORE *ctx
    long flags

void
X509_STORE_set_purpose(ctx, purpose)
    X509_STORE *ctx
    int purpose

void
X509_STORE_set_trust(ctx, trust)
    X509_STORE *ctx
    int trust

#endif

int
X509_load_cert_file(ctx, file, type)
    X509_LOOKUP *ctx
    char *file
    int type

int
X509_load_crl_file(ctx, file, type)
    X509_LOOKUP *ctx
    char *file
    int type

int
X509_load_cert_crl_file(ctx, file, type)
    X509_LOOKUP *ctx
    char *file
    int type

const char *
X509_verify_cert_error_string(n)
    long n


ASN1_UTCTIME *
X509_get_notBefore(cert)
     X509 * cert

ASN1_UTCTIME *
X509_get_notAfter(cert)
     X509 * cert

void
P_ASN1_UTCTIME_put2string(tm)
     ASN1_UTCTIME * tm
     PREINIT:
     BIO *bp;
     int i;
     char buffer[256];
     CODE:
     bp = BIO_new(BIO_s_mem());
     ASN1_UTCTIME_print(bp,tm);
     i = BIO_read(bp,buffer,255);
     buffer[i] = '\0';
     ST(0) = sv_newmortal(); /* Undefined to start with */
     if ( i > 0 )
         sv_setpvn( ST(0), buffer, i );
     BIO_free(bp);

int
EVP_PKEY_copy_parameters(to,from)
     EVP_PKEY * to
     EVP_PKEY * from

void
PEM_get_string_X509(x509)
     X509 * x509
     PREINIT:
     BIO *bp;
     int i;
     char buffer[8196];
     CODE:
     bp = BIO_new(BIO_s_mem());
     PEM_write_bio_X509(bp,x509);
     i = BIO_read(bp,buffer,8195);
     buffer[i] = '\0';
     ST(0) = sv_newmortal(); /* Undefined to start with */
     if ( i > 0 )
         sv_setpvn( ST(0), buffer, i );
     BIO_free(bp);

void
MD2(data)
PREINIT:
STRLEN len;
unsigned char md[MD2_DIGEST_LENGTH];
unsigned char * ret;
INPUT:
unsigned char* data = (unsigned char *) SvPV( ST(0), len);
CODE:
ret = MD2(data,len,md);
if (ret!=NULL) {
XSRETURN_PVN((char *) md, MD2_DIGEST_LENGTH);
} else {
XSRETURN_UNDEF;
}

void
MD4(data)
PREINIT:
STRLEN len;
unsigned char md[MD4_DIGEST_LENGTH];
unsigned char * ret;
INPUT:
unsigned char* data = (unsigned char *) SvPV( ST(0), len );
CODE:
ret = MD4(data,len,md);
if (ret!=NULL) {
XSRETURN_PVN((char *) md, MD4_DIGEST_LENGTH);
} else {
XSRETURN_UNDEF;
}

void
MD5(data)
     PREINIT:
     STRLEN len;
     unsigned char md[MD5_DIGEST_LENGTH];
     unsigned char * ret;
     INPUT:
     unsigned char * data = (unsigned char *) SvPV( ST(0), len);
     CODE:
     ret = MD5(data,len,md);
     if (ret!=NULL) {
XSRETURN_PVN((char *) md, MD5_DIGEST_LENGTH);
     } else {
XSRETURN_UNDEF;
     }

SSL_METHOD *
SSLv2_method()

SSL_METHOD *
SSLv3_method()

SSL_METHOD *
TLSv1_method()

int
SSL_set_ssl_method(ssl, method)
     SSL * ssl
     SSL_METHOD * method

SSL_METHOD *
SSL_get_ssl_method(ssl)
     SSL * ssl

#define REM_AUTOMATICALLY_GENERATED_1_09

BIO *
BIO_new_buffer_ssl_connect(ctx)
     SSL_CTX * ctx

BIO *
BIO_new_file(filename,mode)
     char * filename
     char * mode

BIO *
BIO_new_ssl(ctx,client)
     SSL_CTX * ctx
     int client

BIO *
BIO_new_ssl_connect(ctx)
     SSL_CTX * ctx

BIO *
BIO_new(type)
     BIO_METHOD * type;

int
BIO_free(bio)
     BIO * bio;

void
BIO_read(s,max=32768)
BIO * s
int max
PREINIT:
char *buf = NULL;
int got;
CODE:
New(0, buf, max, char);
ST(0) = sv_newmortal(); /* Undefined to start with */
if ((got = BIO_read(s, buf, max)) >= 0)
sv_setpvn( ST(0), buf, got);
Safefree(buf);

int
BIO_write(s,buf)
     BIO * s
     PREINIT:
     STRLEN len;
     INPUT:
     char * buf = SvPV( ST(1), len);
     CODE:
     RETVAL = BIO_write (s, buf, (int)len);
     OUTPUT:
     RETVAL

int
BIO_eof(s)
     BIO * s

int
BIO_pending(s)
     BIO * s

int
BIO_wpending(s)
     BIO * s

int
BIO_ssl_copy_session_id(to,from)
     BIO * to
     BIO * from

void
BIO_ssl_shutdown(ssl_bio)
     BIO * ssl_bio

int
SSL_add_client_CA(ssl,x)
     SSL * ssl
     X509 * x

const char *
SSL_alert_desc_string(value)
     int value

const char *
SSL_alert_desc_string_long(value)
     int value

const char *
SSL_alert_type_string(value)
     int value

const char *
SSL_alert_type_string_long(value)
     int value

long
SSL_callback_ctrl(ssl,i,fp)
     SSL * ssl
     int i
     callback_no_ret * fp

int
SSL_check_private_key(ctx)
     SSL * ctx

char *
SSL_CIPHER_description(cipher,buf,size)
     SSL_CIPHER * cipher
     char * buf
     int size

int
SSL_CIPHER_get_bits(c,alg_bits)
     SSL_CIPHER * c
     int * alg_bits

int
SSL_COMP_add_compression_method(id,cm)
     int id
     COMP_METHOD * cm

int
SSL_CTX_add_client_CA(ctx,x)
     SSL_CTX * ctx
     X509 * x

long
SSL_CTX_callback_ctrl(ctx,i,fp)
     SSL_CTX * ctx
     int i
     callback_no_ret * fp

int
SSL_CTX_check_private_key(ctx)
     SSL_CTX * ctx

void *
SSL_CTX_get_ex_data(ssl,idx)
     SSL_CTX * ssl
     int idx

int
SSL_CTX_get_quiet_shutdown(ctx)
     SSL_CTX * ctx

long
SSL_CTX_get_timeout(ctx)
     SSL_CTX * ctx

int
SSL_CTX_get_verify_depth(ctx)
     SSL_CTX * ctx

int
SSL_CTX_get_verify_mode(ctx)
     SSL_CTX * ctx

void
SSL_CTX_set_cert_store(ctx,store)
     SSL_CTX * ctx
     X509_STORE * store

X509_STORE *
SSL_CTX_get_cert_store(ctx)
     SSL_CTX * ctx

void
SSL_CTX_set_cert_verify_callback(ctx,func,data=NULL)
SSL_CTX* ctx
SV* func
SV* data
PREINIT:
ssleay_ctx_cert_verify_cb_t* cb;
CODE:
if (func == NULL || func == &PL_sv_undef) {
ssleay_ctx_cert_verify_cb_free(ctx);
SSL_CTX_set_cert_verify_callback(ctx, NULL, NULL);
} else {
cb = ssleay_ctx_cert_verify_cb_new(ctx, func, data);
SSL_CTX_set_cert_verify_callback(ctx, ssleay_ctx_cert_verify_cb_invoke, cb);
}

void
SSL_CTX_set_client_CA_list(ctx,list)
     SSL_CTX * ctx
     X509_NAME_STACK * list

void
SSL_CTX_set_default_passwd_cb(ctx,func=NULL)
SSL_CTX * ctx
SV * func
PREINIT:
ssleay_ctx_passwd_cb_t* cb;
CODE:
if (func == NULL || func == &PL_sv_undef) {
ssleay_ctx_passwd_cb_free_func(ctx);
SSL_CTX_set_default_passwd_cb(ctx, NULL);
} else {
cb = ssleay_ctx_passwd_cb_get(ctx);
ssleay_ctx_passwd_cb_func_set(ctx, func);
SSL_CTX_set_default_passwd_cb(ctx, &ssleay_ctx_passwd_cb_invoke);
SSL_CTX_set_default_passwd_cb_userdata(ctx, (void*)cb);
}

void
SSL_CTX_set_default_passwd_cb_userdata(ctx,u=NULL)
SSL_CTX * ctx
SV* u
CODE:
if (u == NULL) {
ssleay_ctx_passwd_cb_free_userdata(ctx);
} else {
ssleay_ctx_passwd_cb_userdata_set(ctx, u);
}

int
SSL_CTX_set_ex_data(ssl,idx,data)
     SSL_CTX * ssl
     int idx
     void * data

int
SSL_CTX_set_purpose(s,purpose)
     SSL_CTX * s
     int purpose

void
SSL_CTX_set_quiet_shutdown(ctx,mode)
     SSL_CTX * ctx
     int mode

int
SSL_CTX_set_ssl_version(ctx,meth)
     SSL_CTX * ctx
     SSL_METHOD * meth

long
SSL_CTX_set_timeout(ctx,t)
     SSL_CTX * ctx
     long t

int
SSL_CTX_set_trust(s,trust)
     SSL_CTX * s
     int trust

void
SSL_CTX_set_verify_depth(ctx,depth)
     SSL_CTX * ctx
     int depth

int
SSL_CTX_use_certificate(ctx,x)
     SSL_CTX * ctx
     X509 * x

int
SSL_CTX_use_certificate_chain_file(ctx,file)
     SSL_CTX * ctx
     const char * file

int
SSL_CTX_use_PrivateKey(ctx,pkey)
     SSL_CTX * ctx
     EVP_PKEY * pkey

int
SSL_CTX_use_RSAPrivateKey(ctx,rsa)
     SSL_CTX * ctx
     RSA * rsa

int
SSL_do_handshake(s)
     SSL * s

SSL *
SSL_dup(ssl)
     SSL * ssl

SSL_CIPHER *
SSL_get_current_cipher(s)
     SSL * s

long
SSL_get_default_timeout(s)
     SSL * s

void *
SSL_get_ex_data(ssl,idx)
     SSL * ssl
     int idx

size_t
SSL_get_finished(s,buf,count)
     SSL * s
     void * buf
     size_t count

size_t
SSL_get_peer_finished(s,buf,count)
     SSL * s
     void * buf
     size_t count

int
SSL_get_quiet_shutdown(ssl)
     SSL * ssl

int
SSL_get_shutdown(ssl)
     SSL * ssl

int
SSL_get_verify_depth(s)
     SSL * s

int
SSL_get_verify_mode(s)
     SSL * s

long
SSL_get_verify_result(ssl)
     SSL * ssl

int
SSL_renegotiate(s)
     SSL * s

int
SSL_SESSION_cmp(a,b)
     SSL_SESSION * a
     SSL_SESSION * b

void *
SSL_SESSION_get_ex_data(ss,idx)
     SSL_SESSION * ss
     int idx

long
SSL_SESSION_get_time(s)
     SSL_SESSION * s

long
SSL_SESSION_get_timeout(s)
     SSL_SESSION * s

int
SSL_SESSION_print_fp(fp,ses)
     FILE * fp
     SSL_SESSION * ses

int
SSL_SESSION_set_ex_data(ss,idx,data)
     SSL_SESSION * ss
     int idx
     void * data

long
SSL_SESSION_set_time(s,t)
     SSL_SESSION * s
     long t

long
SSL_SESSION_set_timeout(s,t)
     SSL_SESSION * s
     long t

void
SSL_set_accept_state(s)
     SSL * s

void
SSL_set_client_CA_list(s,list)
     SSL * s
     X509_NAME_STACK * list

void
SSL_set_connect_state(s)
     SSL * s

int
SSL_set_ex_data(ssl,idx,data)
     SSL * ssl
     int idx
     void * data

void
SSL_set_info_callback(ssl,cb)
     SSL * ssl
     cb_ssl_int_int_ret_void * cb

int
SSL_set_purpose(s,purpose)
     SSL * s
     int purpose

void
SSL_set_quiet_shutdown(ssl,mode)
     SSL * ssl
     int mode

void
SSL_set_shutdown(ssl,mode)
     SSL * ssl
     int mode

int
SSL_set_trust(s,trust)
     SSL * s
     int trust

void
SSL_set_verify_depth(s,depth)
     SSL * s
     int depth

void
SSL_set_verify_result(ssl,v)
     SSL * ssl
     long v

int
SSL_shutdown(s)
     SSL * s

int
SSL_version(ssl)
     SSL * ssl

#define REM_MANUALLY_ADDED_1_09

X509_NAME_STACK *
SSL_load_client_CA_file(file)
     const char * file

int
SSL_add_file_cert_subjects_to_stack(stackCAs,file)
     X509_NAME_STACK * stackCAs
     const char * file

#ifndef WIN32
#ifndef VMS
#ifndef MAC_OS_pre_X

int
SSL_add_dir_cert_subjects_to_stack(stackCAs,dir)
     X509_NAME_STACK * stackCAs
     const char * dir

#endif
#endif
#endif

int
SSL_CTX_get_ex_new_index(argl,argp,new_func,dup_func,free_func)
     long argl
     void * argp
     CRYPTO_EX_new * new_func
     CRYPTO_EX_dup * dup_func
     CRYPTO_EX_free * free_func

int
SSL_CTX_set_session_id_context(ctx,sid_ctx,sid_ctx_len)
     SSL_CTX * ctx
     const unsigned char * sid_ctx
     unsigned int sid_ctx_len

int
SSL_set_session_id_context(ssl,sid_ctx,sid_ctx_len)
     SSL * ssl
     const unsigned char * sid_ctx
     unsigned int sid_ctx_len

void
SSL_CTX_set_tmp_rsa_callback(ctx, cb)
     SSL_CTX * ctx
     cb_ssl_int_int_ret_RSA * cb

void
SSL_set_tmp_rsa_callback(ssl, cb)
     SSL * ssl
     cb_ssl_int_int_ret_RSA * cb

void
SSL_CTX_set_tmp_dh_callback(ctx, dh)
     SSL_CTX * ctx
     cb_ssl_int_int_ret_DH * dh

void
SSL_set_tmp_dh_callback(ssl,dh)
     SSL * ssl
     cb_ssl_int_int_ret_DH * dh

int
SSL_get_ex_new_index(argl, argp, new_func, dup_func, free_func)
     long argl
     void * argp
     CRYPTO_EX_new * new_func
     CRYPTO_EX_dup * dup_func
     CRYPTO_EX_free * free_func

int
SSL_SESSION_get_ex_new_index(argl, argp, new_func, dup_func, free_func)
     long argl
     void * argp
     CRYPTO_EX_new * new_func
     CRYPTO_EX_dup * dup_func
     CRYPTO_EX_free * free_func

#define REM_SEMIAUTOMATIC_MACRO_GEN_1_09

long
SSL_clear_num_renegotiations(ssl)
  SSL * ssl
  CODE:
  RETVAL = SSL_ctrl(ssl,SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS,0,NULL);
  OUTPUT:
  RETVAL

long
SSL_CTX_add_extra_chain_cert(ctx,x509)
     SSL_CTX * ctx
     X509 * x509
  CODE:
  RETVAL = SSL_CTX_ctrl(ctx,SSL_CTRL_EXTRA_CHAIN_CERT,0,(char*)x509);
  OUTPUT:
  RETVAL

void *
SSL_CTX_get_app_data(ctx)
     SSL_CTX * ctx
  CODE:
  RETVAL = SSL_CTX_get_ex_data(ctx,0);
  OUTPUT:
  RETVAL

long
SSL_CTX_get_mode(ctx)
     SSL_CTX * ctx
  CODE:
  RETVAL = SSL_CTX_ctrl(ctx,SSL_CTRL_MODE,0,NULL);
  OUTPUT:
  RETVAL

long
SSL_CTX_get_read_ahead(ctx)
     SSL_CTX * ctx
  CODE:
  RETVAL = SSL_CTX_ctrl(ctx,SSL_CTRL_GET_READ_AHEAD,0,NULL);
  OUTPUT:
  RETVAL

long
SSL_CTX_get_session_cache_mode(ctx)
     SSL_CTX * ctx
  CODE:
  RETVAL = SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_MODE,0,NULL);
  OUTPUT:
  RETVAL

long
SSL_CTX_need_tmp_RSA(ctx)
     SSL_CTX * ctx
  CODE:
  RETVAL = SSL_CTX_ctrl(ctx,SSL_CTRL_NEED_TMP_RSA,0,NULL);
  OUTPUT:
  RETVAL

int
SSL_CTX_set_app_data(ctx,arg)
     SSL_CTX * ctx
     char * arg
  CODE:
  RETVAL = SSL_CTX_set_ex_data(ctx,0,arg);
  OUTPUT:
  RETVAL

long
SSL_CTX_set_mode(ctx,op)
     SSL_CTX * ctx
     long op
  CODE:
  RETVAL = SSL_CTX_ctrl(ctx,SSL_CTRL_MODE,op,NULL);
  OUTPUT:
  RETVAL

long
SSL_CTX_set_read_ahead(ctx,m)
     SSL_CTX * ctx
     long m
  CODE:
  RETVAL = SSL_CTX_ctrl(ctx,SSL_CTRL_SET_READ_AHEAD,m,NULL);
  OUTPUT:
  RETVAL

long
SSL_CTX_set_session_cache_mode(ctx,m)
     SSL_CTX * ctx
     long m
  CODE:
  RETVAL = SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_MODE,m,NULL);
  OUTPUT:
  RETVAL

long
SSL_CTX_set_tmp_dh(ctx,dh)
     SSL_CTX * ctx
     DH * dh

long
SSL_CTX_set_tmp_rsa(ctx,rsa)
     SSL_CTX * ctx
     RSA * rsa

void *
SSL_get_app_data(s)
     SSL * s
  CODE:
  RETVAL = SSL_get_ex_data(s,0);
  OUTPUT:
  RETVAL

int
SSL_get_cipher_bits(s,np)
     SSL * s
     int * np
  CODE:
  RETVAL = SSL_CIPHER_get_bits(SSL_get_current_cipher(s),np);
  OUTPUT:
  RETVAL

long
SSL_get_mode(ssl)
     SSL * ssl
  CODE:
  RETVAL = SSL_ctrl(ssl,SSL_CTRL_MODE,0,NULL);
  OUTPUT:
  RETVAL

int
SSL_get_state(ssl)
     SSL * ssl
  CODE:
  RETVAL = SSL_state(ssl);
  OUTPUT:
  RETVAL

long
SSL_need_tmp_RSA(ssl)
     SSL * ssl
  CODE:
  RETVAL = SSL_ctrl(ssl,SSL_CTRL_NEED_TMP_RSA,0,NULL);
  OUTPUT:
  RETVAL

long
SSL_num_renegotiations(ssl)
     SSL * ssl
  CODE:
  RETVAL = SSL_ctrl(ssl,SSL_CTRL_GET_NUM_RENEGOTIATIONS,0,NULL);
  OUTPUT:
  RETVAL

void *
SSL_SESSION_get_app_data(ses)
     SSL_SESSION * ses
  CODE:
  RETVAL = SSL_SESSION_get_ex_data(ses,0);
  OUTPUT:
  RETVAL

long
SSL_session_reused(ssl)
     SSL * ssl
  CODE:
  RETVAL = SSL_ctrl(ssl,SSL_CTRL_GET_SESSION_REUSED,0,NULL);
  OUTPUT:
  RETVAL

int
SSL_SESSION_set_app_data(s,a)
     SSL_SESSION * s
     void * a
  CODE:
  RETVAL = SSL_SESSION_set_ex_data(s,0,(char *)a);
  OUTPUT:
  RETVAL

int
SSL_set_app_data(s,arg)
     SSL * s
     void * arg
  CODE:
  RETVAL = SSL_set_ex_data(s,0,(char *)arg);
  OUTPUT:
  RETVAL

long
SSL_set_mode(ssl,op)
     SSL * ssl
     long op
  CODE:
  RETVAL = SSL_ctrl(ssl,SSL_CTRL_MODE,op,NULL);
  OUTPUT:
  RETVAL

int
SSL_set_pref_cipher(s,n)
     SSL * s
     const char * n
  CODE:
  RETVAL = SSL_set_cipher_list(s,n);
  OUTPUT:
  RETVAL

long
SSL_set_tmp_dh(ssl,dh)
     SSL * ssl
     DH * dh

long
SSL_set_tmp_rsa(ssl,rsa)
     SSL * ssl
     char * rsa
  CODE:
  RETVAL = SSL_ctrl(ssl,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa);
  OUTPUT:
  RETVAL

RSA *
RSA_generate_key(bits,e,perl_cb=NULL,perl_cb_arg=NULL)
int bits
unsigned long e
SV* perl_cb
SV* perl_cb_arg
PREINIT:
ssleay_RSA_generate_key_cb_t* cb = NULL;
CODE:
cb = ssleay_RSA_generate_key_cb_new(perl_cb, perl_cb_arg);
RETVAL = RSA_generate_key(bits, e, ssleay_RSA_generate_key_cb_invoke, cb);
ssleay_RSA_generate_key_cb_free(cb);
OUTPUT:
RETVAL

void
RSA_free(r)
    RSA * r

void
X509_free(a)
    X509 * a

DH *
PEM_read_bio_DHparams(bio,x=NULL,cb=NULL,u=NULL)
BIO * bio
void * x
pem_password_cb * cb
void * u

X509_CRL *
PEM_read_bio_X509_CRL(bio,x=NULL,cb=NULL,u=NULL)
BIO * bio
void * x
pem_password_cb * cb
void * u

void
DH_free(dh)
DH * dh

long
SSL_total_renegotiations(ssl)
     SSL * ssl
  CODE:
  RETVAL = SSL_ctrl(ssl,SSL_CTRL_GET_TOTAL_RENEGOTIATIONS,0,NULL);
  OUTPUT:
  RETVAL

void
SSL_SESSION_get_master_key(s)
     SSL_SESSION * s
     CODE:
     ST(0) = sv_newmortal(); /* Undefined to start with */
     sv_setpvn(ST(0), (const char*)s->master_key, s->master_key_length);

void
SSL_SESSION_set_master_key(s,key)
     SSL_SESSION * s
     PREINIT:
     STRLEN len;
     INPUT:
     char * key = SvPV(ST(1), len);
     CODE:
     memcpy(s->master_key, key, len);
     s->master_key_length = len;

void
SSL_get_client_random(s)
     SSL * s
     CODE:
     ST(0) = sv_newmortal(); /* Undefined to start with */
     sv_setpvn(ST(0), (const char*)s->s3->client_random, SSL3_RANDOM_SIZE);

void
SSL_get_server_random(s)
     SSL * s
     CODE:
     ST(0) = sv_newmortal(); /* Undefined to start with */
     sv_setpvn(ST(0), (const char*)s->s3->server_random, SSL3_RANDOM_SIZE);

int
SSL_get_keyblock_size(s)
     SSL * s
     CODE:
     if (s == NULL ||
s->enc_read_ctx == NULL ||
s->enc_read_ctx->cipher == NULL ||
s->read_hash == NULL)
     {
RETVAL = -1;
     }
     else
     {
const EVP_CIPHER *c;
const EVP_MD *h;
c = s->enc_read_ctx->cipher;
#if OPENSSL_VERSION_NUMBER >= 0x00909000L
h = EVP_MD_CTX_md(s->read_hash);
#else
h = s->read_hash;
#endif

RETVAL = 2 * (EVP_CIPHER_key_length(c) +
EVP_MD_size(h) +
EVP_CIPHER_iv_length(c));
     }
     OUTPUT:
     RETVAL



#ifdef SSL_F_SSL_SET_HELLO_EXTENSION
int
SSL_set_hello_extension(s, type, data)
     SSL * s
     int type
     PREINIT:
     STRLEN len;
     INPUT:
     char * data = SvPV( ST(2), len);
     CODE:
     RETVAL = SSL_set_hello_extension(s, type, data, len);
     OUTPUT:
     RETVAL

void
SSL_set_session_secret_cb(s,func,data=NULL)
SSL * s
SV* func
SV* data
PREINIT:
ssleay_session_secret_cb_t* cb;
CODE:
if (func == NULL || func == &PL_sv_undef) {
ssleay_session_secret_cb_free(s);
SSL_set_session_secret_cb(s, NULL, NULL);
} else {
cb = ssleay_session_secret_cb_new(s, func, data);
SSL_set_session_secret_cb(s, (int (*)(SSL *s, void *secret, int *secret_len,
STACK_OF(SSL_CIPHER) *peer_ciphers,
SSL_CIPHER **cipher, void *arg))&ssleay_session_secret_cb_invoke, cb);
}

#endif

#define REM_EOF "/* EOF - SSLeay.xs */"
Something went wrong with that request. Please try again.