|
AnyConnect Secure Mobility Client 3.1.00495
|
00001 /************************************************************************** 00002 * Copyright (c) 2006, Cisco Systems, All Rights Reserved 00003 *************************************************************************** 00004 * 00005 * File: ClientIfcBase.h 00006 * Author: Chris Fitzgerald 00007 * Date: 08/2007 00008 * 00009 *************************************************************************** 00010 * 00011 * Client Interface Base class implementation for the Client API. 00012 * 00013 ***************************************************************************/ 00014 00015 // The ClientIfcBase class contains the majority of private methods and members. 00016 // The purpose of this class is to hide all but the necessary methods from 00017 // being exposed. 00018 // 00019 00020 #ifndef _CLIENTIFCBASE_ 00021 #define _CLIENTIFCBASE_ 00022 00023 #include <list> 00024 #include <vector> 00025 00026 /* 00027 * When changing the SCRIPTING_SUPPORTED definition, you MUST also update GenDefs.h! 00028 * We duplicate this definition here due to the manner in which we distribute our 00029 * code to partners; we cannot include GenDefs.h from here. 00030 */ 00031 #if !defined(PLATFORM_APPLE_SSLVPN) && !defined(PLATFORM_ANDROID) 00032 #define SCRIPTING_SUPPORTED 00033 #endif 00034 00035 #include "api.h" 00036 #include "PreferenceUpdate.h" 00037 00038 class ConnectPromptInfo; 00039 class ConnectMgr; 00040 class MsgWithArg; 00041 class VPNStats; 00042 class AgentIfc; 00043 class ProfileMgr; 00044 class ApiThread; 00045 class EventMgr; 00046 class PreferenceMgr; 00047 class PreferenceInfo; 00048 class UserPreferences; 00049 class CScriptingMgr; 00050 class CManualLock; 00051 class ApiThread; 00052 class ProxyIfc; 00053 class CIpcMessage; 00054 class SCEPIfc; 00055 class CertObj; 00056 class CExecutionContext; 00057 class HostEntry; 00058 00059 #if !defined(PLATFORM_APPLE_SSLVPN) 00060 class CStoragePath; 00061 #endif 00062 00063 #ifdef ANYCONNECT_USE_SNAK 00064 class PluginLoader; 00065 class SNAK_StoragePlugin; 00066 class SNAK_CertPlugin; 00067 class SNAK_SocketPlugin; 00068 #endif 00069 00070 class VPN_VPNAPI ClientIfcBase : private IPreferenceUpdateCB 00071 { 00072 friend class EventMgr; 00073 00074 protected: 00075 00076 virtual void StatsCB(VPNStats &stats) = 0; 00077 00078 virtual void StateCB(const VPNState state, 00079 const tstring stateString) = 0; 00080 00081 virtual void BannerCB(const tstring &banner) = 0; 00082 00083 virtual void NoticeCB(const tstring notice, 00084 const MessageType type) = 0; 00085 00086 virtual void ExitNoticeCB(const tstring &tstrNotice, 00087 const int returnCode); 00088 00089 virtual void ServiceReadyCB() = 0; 00090 00091 virtual void UserPromptCB(ConnectPromptInfo &ConnectPrompt) = 0; 00092 00093 virtual void WMHintCB(const WMHint hint, 00094 const WMHintReason reason); 00095 00096 virtual void deliverWebLaunchHostCB(const tstring &activeHost); 00097 00098 virtual void EventAvailable(); 00099 00100 #ifdef PLATFORM_ANDROID 00101 virtual void ClientCertificateCB(std::vector< std::pair<uint32_t, uint8_t*> > certList) = 0; 00102 virtual void AgentDetachedCB(); 00103 #endif 00104 00105 virtual void ImportPKCS12ResultCB(bool bResult, const tstring &strError); 00106 00107 virtual void CertBlockedCB(const tstring &rtstrUntrustedServer) = 0; 00108 virtual void CertWarningCB(const tstring &rtstrUntrustedServer, 00109 const std::list<tstring> &rltstrCertErrors) = 0; 00110 00111 AgentIfc &getAgentIfc(); 00112 00113 ClientIfcBase(); 00114 00115 00116 public: 00117 00118 virtual bool attach(bool SBL = false, 00119 bool isGUI = true, 00120 bool requestFullCapabilities = true, 00121 bool suppressAutoConnect = true); 00122 00123 virtual void detach(); 00124 00125 virtual void ProcessEvents(); 00126 00127 virtual bool hasFullCapabilities(); 00128 00129 virtual bool isConnected(); 00130 00131 virtual bool isAvailable(); 00132 00133 virtual std::list<tstring> getHostNames(); 00134 00135 virtual tstring getDefaultHostName(); 00136 00137 #if defined (PLATFORM_ANDROID) 00138 virtual bool connect(tstring host, const CertAuthMode mode=CertAuth_Automatic, const tstring &hash=""); 00139 00140 bool connect(tstring host, unsigned int origin, const CertAuthMode mode=CertAuth_Automatic, const tstring &hash=""); 00141 #else 00142 virtual bool connect(tstring host); 00143 00144 bool connect(tstring host, unsigned int origin); 00145 #endif 00146 00147 virtual bool setNewTunnelGroup(const tstring & group); 00148 00149 virtual void disconnect(); 00150 00151 virtual void resetStats(); 00152 00153 virtual void getState(); 00154 00155 VPNState getCurrentState(); 00156 VPNSubState getCurrentSubState(); 00157 00158 tstring getStateText(); 00159 static tstring getNoticeTypeText(MessageType msgType); 00160 00161 static tstring getStateText(VPNState state, 00162 VPNSubState subState = VPNSS_NORMAL, 00163 NETENV_STATE netEnvState = NES_NETWORK_ACCESSIBLE); 00164 00165 void setNetworkStates(NETENV_STATE netEnvState, 00166 NETCTRL_STATE netCtrlState, 00167 NETWORK_TYPE netType, 00168 bool bUpdateUI); 00169 void refreshOperatingModeForCurrentNetStates(); 00170 NETENV_STATE getCurrentNetEnvState(); 00171 NETCTRL_STATE getCurrentNetCtrlState(); 00172 NETWORK_TYPE getCurrentNetType(); 00173 00174 static tstring getNetCtrlText(NETCTRL_STATE netCtrlState); 00175 static tstring getNetEnvText(NETENV_STATE netEnvState, 00176 bool bSimple = false); 00177 static tstring getNetTypeText(NETWORK_TYPE netType); 00178 static tstring getQuarantinedStatusText(); 00179 static tstring getNetworkStatusSimpleText(const NETENV_STATE netEnvState, 00180 const NETCTRL_STATE netCtrlState); 00181 00182 // can't be static due to requiring operating mode information 00183 tstring getNetworkStatusText(const VPNState state, 00184 const VPNSubState subState, 00185 const NETENV_STATE netEnvState, 00186 const NETCTRL_STATE netCtrlState); 00187 00188 PreferenceInfo &getPreferences(); 00189 00190 bool savePreferences(); 00191 00192 virtual void startStats(); 00193 00194 virtual void stopStats(); 00195 00196 virtual void UserSubmit(); 00197 00198 void setBanner(const tstring &banner); 00199 void setBannerResponse(bool bResponse); 00200 bool getUserResponse(); 00201 bool isUserResponseSet(); 00202 00203 void setCertBlocked(const tstring &tstrUntrustedServer); 00204 void setCertWarning(const tstring &tstrUntrustedServer, const std::list<tstring> <strCertErrors); 00205 bool getCertImportResponse(); 00206 00207 void setUserPrompt(ConnectPromptInfo &ConnectPrompt); 00208 00209 #ifdef PLATFORM_ANDROID 00210 void setClientCertResponse(std::vector< std::pair<uint32_t, uint8_t*> > &derList); 00211 #endif 00212 00213 void setImportPKCS12Result(bool bResult, const tstring &strError); 00214 00215 void setCertBlockedResponse(bool bUnlock); 00216 void setCertWarningResponse(bool bConnect, bool bImportCert); 00217 00218 void insertStateToConnectPrompt(ConnectPromptInfo &ConnectPrompt); 00219 00220 void ExitNotice(const tstring &tstrNotice, const int code = 0); 00221 00222 void notice(const tstring tstrNotice, 00223 const MessageType type = MsgType_Info, 00224 bool bClearLastMsg = false); 00225 00226 void notice(MsgWithArg ¬ice, 00227 const MessageType type = MsgType_Info, 00228 bool bClearLastMsg = false); 00229 00230 void getStats(void); 00231 00232 void setStats(VPNStats &stats); 00233 00234 void exportStats(const tstring &tstrFilePath); 00235 00236 void setState(VPNState state, 00237 VPNState previousState, 00238 VPNSubState subState = VPNSS_NORMAL, 00239 bool bUpdateStateMsg = true, 00240 bool bOnlyUpdateUI = false); 00241 00242 void setWMHint(WMHint hint, 00243 WMHintReason reason); 00244 00245 bool isLastConnectType (const ConnectPromptType connPromptType); 00246 00247 bool isOperatingMode(OperatingMode opMode); 00248 void setOperatingMode(OperatingMode opMode); 00249 void unsetOperatingMode(OperatingMode opMode); 00250 00251 bool CanRemediateCaptivePortal(); 00252 00253 bool isUsingEventModel(); 00254 00255 time_t getLastDisconnectTime(); 00256 00257 ConnectPromptInfo getConnectPromptInfo(); 00258 00259 void setStandaloneConnection(bool isStandalone); 00260 00261 void deliverActiveHost(const tstring &activeHost, 00262 ConnectProtocolType vpnProtocol = PROTOCOL_TYPE_UNKNOWN); 00263 00264 bool isVPNServiceReady(); 00265 00266 // reset last disconnect time indicator. 00267 // 00268 void resetLastDisconnectTime(time_t time = 1); 00269 00270 void processMinimize(); 00271 00272 // cert enrollment 00273 void setEnrollClientCert(CertObj* pCert); 00274 00275 // Show user banner for cert import warning on linux 00276 // SCEPIfc to ConnectMgr 00277 void linuxCertImportWarnUser(); 00278 00279 // Response to cert warning on linux 00280 // ConnectMgr to SCEPIfc 00281 void linuxCertImportWarnUserResponse(bool bAccept); 00282 00283 void setDefaultHost(tstring &host); 00284 00285 #ifdef PLATFORM_ANDROID 00286 bool requestClientCertificates(); 00287 #endif 00288 00289 bool requestImportPKCS12(const std::vector<unsigned char> &der); 00290 00291 bool requestImportLocalization(const tstring tstrLocale, 00292 const std::vector<unsigned char> &MoFileData); 00293 00294 // Start the Automatic Headend Selection operation 00295 void startAHS(const unsigned int uiReason, 00296 const ProxyIfc& proxy); 00297 // statusReturnCode is a long to match the current type of STATUSCODE. 00298 // It is not using a STATUSCODE directly so that we do not have to 00299 // expose the header files for STATUSCODEs to ClientIfcBase.h 00300 void AHSSelectedHost(const unsigned int uiReason, 00301 const std::vector<tstring> &headendList, 00302 const long statusReturnCode, 00303 const tstring& extraInfo); 00304 std::vector<tstring> getAHSHostList(); 00305 unsigned int getAHSState(); 00306 bool isAHSHasRun(); 00307 00308 bool suppressConnectionErrorPopups(); 00309 00310 tstring getCaptivePortalDetectedMsg(); 00311 00312 void setProxyAuthPrompts(ProxyIfc* pProxy, 00313 const tstring& promptMsg); 00314 00315 00316 bool handleIpcMessage(CIpcMessage *pIpcMessage); 00317 00318 bool IsCsdTokenVerified() const; 00319 00320 bool isConnectRequestActive(); 00321 00322 virtual ~ClientIfcBase(); 00323 00324 private: 00325 CExecutionContext* m_pExecutionContext; 00326 00327 AgentIfc *mo_AgentIfc; 00328 00329 ConnectMgr *mo_ConnectMgr; 00330 00331 ApiThread *mo_ConnectThread; 00332 00333 EventMgr *mo_EventMgr; 00334 00335 PreferenceMgr *mo_PreferenceMgr; 00336 00337 ConnectPromptInfo *mp_currentConnectPromptInfo; 00338 00339 PreferenceInfo *mo_EditablePrefs; 00340 00341 #if defined(SCRIPTING_SUPPORTED) 00342 CScriptingMgr *mo_ScriptingMgr; 00343 #endif // SCRIPTING_SUPPORTED 00344 #ifndef PLATFORM_APPLE_SSLVPN 00345 SCEPIfc* m_pSCEPIfc; 00346 bool m_bInformedAgentOfSCEP; 00347 CStoragePath* m_pStoragePath; 00348 #endif // !PLATFORM_APPLE_SSLVPN 00349 00350 #ifdef ANYCONNECT_USE_SNAK 00351 PluginLoader *m_pPluginLoader; 00352 SNAK_CertPlugin *m_pSNAKCert; 00353 SNAK_SocketPlugin *m_pSNAKSocket; 00354 SNAK_StoragePlugin *m_pSNAKStorage; 00355 00356 bool mb_SNAKInitialized; 00357 #endif 00358 00359 bool mb_PreferenceMgrCreated; 00360 bool mb_StandaloneConnection; 00361 bool mb_UsingEventModel; 00362 bool mb_UserResponse; 00363 bool mb_IsUserResponseSet; 00364 bool mb_PerformedAutoCertEnrollment; 00365 tstring ms_PostEnrollmentConnectHost; 00366 bool mb_CaptivePortalMsgDisplayed; 00367 bool m_bSuppressMinimizeOnConnect; 00368 bool m_bSuppressConnectionErrorPopups; 00369 bool m_bLastConnectionAutomatic; 00370 bool m_bImportCertResp; 00371 00372 unsigned int mui_OperatingMode; 00373 NETENV_STATE m_currentNetEnvState; 00374 NETCTRL_STATE m_currentNetCtrlState; 00375 NETWORK_TYPE m_currentNetType; 00376 00377 tstring ms_message; 00378 00379 time_t m_disconnectTime; 00380 00381 static std::string ms_ThreadName; 00382 00383 CManualLock* m_pClientIfcStateLock; 00384 CManualLock* m_pClientIfcLock; 00385 CManualLock* m_pClientIfcPromptsLock; 00386 CManualLock* m_pClientIfcOpModeLock; 00387 CManualLock* m_pClientIfcAHSLock; 00388 CManualLock* m_pClientIfcConnectModeLock; 00389 CManualLock* m_pClientIfcInformAgentOfSCEPLock; 00390 00391 std::vector<tstring> msl_AHSSelectedHosts; 00392 ApiThread* m_pAHSThread; 00393 unsigned int m_uiAHSState; 00394 00395 static volatile bool mb_deleteFirstPass; 00396 00397 ConnectMgr &getConnectMgr(); 00398 00399 ProfileMgr &getProfileMgr(); 00400 UserPreferences &getUserPreferences(); 00401 00402 void displayAgentAttachMessage(); 00403 00404 void setLastDisconnectTime(time_t time); 00405 00406 void setCurrentStatePrompts(const VPNState state, 00407 const VPNState prevState, 00408 const VPNSubState subState, 00409 const bool bUpdateStateMsg); 00410 void setCurrentStateErrorMessage(VPNState state, CONNECT_FAILURE_REASON cfr); 00411 void getStateMessage(const VPNState state, 00412 const VPNState prevState, 00413 const VPNSubState subState, 00414 const NETENV_STATE neState, 00415 /*out*/ MsgWithArg& stateMessage); 00416 00417 bool isStandaloneConnection(); 00418 00419 virtual void OnLoadPreferencesComplete(); 00420 00421 void displayAHSPrompt(const bool isComplete); 00422 void handleAHSPreferences(const unsigned int uiReason); 00423 void setAHSState(const unsigned int ahsState); 00424 00425 bool autoConnectIfEnabled(const bool suppressAutoConnect); 00426 00427 void clearUserSetResponseFlag(); 00428 00429 #ifndef PLATFORM_APPLE_SSLVPN 00430 bool processSCEPIpcMessage(CIpcMessage *pIpcMessage); 00431 bool isSCEPRedirect(); 00432 void processSCEPRedirect(); 00433 #endif // PLATFORM_APPLE_SSLVPN 00434 00435 ClientIfcBase(const ClientIfcBase& other); 00436 ClientIfcBase& operator=(const ClientIfcBase& other); 00437 00438 #ifdef ANYCONNECT_USE_SNAK 00439 bool initializeSNAK(); 00440 #endif 00441 00442 }; 00443 00444 00445 #endif // _CLIENTIFCBASE_