/[resiprocate]/main/reTurn/UserAuthData.cxx
ViewVC logotype

Contents of /main/reTurn/UserAuthData.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10779 - (show annotations) (download)
Tue Dec 24 01:26:14 2013 UTC (5 years, 10 months ago) by Dpocock
File size: 2781 byte(s)
reTurn: support for hashed passwords in user database file
1 #include "UserAuthData.hxx"
2
3 #include <rutil/ConfigParse.hxx>
4 #include <rutil/MD5Stream.hxx>
5
6 #include "ReTurnSubsystem.hxx"
7
8 #define RESIPROCATE_SUBSYSTEM ReTurnSubsystem::RETURN
9
10 using namespace std;
11 using namespace resip;
12
13 namespace reTurn {
14
15 UserAuthData::UserAuthData(const resip::Data& userName, const resip::Data& realm, const resip::Data& ha1) :
16 mUserName(userName),
17 mRealm(realm),
18 mHa1(ha1)
19 {
20 }
21
22 UserAuthData::~UserAuthData()
23 {
24 }
25
26 UserAuthData
27 UserAuthData::createFromPassword(const resip::Data& userName, const resip::Data& realm, const resip::Data& password)
28 {
29 MD5Stream r;
30 r << userName << ":" << realm << ":" << password;
31 Data ha1(r.getBin());
32 return UserAuthData(userName, realm, ha1);
33 }
34
35 UserAuthData
36 UserAuthData::createFromHex(const resip::Data& userName, const resip::Data& realm, const resip::Data& ha1Hex)
37 {
38 if(ha1Hex.size() != 32)
39 {
40 throw ConfigParse::Exception("H(A1) password field must contain 32 character hex string", __FILE__, __LINE__);
41 }
42 return UserAuthData(userName, realm, ha1Hex.fromHex());
43 }
44
45 } // namespace
46
47
48 /* ====================================================================
49
50 Copyright (c) 2012, Ready Technology (UK) Limited
51 All rights reserved.
52
53 Redistribution and use in source and binary forms, with or without
54 modification, are permitted provided that the following conditions are
55 met:
56
57 1. Redistributions of source code must retain the above copyright
58 notice, this list of conditions and the following disclaimer.
59
60 2. Redistributions in binary form must reproduce the above copyright
61 notice, this list of conditions and the following disclaimer in the
62 documentation and/or other materials provided with the distribution.
63
64 3. Neither the name of Ready Technology nor the names of its contributors
65 may be used to endorse or promote products derived from this
66 software without specific prior written permission.
67
68 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
69 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
70 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
71 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
72 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
73 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
74 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
75 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
76 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
77 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
78 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
79
80 ==================================================================== */

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27