|
reSIProcate/stack
9694
|
00001 #ifdef HAVE_CONFIG_H 00002 #include "config.h" 00003 #endif 00004 00005 #include <cassert> 00006 #include <fstream> 00007 #include <ostream> 00008 00009 #include "rutil/Logger.hxx" 00010 00011 #ifdef USE_SSL 00012 #include "resip/stack/ssl/Security.hxx" 00013 #endif 00014 00015 #include "TestSupport.hxx" 00016 00017 00018 using namespace resip; 00019 using namespace std; 00020 00021 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST 00022 00023 00024 int 00025 main(int argc, char* argv[]) 00026 { 00027 Log::initialize(Log::Cout, Log::Debug, Data::Empty); 00028 00029 #ifdef USE_SSL 00030 Security* security=0; 00031 try 00032 { 00033 security = new Security; 00034 } 00035 catch( ... ) 00036 { 00037 security = 0; 00038 ErrLog( << "Got a exception setting up Security" ); 00039 return -1; 00040 } 00041 00042 try 00043 { 00044 assert(security != 0); 00045 security->preload(); 00046 } 00047 catch( ... ) 00048 { 00049 ErrLog( << "Got a exception loading certificates" ); 00050 return -1; 00051 } 00052 00053 assert( security ); 00054 00055 { 00056 ErrLog( << "\n\nStarting test one" ); 00057 00058 Data txt1 = 00059 "INVITE sip:bob@biloxi.exmple.org SIP/2.0\r\n" 00060 "Via: SIP/2.0/TLS pc33.atlanta.example.com;branch=z9hG4bKnashds8\r\n" 00061 "To: Bob <sip:bob@biloxi.example.org>\r\n" 00062 "From: Alice <sip:alice@atlanta.example.com>;tag=1928301774\r\n" 00063 "Call-ID: a84b4c76e66710\r\n" 00064 "CSeq: 314159 INVITE\r\n" 00065 "Max-Forwards: 70\r\n" 00066 "Date: Thu, 21 Feb 2002 13:02:03 GMT\r\n" 00067 "Contact: <sip:alice@pc33.atlanta.example.com>\r\n" 00068 "Content-Type: application/sdp\r\n" 00069 "Content-Length: 147\r\n" 00070 "\r\n" 00071 "v=0\r\n" 00072 "o=UserA 2890844526 2890844526 IN IP4 pc33.atlanta.example.com\r\n" 00073 "s=Session SDP\r\n" 00074 "c=IN IP4 pc33.atlanta.example.com\r\n" 00075 "t=0 0\r\n" 00076 "m=audio 49172 RTP/AVP 0\r\n" 00077 "a=rtpmap:0 PCMU/8000\r\n"; 00078 00079 auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt1)); 00080 00081 try 00082 { 00083 const Data& domain = msg->header(h_From).uri().host(); 00084 msg->header(h_Identity).value() = security->computeIdentity( domain, 00085 msg->getCanonicalIdentityString()); 00086 } 00087 catch (Security::Exception& e) 00088 { 00089 ErrLog (<< "Couldn't add identity header: " << e); 00090 msg->remove(h_Identity); 00091 } 00092 00093 ErrLog( << "INVITE base64 identity is " << msg->header(h_Identity).value() ); 00094 } 00095 00096 { 00097 ErrLog( << "\n\nStarting test two" ); 00098 00099 Data txt2 = 00100 "BYE sip:alice@pc33.atlanta.example.com SIP/2.0\r\n" 00101 "Via: SIP/2.0/TLS 192.0.2.4;branch=z9hG4bKnashds10\r\n" 00102 "Max-Forwards: 70\r\n" 00103 "From: Bob <sip:bob@biloxi.example.org>;tag=a6c85cf\r\n" 00104 "To: Alice <sip:alice@atlanta.example.com>;tag=1928301774\r\n" 00105 "Date: Thu, 21 Feb 2002 14:19:51 GMT\r\n" 00106 "Call-ID: a84b4c76e66710\r\n" 00107 "CSeq: 231 BYE\r\n" 00108 "Content-Length: 0\r\n" 00109 "\r\n" 00110 ; 00111 00112 auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt2)); 00113 00114 try 00115 { 00116 const Data& domain = msg->header(h_From).uri().host(); 00117 00118 Data identString = msg->getCanonicalIdentityString(); 00119 00120 msg->header(h_Identity).value() = security->computeIdentity( domain, identString ); 00121 } 00122 catch (Security::Exception& e) 00123 { 00124 ErrLog (<< "Couldn't add identity header: " << e); 00125 msg->remove(h_Identity); 00126 } 00127 00128 ErrLog( << "BYE base64 identity is " << msg->header(h_Identity).value() ); 00129 } 00130 00131 00132 00133 { 00134 ErrLog( << "\n\nStarting test three - conect iden - invite(2) " ); 00135 00136 Data txt1 = 00137 00138 "INVITE sip:Carol@ua2.example.com SIP/2.0\r\n" 00139 "Via: SIP/2.0/TLS proxy.example.com;branch=z9hG4bK776asdhds\r\n" 00140 "Via: SIP/2.0/TLS ua1.example.com;branch=z9hG4bKnashds8;received=192.0.2.1\r\n" 00141 "To: Bob <sip:bob@example.com>\r\n" 00142 "From: Alice <sip:alice@example.com>;tag=13adc987\r\n" 00143 "Call-ID: 12345600@ua1.example.com\r\n" 00144 "CSeq: 1 INVITE\r\n" 00145 "Max-Forwards: 69\r\n" 00146 "Date: Thu, 21 Feb 2002 13:02:03 GMT\r\n" 00147 "Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, UPDATE\r\n" 00148 "Supported: from-change\r\n" 00149 "Contact: <sip:alice@ua1.example.com>\r\n" 00150 "Record-Route: <sip:proxy.example.com;lr>\r\n" 00151 "Identity-Info: <https://example.com/example.cer>;alg=rsa-sha1\r\n" 00152 "Content-Type: application/sdp\r\n" 00153 "Content-Length: 154\r\n" 00154 "\r\n" 00155 "v=0\r\n" 00156 "o=UserA 2890844526 2890844526 IN IP4 ua1.example.com\r\n" 00157 "s=Session SDP\r\n" 00158 "c=IN IP4 ua1.example.com\r\n" 00159 "t=0 0\r\n" 00160 "m=audio 49172 RTP/AVP 0\r\n" 00161 "a=rtpmap:0 PCMU/8000\r\n" 00162 ; 00163 00164 00165 auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt1)); 00166 00167 try 00168 { 00169 const Data& domain = msg->header(h_From).uri().host(); 00170 msg->header(h_Identity).value() = security->computeIdentity( domain, 00171 msg->getCanonicalIdentityString()); 00172 } 00173 catch (Security::Exception& e) 00174 { 00175 ErrLog (<< "Couldn't add identity header: " << e); 00176 msg->remove(h_Identity); 00177 } 00178 00179 ErrLog( << "base64 identity is " << msg->header(h_Identity).value() ); 00180 } 00181 00182 00183 00184 00185 { 00186 ErrLog( << "\n\nStarting test four - connected-id update(8) " ); 00187 00188 Data txt2 = 00189 00190 "UPDATE sip:Alice@ua1.example.com SIP/2.0\r\n" 00191 "Via: SIP/2.0/TLS proxy.example.com;branch=z9hG4bK776asdhdu\r\n" 00192 "Via: SIP/2.0/TLS ua2.example.com;branch=z9hG4bKnashdt1;received=192.0.2.3\r\n" 00193 "From: Carol <sip:Carol@example.com>;tag=2ge46ab5\r\n" 00194 "To: Alice <sip:Alice@example.com>;tag=13adc987\r\n" 00195 "Call-ID: 12345600@ua1.example.com\r\n" 00196 "CSeq: 2 UPDATE\r\n" 00197 "Max-Forwards: 69\r\n" 00198 "Date: Thu, 21 Feb 2002 13:02:15 GMT\r\n" 00199 "Contact: <sip:Carol@ua2.example.com>\r\n" 00200 "Identity-Info: <https://example.com/cert>;alg=rsa-sha1\r\n" 00201 "Content-Length: 0\r\n" 00202 "\r\n" 00203 ; 00204 00205 00206 auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt2)); 00207 00208 try 00209 { 00210 const Data& domain = msg->header(h_From).uri().host(); 00211 00212 Data identString = msg->getCanonicalIdentityString(); 00213 00214 msg->header(h_Identity).value() = security->computeIdentity( domain, identString ); 00215 } 00216 catch (Security::Exception& e) 00217 { 00218 ErrLog (<< "Couldn't add identity header: " << e); 00219 msg->remove(h_Identity); 00220 } 00221 00222 ErrLog( << "base64 identity is " << msg->header(h_Identity).value() ); 00223 } 00224 00225 00226 00227 00228 { 00229 ErrLog( << "\n\nStarting test five - connected-id reinvite 6 " ); 00230 00231 Data txt2 = 00232 00233 "INVITE sip:alice@ua1.example.com SIP/2.0\r\n" 00234 "Via: SIP/2.0/TLS b2bua.example.com;branch=z9hG4bKnashdxy\r\n" 00235 "From: Carol <sip:Carol@example.com>;tag=2ge46ab5\r\n" 00236 "To: Alice <sip:Alice@example.com>;tag=13adc987\r\n" 00237 "Call-ID: 12345600@ua1.example.com\r\n" 00238 "CSeq: 3 INVITE\r\n" 00239 "Max-Forwards: 70\r\n" 00240 "Date: Thu, 21 Feb 2002 13:03:20 GMT\r\n" 00241 "Contact: <sip:xyz@b2bua.example.com>\r\n" 00242 "Identity-Info: <https://example.com/cert>;alg=rsa-sha1\r\n" 00243 "Content-Length: 0\r\n" 00244 "\r\n"; 00245 00246 auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt2)); 00247 00248 try 00249 { 00250 const Data& domain = msg->header(h_From).uri().host(); 00251 00252 Data identString = msg->getCanonicalIdentityString(); 00253 00254 msg->header(h_Identity).value() = security->computeIdentity( domain, identString ); 00255 } 00256 catch (Security::Exception& e) 00257 { 00258 ErrLog (<< "Couldn't add identity header: " << e); 00259 msg->remove(h_Identity); 00260 } 00261 ErrLog( << "base64 identity is " << msg->header(h_Identity).value() ); 00262 } 00263 00264 00265 00266 00267 00268 00269 #endif // use_ssl 00270 00271 return 0; 00272 } 00273 00274 /* ==================================================================== 00275 * The Vovida Software License, Version 1.0 00276 * 00277 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00278 * 00279 * Redistribution and use in source and binary forms, with or without 00280 * modification, are permitted provided that the following conditions 00281 * are met: 00282 * 00283 * 1. Redistributions of source code must retain the above copyright 00284 * notice, this list of conditions and the following disclaimer. 00285 * 00286 * 2. Redistributions in binary form must reproduce the above copyright 00287 * notice, this list of conditions and the following disclaimer in 00288 * the documentation and/or other materials provided with the 00289 * distribution. 00290 * 00291 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00292 * and "Vovida Open Communication Application Library (VOCAL)" must 00293 * not be used to endorse or promote products derived from this 00294 * software without prior written permission. For written 00295 * permission, please contact vocal@vovida.org. 00296 * 00297 * 4. Products derived from this software may not be called "VOCAL", nor 00298 * may "VOCAL" appear in their name, without prior written 00299 * permission of Vovida Networks, Inc. 00300 * 00301 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00302 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00303 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00304 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00305 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00306 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00307 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00308 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00309 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00310 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00311 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00312 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00313 * DAMAGE. 00314 * 00315 * ==================================================================== 00316 * 00317 * This software consists of voluntary contributions made by Vovida 00318 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00319 * Inc. For more information on Vovida Networks, Inc., please see 00320 * <http://www.vovida.org/>. 00321 * 00322 */
1.7.5.1