reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
BasicNonceHelper.cxx
Go to the documentation of this file.
1#include <ctype.h>
2
4#include "rutil/Logger.hxx"
6#include "rutil/Random.hxx"
7
8using namespace resip;
9
10#define RESIPROCATE_SUBSYSTEM Subsystem::SIP
11
12
26{
27 //privateKey = Data("asdfklsadflkj");
28 privateKey = Random::getCryptoRandomHex(24);
29}
30
34
35void
37{
38 this->privateKey = pprivateKey;
39}
40
41Data
42BasicNonceHelper::makeNonce(const SipMessage& request, const Data& timestamp)
43{
44 Data nonce(100, Data::Preallocate);
45 nonce += timestamp;
46 nonce += Symbols::COLON;
47 Data noncePrivate(100, Data::Preallocate);
48 noncePrivate += timestamp;
49 noncePrivate += Symbols::COLON;
50 // !jf! don't include the Call-Id since it might not be the same.
51 // noncePrivate += request.header(h_CallId).value();
52 noncePrivate += request.header(h_From).uri().user();
53 noncePrivate += privateKey;
54 nonce += noncePrivate.md5();
55 return nonce;
56}
57
60{
61 ParseBuffer pb(nonce.data(), nonce.size());
62 if (!pb.eof() && !isdigit(static_cast< unsigned char >(*pb.position())))
63 {
64 DebugLog(<< "Invalid nonce; expected timestamp.");
66 }
67 const char* anchor = pb.position();
69 if (pb.eof())
70 {
71 DebugLog(<< "Invalid nonce; expected timestamp terminator.");
73 }
74 Data creationTime;
75 pb.data(creationTime, anchor);
76 return BasicNonceHelper::Nonce(creationTime.convertUInt64());
77}
78
79
80/* ====================================================================
81 * The Vovida Software License, Version 1.0
82 *
83 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
84 *
85 * Redistribution and use in source and binary forms, with or without
86 * modification, are permitted provided that the following conditions
87 * are met:
88 *
89 * 1. Redistributions of source code must retain the above copyright
90 * notice, this list of conditions and the following disclaimer.
91 *
92 * 2. Redistributions in binary form must reproduce the above copyright
93 * notice, this list of conditions and the following disclaimer in
94 * the documentation and/or other materials provided with the
95 * distribution.
96 *
97 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
98 * and "Vovida Open Communication Application Library (VOCAL)" must
99 * not be used to endorse or promote products derived from this
100 * software without prior written permission. For written
101 * permission, please contact vocal@vovida.org.
102 *
103 * 4. Products derived from this software may not be called "VOCAL", nor
104 * may "VOCAL" appear in their name, without prior written
105 * permission of Vovida Networks, Inc.
106 *
107 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
108 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
109 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
110 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
111 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
112 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
113 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
114 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
115 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
116 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
117 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
118 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
119 * DAMAGE.
120 *
121 * ====================================================================
122 *
123 * This software consists of voluntary contributions made by Vovida
124 * Networks, Inc. and many individuals on behalf of Vovida Networks,
125 * Inc. For more information on Vovida Networks, Inc., please see
126 * <http://www.vovida.org/>.
127 *
128 */
129
#define DebugLog(args_)
Definition Logger.hxx:128
Nonce parseNonce(const Data &nonce)
BasicNonceHelper()
BasicNonceHelper implements the makeNonce function in the same way as the original implementation of ...
Data makeNonce(const SipMessage &request, const Data &timestamp)
void setPrivateKey(const Data &privateKey)
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
uint64_t convertUInt64() const
Takes the contents of the Data and converts them to an unsigned 64-bit integer.
Definition Data.cxx:1758
static const PreallocateType Preallocate
used only to disambiguate constructors
Definition Data.hxx:116
size_type size() const noexcept
Returns the number of bytes in this Data.
Definition Data.hxx:599
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
Provides string-parsing functionality with protection from buffer overflow.
CurrentPosition skipToChar(char c)
CurrentPosition position() const
void data(Data &data, const char *start) const
make the passed in data share memory with the buffer (uses Data::Share)
static Data getCryptoRandomHex(unsigned int numBytes)
Definition Random.cxx:394
const Uri & uri() const
Represents a SIP message.
const RequestLine & header(const RequestLineType &l) const
Returns the RequestLine. This is only valid for request messages.
static const char * COLON
Definition Symbols.hxx:15
Data & user()
Definition Uri.hxx:42
dcm! – add UnusedChecking(_enum) below;