Coverage Report

Created: 2025-11-16 06:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/resiprocate/resip/stack/BasicNonceHelper.cxx
Line
Count
Source
1
#include <ctype.h>
2
3
#include "resip/stack/BasicNonceHelper.hxx"
4
#include "rutil/Logger.hxx"
5
#include "rutil/ParseBuffer.hxx"
6
#include "rutil/Random.hxx"
7
8
using namespace resip;
9
10
#define RESIPROCATE_SUBSYSTEM Subsystem::SIP
11
12
13
/**
14
 * BasicNonceHelper implements the makeNonce function in the same way
15
 * as the original implementation of makeNonce within Helper.cxx
16
 *
17
 * To operate a farm/cluster of UASs/proxies, you must:
18
 * a) make sure the clocks are sychronized (using ntpd for instance)
19
 * b) use the same privateKey value on every instance of the application
20
 *
21
 * To operate with SER, use the SERNonceHelper instead, as that generates
22
 * the nonce string the same way as SER.  You must also observe the same
23
 * conditions above regarding clock and key synchronization.
24
 */
25
BasicNonceHelper::BasicNonceHelper() 
26
0
{
27
  //privateKey = Data("asdfklsadflkj");
28
0
  privateKey = Random::getCryptoRandomHex(24);
29
0
}
30
31
BasicNonceHelper::~BasicNonceHelper() 
32
0
{
33
0
}
34
35
void
36
BasicNonceHelper::setPrivateKey(const Data& pprivateKey)
37
0
{
38
0
  this->privateKey = pprivateKey;
39
0
}
40
41
Data 
42
BasicNonceHelper::makeNonce(const SipMessage& request, const Data& timestamp) 
43
0
{
44
0
   Data nonce(100, Data::Preallocate);
45
0
   nonce += timestamp;
46
0
   nonce += Symbols::COLON;
47
0
   Data noncePrivate(100, Data::Preallocate);
48
0
   noncePrivate += timestamp;
49
0
   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
0
   noncePrivate += request.header(h_From).uri().user();
53
0
   noncePrivate += privateKey;
54
0
   nonce += noncePrivate.md5();
55
0
   return nonce;
56
0
}
57
58
NonceHelper::Nonce
59
BasicNonceHelper::parseNonce(const Data& nonce) 
60
0
{
61
0
   ParseBuffer pb(nonce.data(), nonce.size());
62
0
   if (!pb.eof() && !isdigit(static_cast< unsigned char >(*pb.position())))
63
0
   {
64
0
      DebugLog(<< "Invalid nonce; expected timestamp.");
65
0
      return BasicNonceHelper::Nonce(0);
66
0
   }
67
0
   const char* anchor = pb.position();
68
0
   pb.skipToChar(Symbols::COLON[0]);
69
0
   if (pb.eof())
70
0
   {
71
0
      DebugLog(<< "Invalid nonce; expected timestamp terminator.");
72
0
      return BasicNonceHelper::Nonce(0);
73
0
   }
74
0
   Data creationTime;
75
0
   pb.data(creationTime, anchor);
76
0
   return BasicNonceHelper::Nonce(creationTime.convertUInt64());
77
0
}
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