/[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 6425 - (show annotations) (download)
Wed Jul 26 04:28:50 2006 UTC (13 years, 4 months ago) by fluffy
File MIME type: text/plain
File size: 5965 byte(s)
fluffy fix
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 {
50 ErrLog( << "\n\nStarting test one" );
51
52 Data txt1 =
53 "INVITE sip:bob@biloxi.exmple.org SIP/2.0\r\n"
54 "Via: SIP/2.0/TLS pc33.atlanta.example.com;branch=z9hG4bKnashds8\r\n"
55 "To: Bob <sip:bob@biloxi.example.org>\r\n"
56 "From: Alice <sip:alice@atlanta.example.com>;tag=1928301774\r\n"
57 "Call-ID: a84b4c76e66710\r\n"
58 "CSeq: 314159 INVITE\r\n"
59 "Max-Forwards: 70\r\n"
60 "Date: Thu, 21 Feb 2002 13:02:03 GMT\r\n"
61 "Contact: <sip:alice@pc33.atlanta.example.com>\r\n"
62 "Content-Type: application/sdp\r\n"
63 "Content-Length: 147\r\n"
64 "\r\n"
65 "v=0\r\n"
66 "o=UserA 2890844526 2890844526 IN IP4 pc33.atlanta.example.com\r\n"
67 "s=Session SDP\r\n"
68 "c=IN IP4 pc33.atlanta.example.com\r\n"
69 "t=0 0\r\n"
70 "m=audio 49172 RTP/AVP 0\r\n"
71 "a=rtpmap:0 PCMU/8000\r\n";
72
73 auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt1));
74
75 try
76 {
77 const Data& domain = msg->header(h_From).uri().host();
78 msg->header(h_Identity).value() = security->computeIdentity( domain,
79 msg->getCanonicalIdentityString());
80 }
81 catch (Security::Exception& e)
82 {
83 ErrLog (<< "Couldn't add identity header: " << e);
84 msg->remove(h_Identity);
85 }
86
87 ErrLog( << "INVITE base64 identity is " << msg->header(h_Identity).value() );
88 }
89
90 {
91 ErrLog( << "\n\nStarting test two" );
92
93 Data txt2 =
94 "BYE sip:alice@pc33.atlanta.example.com SIP/2.0\r\n"
95 "Via: SIP/2.0/TLS 192.0.2.4;branch=z9hG4bKnashds10\r\n"
96 "Max-Forwards: 70\r\n"
97 "From: Bob <sip:bob@biloxi.example.org>;tag=a6c85cf\r\n"
98 "To: Alice <sip:alice@atlanta.example.com>;tag=1928301774\r\n"
99 "Date: Thu, 21 Feb 2002 14:19:51 GMT\r\n"
100 "Call-ID: a84b4c76e66710\r\n"
101 "CSeq: 231 BYE\r\n"
102 "Content-Length: 0\r\n"
103 "\r\n"
104 ;
105
106 auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt2));
107
108 try
109 {
110 const Data& domain = msg->header(h_From).uri().host();
111
112 Data identString = msg->getCanonicalIdentityString();
113
114 #if 0 // this should not be here but used for testing with other
115 identString += "\r\n";
116 #endif
117
118 ErrLog( << "canonical string in <> is <" << identString << ">" );
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 #endif // use_ssl
132
133 return 0;
134 }
135
136 /* ====================================================================
137 * The Vovida Software License, Version 1.0
138 *
139 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
140 *
141 * Redistribution and use in source and binary forms, with or without
142 * modification, are permitted provided that the following conditions
143 * are met:
144 *
145 * 1. Redistributions of source code must retain the above copyright
146 * notice, this list of conditions and the following disclaimer.
147 *
148 * 2. Redistributions in binary form must reproduce the above copyright
149 * notice, this list of conditions and the following disclaimer in
150 * the documentation and/or other materials provided with the
151 * distribution.
152 *
153 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
154 * and "Vovida Open Communication Application Library (VOCAL)" must
155 * not be used to endorse or promote products derived from this
156 * software without prior written permission. For written
157 * permission, please contact vocal@vovida.org.
158 *
159 * 4. Products derived from this software may not be called "VOCAL", nor
160 * may "VOCAL" appear in their name, without prior written
161 * permission of Vovida Networks, Inc.
162 *
163 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
164 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
165 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
166 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
167 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
168 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
169 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
170 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
171 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
172 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
173 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
174 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
175 * DAMAGE.
176 *
177 * ====================================================================
178 *
179 * This software consists of voluntary contributions made by Vovida
180 * Networks, Inc. and many individuals on behalf of Vovida Networks,
181 * Inc. For more information on Vovida Networks, Inc., please see
182 * <http://www.vovida.org/>.
183 *
184 */

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