Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "ink_config.h"
00023
00024 #include "P_Net.h"
00025 #include "I_Layout.h"
00026 #include "I_RecHttp.h"
00027 #include "P_SSLUtils.h"
00028 #include "P_OCSPStapling.h"
00029
00030
00031
00032
00033
00034 SSLNetProcessor ssl_NetProcessor;
00035 NetProcessor& sslNetProcessor = ssl_NetProcessor;
00036 EventType SSLNetProcessor::ET_SSL;
00037
00038 #ifdef HAVE_OPENSSL_OCSP_STAPLING
00039 struct OCSPContinuation:public Continuation
00040 {
00041 int mainEvent(int , Event* )
00042 {
00043 ocsp_update();
00044
00045 return EVENT_CONT;
00046 }
00047
00048 OCSPContinuation():Continuation(new_ProxyMutex())
00049 {
00050 SET_HANDLER(&OCSPContinuation::mainEvent);
00051 }
00052 };
00053 #endif
00054
00055 void
00056 SSLNetProcessor::cleanup(void)
00057 {
00058 if (client_ctx) {
00059 SSL_CTX_free(client_ctx);
00060 client_ctx = NULL;
00061 }
00062 }
00063
00064 int
00065 SSLNetProcessor::start(int number_of_ssl_threads, size_t stacksize)
00066 {
00067
00068 SSLInitializeLibrary();
00069 SSLConfig::startup();
00070
00071 SSLCertificateConfig::startup();
00072
00073
00074 SSLConfig::scoped_config params;
00075
00076
00077
00078
00079 client_ctx = SSLInitClientContext(params);
00080 if (!client_ctx) {
00081 SSLError("Can't initialize the SSL client, HTTPS in remap rules will not function");
00082 }
00083
00084
00085 SSLInitializeStatistics();
00086
00087
00088 if (number_of_ssl_threads == 0) {
00089 return -1;
00090 }
00091
00092 #ifdef HAVE_OPENSSL_OCSP_STAPLING
00093 if (SSLConfigParams::ssl_ocsp_enabled) {
00094 EventType ET_OCSP = eventProcessor.spawn_event_threads(1, "ET_OCSP", stacksize);
00095 eventProcessor.schedule_every(new OCSPContinuation(), HRTIME_SECONDS(SSLConfigParams::ssl_ocsp_update_period), ET_OCSP);
00096 }
00097 #endif
00098
00099
00100 if (number_of_ssl_threads == -1) {
00101
00102
00103 SSLDebug("Disabling ET_SSL threads (config is set to -1), using thread group ET_NET=%d", ET_NET);
00104 SSLNetProcessor::ET_SSL = ET_NET;
00105 return 0;
00106 }
00107
00108 SSLNetProcessor::ET_SSL = eventProcessor.spawn_event_threads(number_of_ssl_threads, "ET_SSL", stacksize);
00109 return UnixNetProcessor::start(0, stacksize);
00110 }
00111
00112 NetAccept *
00113 SSLNetProcessor::createNetAccept()
00114 {
00115 return (NetAccept *) new SSLNetAccept;
00116 }
00117
00118
00119
00120 void
00121 SSLNetProcessor::upgradeEtype(EventType & etype)
00122 {
00123 if (etype == ET_NET) {
00124 etype = ET_SSL;
00125 }
00126 }
00127
00128 NetVConnection *
00129 SSLNetProcessor::allocate_vc(EThread *t)
00130 {
00131 SSLNetVConnection *vc;
00132
00133 if (t) {
00134 vc = THREAD_ALLOC(sslNetVCAllocator, t);
00135 } else {
00136 if (likely(vc = sslNetVCAllocator.alloc())) {
00137 vc->from_accept_thread = true;
00138 }
00139 }
00140
00141 return vc;
00142 }
00143
00144 SSLNetProcessor::SSLNetProcessor()
00145 : client_ctx(NULL)
00146 {
00147 }
00148
00149 SSLNetProcessor::~SSLNetProcessor()
00150 {
00151 cleanup();
00152 }