/[resiprocate]/branches/b-identity-0505/Helper.hxx
ViewVC logotype

Contents of /branches/b-identity-0505/Helper.hxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4598 - (show annotations) (download)
Wed May 11 22:53:07 2005 UTC (14 years, 6 months ago) by derek
File size: 13032 byte(s)
set svn:eol-style to LF
1 #if !defined(RESIP_HELPER_HXX)
2 #define RESIP_HELPER_HXX
3
4 #include <time.h>
5
6 #include "resiprocate/Symbols.hxx"
7 #include "resiprocate/Uri.hxx"
8 #include "resiprocate/MethodTypes.hxx"
9 #include "resiprocate/os/BaseException.hxx"
10
11 namespace resip
12 {
13
14 class SipMessage;
15 class NameAddr;
16 class SecurityAttributes;
17 class Security;
18
19 class UnsupportedAuthenticationScheme : public BaseException
20 {
21 public:
22 UnsupportedAuthenticationScheme(const Data& msg, const Data& file, const int line)
23 : BaseException(msg, file, line) {}
24
25 const char* name() const { return "UnsupportedAuthenticationScheme"; }
26 };
27
28 class Helper
29 {
30 public:
31
32 const static int tagSize; //bytes in to-tag& from-tag, should prob. live
33 //somewhere else
34
35 // Sorry if this doesn't build in Win32, let me know (jf)
36 template<typename T>
37 static T aBitSmallerThan(T secs)
38 {
39 return resipMax(T(0), resipMin(T(secs-5), T(9*secs/10)));
40 }
41
42 // e.g. to jitter the expires in a SUBSCRIBE or REGISTER expires header
43 static int jitterValue(int input, int lowerPercentage, int upperPercentage, int minimum=0);
44
45 //in general content length handled automatically by SipMessage?
46 static SipMessage* makeInvite(const NameAddr& target, const NameAddr& from);
47 static SipMessage* makeInvite(const NameAddr& target, const NameAddr& from, const NameAddr& contact);
48 static SipMessage* makeForwardedInvite(const SipMessage& invite);
49 static void makeResponse(SipMessage& response,
50 const SipMessage& request,
51 int responseCode,
52 const Data& reason = Data::Empty,
53 const Data& hostname = Data::Empty,
54 const Data& warning=Data::Empty);
55 static void makeResponse(SipMessage& response,
56 const SipMessage& request,
57 int responseCode,
58 const NameAddr& myContact,
59 const Data& reason = Data::Empty,
60 const Data& hostname = Data::Empty,
61 const Data& warning=Data::Empty);
62 static SipMessage* makeResponse(const SipMessage& request,
63 int responseCode,
64 const Data& reason = Data::Empty,
65 const Data& hostname = Data::Empty,
66 const Data& warning=Data::Empty);
67 static SipMessage* makeResponse(const SipMessage& request,
68 int responseCode,
69 const NameAddr& myContact,
70 const Data& reason = Data::Empty,
71 const Data& hostname = Data::Empty,
72 const Data& warning=Data::Empty);
73
74 //to, maxforwards=70, requestLine& cseq method set, cseq sequence is 1
75 //static SipMessage* makeRequest(const NameAddr& target, MethodTypes method); // deprecated
76
77 //to, maxforward=70, requestline created, cseq method set, cseq sequence
78 //is 1, from and from tag set, contact set, CallId created
79 //while contact is only necessary for requests that establish a dialog,
80 //those ar the requests most likely created by this method, others will
81 //be generated by the dialog.
82 static SipMessage* make405(const SipMessage& request,
83 const int* allowedMethods = 0,
84 int nMethods = -1);
85
86 static SipMessage* makeRequest(const NameAddr& target, const NameAddr& from, const NameAddr& contact, MethodTypes method);
87 static SipMessage* makeRequest(const NameAddr& target, const NameAddr& from, MethodTypes method);
88 static SipMessage* makeCancel(const SipMessage& request);
89
90 //creates to, from with tag, cseq method set, cseq sequence is 1
91 static SipMessage* makeRegister(const NameAddr& to, const NameAddr& from, const NameAddr& contact);
92 static SipMessage* makeRegister(const NameAddr& to, const NameAddr& from);
93 static SipMessage* makeRegister(const NameAddr& to, const Data& transport, const NameAddr& contact);
94 static SipMessage* makeRegister(const NameAddr& to, const Data& transport);
95 static SipMessage* makeSubscribe(const NameAddr& target, const NameAddr& from, const NameAddr& contact);
96 static SipMessage* makeSubscribe(const NameAddr& target, const NameAddr& from);
97 static SipMessage* makeMessage(const NameAddr& target, const NameAddr& from, const NameAddr& contact);
98 static SipMessage* makeMessage(const NameAddr& target, const NameAddr& from);
99 static SipMessage* makePublish(const NameAddr& target, const NameAddr& from, const NameAddr& contact);
100 static SipMessage* makePublish(const NameAddr& target, const NameAddr& from);
101 static SipMessage* makeFailureAck(const SipMessage& request, const SipMessage& response);
102
103 static Data computeUniqueBranch();
104 static Data computeProxyBranch(const SipMessage& request);
105
106 static Data computeCallId();
107 static Data computeTag(int numBytes);
108
109 enum AuthResult {Failed = 1, Authenticated, Expired, BadlyFormed};
110
111 static AuthResult authenticateRequest(const SipMessage& request,
112 const Data& realm,
113 const Data& password,
114 int expiresDelta = 0);
115
116 static std::pair<AuthResult,Data>
117 advancedAuthenticateRequest(const SipMessage& request,
118 const Data& realm,
119 const Data& a1,
120 int expiresDelta = 0);
121
122 // create a 407 response with Proxy-Authenticate header filled in
123 static SipMessage* makeProxyChallenge(const SipMessage& request,
124 const Data& realm,
125 bool useAuth = true,
126 bool stale = false);
127
128 // adds authorization headers in reponse to the 401 or 407--currently
129 // only supports md5.
130 static SipMessage& addAuthorization(SipMessage& request,
131 const SipMessage& challenge,
132 const Data& username,
133 const Data& password,
134 const Data& cnonce,
135 unsigned int& nonceCount);
136
137 static Auth makeChallengeResponseAuth(SipMessage& request,
138 const Data& username,
139 const Data& password,
140 const Auth& challenge,
141 const Data& cnonce,
142 unsigned int& nonceCount,
143 Data& nonceCountString);
144 static Auth makeChallengeResponseAuthWithA1(const SipMessage& request,
145 const Data& username,
146 const Data& passwordHashA1,
147 const Auth& challenge,
148 const Data& cnonce,
149 unsigned int& nonceCount,
150 Data& nonceCountString);
151
152 static Data makeResponseMD5WithA1(const Data& a1,
153 const Data& method, const Data& digestUri, const Data& nonce,
154 const Data& qop = Data::Empty, const Data& cnonce = Data::Empty,
155 const Data& cnonceCount = Data::Empty, const Contents *entityBody = 0);
156
157 static Data makeResponseMD5(const Data& username, const Data& password, const Data& realm,
158 const Data& method, const Data& digestUri, const Data& nonce,
159 const Data& qop = Data::Empty, const Data& cnonce = Data::Empty,
160 const Data& cnonceCount = Data::Empty, const Contents *entityBody = 0);
161
162
163 static Data makeNonce(const SipMessage& request, const Data& timestamp);
164
165 static Uri makeUri(const Data& aor, const Data& scheme=Symbols::DefaultSipScheme);
166
167 static void processStrictRoute(SipMessage& request);
168
169 // renamed to make more explicit that this is the port that we should reply too
170 // given that we are following SIP rules WRT rport etc.
171 static int getPortForReply(SipMessage& request);
172
173 static Uri fromAor(const Data& aor, const Data& scheme=Symbols::DefaultSipScheme);
174
175 // Do basic checks to validate a received message off the wire
176 static bool validateMessage(const SipMessage& message);
177
178 // GRUU support -- reversibly and opaquely combine instance id and aor
179 static Data gruuUserPart(const Data& instanceId,
180 const Data& aor,
181 const Data& key);
182
183 // GRUU support -- extract instance id and aor from user portion
184 static std::pair<Data,Data> fromGruuUserPart(const Data& gruuUserPart,
185 const Data& key);
186
187 struct ContentsSecAttrs
188 {
189 ContentsSecAttrs();
190 ContentsSecAttrs(std::auto_ptr<Contents> contents,
191 std::auto_ptr<SecurityAttributes> attributes);
192 ContentsSecAttrs(const ContentsSecAttrs& rhs);
193 ContentsSecAttrs& operator=(const ContentsSecAttrs& rhs);
194 mutable std::auto_ptr<Contents> mContents;
195 mutable std::auto_ptr<SecurityAttributes> mAttributes;
196 };
197
198 static ContentsSecAttrs extractFromPkcs7(const SipMessage& message, Security& security);
199
200
201 enum FailureMessageEffect{ DialogTermination, TransactionTermination, UsageTermination,
202 RetryAfter, OptionalRetryAfter, ApplicationDependant };
203
204 static FailureMessageEffect determineFailureMessageEffect(const SipMessage& response);
205
206 private:
207 static Data qopOption(const Auth& challenge);
208 };
209
210 }
211
212 #endif
213
214 /* ====================================================================
215 * The Vovida Software License, Version 1.0
216 *
217 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
218 *
219 * Redistribution and use in source and binary forms, with or without
220 * modification, are permitted provided that the following conditions
221 * are met:
222 *
223 * 1. Redistributions of source code must retain the above copyright
224 * notice, this list of conditions and the following disclaimer.
225 *
226 * 2. Redistributions in binary form must reproduce the above copyright
227 * notice, this list of conditions and the following disclaimer in
228 * the documentation and/or other materials provided with the
229 * distribution.
230 *
231 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
232 * and "Vovida Open Communication Application Library (VOCAL)" must
233 * not be used to endorse or promote products derived from this
234 * software without prior written permission. For written
235 * permission, please contact vocal@vovida.org.
236 *
237 * 4. Products derived from this software may not be called "VOCAL", nor
238 * may "VOCAL" appear in their name, without prior written
239 * permission of Vovida Networks, Inc.
240 *
241 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
242 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
243 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
244 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
245 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
246 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
247 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
248 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
249 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
250 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
251 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
252 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
253 * DAMAGE.
254 *
255 * ====================================================================
256 *
257 * This software consists of voluntary contributions made by Vovida
258 * Networks, Inc. and many individuals on behalf of Vovida Networks,
259 * Inc. For more information on Vovida Networks, Inc., please see
260 * <http://www.vovida.org/>.
261 *
262 */

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27