reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
SERNonceHelper.cxx
Go to the documentation of this file.
1
3#include "rutil/Random.hxx"
5
6using namespace resip;
7
8#define RESIPROCATE_SUBSYSTEM Subsystem::SIP
9
10
24SERNonceHelper::SERNonceHelper(int serOffset) : serOffset(serOffset)
25{
26 //privateKey = Data("asdfklsadflkj");
27 privateKey = Random::getCryptoRandomHex(24);
28}
29
33
34void
36{
37 this->privateKey = pprivateKey;
38}
39
40Data
41SERNonceHelper::makeNonce(const SipMessage& request, const Data& timestamp)
42{
43 char buf[8];
44 Data md5buf(8, Data::Preallocate);
45 Data nonce(40, Data::Preallocate);
46 int ts = timestamp.convertInt() + serOffset;
47 Helper::integer2hex(buf, ts);
48 md5buf.append(buf, 8);
49 nonce.append(buf, 8);
50 md5buf += privateKey;
51 nonce += md5buf.md5();
52 return nonce;
53}
54
57{
58 if(nonce.size() != 40)
59 {
60 return SERNonceHelper::Nonce(0);
61 }
62 const char *s = nonce.data();
63 unsigned int ts = Helper::hex2integer(s) - serOffset;
64 return SERNonceHelper::Nonce(ts);
65}
66
67
68/* ====================================================================
69 * The Vovida Software License, Version 1.0
70 *
71 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
72 *
73 * Redistribution and use in source and binary forms, with or without
74 * modification, are permitted provided that the following conditions
75 * are met:
76 *
77 * 1. Redistributions of source code must retain the above copyright
78 * notice, this list of conditions and the following disclaimer.
79 *
80 * 2. Redistributions in binary form must reproduce the above copyright
81 * notice, this list of conditions and the following disclaimer in
82 * the documentation and/or other materials provided with the
83 * distribution.
84 *
85 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
86 * and "Vovida Open Communication Application Library (VOCAL)" must
87 * not be used to endorse or promote products derived from this
88 * software without prior written permission. For written
89 * permission, please contact vocal@vovida.org.
90 *
91 * 4. Products derived from this software may not be called "VOCAL", nor
92 * may "VOCAL" appear in their name, without prior written
93 * permission of Vovida Networks, Inc.
94 *
95 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
96 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
97 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
98 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
99 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
100 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
101 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
102 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
103 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
104 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
105 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
106 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
107 * DAMAGE.
108 *
109 * ====================================================================
110 *
111 * This software consists of voluntary contributions made by Vovida
112 * Networks, Inc. and many individuals on behalf of Vovida Networks,
113 * Inc. For more information on Vovida Networks, Inc., please see
114 * <http://www.vovida.org/>.
115 *
116 */
117
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
static const PreallocateType Preallocate
used only to disambiguate constructors
Definition Data.hxx:116
Data & append(const char *str, size_type len)
Appends the specified number of bytes to the end of this Data.
Definition Data.cxx:1058
size_type size() const noexcept
Returns the number of bytes in this Data.
Definition Data.hxx:599
int convertInt() const
Takes the contents of the Data and converts them to an integer.
Definition Data.cxx:1684
Data md5(EncodingType type=HEX) const
Computes the MD5 hash of the current data.
Definition Data.cxx:1174
const char * data() const noexcept
Returns a pointer to the contents of this Data.
Definition Data.hxx:608
static unsigned int hex2integer(const char *_s)
Converts a character string containing a hexidecimal value into an unsigned int.
Definition Helper.cxx:92
static void integer2hex(char *_d, unsigned int _s, bool _l=true)
Converts an interger in a character string containing the hexidecimal representation of the integer.
Definition Helper.cxx:52
static Data getCryptoRandomHex(unsigned int numBytes)
Definition Random.cxx:394
Nonce parseNonce(const Data &nonce)
Data makeNonce(const SipMessage &request, const Data &timestamp)
void setPrivateKey(const Data &privateKey)
SERNonceHelper(int serOffset)
SERNonceHelper implements the makeNonce function in the same way as SIP Express Router (SER) - http:/...
Represents a SIP message.
dcm! – add UnusedChecking(_enum) below;