• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  This file is part of libmicrohttpd
3  Copyright (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 tls_authentication_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 <curl/curl.h>
30 #include <limits.h>
31 #include <sys/stat.h>
32 #include <gcrypt.h>
33 #include "tls_test_common.h"
34 
35 extern int curl_check_version (const char *req_version, ...);
36 extern const char test_file_data[];
37 
38 extern const char ca_key_pem[];
39 extern const char ca_cert_pem[];
40 extern const char srv_signed_cert_pem[];
41 extern const char srv_signed_key_pem[];
42 
43 
44 
45 /* perform a HTTP GET request via SSL/TLS */
46 static int
test_secure_get(void * cls,char * cipher_suite,int proto_version)47 test_secure_get (void * cls, char *cipher_suite, int proto_version)
48 {
49   int ret;
50   struct MHD_Daemon *d;
51 
52   d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL |
53                         MHD_USE_DEBUG, DEAMON_TEST_PORT,
54                         NULL, NULL, &http_ahc, NULL,
55                         MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem,
56                         MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem,
57                         MHD_OPTION_END);
58 
59   if (d == NULL)
60     {
61       fprintf (stderr, MHD_E_SERVER_INIT);
62       return -1;
63     }
64 
65   ret = test_daemon_get (NULL, cipher_suite, proto_version, DEAMON_TEST_PORT, 0);
66 
67   MHD_stop_daemon (d);
68   return ret;
69 }
70 
71 
72 int
main(int argc,char * const * argv)73 main (int argc, char *const *argv)
74 {
75   unsigned int errorCount = 0;
76 
77   gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
78 #ifdef GCRYCTL_INITIALIZATION_FINISHED
79   gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
80 #endif
81   if (setup_ca_cert () == NULL)
82     {
83       fprintf (stderr, MHD_E_TEST_FILE_CREAT);
84       return -1;
85     }
86 
87   if (0 != curl_global_init (CURL_GLOBAL_ALL))
88     {
89       fprintf (stderr, "Error (code: %u)\n", errorCount);
90       return -1;
91     }
92 
93   char *aes256_sha = "AES256-SHA";
94   if (curl_uses_nss_ssl() == 0)
95     {
96       aes256_sha = "rsa_aes_256_sha";
97     }
98 
99   errorCount +=
100     test_secure_get (NULL, aes256_sha, CURL_SSLVERSION_TLSv1);
101 
102   print_test_result (errorCount, argv[0]);
103 
104   curl_global_cleanup ();
105   if (0 != remove (ca_cert_file_name))
106     fprintf (stderr,
107 	     "Failed to remove `%s'\n",
108 	     ca_cert_file_name);
109   return errorCount != 0;
110 }
111