• 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 #ifndef TLS_TEST_COMMON_H_
22 #define TLS_TEST_COMMON_H_
23 
24 #include "platform.h"
25 #include "microhttpd.h"
26 #include <curl/curl.h>
27 #include <sys/stat.h>
28 #include <limits.h>
29 #include <gnutls/gnutls.h>
30 
31 /* this enables verbos CURL version checking */
32 #define DEBUG_HTTPS_TEST 0
33 #define CURL_VERBOS_LEVEL 0
34 
35 #define DEAMON_TEST_PORT 4233
36 
37 #define test_data "Hello World\n"
38 #define ca_cert_file_name "tmp_ca_cert.pem"
39 
40 #define EMPTY_PAGE "<html><head><title>Empty page</title></head><body>Empty page</body></html>"
41 #define PAGE_NOT_FOUND "<html><head><title>File not found</title></head><body>File not found</body></html>"
42 
43 #define MHD_E_MEM "Error: memory error\n"
44 #define MHD_E_SERVER_INIT "Error: failed to start server\n"
45 #define MHD_E_TEST_FILE_CREAT "Error: failed to setup test file\n"
46 #define MHD_E_CERT_FILE_CREAT "Error: failed to setup test certificate\n"
47 #define MHD_E_KEY_FILE_CREAT "Error: failed to setup test certificate\n"
48 #define MHD_E_FAILED_TO_CONNECT "Error: server connection could not be established\n"
49 
50 /* TODO rm if unused */
51 struct https_test_data
52 {
53   void *cls;
54   const char *cipher_suite;
55   int proto_version;
56 };
57 
58 struct CBC
59 {
60   char *buf;
61   size_t pos;
62   size_t size;
63 };
64 
65 struct CipherDef
66 {
67   int options[2];
68   char *curlname;
69 };
70 
71 
72 int curl_check_version (const char *req_version, ...);
73 int curl_uses_nss_ssl ();
74 
75 
76 FILE *
77 setup_ca_cert ();
78 
79 /**
80  * perform cURL request for file
81  */
82 int
83 test_daemon_get (void * cls,
84 		 const char *cipher_suite, int proto_version,
85                  int port, int ver_peer);
86 
87 void print_test_result (int test_outcome, char *test_name);
88 
89 size_t copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx);
90 
91 int
92 http_ahc (void *cls, struct MHD_Connection *connection,
93           const char *url, const char *method, const char *upload_data,
94           const char *version, size_t *upload_data_size, void **ptr);
95 
96 int
97 http_dummy_ahc (void *cls, struct MHD_Connection *connection,
98                 const char *url, const char *method, const char *upload_data,
99                 const char *version, size_t *upload_data_size,
100                 void **ptr);
101 
102 
103 /**
104  * compile test file url pointing to the current running directory path
105  *
106  * @param url - char buffer into which the url is compiled
107  * @param port port to use for the test
108  * @return -1 on error
109  */
110 int gen_test_file_url (char *url, int port);
111 
112 int
113 send_curl_req (char *url, struct CBC *cbc, const char *cipher_suite,
114                int proto_version);
115 
116 int
117 test_https_transfer (void *cls, const char *cipher_suite, int proto_version);
118 
119 int
120 setup_testcase (struct MHD_Daemon **d, int daemon_flags, va_list arg_list);
121 
122 void teardown_testcase (struct MHD_Daemon *d);
123 
124 int
125 setup_session (gnutls_session_t * session,
126                gnutls_datum_t * key,
127                gnutls_datum_t * cert,
128                gnutls_certificate_credentials_t * xcred);
129 
130 int
131 teardown_session (gnutls_session_t session,
132                   gnutls_datum_t * key,
133                   gnutls_datum_t * cert,
134                   gnutls_certificate_credentials_t xcred);
135 
136 int
137 test_wrap (const char *test_name, int
138            (*test_function) (void * cls, const char *cipher_suite,
139                              int proto_version), void *test_function_cls,
140            int daemon_flags, const char *cipher_suite, int proto_version, ...);
141 #endif /* TLS_TEST_COMMON_H_ */
142