|
reSIProcate/DialogUsageManager
9680
|
00001 00002 #if defined(HAVE_CONFIG_H) 00003 #include "config.h" 00004 #endif 00005 00006 #include "rutil/Logger.hxx" 00007 #include "resip/stack/SipMessage.hxx" 00008 #include "resip/dum/IdentityHandler.hxx" 00009 #include "resip/dum/HttpProvider.hxx" 00010 #include "resip/dum/HttpGetMessage.hxx" 00011 #include "resip/dum/DialogUsageManager.hxx" 00012 #include "rutil/WinLeakCheck.hxx" 00013 00014 #ifdef USE_SSL 00015 #include "resip/stack/ssl/Security.hxx" 00016 #endif 00017 00018 using namespace resip; 00019 using namespace std; 00020 00021 #define RESIPROCATE_SUBSYSTEM Subsystem::DUM 00022 00023 IdentityHandler::IdentityHandler(DialogUsageManager& dum, TargetCommand::Target& target) 00024 : DumFeature(dum, target) 00025 { 00026 } 00027 00028 IdentityHandler::~IdentityHandler() 00029 { 00030 for (RequiresCerts::iterator it = mRequiresCerts.begin(); it != mRequiresCerts.end(); ++it) 00031 { 00032 delete it->second; 00033 } 00034 } 00035 00036 DumFeature::ProcessingResult 00037 IdentityHandler::process(Message* msg) 00038 { 00039 SipMessage* sipMsg = dynamic_cast<SipMessage*>(msg); 00040 if (sipMsg) 00041 { 00042 if (queueForIdentityCheck(sipMsg)) 00043 { 00044 return EventTaken; 00045 } 00046 else 00047 { 00048 return FeatureDone; 00049 } 00050 } 00051 00052 HttpGetMessage* httpMsg = dynamic_cast<HttpGetMessage*>(msg); 00053 if (httpMsg) 00054 { 00055 processIdentityCheckResponse(*httpMsg); 00056 return FeatureDoneAndEventDone; 00057 } 00058 00059 return FeatureDone; 00060 } 00061 00062 bool 00063 IdentityHandler::queueForIdentityCheck(SipMessage* sipMsg) 00064 { 00065 #if defined(USE_SSL) 00066 if (sipMsg->exists(h_Identity) && 00067 sipMsg->exists(h_IdentityInfo) && 00068 sipMsg->exists(h_Date)) 00069 { 00070 if (mDum.getSecurity()->hasDomainCert(sipMsg->header(h_From).uri().host())) 00071 { 00072 mDum.getSecurity()->checkAndSetIdentity(*sipMsg); 00073 return false; 00074 } 00075 else 00076 { 00077 if (!HttpProvider::instance()) 00078 { 00079 return false; 00080 } 00081 00082 try 00083 { 00084 mRequiresCerts[sipMsg->getTransactionId()] = sipMsg; 00085 InfoLog( << "Dum::queueForIdentityCheck, sending http request to: " 00086 << sipMsg->header(h_IdentityInfo)); 00087 00088 HttpProvider::instance()->get(sipMsg->header(h_IdentityInfo), 00089 sipMsg->getTransactionId(), 00090 mDum, 00091 mDum.dumIncomingTarget()); 00092 return true; 00093 } 00094 catch (BaseException&) 00095 { 00096 } 00097 } 00098 } 00099 #endif 00100 00101 std::auto_ptr<SecurityAttributes> sec(new SecurityAttributes); 00102 sec->setIdentity(sipMsg->header(h_From).uri().getAor()); 00103 sec->setIdentityStrength(SecurityAttributes::From); 00104 sipMsg->setSecurityAttributes(sec); 00105 return false; 00106 } 00107 00108 void 00109 IdentityHandler::processIdentityCheckResponse(const HttpGetMessage& msg) 00110 { 00111 #if defined(USE_SSL) 00112 InfoLog(<< "DialogUsageManager::processIdentityCheckResponse: " << msg.brief()); 00113 RequiresCerts::iterator it = mRequiresCerts.find(msg.getTransactionId()); 00114 if (it != mRequiresCerts.end()) 00115 { 00116 mDum.getSecurity()->checkAndSetIdentity( *it->second, msg.getBodyData() ); 00117 postCommand(auto_ptr<Message>(it->second)); 00118 mRequiresCerts.erase(it); 00119 } 00120 #endif 00121 }
1.7.5.1