1 |
fluffy |
3326 |
|
2 |
fluffy |
3327 |
#include <cassert> |
3 |
fluffy |
3330 |
#include <fstream> |
4 |
|
|
#include <ostream> |
5 |
fluffy |
3327 |
|
6 |
jason |
5276 |
#include "rutil/Logger.hxx" |
7 |
derek |
5283 |
#include "resip/stack/Security.hxx" |
8 |
fluffy |
3326 |
|
9 |
fluffy |
5739 |
#include "TestSupport.hxx" |
10 |
fluffy |
3327 |
|
11 |
fluffy |
5739 |
|
12 |
fluffy |
3326 |
using namespace resip; |
13 |
|
|
using namespace std; |
14 |
|
|
|
15 |
fluffy |
3327 |
#define RESIPROCATE_SUBSYSTEM Subsystem::TEST |
16 |
fluffy |
3326 |
|
17 |
|
|
|
18 |
|
|
int |
19 |
|
|
main(int argc, char* argv[]) |
20 |
|
|
{ |
21 |
|
|
Log::initialize(Log::Cout, Log::Debug, Data::Empty); |
22 |
fluffy |
3327 |
|
23 |
|
|
#ifdef USE_SSL |
24 |
|
|
Security* security=0; |
25 |
|
|
try |
26 |
|
|
{ |
27 |
fluffy |
3587 |
security = new Security; |
28 |
fluffy |
3327 |
} |
29 |
|
|
catch( ... ) |
30 |
|
|
{ |
31 |
|
|
security = 0; |
32 |
|
|
ErrLog( << "Got a exception setting up Security" ); |
33 |
fluffy |
5739 |
return -1; |
34 |
fluffy |
3327 |
} |
35 |
|
|
|
36 |
|
|
try |
37 |
|
|
{ |
38 |
|
|
assert(security != 0); |
39 |
fluffy |
3587 |
security->preload(); |
40 |
fluffy |
3327 |
} |
41 |
|
|
catch( ... ) |
42 |
|
|
{ |
43 |
|
|
ErrLog( << "Got a exception loading certificates" ); |
44 |
fluffy |
5739 |
return -1; |
45 |
fluffy |
3327 |
} |
46 |
|
|
|
47 |
|
|
assert( security ); |
48 |
fluffy |
3328 |
|
49 |
fluffy |
5739 |
#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 |
fluffy |
3330 |
strm.write( in.data(), in.size() ); |
79 |
|
|
strm.flush(); |
80 |
fluffy |
3328 |
|
81 |
fluffy |
5739 |
Data res = security->computeIdentity( Data("atlanta.example.com"), in ); |
82 |
fluffy |
3327 |
|
83 |
fluffy |
5739 |
ErrLog( << "input is encoded " << in.charEncoded() ); |
84 |
|
|
ErrLog( << "input is hex " << in.hex() ); |
85 |
|
|
ErrLog( << "input is " << in ); |
86 |
|
|
ErrLog( << "identity is " << res ); |
87 |
fluffy |
3327 |
|
88 |
fluffy |
5739 |
if (true) |
89 |
fluffy |
3330 |
{ |
90 |
fluffy |
5739 |
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 |
fluffy |
3330 |
} |
98 |
fluffy |
5739 |
#endif |
99 |
fluffy |
5742 |
|
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 |
fluffy |
5739 |
"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 |
fluffy |
5742 |
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 |
fluffy |
3327 |
#endif // use_ssl |
170 |
|
|
|
171 |
fluffy |
3326 |
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 |
|
|
*/ |