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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9493 - (show annotations) (download)
Sat Apr 7 10:56:50 2012 UTC (7 years, 7 months ago) by dpocock
File MIME type: text/plain
File size: 9884 byte(s)
Include config.h from even more places where it may be needed
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4
5 #include <cassert>
6 #include <fstream>
7 #include <ostream>
8
9 #include "rutil/Logger.hxx"
10
11 #ifdef USE_SSL
12 #include "resip/stack/ssl/Security.hxx"
13 #endif
14
15 #include "TestSupport.hxx"
16
17
18 using namespace resip;
19 using namespace std;
20
21 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
22
23
24 int
25 main(int argc, char* argv[])
26 {
27 Log::initialize(Log::Cout, Log::Debug, Data::Empty);
28
29 #ifdef USE_SSL
30 Security* security=0;
31 try
32 {
33 security = new Security;
34 }
35 catch( ... )
36 {
37 security = 0;
38 ErrLog( << "Got a exception setting up Security" );
39 return -1;
40 }
41
42 try
43 {
44 assert(security != 0);
45 security->preload();
46 }
47 catch( ... )
48 {
49 ErrLog( << "Got a exception loading certificates" );
50 return -1;
51 }
52
53 assert( security );
54
55 {
56 ErrLog( << "\n\nStarting test one" );
57
58 Data txt1 =
59 "INVITE sip:bob@biloxi.exmple.org SIP/2.0\r\n"
60 "Via: SIP/2.0/TLS pc33.atlanta.example.com;branch=z9hG4bKnashds8\r\n"
61 "To: Bob <sip:bob@biloxi.example.org>\r\n"
62 "From: Alice <sip:alice@atlanta.example.com>;tag=1928301774\r\n"
63 "Call-ID: a84b4c76e66710\r\n"
64 "CSeq: 314159 INVITE\r\n"
65 "Max-Forwards: 70\r\n"
66 "Date: Thu, 21 Feb 2002 13:02:03 GMT\r\n"
67 "Contact: <sip:alice@pc33.atlanta.example.com>\r\n"
68 "Content-Type: application/sdp\r\n"
69 "Content-Length: 147\r\n"
70 "\r\n"
71 "v=0\r\n"
72 "o=UserA 2890844526 2890844526 IN IP4 pc33.atlanta.example.com\r\n"
73 "s=Session SDP\r\n"
74 "c=IN IP4 pc33.atlanta.example.com\r\n"
75 "t=0 0\r\n"
76 "m=audio 49172 RTP/AVP 0\r\n"
77 "a=rtpmap:0 PCMU/8000\r\n";
78
79 auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt1));
80
81 try
82 {
83 const Data& domain = msg->header(h_From).uri().host();
84 msg->header(h_Identity).value() = security->computeIdentity( domain,
85 msg->getCanonicalIdentityString());
86 }
87 catch (Security::Exception& e)
88 {
89 ErrLog (<< "Couldn't add identity header: " << e);
90 msg->remove(h_Identity);
91 }
92
93 ErrLog( << "INVITE base64 identity is " << msg->header(h_Identity).value() );
94 }
95
96 {
97 ErrLog( << "\n\nStarting test two" );
98
99 Data txt2 =
100 "BYE sip:alice@pc33.atlanta.example.com SIP/2.0\r\n"
101 "Via: SIP/2.0/TLS 192.0.2.4;branch=z9hG4bKnashds10\r\n"
102 "Max-Forwards: 70\r\n"
103 "From: Bob <sip:bob@biloxi.example.org>;tag=a6c85cf\r\n"
104 "To: Alice <sip:alice@atlanta.example.com>;tag=1928301774\r\n"
105 "Date: Thu, 21 Feb 2002 14:19:51 GMT\r\n"
106 "Call-ID: a84b4c76e66710\r\n"
107 "CSeq: 231 BYE\r\n"
108 "Content-Length: 0\r\n"
109 "\r\n"
110 ;
111
112 auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt2));
113
114 try
115 {
116 const Data& domain = msg->header(h_From).uri().host();
117
118 Data identString = msg->getCanonicalIdentityString();
119
120 msg->header(h_Identity).value() = security->computeIdentity( domain, identString );
121 }
122 catch (Security::Exception& e)
123 {
124 ErrLog (<< "Couldn't add identity header: " << e);
125 msg->remove(h_Identity);
126 }
127
128 ErrLog( << "BYE base64 identity is " << msg->header(h_Identity).value() );
129 }
130
131
132
133 {
134 ErrLog( << "\n\nStarting test three - conect iden - invite(2) " );
135
136 Data txt1 =
137
138 "INVITE sip:Carol@ua2.example.com SIP/2.0\r\n"
139 "Via: SIP/2.0/TLS proxy.example.com;branch=z9hG4bK776asdhds\r\n"
140 "Via: SIP/2.0/TLS ua1.example.com;branch=z9hG4bKnashds8;received=192.0.2.1\r\n"
141 "To: Bob <sip:bob@example.com>\r\n"
142 "From: Alice <sip:alice@example.com>;tag=13adc987\r\n"
143 "Call-ID: 12345600@ua1.example.com\r\n"
144 "CSeq: 1 INVITE\r\n"
145 "Max-Forwards: 69\r\n"
146 "Date: Thu, 21 Feb 2002 13:02:03 GMT\r\n"
147 "Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, UPDATE\r\n"
148 "Supported: from-change\r\n"
149 "Contact: <sip:alice@ua1.example.com>\r\n"
150 "Record-Route: <sip:proxy.example.com;lr>\r\n"
151 "Identity-Info: <https://example.com/example.cer>;alg=rsa-sha1\r\n"
152 "Content-Type: application/sdp\r\n"
153 "Content-Length: 154\r\n"
154 "\r\n"
155 "v=0\r\n"
156 "o=UserA 2890844526 2890844526 IN IP4 ua1.example.com\r\n"
157 "s=Session SDP\r\n"
158 "c=IN IP4 ua1.example.com\r\n"
159 "t=0 0\r\n"
160 "m=audio 49172 RTP/AVP 0\r\n"
161 "a=rtpmap:0 PCMU/8000\r\n"
162 ;
163
164
165 auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt1));
166
167 try
168 {
169 const Data& domain = msg->header(h_From).uri().host();
170 msg->header(h_Identity).value() = security->computeIdentity( domain,
171 msg->getCanonicalIdentityString());
172 }
173 catch (Security::Exception& e)
174 {
175 ErrLog (<< "Couldn't add identity header: " << e);
176 msg->remove(h_Identity);
177 }
178
179 ErrLog( << "base64 identity is " << msg->header(h_Identity).value() );
180 }
181
182
183
184
185 {
186 ErrLog( << "\n\nStarting test four - connected-id update(8) " );
187
188 Data txt2 =
189
190 "UPDATE sip:Alice@ua1.example.com SIP/2.0\r\n"
191 "Via: SIP/2.0/TLS proxy.example.com;branch=z9hG4bK776asdhdu\r\n"
192 "Via: SIP/2.0/TLS ua2.example.com;branch=z9hG4bKnashdt1;received=192.0.2.3\r\n"
193 "From: Carol <sip:Carol@example.com>;tag=2ge46ab5\r\n"
194 "To: Alice <sip:Alice@example.com>;tag=13adc987\r\n"
195 "Call-ID: 12345600@ua1.example.com\r\n"
196 "CSeq: 2 UPDATE\r\n"
197 "Max-Forwards: 69\r\n"
198 "Date: Thu, 21 Feb 2002 13:02:15 GMT\r\n"
199 "Contact: <sip:Carol@ua2.example.com>\r\n"
200 "Identity-Info: <https://example.com/cert>;alg=rsa-sha1\r\n"
201 "Content-Length: 0\r\n"
202 "\r\n"
203 ;
204
205
206 auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt2));
207
208 try
209 {
210 const Data& domain = msg->header(h_From).uri().host();
211
212 Data identString = msg->getCanonicalIdentityString();
213
214 msg->header(h_Identity).value() = security->computeIdentity( domain, identString );
215 }
216 catch (Security::Exception& e)
217 {
218 ErrLog (<< "Couldn't add identity header: " << e);
219 msg->remove(h_Identity);
220 }
221
222 ErrLog( << "base64 identity is " << msg->header(h_Identity).value() );
223 }
224
225
226
227
228 {
229 ErrLog( << "\n\nStarting test five - connected-id reinvite 6 " );
230
231 Data txt2 =
232
233 "INVITE sip:alice@ua1.example.com SIP/2.0\r\n"
234 "Via: SIP/2.0/TLS b2bua.example.com;branch=z9hG4bKnashdxy\r\n"
235 "From: Carol <sip:Carol@example.com>;tag=2ge46ab5\r\n"
236 "To: Alice <sip:Alice@example.com>;tag=13adc987\r\n"
237 "Call-ID: 12345600@ua1.example.com\r\n"
238 "CSeq: 3 INVITE\r\n"
239 "Max-Forwards: 70\r\n"
240 "Date: Thu, 21 Feb 2002 13:03:20 GMT\r\n"
241 "Contact: <sip:xyz@b2bua.example.com>\r\n"
242 "Identity-Info: <https://example.com/cert>;alg=rsa-sha1\r\n"
243 "Content-Length: 0\r\n"
244 "\r\n";
245
246 auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt2));
247
248 try
249 {
250 const Data& domain = msg->header(h_From).uri().host();
251
252 Data identString = msg->getCanonicalIdentityString();
253
254 msg->header(h_Identity).value() = security->computeIdentity( domain, identString );
255 }
256 catch (Security::Exception& e)
257 {
258 ErrLog (<< "Couldn't add identity header: " << e);
259 msg->remove(h_Identity);
260 }
261 ErrLog( << "base64 identity is " << msg->header(h_Identity).value() );
262 }
263
264
265
266
267
268
269 #endif // use_ssl
270
271 return 0;
272 }
273
274 /* ====================================================================
275 * The Vovida Software License, Version 1.0
276 *
277 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
278 *
279 * Redistribution and use in source and binary forms, with or without
280 * modification, are permitted provided that the following conditions
281 * are met:
282 *
283 * 1. Redistributions of source code must retain the above copyright
284 * notice, this list of conditions and the following disclaimer.
285 *
286 * 2. Redistributions in binary form must reproduce the above copyright
287 * notice, this list of conditions and the following disclaimer in
288 * the documentation and/or other materials provided with the
289 * distribution.
290 *
291 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
292 * and "Vovida Open Communication Application Library (VOCAL)" must
293 * not be used to endorse or promote products derived from this
294 * software without prior written permission. For written
295 * permission, please contact vocal@vovida.org.
296 *
297 * 4. Products derived from this software may not be called "VOCAL", nor
298 * may "VOCAL" appear in their name, without prior written
299 * permission of Vovida Networks, Inc.
300 *
301 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
302 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
303 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
304 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
305 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
306 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
307 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
308 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
309 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
310 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
311 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
312 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
313 * DAMAGE.
314 *
315 * ====================================================================
316 *
317 * This software consists of voluntary contributions made by Vovida
318 * Networks, Inc. and many individuals on behalf of Vovida Networks,
319 * Inc. For more information on Vovida Networks, Inc., please see
320 * <http://www.vovida.org/>.
321 *
322 */

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