reSIProcate/stack  9694
TlsTransport.cxx
Go to the documentation of this file.
00001 #if defined(HAVE_CONFIG_H)
00002 #include "config.h"
00003 #endif
00004 
00005 #ifdef USE_SSL
00006 
00007 #include <memory>
00008 
00009 #include "rutil/compat.hxx"
00010 #include "rutil/Data.hxx"
00011 #include "rutil/Socket.hxx"
00012 #include "rutil/Logger.hxx"
00013 #include "resip/stack/ssl/TlsTransport.hxx"
00014 #include "resip/stack/ssl/TlsConnection.hxx"
00015 #include "resip/stack/ssl/Security.hxx"
00016 #include "rutil/WinLeakCheck.hxx"
00017 
00018 #define RESIPROCATE_SUBSYSTEM Subsystem::TRANSPORT
00019 
00020 using namespace std;
00021 using namespace resip;
00022 
00023 TlsTransport::TlsTransport(Fifo<TransactionMessage>& fifo, 
00024                            int portNum, 
00025                            IpVersion version,
00026                            const Data& interfaceObj,
00027                            Security& security,
00028                            const Data& sipDomain, 
00029                            SecurityTypes::SSLType sslType,
00030                            AfterSocketCreationFuncPtr socketFunc,
00031                            Compression &compression,
00032                            unsigned transportFlags,
00033                            SecurityTypes::TlsClientVerificationMode cvm,
00034                            bool useEmailAsSIP):
00035    TcpBaseTransport(fifo, portNum, version, interfaceObj, socketFunc, compression, transportFlags),
00036    mSecurity(&security),
00037    mSslType(sslType),
00038    mDomainCtx(0),
00039    mClientVerificationMode(cvm),
00040    mUseEmailAsSIP(useEmailAsSIP)
00041 {
00042    setTlsDomain(sipDomain);   
00043    mTuple.setType(transport());
00044 
00045    init();
00046 
00047    // If we have specified a sipDomain, then we need to create a new context for this domain,
00048    // otherwise we will use the SSL Ctx or TLS Ctx created in the Security class
00049    if(!sipDomain.empty())
00050    {
00051       if (sslType == SecurityTypes::SSLv23)
00052       {
00053          mDomainCtx = mSecurity->createDomainCtx(SSLv23_method(), sipDomain);
00054       }
00055       else
00056       {
00057          mDomainCtx = mSecurity->createDomainCtx(TLSv1_method(), sipDomain);
00058       }
00059    }
00060 
00061    InfoLog (<< "Creating TLS transport for domain " 
00062             << sipDomain << " interface=" << interfaceObj 
00063             << " port=" << mTuple.getPort());
00064 
00065    mTxFifo.setDescription("TlsTransport::mTxFifo");
00066 }
00067 
00068 
00069 TlsTransport::~TlsTransport()
00070 {
00071    if (mDomainCtx)
00072    {
00073       SSL_CTX_free(mDomainCtx);mDomainCtx=0;
00074    }
00075 }
00076 
00077 SSL_CTX* 
00078 TlsTransport::getCtx() const 
00079 { 
00080    if(mDomainCtx)
00081    {
00082       return mDomainCtx;
00083    }
00084    else if(mSslType == SecurityTypes::SSLv23)
00085    {
00086       return mSecurity->getSslCtx();
00087    }
00088    return mSecurity->getTlsCtx();
00089 }
00090 
00091 Connection* 
00092 TlsTransport::createConnection(const Tuple& who, Socket fd, bool server)
00093 {
00094    assert(this);
00095    Connection* conn = new TlsConnection(this,who, fd, mSecurity, server,
00096                                         tlsDomain(), mSslType, mCompression );
00097    return conn;
00098 }
00099 
00100 #endif /* USE_SSL */
00101 
00102 /* ====================================================================
00103  * The Vovida Software License, Version 1.0 
00104  * 
00105  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00106  * 
00107  * Redistribution and use in source and binary forms, with or without
00108  * modification, are permitted provided that the following conditions
00109  * are met:
00110  * 
00111  * 1. Redistributions of source code must retain the above copyright
00112  *    notice, this list of conditions and the following disclaimer.
00113  * 
00114  * 2. Redistributions in binary form must reproduce the above copyright
00115  *    notice, this list of conditions and the following disclaimer in
00116  *    the documentation and/or other materials provided with the
00117  *    distribution.
00118  * 
00119  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00120  *    and "Vovida Open Communication Application Library (VOCAL)" must
00121  *    not be used to endorse or promote products derived from this
00122  *    software without prior written permission. For written
00123  *    permission, please contact vocal@vovida.org.
00124  *
00125  * 4. Products derived from this software may not be called "VOCAL", nor
00126  *    may "VOCAL" appear in their name, without prior written
00127  *    permission of Vovida Networks, Inc.
00128  * 
00129  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00130  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00131  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00132  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00133  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00134  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00135  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00136  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00137  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00138  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00139  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00140  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00141  * DAMAGE.
00142  * 
00143  * ====================================================================
00144  * 
00145  * This software consists of voluntary contributions made by Vovida
00146  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00147  * Inc.  For more information on Vovida Networks, Inc., please see
00148  * <http://www.vovida.org/>.
00149  *
00150  */