reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
BasicWsConnectionValidator.cxx
Go to the documentation of this file.
1
2#if defined(HAVE_CONFIG_H)
3 #include "config.h"
4#endif
5
10#include "rutil/stun/Stun.hxx"
11#include "rutil/Logger.hxx"
12
13#include <time.h>
14
15#define RESIPROCATE_SUBSYSTEM resip::Subsystem::REPRO
16
17using namespace resip;
18using namespace repro;
19using namespace std;
20
21
23 : mWsCookieAuthSharedSecret(wsCookieAuthSharedSecret)
24{
25}
26
30
32{
33 Data message = wsCookieContext.getWsSessionInfo() + ':' + wsCookieContext.getWsSessionExtra();
34 unsigned char hmac[20];
35 computeHmac((char*)hmac, message.data(), (int)message.size(), mWsCookieAuthSharedSecret.data(), (int)mWsCookieAuthSharedSecret.size());
36
37 if(strncasecmp(wsCookieContext.getWsSessionMAC().data(), Data(hmac, 20).hex().data(), 40) != 0)
38 {
39 WarningLog(<< "Cookie MAC validation failed");
40 return false;
41 }
42
43 if(difftime(wsCookieContext.getExpiresTime(), time(NULL)) < 0)
44 {
45 WarningLog(<< "Received expired cookie");
46 return false;
47 }
48
49 return true;
50}
51
52/* ====================================================================
53 * BSD License
54 *
55 * Copyright (c) 2013 Catalin Constantin Usurelu All rights reserved.
56 *
57 * Redistribution and use in source and binary forms, with or without
58 * modification, are permitted provided that the following conditions
59 * are met:
60 *
61 * 1. Redistributions of source code must retain the above copyright
62 * notice, this list of conditions and the following disclaimer.
63 *
64 * 2. Redistributions in binary form must reproduce the above copyright
65 * notice, this list of conditions and the following disclaimer in
66 * the documentation and/or other materials provided with the
67 * distribution.
68 *
69 * 3. Neither the name of the author(s) nor the names of any contributors
70 * may be used to endorse or promote products derived from this software
71 * without specific prior written permission.
72 *
73 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS "AS IS" AND
74 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
75 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
76 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE
77 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
78 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
79 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
80 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
81 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
82 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
83 * SUCH DAMAGE.
84 *
85 * ====================================================================
86 *
87 */
#define WarningLog(args_)
Definition Logger.hxx:134
BasicWsConnectionValidator(const Data &wsCookieAuthSharedSecret)
virtual bool validateConnection(const resip::WsCookieContext &wsCookieContext)
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
size_type size() const noexcept
Returns the number of bytes in this Data.
Definition Data.hxx:599
const char * data() const noexcept
Returns a pointer to the contents of this Data.
Definition Data.hxx:608
time_t getExpiresTime() const
This Class is used to implement a primitive form of RPC using loose XML formatting.
dcm! – add UnusedChecking(_enum) below;
void computeHmac(char *hmac, const char *input, int length, const char *key, int sizeKey)
Definition Stun.cxx:943