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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8228 - (hide annotations) (download)
Tue Sep 23 08:30:37 2008 UTC (11 years, 2 months ago) by bcampen
File MIME type: text/plain
File size: 9835 byte(s)
Merge work from b-bwc-define_cleanup.

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

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