reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
TlsPeerIdentityStore.cxx
Go to the documentation of this file.
1
2
3#include "rutil/ResipAssert.h"
4
5#include "rutil/Data.hxx"
8#include "rutil/Logger.hxx"
11
13#include "repro/AbstractDb.hxx"
15
16
17using namespace resip;
18using namespace repro;
19using namespace std;
20
21#define RESIPROCATE_SUBSYSTEM Subsystem::REPRO
22
23const resip::Data TlsPeerIdentityStore::SEPARATOR(",");
24
28
32
35{
36 return mDb.getTlsPeerIdentity(key);
37}
38
39bool
40TlsPeerIdentityStore::isAuthorized( const std::set<resip::Data>& peerNames,
41 const std::set<resip::Data>& identities ) const
42{
43 return mDb.isAuthorized( peerNames, identities );
44}
45
46bool
48 const Data& authorizedIdentity)
49{
51 rec.peerName = peerName;
52 rec.authorizedIdentity = authorizedIdentity;
53
54 return mDb.addTlsPeerIdentity( buildKey(peerName, authorizedIdentity), rec);
55}
56
57void
62
63bool
65 const resip::Data& peerName,
66 const resip::Data& authorizedIdentity)
67{
68 Key newkey = buildKey(peerName, authorizedIdentity);
69
70 bool ret = addTlsPeerIdentity(peerName, authorizedIdentity);
71 if ( newkey != originalKey )
72 {
73 eraseTlsPeerIdentity(originalKey);
74 }
75 return ret;
76}
77
83
89
91TlsPeerIdentityStore::buildKey( const resip::Data& peerName, const resip::Data& authorizedIdentity)
92{
93 Data ret = peerName + Data(SEPARATOR) + authorizedIdentity;
94 return ret;
95}
96
97void
98TlsPeerIdentityStore::getTlsPeerIdentityFromKey(const Key& key, Data& peerName, Data& authorizedIdentity)
99{
100 ParseBuffer pb(key);
101 const char* start = pb.position();
102 pb.skipToOneOf(SEPARATOR);
103 pb.data(peerName, start);
104 const char* anchor = pb.skipChar();
105 pb.skipToEnd();
106 pb.data(authorizedIdentity, anchor);
107}
108
109/* ====================================================================
110 *
111 * Copyright 2014 Daniel Pocock http://danielpocock.com All rights reserved.
112 *
113 * Redistribution and use in source and binary forms, with or without
114 * modification, are permitted provided that the following conditions
115 * are met:
116 *
117 * 1. Redistributions of source code must retain the above copyright
118 * notice, this list of conditions and the following disclaimer.
119 *
120 * 2. Redistributions in binary form must reproduce the above copyright
121 * notice, this list of conditions and the following disclaimer in
122 * the documentation and/or other materials provided with the
123 * distribution.
124 *
125 * 3. Neither the name of the author(s) nor the names of any contributors
126 * may be used to endorse or promote products derived from this software
127 * without specific prior written permission.
128 *
129 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS "AS IS" AND
130 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
131 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
132 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE
133 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
134 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
135 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
136 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
137 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
138 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
139 * SUCH DAMAGE.
140 *
141 * ====================================================================
142 *
143 *
144 */
145
virtual bool addTlsPeerIdentity(const Key &key, const TlsPeerIdentityRecord &rec)
virtual Key nextTlsPeerIdentityKey()
virtual void eraseTlsPeerIdentity(const Key &key)
virtual bool isAuthorized(const std::set< resip::Data > &peerNames, const std::set< resip::Data > &identities) const
virtual Key firstTlsPeerIdentityKey()
virtual TlsPeerIdentityRecord getTlsPeerIdentity(const Key &key) const
bool updateTlsPeerIdentity(const Key &originalKey, const resip::Data &peerName, const resip::Data &authorizedIdentity)
bool addTlsPeerIdentity(const resip::Data &peerName, const resip::Data &authorizedIdentity)
static Key buildKey(const resip::Data &peerName, const resip::Data &authorizedIdentity)
bool isAuthorized(const std::set< resip::Data > &peerNames, const std::set< resip::Data > &identities) const
void eraseTlsPeerIdentity(const Key &key)
static void getTlsPeerIdentityFromKey(const AbstractDb::Key &key, resip::Data &peerName, resip::Data &authorizedIdentity)
AbstractDb::TlsPeerIdentityRecord getTlsPeerIdentityInfo(const Key &key) const
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
Provides string-parsing functionality with protection from buffer overflow.
CurrentPosition skipToEnd()
CurrentPosition position() const
CurrentPosition skipToOneOf(const char *cs)
CurrentPosition skipChar()
void data(Data &data, const char *start) const
make the passed in data share memory with the buffer (uses Data::Share)
This Class is used to implement a primitive form of RPC using loose XML formatting.
dcm! – add UnusedChecking(_enum) below;