diff options
Diffstat (limited to 'src/testcurl/https/test_https_get.c')
-rw-r--r-- | src/testcurl/https/test_https_get.c | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/src/testcurl/https/test_https_get.c b/src/testcurl/https/test_https_get.c new file mode 100644 index 00000000..f279ac9f --- /dev/null +++ b/src/testcurl/https/test_https_get.c | |||
@@ -0,0 +1,127 @@ | |||
1 | /* | ||
2 | This file is part of libmicrohttpd | ||
3 | (C) 2007 Christian Grothoff | ||
4 | |||
5 | libmicrohttpd is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | libmicrohttpd is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with libmicrohttpd; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file mhds_get_test.c | ||
23 | * @brief Testcase for libmicrohttpd HTTPS GET operations | ||
24 | * @author Sagie Amir | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "microhttpd.h" | ||
29 | #include <limits.h> | ||
30 | #include <sys/stat.h> | ||
31 | #include <curl/curl.h> | ||
32 | #include <gcrypt.h> | ||
33 | #include "tls_test_common.h" | ||
34 | |||
35 | extern const char srv_key_pem[]; | ||
36 | extern const char srv_self_signed_cert_pem[]; | ||
37 | extern const char srv_signed_cert_pem[]; | ||
38 | extern const char srv_signed_key_pem[]; | ||
39 | |||
40 | static int | ||
41 | test_cipher_option (FILE * test_fd, char *cipher_suite, int proto_version) | ||
42 | { | ||
43 | |||
44 | int ret; | ||
45 | struct MHD_Daemon *d; | ||
46 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL | | ||
47 | MHD_USE_DEBUG, 4233, | ||
48 | NULL, NULL, &http_ahc, NULL, | ||
49 | MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, | ||
50 | MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, | ||
51 | MHD_OPTION_END); | ||
52 | |||
53 | if (d == NULL) | ||
54 | { | ||
55 | fprintf (stderr, MHD_E_SERVER_INIT); | ||
56 | return -1; | ||
57 | } | ||
58 | |||
59 | ret = test_https_transfer (test_fd, cipher_suite, proto_version); | ||
60 | |||
61 | MHD_stop_daemon (d); | ||
62 | return ret; | ||
63 | } | ||
64 | |||
65 | /* perform a HTTP GET request via SSL/TLS */ | ||
66 | int | ||
67 | test_secure_get (FILE * test_fd, char *cipher_suite, int proto_version) | ||
68 | { | ||
69 | int ret; | ||
70 | struct MHD_Daemon *d; | ||
71 | |||
72 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL | | ||
73 | MHD_USE_DEBUG, 4233, | ||
74 | NULL, NULL, &http_ahc, NULL, | ||
75 | MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem, | ||
76 | MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem, | ||
77 | MHD_OPTION_END); | ||
78 | |||
79 | if (d == NULL) | ||
80 | { | ||
81 | fprintf (stderr, MHD_E_SERVER_INIT); | ||
82 | return -1; | ||
83 | } | ||
84 | |||
85 | ret = test_https_transfer (test_fd, cipher_suite, proto_version); | ||
86 | |||
87 | MHD_stop_daemon (d); | ||
88 | return ret; | ||
89 | } | ||
90 | |||
91 | int | ||
92 | main (int argc, char *const *argv) | ||
93 | { | ||
94 | unsigned int errorCount = 0; | ||
95 | |||
96 | if (!gcry_check_version (GCRYPT_VERSION)) | ||
97 | abort (); | ||
98 | if (0 != curl_global_init (CURL_GLOBAL_ALL)) | ||
99 | { | ||
100 | fprintf (stderr, "Error: %s\n", strerror (errno)); | ||
101 | return -1; | ||
102 | } | ||
103 | |||
104 | char *aes256_sha_tlsv1 = "AES256-SHA"; | ||
105 | char *aes256_sha_sslv3 = "AES256-SHA"; | ||
106 | char *des_cbc3_sha_tlsv1 = "DES-CBC3-SHA"; | ||
107 | |||
108 | if (curl_uses_nss_ssl() == 0) | ||
109 | { | ||
110 | aes256_sha_tlsv1 = "rsa_aes_256_sha"; | ||
111 | aes256_sha_sslv3 = "rsa_aes_256_sha"; | ||
112 | des_cbc3_sha_tlsv1 = "rsa_aes_128_sha"; | ||
113 | } | ||
114 | |||
115 | errorCount += | ||
116 | test_secure_get (NULL, aes256_sha_tlsv1, CURL_SSLVERSION_TLSv1); | ||
117 | errorCount += | ||
118 | test_secure_get (NULL, aes256_sha_sslv3, CURL_SSLVERSION_SSLv3); | ||
119 | errorCount += | ||
120 | test_cipher_option (NULL, des_cbc3_sha_tlsv1, CURL_SSLVERSION_TLSv1); | ||
121 | |||
122 | print_test_result (errorCount, argv[0]); | ||
123 | |||
124 | curl_global_cleanup (); | ||
125 | |||
126 | return errorCount != 0; | ||
127 | } | ||