• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

SSLNetProcessor.cc

Go to the documentation of this file.
00001 /** @file
00002 
00003   @section license License
00004 
00005   Licensed to the Apache Software Foundation (ASF) under one
00006   or more contributor license agreements.  See the NOTICE file
00007   distributed with this work for additional information
00008   regarding copyright ownership.  The ASF licenses this file
00009   to you under the Apache License, Version 2.0 (the
00010   "License"); you may not use this file except in compliance
00011   with the License.  You may obtain a copy of the License at
00012 
00013       http://www.apache.org/licenses/LICENSE-2.0
00014 
00015   Unless required by applicable law or agreed to in writing, software
00016   distributed under the License is distributed on an "AS IS" BASIS,
00017   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00018   See the License for the specific language governing permissions and
00019   limitations under the License.
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 // Global Data
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 ATS_UNUSED */, Event* /* e ATS_UNUSED */)
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 /* HAVE_OPENSSL_OCSP_STAPLING */
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   // This initialization order matters ...
00068   SSLInitializeLibrary();
00069   SSLConfig::startup();
00070 
00071   SSLCertificateConfig::startup();
00072 
00073   // Acquire a SSLConfigParams instance *after* we start SSL up.
00074   SSLConfig::scoped_config params;
00075 
00076   // Enable client regardless of config file settings as remap file
00077   // can cause HTTP layer to connect using SSL. But only if SSL
00078   // initialization hasn't failed already.
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   // Initialize SSL statistics. This depends on an initial set of certificates being loaded above.
00085   SSLInitializeStatistics();
00086 
00087   // Shouldn't this be handled the same as -1?
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 /* HAVE_OPENSSL_OCSP_STAPLING */
00098 
00099 
00100   if (number_of_ssl_threads == -1) {
00101     // We've disabled ET_SSL threads, so we will mark all ET_NET threads as having
00102     // ET_SSL thread capabilities and just keep on chugging.
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; // Set the event type for ET_SSL to be 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 // Virtual function allows etype to be upgraded to ET_SSL for SSLNetProcessor.  Does
00119 // nothing for NetProcessor
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 }

Generated by  doxygen 1.7.1