46 |
|
// |
47 |
|
// Douglas Thrift |
48 |
|
// |
49 |
< |
// $Id: HttpHandler.cpp,v 1.21 2003/07/18 07:26:41 douglas Exp $ |
49 |
> |
// $Id: HttpHandler.cpp,v 1.22 2003/07/20 01:46:12 douglas Exp $ |
50 |
|
|
51 |
|
#include "HttpHandler.h" |
52 |
|
|
58 |
|
#include <sys/socket.h> |
59 |
|
#include <netinet/in.h> |
60 |
|
#include <netdb.h> |
61 |
– |
|
62 |
– |
#define INVALID_SOCKET -1 |
63 |
– |
#define SOCKET_ERROR -1 |
64 |
– |
|
65 |
– |
inline int closesocket(SOCKET s) { return close(s); } |
61 |
|
#endif |
62 |
|
|
63 |
|
HttpHandler::HttpHandler() |
756 |
|
SSL_load_error_strings(); |
757 |
|
SSL_library_init(); |
758 |
|
|
759 |
< |
// |
759 |
> |
#ifndef _urandomdev_ |
760 |
> |
int pid = getpid(); |
761 |
> |
int now = time(NULL); |
762 |
> |
|
763 |
> |
unsigned seed = now > pid ? now - pid : pid - now; |
764 |
> |
|
765 |
> |
char* junk = new char[seed % 30 + 2]; |
766 |
> |
junk[0] = pid; |
767 |
> |
junk[seed % 30 + 1] = now; |
768 |
> |
|
769 |
> |
srand(seed); |
770 |
> |
|
771 |
> |
for (int index = 1; index < seed % 30 + 1; index++) |
772 |
> |
{ |
773 |
> |
junk[index] = rand(); |
774 |
> |
} |
775 |
> |
|
776 |
> |
if (debug) |
777 |
> |
{ |
778 |
> |
cerr << "junk = {\n"; |
779 |
> |
|
780 |
> |
for (int index = 1; index < seed % 30 + 2; index++) |
781 |
> |
{ |
782 |
> |
cerr << " [" << index << "] = " << int(junk[index]) << "\n"; |
783 |
> |
} |
784 |
> |
|
785 |
> |
cerr << "}\n"; |
786 |
> |
} |
787 |
> |
|
788 |
> |
RAND_seed(junk, seed % 30 + 2); |
789 |
> |
|
790 |
> |
delete junk; |
791 |
> |
#endif |
792 |
> |
|
793 |
> |
ctx = SSL_CTX_new(TLSv1_client_method()); |
794 |
> |
|
795 |
> |
if (ctx == NULL) |
796 |
> |
{ |
797 |
> |
cerr << program << ": SSL CTX New: " |
798 |
> |
<< ERR_reason_error_string(ERR_get_error()) << "\n"; |
799 |
> |
return false; |
800 |
> |
} |
801 |
> |
|
802 |
> |
ssl = SSL_new(ctx); |
803 |
> |
|
804 |
> |
if (SSL_set_fd(ssl, http) == 0) |
805 |
> |
{ |
806 |
> |
cerr << program << ": SSL Set FD: " |
807 |
> |
<< ERR_reason_error_string(ERR_get_error()) << "\n"; |
808 |
> |
return false; |
809 |
> |
} |
810 |
> |
|
811 |
> |
int number; |
812 |
> |
|
813 |
> |
if ((number = SSL_connect(ssl)) <= 0) |
814 |
> |
{ |
815 |
> |
error(program + ": SSL Connect", number); |
816 |
> |
return false; |
817 |
> |
} |
818 |
|
|
819 |
|
return true; |
820 |
|
} |