reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
EncryptionManager.hxx
Go to the documentation of this file.
1#if !defined(RESIP_ENCRYPTIONMANAGER_HXX)
2#define RESIP_ENCRYPTIONMANAGER_HXX
3
4#include <memory>
5
6#if defined(HAVE_CONFIG_H)
7 #include "config.h"
8#endif
9
10#include "rutil/Data.hxx"
20
21namespace resip
22{
23class Security;
24
26{
27 public:
28 class Exception final : public BaseException
29 {
30 public:
31 Exception(const Data& msg, const Data& file, int line);
32 const char* name() const noexcept override { return "EncryptionManagerException"; }
33 };
34
36 virtual ~EncryptionManager();
37 void setRemoteCertStore(std::unique_ptr<RemoteCertStore> store);
39
40 private:
41
42 typedef enum
43 {
44 Pending,
45 Complete
46 } Result;
47
48 EncryptionManager::Result processCertMessage(CertMessage* cert);
49 Contents* sign(std::shared_ptr<SipMessage> msg, const Data& senderAor, bool* noCerts);
50 Contents* encrypt(std::shared_ptr<SipMessage> msg, const Data& recipientAor, bool* noCerts);
51 Contents* signAndEncrypt(std::shared_ptr<SipMessage> msg, const Data& senderAor, const Data& recipientAor, bool* noCerts);
52 bool decrypt(SipMessage* msg);
53
54 class Request
55 {
56 public:
57 Request(DialogUsageManager& dum, RemoteCertStore* store, std::shared_ptr<SipMessage> msg, DumFeature& feature);
58 virtual ~Request();
59 virtual Result received(bool success, MessageId::Type type, const Data& aor, const Data& data) = 0;
60 Data getId() const { return mMsgToEncrypt->getTransactionId(); }
61 //void setTaken() { mTaken = true; }
62 //void handleInvalidContents(SipMessage*, const Data& originalBody, const Mime& originalType);
63
64 protected:
65 DialogUsageManager& mDum;
66 RemoteCertStore* mStore;
67 std::shared_ptr<SipMessage> mMsgToEncrypt; // initial message.
68 int mPendingRequests;
69 DumFeature& mFeature;
70 //bool mTaken;
71
72 void response415();
73 };
74
75 class Sign : public Request
76 {
77 public:
78 Sign(DialogUsageManager& dum, RemoteCertStore* store, std::shared_ptr<SipMessage> msg, const Data& senderAor, DumFeature& feature);
79 Result received(bool success, MessageId::Type type, const Data& aor, const Data& data);
80 bool sign(Contents**, bool* noCerts);
81
82 protected:
83 Data mSenderAor;
84 };
85
86 class Encrypt : public Request
87 {
88 public:
89 Encrypt(DialogUsageManager& dum, RemoteCertStore* store, std::shared_ptr<SipMessage> msg, const Data& recipientAor, DumFeature& feature);
90 Result received(bool success, MessageId::Type type, const Data& aor, const Data& data);
91 bool encrypt(Contents**, bool* noCerts);
92
93 protected:
94 Data mRecipientAor;
95 };
96
97 class SignAndEncrypt : public Request
98 {
99 public:
100 SignAndEncrypt(DialogUsageManager& dum, RemoteCertStore* store, std::shared_ptr<SipMessage> msg, const Data& senderAor, const Data& recipientAor, DumFeature& feature);
101 Result received(bool success, MessageId::Type type, const Data& aor, const Data& data);
102 bool signAndEncrypt(Contents**, bool* noCerts);
103
104 protected:
105 Data mSenderAor;
106 Data mRecipientAor;
107
108 private:
109 Contents* doWork();
110 };
111
112 class Decrypt : public Request
113 {
114 public:
115 Decrypt(DialogUsageManager& dum, RemoteCertStore* store, SipMessage* msg, DumFeature& feature);
116 virtual ~Decrypt();
117 Result received(bool success, MessageId::Type type, const Data& aor, const Data& data);
118 bool decrypt(Helper::ContentsSecAttrs& csa);
119 const Mime& getOriginalContentsType() const { return mOriginalMsgContentsType; }
120 const Data& getOriginalContents() const { return mOriginalMsgContents; }
121 void handleInvalidContents();
122 Data getId() const { return mMsgToDecrypt->getTransactionId(); }
123
124 private:
125 bool isEncrypted();
126 bool isSigned(bool noDecryptionKey);
127 bool isEncryptedRecurse(Contents**);
128 bool isSignedRecurse(Contents**, const Data& decryptorAor, bool noDecryptionKey);
129 Helper::ContentsSecAttrs getContents(SipMessage* msg, Security& security, bool noDecryption);
130 Contents* getContentsRecurse(Contents**, Security&, bool, SecurityAttributes* attr);
131 InvalidContents* createInvalidContents(Contents*);
132 bool isMultipart(Contents*);
133 Data mDecryptor;
134 Data mSigner;
135 Data mOriginalMsgContents;
136 Mime mOriginalMsgContentsType;
137 bool mIsEncrypted; // the whole body is encrypted in original message.
138 SipMessage* mMsgToDecrypt; // original messge.
139 bool mMessageTaken;
140 };
141
142 std::unique_ptr<RemoteCertStore> mRemoteCertStore;
143
144 typedef std::list<Request*> RequestList;
145 RequestList mRequests;
146};
147
148}
149
150#endif
151
152/* ====================================================================
153 * The Vovida Software License, Version 1.0
154 *
155 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
156 *
157 * Redistribution and use in source and binary forms, with or without
158 * modification, are permitted provided that the following conditions
159 * are met:
160 *
161 * 1. Redistributions of source code must retain the above copyright
162 * notice, this list of conditions and the following disclaimer.
163 *
164 * 2. Redistributions in binary form must reproduce the above copyright
165 * notice, this list of conditions and the following disclaimer in
166 * the documentation and/or other materials provided with the
167 * distribution.
168 *
169 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
170 * and "Vovida Open Communication Application Library (VOCAL)" must
171 * not be used to endorse or promote products derived from this
172 * software without prior written permission. For written
173 * permission, please contact vocal@vovida.org.
174 *
175 * 4. Products derived from this software may not be called "VOCAL", nor
176 * may "VOCAL" appear in their name, without prior written
177 * permission of Vovida Networks, Inc.
178 *
179 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
180 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
181 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
182 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
183 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
184 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
185 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
186 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
187 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
188 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
189 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
190 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
191 * DAMAGE.
192 *
193 * ====================================================================
194 *
195 * This software consists of voluntary contributions made by Vovida
196 * Networks, Inc. and many individuals on behalf of Vovida Networks,
197 * Inc. For more information on Vovida Networks, Inc., please see
198 * <http://www.vovida.org/>.
199 *
200 */
The abstract base-class for all exceptions thrown by resip code.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
const char * name() const noexcept override
virtual DumFeature::ProcessingResult process(Message *msg)
void setRemoteCertStore(std::unique_ptr< RemoteCertStore > store)
The base-class used for message-passing.
Definition Message.hxx:21
dcm! – add UnusedChecking(_enum) below;