|
reSIProcate/DialogUsageManager
9680
|
00001 #if !defined(RESIP_ENCRYPTIONMANAGER_HXX) 00002 #define RESIP_ENCRYPTIONMANAGER_HXX 00003 00004 #include <memory> 00005 00006 #if defined(HAVE_CONFIG_H) 00007 #include "config.h" 00008 #endif 00009 00010 #include "rutil/SharedPtr.hxx" 00011 #include "rutil/Data.hxx" 00012 #include "rutil/BaseException.hxx" 00013 #include "resip/stack/SipMessage.hxx" 00014 #include "resip/stack/Contents.hxx" 00015 #include "resip/dum/DialogUsageManager.hxx" 00016 #include "resip/stack/Helper.hxx" 00017 #include "resip/dum/CertMessage.hxx" 00018 #include "resip/dum/RemoteCertStore.hxx" 00019 #include "resip/dum/DumFeature.hxx" 00020 #include "resip/stack/InvalidContents.hxx" 00021 00022 namespace resip 00023 { 00024 class Security; 00025 00026 class EncryptionManager : public DumFeature 00027 { 00028 public: 00029 class Exception : public BaseException 00030 { 00031 public: 00032 Exception(const Data& msg, const Data& file, const int line); 00033 const char* name() const { return "EncryptionManagerException"; } 00034 }; 00035 00036 EncryptionManager(DialogUsageManager& dum, TargetCommand::Target& target); 00037 virtual ~EncryptionManager(); 00038 void setRemoteCertStore(std::auto_ptr<RemoteCertStore> store); 00039 virtual DumFeature::ProcessingResult process(Message* msg); 00040 00041 private: 00042 00043 typedef enum 00044 { 00045 Pending, 00046 Complete 00047 } Result; 00048 00049 EncryptionManager::Result processCertMessage(CertMessage* cert); 00050 Contents* sign(SharedPtr<SipMessage> msg, const Data& senderAor, bool* noCerts); 00051 Contents* encrypt(SharedPtr<SipMessage> msg, const Data& recipientAor, bool* noCerts); 00052 Contents* signAndEncrypt(SharedPtr<SipMessage> msg, const Data& senderAor, const Data& recipientAor, bool* noCerts); 00053 bool decrypt(SipMessage* msg); 00054 00055 class Request 00056 { 00057 public: 00058 Request(DialogUsageManager& dum, RemoteCertStore* store, SharedPtr<SipMessage> msg, DumFeature& feature); 00059 virtual ~Request(); 00060 virtual Result received(bool success, MessageId::Type type, const Data& aor, const Data& data) = 0; 00061 Data getId() const { return mMsgToEncrypt->getTransactionId(); } 00062 //void setTaken() { mTaken = true; } 00063 //void handleInvalidContents(SipMessage*, const Data& originalBody, const Mime& originalType); 00064 00065 protected: 00066 DialogUsageManager& mDum; 00067 RemoteCertStore* mStore; 00068 SharedPtr<SipMessage> mMsgToEncrypt; // initial message. 00069 int mPendingRequests; 00070 DumFeature& mFeature; 00071 //bool mTaken; 00072 00073 void response415(); 00074 }; 00075 00076 class Sign : public Request 00077 { 00078 public: 00079 Sign(DialogUsageManager& dum, RemoteCertStore* store, SharedPtr<SipMessage> msg, const Data& senderAor, DumFeature& feature); 00080 virtual ~Sign(); 00081 Result received(bool success, MessageId::Type type, const Data& aor, const Data& data); 00082 bool sign(Contents**, bool* noCerts); 00083 00084 protected: 00085 Data mSenderAor; 00086 }; 00087 00088 class Encrypt : public Request 00089 { 00090 public: 00091 Encrypt(DialogUsageManager& dum, RemoteCertStore* store, SharedPtr<SipMessage> msg, const Data& recipientAor, DumFeature& feature); 00092 virtual ~Encrypt(); 00093 Result received(bool success, MessageId::Type type, const Data& aor, const Data& data); 00094 bool encrypt(Contents**, bool* noCerts); 00095 00096 protected: 00097 Data mRecipientAor; 00098 }; 00099 00100 class SignAndEncrypt : public Request 00101 { 00102 public: 00103 SignAndEncrypt(DialogUsageManager& dum, RemoteCertStore* store, SharedPtr<SipMessage> msg, const Data& senderAor, const Data& recipientAor, DumFeature& feature); 00104 ~SignAndEncrypt(); 00105 Result received(bool success, MessageId::Type type, const Data& aor, const Data& data); 00106 bool signAndEncrypt(Contents**, bool* noCerts); 00107 00108 protected: 00109 Data mSenderAor; 00110 Data mRecipientAor; 00111 00112 private: 00113 Contents* doWork(); 00114 }; 00115 00116 class Decrypt : public Request 00117 { 00118 public: 00119 Decrypt(DialogUsageManager& dum, RemoteCertStore* store, SipMessage* msg, DumFeature& feature); 00120 virtual ~Decrypt(); 00121 Result received(bool success, MessageId::Type type, const Data& aor, const Data& data); 00122 bool decrypt(Helper::ContentsSecAttrs& csa); 00123 const Mime& getOriginalContentsType() const { return mOriginalMsgContentsType; } 00124 const Data& getOriginalContents() const { return mOriginalMsgContents; } 00125 void handleInvalidContents(); 00126 Data getId() const { return mMsgToDecrypt->getTransactionId(); } 00127 00128 private: 00129 bool isEncrypted(); 00130 bool isSigned(bool noDecryptionKey); 00131 bool isEncryptedRecurse(Contents**); 00132 bool isSignedRecurse(Contents**, const Data& decryptorAor, bool noDecryptionKey); 00133 Helper::ContentsSecAttrs getContents(SipMessage* msg, Security& security, bool noDecryption); 00134 Contents* getContentsRecurse(Contents**, Security&, bool, SecurityAttributes* attr); 00135 InvalidContents* createInvalidContents(Contents*); 00136 bool isMultipart(Contents*); 00137 Data mDecryptor; 00138 Data mSigner; 00139 Data mOriginalMsgContents; 00140 Mime mOriginalMsgContentsType; 00141 bool mIsEncrypted; // the whole body is encrypted in original message. 00142 SipMessage* mMsgToDecrypt; // original messge. 00143 bool mMessageTaken; 00144 }; 00145 00146 std::auto_ptr<RemoteCertStore> mRemoteCertStore; 00147 00148 typedef std::list<Request*> RequestList; 00149 RequestList mRequests; 00150 }; 00151 00152 } 00153 00154 #endif 00155 00156 /* ==================================================================== 00157 * The Vovida Software License, Version 1.0 00158 * 00159 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00160 * 00161 * Redistribution and use in source and binary forms, with or without 00162 * modification, are permitted provided that the following conditions 00163 * are met: 00164 * 00165 * 1. Redistributions of source code must retain the above copyright 00166 * notice, this list of conditions and the following disclaimer. 00167 * 00168 * 2. Redistributions in binary form must reproduce the above copyright 00169 * notice, this list of conditions and the following disclaimer in 00170 * the documentation and/or other materials provided with the 00171 * distribution. 00172 * 00173 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00174 * and "Vovida Open Communication Application Library (VOCAL)" must 00175 * not be used to endorse or promote products derived from this 00176 * software without prior written permission. For written 00177 * permission, please contact vocal@vovida.org. 00178 * 00179 * 4. Products derived from this software may not be called "VOCAL", nor 00180 * may "VOCAL" appear in their name, without prior written 00181 * permission of Vovida Networks, Inc. 00182 * 00183 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00184 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00185 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00186 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00187 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00188 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00189 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00190 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00191 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00192 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00193 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00194 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00195 * DAMAGE. 00196 * 00197 * ==================================================================== 00198 * 00199 * This software consists of voluntary contributions made by Vovida 00200 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00201 * Inc. For more information on Vovida Networks, Inc., please see 00202 * <http://www.vovida.org/>. 00203 * 00204 */
1.7.5.1