/[resiprocate]/main/resip/stack/test/testSecurity.cxx
ViewVC logotype

Contents of /main/resip/stack/test/testSecurity.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9485 - (show annotations) (download)
Sat Apr 7 00:34:03 2012 UTC (7 years, 7 months ago) by dpocock
File MIME type: text/plain
File size: 4765 byte(s)
Switch over to autotools build system from dpocock-autotools branch
1 #if defined(HAVE_CONFIG_H)
2 #include "config.h"
3 #endif
4
5 #include <iostream>
6
7 #include "resip/stack/ssl/Security.hxx"
8 //#include "rutil/ssl/OpenSSLInit.hxx"
9 #include "rutil/ThreadIf.hxx"
10 #include "rutil/Log.hxx"
11 #include "rutil/Logger.hxx"
12
13 #ifdef USE_SSL
14 #include <openssl/evp.h>
15 #endif
16
17 using namespace std;
18 using namespace resip;
19
20 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
21
22 // the destructor in BaseSecurity started crashing on the Mac and Windows
23 // at Revision 5785. The crash can be reproduced by creating 2 security
24 // objects, one after another.
25 void testMultiple()
26 {
27 {
28 Security security;
29 }
30 #ifdef WIN32
31 Sleep(10000);
32 #else
33 sleep(10);
34 #endif
35 {
36 Security security;
37 }
38 }
39
40 class HashThread : public ThreadIf
41 {
42 public:
43 void thread()
44 {
45 Security security;
46 for(int i = 0; i < 500000; i++)
47 {
48 if (i % 1000 == 0)
49 {
50 DebugLog(<< "1000 digest calculations complete. ");
51 }
52 makeMD5Digest("I don't give a damn about digest");
53 }
54 }
55 private:
56 void makeMD5Digest(const char *pBuf)
57 {
58
59 #ifdef USE_SSL
60 unsigned char MD5_digest[EVP_MAX_MD_SIZE+1];
61 unsigned int iDigest = 0;
62 memset(MD5_digest, 0, sizeof(MD5_digest));
63
64 if(0 == pBuf)
65 return;
66
67 const EVP_MD *pDigest = EVP_md5();
68 if( 0 == pDigest)
69 return;
70
71 EVP_MD_CTX cCtx;
72 EVP_DigestInit(&cCtx, pDigest);
73 EVP_DigestUpdate(&cCtx, pBuf, strlen(pBuf));
74 EVP_DigestFinal(&cCtx, MD5_digest, &iDigest);
75 EVP_MD_CTX_cleanup(&cCtx);
76
77 // cout << "Your digest is: " << MD5_digest << endl;
78 #else
79 // cout << "OpenSSL not enabled; cannot calculate digest !!!";
80 #endif
81 }
82 };
83
84 class DumbInitThread : public ThreadIf
85 {
86 public:
87 void thread()
88 {
89 for(int i = 0; i < 500; i++)
90 {
91 DebugLog(<< "Creating Security object on stack");
92 Security security;
93 }
94 }
95 };
96
97 void testSecurityMultiThread()
98 {
99 HashThread t1;
100 DumbInitThread t2;
101
102 t1.run();
103 t2.run();
104
105 t1.join();
106 t2.join();
107 }
108
109
110 int
111 main(int argc, const char** argv)
112 {
113 Log::initialize(Log::Cout, Log::Debug, argv[0]);
114 #if 0
115 testMultiple();
116 #else
117 testSecurityMultiThread();
118 #endif
119 return 0;
120 }
121
122
123 /* ====================================================================
124 * The Vovida Software License, Version 1.0
125 *
126 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
127 *
128 * Redistribution and use in source and binary forms, with or without
129 * modification, are permitted provided that the following conditions
130 * are met:
131 *
132 * 1. Redistributions of source code must retain the above copyright
133 * notice, this list of conditions and the following disclaimer.
134 *
135 * 2. Redistributions in binary form must reproduce the above copyright
136 * notice, this list of conditions and the following disclaimer in
137 * the documentation and/or other materials provided with the
138 * distribution.
139 *
140 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
141 * and "Vovida Open Communication Application Library (VOCAL)" must
142 * not be used to endorse or promote products derived from this
143 * software without prior written permission. For written
144 * permission, please contact vocal@vovida.org.
145 *
146 * 4. Products derived from this software may not be called "VOCAL", nor
147 * may "VOCAL" appear in their name, without prior written
148 * permission of Vovida Networks, Inc.
149 *
150 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
151 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
152 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
153 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
154 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
155 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
156 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
157 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
158 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
159 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
160 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
161 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
162 * DAMAGE.
163 *
164 * ====================================================================
165 *
166 * This software consists of voluntary contributions made by Vovida
167 * Networks, Inc. and many individuals on behalf of Vovida Networks,
168 * Inc. For more information on Vovida Networks, Inc., please see
169 * <http://www.vovida.org/>.
170 *
171 */

Properties

Name Value
svn:eol-style native
svn:mime-type text/plain

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27