"Fossies" - the Fresh Open Source Software Archive

Member "links-1.03/https.c" (11 Sep 2006, 2025 Bytes) of archive /linux/www/links-1.03.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "https.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.8_vs_1.03.

    1 /* https.c
    2  * HTTPS protocol client implementation
    3  * (c) 2002 Mikulas Patocka
    4  * This file is a part of the Links program, released under GPL.
    5 
    6  * In addition, as a special exception, the copyright holders give
    7  * permission to link the code of portions of this program with the
    8  * OpenSSL library under certain conditions as described in each
    9  * individual source file, and distribute linked combinations
   10  * including the two.
   11  * You must obey the GNU General Public License in all respects
   12  * for all of the code used other than OpenSSL.  If you modify
   13  * file(s) with this exception, you may extend this exception to your
   14  * version of the file(s), but you are not obligated to do so.  If you
   15  * do not wish to do so, delete this exception statement from your
   16  * version.  If you delete this exception statement from all source
   17  * files in the program, then also delete it here.
   18  */
   19 
   20 #include "links.h"
   21 
   22 #ifndef PATH_MAX
   23 #define PATH_MAX 255
   24 #endif
   25 
   26 #ifdef HAVE_SSL
   27 
   28 SSL_CTX *context = NULL;
   29 
   30 SSL *getSSL(void)
   31 {
   32     if (!context) {
   33         char f_randfile[PATH_MAX];
   34 
   35         const char *f = RAND_file_name(f_randfile, sizeof(f_randfile));
   36         if (f && RAND_egd(f)<0) {
   37             /* Not an EGD, so read and write to it */
   38             if (RAND_load_file(f_randfile, -1))
   39                 RAND_write_file(f_randfile);
   40         }
   41         SSLeay_add_ssl_algorithms();
   42         context = SSL_CTX_new(SSLv23_client_method());
   43         SSL_CTX_set_options(context, SSL_OP_ALL);
   44         SSL_CTX_set_default_verify_paths(context);
   45 /* needed for systems without /dev/random, but obviously kills security. */
   46         /*{
   47             char pool[32768];
   48             int i;
   49             struct timeval tv;
   50             gettimeofday(&tv, NULL);
   51             for (i = 0; i < sizeof pool; i++) pool[i] = random() ^ tv.tv_sec ^ tv.tv_usec;
   52             RAND_add(pool, sizeof pool, sizeof pool);
   53         }*/
   54     }
   55     return (SSL_new(context));
   56 }
   57 void ssl_finish(void)
   58 {
   59     if (context) SSL_CTX_free(context);
   60 }
   61 
   62 void https_func(struct connection *c)
   63 {
   64     c->ssl = (void *)-1;
   65     http_func(c);
   66 }
   67 
   68 #else
   69 
   70 void https_func(struct connection *c)
   71 {
   72     setcstate(c, S_NO_SSL);
   73     abort_connection(c);
   74 }
   75 
   76 #endif