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

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