Home | History | Annotate | Download | only in https
      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 3, 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 test_https_get.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 
     41 static int
     42 test_cipher_option (FILE * test_fd,
     43 		    const char *cipher_suite,
     44 		    int proto_version)
     45 {
     46 
     47   int ret;
     48   struct MHD_Daemon *d;
     49   d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL |
     50                         MHD_USE_DEBUG, 4233,
     51                         NULL, NULL, &http_ahc, NULL,
     52                         MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
     53                         MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
     54                         MHD_OPTION_END);
     55 
     56   if (d == NULL)
     57     {
     58       fprintf (stderr, MHD_E_SERVER_INIT);
     59       return -1;
     60     }
     61 
     62   ret = test_https_transfer (test_fd, cipher_suite, proto_version);
     63 
     64   MHD_stop_daemon (d);
     65   return ret;
     66 }
     67 
     68 
     69 /* perform a HTTP GET request via SSL/TLS */
     70 static int
     71 test_secure_get (FILE * test_fd,
     72 		 const char *cipher_suite,
     73 		 int proto_version)
     74 {
     75   int ret;
     76   struct MHD_Daemon *d;
     77 
     78   d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL |
     79                         MHD_USE_DEBUG, 4233,
     80                         NULL, NULL, &http_ahc, NULL,
     81                         MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem,
     82                         MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem,
     83                         MHD_OPTION_END);
     84 
     85   if (d == NULL)
     86     {
     87       fprintf (stderr, MHD_E_SERVER_INIT);
     88       return -1;
     89     }
     90 
     91   ret = test_https_transfer (test_fd, cipher_suite, proto_version);
     92 
     93   MHD_stop_daemon (d);
     94   return ret;
     95 }
     96 
     97 
     98 int
     99 main (int argc, char *const *argv)
    100 {
    101   unsigned int errorCount = 0;
    102   const char *aes256_sha_tlsv1   = "AES256-SHA";
    103   const char *des_cbc3_sha_tlsv1 = "DES-CBC3-SHA";
    104 
    105   gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
    106 #ifdef GCRYCTL_INITIALIZATION_FINISHED
    107   gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
    108 #endif
    109   if (0 != curl_global_init (CURL_GLOBAL_ALL))
    110     {
    111       fprintf (stderr, "Error: %s\n", strerror (errno));
    112       return -1;
    113     }
    114 
    115   if (curl_uses_nss_ssl() == 0)
    116     {
    117       aes256_sha_tlsv1 = "rsa_aes_256_sha";
    118       des_cbc3_sha_tlsv1 = "rsa_aes_128_sha";
    119     }
    120 
    121   errorCount +=
    122     test_secure_get (NULL, aes256_sha_tlsv1, CURL_SSLVERSION_TLSv1);
    123   errorCount +=
    124     test_cipher_option (NULL, des_cbc3_sha_tlsv1, CURL_SSLVERSION_TLSv1);
    125   print_test_result (errorCount, argv[0]);
    126 
    127   curl_global_cleanup ();
    128 
    129   return errorCount != 0;
    130 }
    131