/[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 5742 - (show annotations) (download)
Tue Dec 13 04:42:58 2005 UTC (14 years ago) by fluffy
File size: 7129 byte(s)
set up for examples in draft
1
2 #include <cassert>
3 #include <fstream>
4 #include <ostream>
5
6 #include "rutil/Logger.hxx"
7 #include "resip/stack/Security.hxx"
8
9 #include "TestSupport.hxx"
10
11
12 using namespace resip;
13 using namespace std;
14
15 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
16
17
18 int
19 main(int argc, char* argv[])
20 {
21 Log::initialize(Log::Cout, Log::Debug, Data::Empty);
22
23 #ifdef USE_SSL
24 Security* security=0;
25 try
26 {
27 security = new Security;
28 }
29 catch( ... )
30 {
31 security = 0;
32 ErrLog( << "Got a exception setting up Security" );
33 return -1;
34 }
35
36 try
37 {
38 assert(security != 0);
39 security->preload();
40 }
41 catch( ... )
42 {
43 ErrLog( << "Got a exception loading certificates" );
44 return -1;
45 }
46
47 assert( security );
48
49 #if 0
50 Data in1("sip:alice@atlanta.example.com"
51 "|sip:bob@biloxi.example.org"
52 "|a84b4c76e66710"
53 "|314159 INVITE"
54 //":314159 INVITE"
55 "|Thu, 21 Feb 2002 13:02:03 GMT"
56 "|sip:alice@pc33.atlanta.example.com"
57 "|v=0\r\n"
58 "o=UserA 2890844526 2890844526 IN IP4 pc33.atlanta.example.com\r\n"
59 "s=Session SDP\r\n"
60 "c=IN IP4 pc33.atlanta.example.com\r\n"
61 "t=0 0\r\n"
62 "m=audio 49172 RTP/AVP 0\r\n"
63 "a=rtpmap:0 PCMU/8000\r\n");
64
65 Data in2("sip:bob@biloxi.example.org"
66 "|sip:alice@atlanta.example.com"
67 "|a84b4c76e66710"
68 "|231 BYE"
69 "|Thu, 21 Feb 2002 14:19:51 GMT"
70 "|"
71 "|"
72 //"|\r\n"
73 );
74
75 Data& in=in1;
76
77 ofstream strm("identity-in", std::ios_base::trunc);
78 strm.write( in.data(), in.size() );
79 strm.flush();
80
81 Data res = security->computeIdentity( Data("atlanta.example.com"), in );
82
83 ErrLog( << "input is encoded " << in.charEncoded() );
84 ErrLog( << "input is hex " << in.hex() );
85 ErrLog( << "input is " << in );
86 ErrLog( << "identity is " << res );
87
88 if (true)
89 {
90 bool c = security->checkIdentity( Data("atlanta.example.com"), in , res );
91
92 if ( !c )
93 {
94 ErrLog( << "Identity check failed" << res );
95 return -1;
96 }
97 }
98 #endif
99
100 {
101 Data txt1 =
102 "INVITE sip:bob@biloxi.exmple.org SIP/2.0\r\n"
103 "Via: SIP/2.0/TLS pc33.atlanta.example.com;branch=z9hG4bKnashds8\r\n"
104 "To: Bob <sip:bob@biloxi.example.org>\r\n"
105 "From: Alice <sip:alice@atlanta.example.com>;tag=1928301774\r\n"
106 "Call-ID: a84b4c76e66710\r\n"
107 "CSeq: 314159 INVITE\r\n"
108 "Max-Forwards: 70\r\n"
109 "Date: Thu, 21 Feb 2002 13:02:03 GMT\r\n"
110 "Contact: <sip:alice@pc33.atlanta.example.com>\r\n"
111 "Content-Type: application/sdp\r\n"
112 "Content-Length: 147\r\n"
113 "\r\n"
114 "v=0\r\n"
115 "o=UserA 2890844526 2890844526 IN IP4 pc33.atlanta.example.com\r\n"
116 "s=Session SDP\r\n"
117 "c=IN IP4 pc33.atlanta.example.com\r\n"
118 "t=0 0\r\n"
119 "m=audio 49172 RTP/AVP 0\r\n"
120 "a=rtpmap:0 PCMU/8000\r\n";
121
122 auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt1));
123
124 try
125 {
126 const Data& domain = msg->header(h_From).uri().host();
127 msg->header(h_Identity).value() = security->computeIdentity( domain,
128 msg->getCanonicalIdentityString());
129 }
130 catch (Security::Exception& e)
131 {
132 ErrLog (<< "Couldn't add identity header: " << e);
133 msg->remove(h_Identity);
134 }
135
136 ErrLog( << "INVITE base64 identity is " << msg->header(h_Identity).value() );
137 }
138
139 {
140 Data txt2 =
141 "BYE sip:alice@pc33.atlanta.example.com SIP/2.0\r\n"
142 "Via: SIP/2.0/TLS 192.0.2.4;branch=z9hG4bKnashds10\r\n"
143 "Max-Forwards: 70\r\n"
144 "From: Bob <sip:bob@biloxi.example.org>;tag=a6c85cf\r\n"
145 "To: Alice <sip:alice@atlanta.example.com>;tag=1928301774\r\n"
146 "Date: Thu, 21 Feb 2002 14:19:51 GMT\r\n"
147 "Call-ID: a84b4c76e66710\r\n"
148 "CSeq: 231 BYE\r\n"
149 "Content-Length: 0\r\n"
150 "\r\n";
151
152 auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt2));
153
154 try
155 {
156 const Data& domain = msg->header(h_From).uri().host();
157 msg->header(h_Identity).value() = security->computeIdentity( domain,
158 msg->getCanonicalIdentityString());
159 }
160 catch (Security::Exception& e)
161 {
162 ErrLog (<< "Couldn't add identity header: " << e);
163 msg->remove(h_Identity);
164 }
165
166 ErrLog( << "BYE base64 identity is " << msg->header(h_Identity).value() );
167 }
168
169 #endif // use_ssl
170
171 return 0;
172 }
173
174 /* ====================================================================
175 * The Vovida Software License, Version 1.0
176 *
177 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
178 *
179 * Redistribution and use in source and binary forms, with or without
180 * modification, are permitted provided that the following conditions
181 * are met:
182 *
183 * 1. Redistributions of source code must retain the above copyright
184 * notice, this list of conditions and the following disclaimer.
185 *
186 * 2. Redistributions in binary form must reproduce the above copyright
187 * notice, this list of conditions and the following disclaimer in
188 * the documentation and/or other materials provided with the
189 * distribution.
190 *
191 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
192 * and "Vovida Open Communication Application Library (VOCAL)" must
193 * not be used to endorse or promote products derived from this
194 * software without prior written permission. For written
195 * permission, please contact vocal@vovida.org.
196 *
197 * 4. Products derived from this software may not be called "VOCAL", nor
198 * may "VOCAL" appear in their name, without prior written
199 * permission of Vovida Networks, Inc.
200 *
201 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
202 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
203 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
204 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
205 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
206 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
207 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
208 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
209 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
210 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
211 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
212 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
213 * DAMAGE.
214 *
215 * ====================================================================
216 *
217 * This software consists of voluntary contributions made by Vovida
218 * Networks, Inc. and many individuals on behalf of Vovida Networks,
219 * Inc. For more information on Vovida Networks, Inc., please see
220 * <http://www.vovida.org/>.
221 *
222 */

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27