AnyConnect Secure Mobility Client 4.3.00748
|
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, 00110 bool bAllowImport) = 0; 00111 00112 AgentIfc &getAgentIfc(); 00113 00114 ClientIfcBase(); 00115 00116 00117 public: 00118 00119 virtual bool attach(bool SBL = false, 00120 bool isGUI = true, 00121 bool requestFullCapabilities = true, 00122 bool suppressAutoConnect = true); 00123 00124 virtual void detach(); 00125 00126 virtual void ProcessEvents(); 00127 00128 virtual bool hasFullCapabilities(); 00129 00130 virtual bool isConnected(); 00131 00132 virtual bool isAvailable(); 00133 00134 virtual std::list<tstring> getHostNames(); 00135 00136 virtual tstring getDefaultHostName(); 00137 00138 #if defined (PLATFORM_ANDROID) 00139 virtual bool connect(tstring host, const CertAuthMode mode=CertAuth_Automatic, const tstring &hash=""); 00140 00141 bool connect(tstring host, unsigned int origin, const CertAuthMode mode=CertAuth_Automatic, const tstring &hash=""); 00142 #else 00143 virtual bool connect(tstring host); 00144 00145 bool connect(tstring host, unsigned int origin); 00146 #endif 00147 00148 virtual bool setNewTunnelGroup(const tstring & group); 00149 00150 virtual void disconnect(); 00151 00152 virtual void cancel(); 00153 00154 virtual void resetStats(); 00155 00156 virtual void getState(); 00157 00158 VPNState getCurrentState(); 00159 VPNSubState getCurrentSubState(); 00160 VPNSubState getPreviousSubState(); 00161 00162 tstring getStateText(); 00163 static tstring getNoticeTypeText(MessageType msgType); 00164 00165 static tstring getStateText(VPNState state, 00166 VPNSubState subState = VPNSS_NORMAL, 00167 NETENV_STATE netEnvState = NES_NETWORK_ACCESSIBLE); 00168 00169 void setNetworkStates(NETENV_STATE netEnvState, 00170 NETCTRL_STATE netCtrlState, 00171 NETWORK_TYPE netType, 00172 bool bUpdateUI); 00173 void refreshOperatingModeForCurrentNetStates(); 00174 NETENV_STATE getCurrentNetEnvState(); 00175 NETENV_STATE getPreviousNetEnvState(); 00176 NETCTRL_STATE getCurrentNetCtrlState(); 00177 NETWORK_TYPE getCurrentNetType(); 00178 00179 static tstring getNetCtrlText(NETCTRL_STATE netCtrlState); 00180 static tstring getNetEnvText(NETENV_STATE netEnvState, 00181 bool bSimple = false); 00182 static tstring getNetTypeText(NETWORK_TYPE netType); 00183 static tstring getQuarantinedStatusText(); 00184 static tstring getNetworkStatusSimpleText(const NETENV_STATE netEnvState, 00185 const NETCTRL_STATE netCtrlState); 00186 00187 // can't be static due to requiring operating mode information 00188 tstring getNetworkStatusText(const VPNState state, 00189 const VPNSubState subState, 00190 const NETENV_STATE netEnvState, 00191 const NETCTRL_STATE netCtrlState); 00192 00193 PreferenceInfo &getPreferences(); 00194 00195 bool savePreferences(); 00196 00197 virtual void startStats(); 00198 00199 virtual void stopStats(); 00200 00201 virtual void UserSubmit(); 00202 00203 void setBanner(const tstring &banner); 00204 void setBannerResponse(bool bResponse); 00205 bool getUserResponse(); 00206 bool isUserResponseSet(); 00207 00208 void setCertBlocked(const tstring &tstrUntrustedServer); 00209 void setCertWarning(const tstring &tstrUntrustedServer, 00210 const std::list<tstring> <strCertErrors, 00211 bool bAllowImport); 00212 bool getCertImportResponse(); 00213 00214 void setUserPrompt(ConnectPromptInfo &ConnectPrompt); 00215 00216 #ifdef PLATFORM_ANDROID 00217 void setClientCertResponse(std::vector< std::pair<uint32_t, uint8_t*> > &derList); 00218 #endif 00219 00220 void setImportPKCS12Result(bool bResult, const tstring &strError); 00221 00222 void setCertBlockedResponse(bool bUnlock); 00223 void setCertWarningResponse(bool bConnect, bool bImportCert); 00224 00225 void insertStateToConnectPrompt(ConnectPromptInfo &ConnectPrompt); 00226 00227 void ExitNotice(const tstring &tstrNotice, const int code = 0); 00228 00229 void notice(const tstring tstrNotice, 00230 const MessageType type = MsgType_Info, 00231 bool bClearLastMsg = false); 00232 00233 void notice(MsgWithArg ¬ice, 00234 const MessageType type = MsgType_Info, 00235 bool bClearLastMsg = false); 00236 00237 void getStats(void); 00238 00239 void setStats(VPNStats &stats); 00240 00241 void exportStats(const tstring &tstrFilePath); 00242 00243 void setState(VPNState state, 00244 VPNState previousState, 00245 VPNSubState subState = VPNSS_NORMAL, 00246 bool bUpdateStateMsg = true, 00247 bool bOnlyUpdateUI = false); 00248 00249 void setWMHint(WMHint hint, 00250 WMHintReason reason); 00251 00252 bool isLastConnectType (const ConnectPromptType connPromptType); 00253 00254 bool isOperatingMode(OperatingMode opMode); 00255 void setOperatingMode(OperatingMode opMode); 00256 void unsetOperatingMode(OperatingMode opMode); 00257 00258 bool CanRemediateCaptivePortal(); 00259 00260 bool isUsingEventModel(); 00261 00262 time_t getLastDisconnectTime(); 00263 00264 ConnectPromptInfo getConnectPromptInfo(); 00265 00266 void setStandaloneConnection(bool isStandalone); 00267 00268 void deliverActiveHost(const tstring &activeHost, 00269 ConnectProtocolType vpnProtocol = PROTOCOL_TYPE_UNKNOWN); 00270 00271 bool isVPNServiceReady(); 00272 00273 // reset last disconnect time indicator. 00274 // 00275 void resetLastDisconnectTime(time_t time = 1); 00276 00277 void processMinimize(); 00278 00279 // cert enrollment 00280 void setEnrollClientCert(CertObj* pCert); 00281 00282 // Show user banner for cert import warning on linux 00283 // SCEPIfc to ConnectMgr 00284 void linuxCertImportWarnUser(); 00285 00286 // Response to cert warning on linux 00287 // ConnectMgr to SCEPIfc 00288 void linuxCertImportWarnUserResponse(bool bAccept); 00289 00290 void setDefaultHost(tstring &host); 00291 00292 #ifdef PLATFORM_ANDROID 00293 bool requestClientCertificates(); 00294 #endif 00295 00296 bool requestImportPKCS12(const std::vector<unsigned char> &der); 00297 00298 bool requestImportLocalization(const tstring tstrLocale, 00299 const std::vector<unsigned char> &MoFileData); 00300 00301 // Start the Automatic Headend Selection operation 00302 void startAHS(const unsigned int uiReason, 00303 const ProxyIfc& proxy); 00304 // statusReturnCode is a long to match the current type of STATUSCODE. 00305 // It is not using a STATUSCODE directly so that we do not have to 00306 // expose the header files for STATUSCODEs to ClientIfcBase.h 00307 void AHSSelectedHost(const unsigned int uiReason, 00308 const std::vector<tstring> &headendList, 00309 const long statusReturnCode, 00310 const tstring& extraInfo); 00311 std::vector<tstring> getAHSHostList(); 00312 unsigned int getAHSState(); 00313 bool isAHSHasRun(); 00314 00315 bool suppressConnectionErrorPopups(); 00316 00317 tstring getCaptivePortalDetectedMsg(); 00318 00319 void setProxyAuthPrompts(ProxyIfc* pProxy, 00320 const tstring& promptMsg); 00321 00322 00323 bool handleIpcMessage(CIpcMessage *pIpcMessage); 00324 00325 bool IsCsdTokenVerified() const; 00326 00327 bool isConnectRequestActive(); 00328 00329 virtual ~ClientIfcBase(); 00330 00331 tstring getConnectHost(); 00332 00333 private: 00334 CExecutionContext* m_pExecutionContext; 00335 00336 AgentIfc *mo_AgentIfc; 00337 00338 ConnectMgr *mo_ConnectMgr; 00339 00340 ApiThread *mo_ConnectThread; 00341 00342 EventMgr *mo_EventMgr; 00343 00344 PreferenceMgr *mo_PreferenceMgr; 00345 00346 ConnectPromptInfo *mp_currentConnectPromptInfo; 00347 00348 PreferenceInfo *mo_EditablePrefs; 00349 00350 #if defined(SCRIPTING_SUPPORTED) 00351 CScriptingMgr *mo_ScriptingMgr; 00352 #endif // SCRIPTING_SUPPORTED 00353 #ifndef PLATFORM_APPLE_SSLVPN 00354 SCEPIfc* m_pSCEPIfc; 00355 bool m_bInformedAgentOfSCEP; 00356 CStoragePath* m_pStoragePath; 00357 #endif // !PLATFORM_APPLE_SSLVPN 00358 00359 #ifdef ANYCONNECT_USE_SNAK 00360 PluginLoader *m_pPluginLoader; 00361 SNAK_CertPlugin *m_pSNAKCert; 00362 SNAK_SocketPlugin *m_pSNAKSocket; 00363 SNAK_StoragePlugin *m_pSNAKStorage; 00364 00365 bool mb_SNAKInitialized; 00366 #endif 00367 00368 bool mb_PreferenceMgrCreated; 00369 bool mb_StandaloneConnection; 00370 bool mb_UsingEventModel; 00371 bool mb_UserResponse; 00372 bool mb_IsUserResponseSet; 00373 bool mb_PerformedAutoCertEnrollment; 00374 tstring ms_PostEnrollmentConnectHost; 00375 bool mb_CaptivePortalMsgDisplayed; 00376 bool m_bSuppressMinimizeOnConnect; 00377 bool m_bSuppressConnectionErrorPopups; 00378 bool m_bLastConnectionAutomatic; 00379 bool m_bImportCertResp; 00380 00381 unsigned int mui_OperatingMode; 00382 NETENV_STATE m_currentNetEnvState; 00383 NETENV_STATE m_previousNetEnvState; 00384 NETCTRL_STATE m_currentNetCtrlState; 00385 NETWORK_TYPE m_currentNetType; 00386 00387 tstring ms_message; 00388 00389 time_t m_disconnectTime; 00390 00391 static std::string ms_ThreadName; 00392 00393 CManualLock* m_pClientIfcStateLock; 00394 CManualLock* m_pClientIfcLock; 00395 CManualLock* m_pClientIfcPromptsLock; 00396 CManualLock* m_pClientIfcOpModeLock; 00397 CManualLock* m_pClientIfcAHSLock; 00398 CManualLock* m_pClientIfcConnectModeLock; 00399 CManualLock* m_pClientIfcInformAgentOfSCEPLock; 00400 00401 std::vector<tstring> msl_AHSSelectedHosts; 00402 ApiThread* m_pAHSThread; 00403 unsigned int m_uiAHSState; 00404 00405 static volatile bool mb_deleteFirstPass; 00406 00407 ConnectMgr &getConnectMgr(); 00408 00409 ProfileMgr &getProfileMgr(); 00410 UserPreferences &getUserPreferences(); 00411 00412 void displayAgentAttachMessage(); 00413 00414 void setLastDisconnectTime(time_t time); 00415 00416 void setCurrentStatePrompts(const VPNState state, 00417 const VPNState prevState, 00418 const VPNSubState subState, 00419 const bool bUpdateStateMsg); 00420 void setCurrentStateErrorMessage(VPNState state, CONNECT_FAILURE_REASON cfr); 00421 void getStateMessage(const VPNState state, 00422 const VPNState prevState, 00423 const VPNSubState subState, 00424 const NETENV_STATE neState, 00425 /*out*/ MsgWithArg& stateMessage); 00426 00427 bool isStandaloneConnection(); 00428 00429 virtual void OnLoadPreferencesComplete(); 00430 void RefreshPreferences(void); 00431 00432 void displayAHSPrompt(const bool isComplete); 00433 void handleAHSPreferences(const unsigned int uiReason); 00434 void setAHSState(const unsigned int ahsState); 00435 00436 bool autoConnectIfEnabled(const bool suppressAutoConnect); 00437 00438 void clearUserSetResponseFlag(); 00439 00440 #ifndef PLATFORM_APPLE_SSLVPN 00441 bool processSCEPIpcMessage(CIpcMessage *pIpcMessage); 00442 bool isSCEPRedirect(); 00443 void processSCEPRedirect(); 00444 #endif // PLATFORM_APPLE_SSLVPN 00445 00446 ClientIfcBase(const ClientIfcBase& other); 00447 ClientIfcBase& operator=(const ClientIfcBase& other); 00448 00449 #ifdef ANYCONNECT_USE_SNAK 00450 bool initializeSNAK(); 00451 #endif 00452 00453 }; 00454 00455 00456 #endif // _CLIENTIFCBASE_