|
reSIProcate/stack
9694
|
00001 #if defined(HAVE_CONFIG_H) 00002 #include "config.h" 00003 #endif 00004 00005 #include <iostream> 00006 00007 #include "resip/stack/ssl/Security.hxx" 00008 //#include "rutil/ssl/OpenSSLInit.hxx" 00009 #include "rutil/ThreadIf.hxx" 00010 #include "rutil/Log.hxx" 00011 #include "rutil/Logger.hxx" 00012 00013 #ifdef USE_SSL 00014 #include <openssl/evp.h> 00015 #endif 00016 00017 using namespace std; 00018 using namespace resip; 00019 00020 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST 00021 00022 // the destructor in BaseSecurity started crashing on the Mac and Windows 00023 // at Revision 5785. The crash can be reproduced by creating 2 security 00024 // objects, one after another. 00025 void testMultiple() 00026 { 00027 { 00028 Security security; 00029 } 00030 #ifdef WIN32 00031 Sleep(10000); 00032 #else 00033 sleep(10); 00034 #endif 00035 { 00036 Security security; 00037 } 00038 } 00039 00040 class HashThread : public ThreadIf 00041 { 00042 public: 00043 void thread() 00044 { 00045 Security security; 00046 for(int i = 0; i < 500000; i++) 00047 { 00048 if (i % 1000 == 0) 00049 { 00050 DebugLog(<< "1000 digest calculations complete. "); 00051 } 00052 makeMD5Digest("I don't give a damn about digest"); 00053 } 00054 } 00055 private: 00056 void makeMD5Digest(const char *pBuf) 00057 { 00058 00059 #ifdef USE_SSL 00060 unsigned char MD5_digest[EVP_MAX_MD_SIZE+1]; 00061 unsigned int iDigest = 0; 00062 memset(MD5_digest, 0, sizeof(MD5_digest)); 00063 00064 if(0 == pBuf) 00065 return; 00066 00067 const EVP_MD *pDigest = EVP_md5(); 00068 if( 0 == pDigest) 00069 return; 00070 00071 EVP_MD_CTX cCtx; 00072 EVP_DigestInit(&cCtx, pDigest); 00073 EVP_DigestUpdate(&cCtx, pBuf, strlen(pBuf)); 00074 EVP_DigestFinal(&cCtx, MD5_digest, &iDigest); 00075 EVP_MD_CTX_cleanup(&cCtx); 00076 00077 // cout << "Your digest is: " << MD5_digest << endl; 00078 #else 00079 // cout << "OpenSSL not enabled; cannot calculate digest !!!"; 00080 #endif 00081 } 00082 }; 00083 00084 class DumbInitThread : public ThreadIf 00085 { 00086 public: 00087 void thread() 00088 { 00089 for(int i = 0; i < 500; i++) 00090 { 00091 DebugLog(<< "Creating Security object on stack"); 00092 Security security; 00093 } 00094 } 00095 }; 00096 00097 void testSecurityMultiThread() 00098 { 00099 HashThread t1; 00100 DumbInitThread t2; 00101 00102 t1.run(); 00103 t2.run(); 00104 00105 t1.join(); 00106 t2.join(); 00107 } 00108 00109 00110 int 00111 main(int argc, const char** argv) 00112 { 00113 Log::initialize(Log::Cout, Log::Debug, argv[0]); 00114 #if 0 00115 testMultiple(); 00116 #else 00117 testSecurityMultiThread(); 00118 #endif 00119 return 0; 00120 } 00121 00122 00123 /* ==================================================================== 00124 * The Vovida Software License, Version 1.0 00125 * 00126 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00127 * 00128 * Redistribution and use in source and binary forms, with or without 00129 * modification, are permitted provided that the following conditions 00130 * are met: 00131 * 00132 * 1. Redistributions of source code must retain the above copyright 00133 * notice, this list of conditions and the following disclaimer. 00134 * 00135 * 2. Redistributions in binary form must reproduce the above copyright 00136 * notice, this list of conditions and the following disclaimer in 00137 * the documentation and/or other materials provided with the 00138 * distribution. 00139 * 00140 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00141 * and "Vovida Open Communication Application Library (VOCAL)" must 00142 * not be used to endorse or promote products derived from this 00143 * software without prior written permission. For written 00144 * permission, please contact vocal@vovida.org. 00145 * 00146 * 4. Products derived from this software may not be called "VOCAL", nor 00147 * may "VOCAL" appear in their name, without prior written 00148 * permission of Vovida Networks, Inc. 00149 * 00150 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00151 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00152 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00153 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00154 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00155 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00156 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00157 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00158 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00159 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00160 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00161 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00162 * DAMAGE. 00163 * 00164 * ==================================================================== 00165 * 00166 * This software consists of voluntary contributions made by Vovida 00167 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00168 * Inc. For more information on Vovida Networks, Inc., please see 00169 * <http://www.vovida.org/>. 00170 * 00171 */
1.7.5.1