AnyConnect Secure Mobility Client  5.1.8.122
ClientIfcBase.h
1 /**************************************************************************
2 * Copyright (c) 2006, 2021-2024 Cisco Systems, Inc.
3 * All Rights Reserved. Cisco Highly Confidential.
4 ***************************************************************************
5 *
6 * File: ClientIfcBase.h
7 * Author: Chris Fitzgerald
8 * Date: 08/2007
9 *
10 ***************************************************************************
11 * Client Interface Base class implementation for the Client API.
12 ***************************************************************************/
13 
14 #ifndef _CLIENTIFCBASE_
15 #define _CLIENTIFCBASE_
16 
17 #include <list>
18 #include <vector>
19 #include <memory>
20 
21 #include "ClientIfcCommon.h"
22 #include "api.h"
23 
24 #if defined(ANYCONNECT_USE_SNAK)
25 #include "SNAK_CertPlugin.h"
26 #endif
27 
28 #if defined(HOST_DATA_SUPPORTED)
29 class IHostData;
30 #endif
31 
32 class ConnectPromptInfo;
33 class MsgWithArg;
34 class VPNStats;
35 class PreferenceInfo;
36 class ProxyIfc;
37 class CIpcMessage;
38 class CertObj;
39 class HostEntry;
40 class ClientIfcInternal;
41 
42 #if defined(VPNAPI_EVENT_NOTIFICATION_SUPPORTED)
43 class CEventNotificationTlv;
44 #endif
45 
46 #if defined(CREDENTIAL_PREFILL_SUPPORTED)
47 class CredentialPrefill;
48 #endif
49 
50 #if (defined(ANYCONNECT_USE_SNAK) || defined(PLATFORM_APPLE_SSLVPN)) && !defined(PLATFORM_WIN_APP)
51 class ManagedCertificate;
52 #endif
53 
54 #if defined(PROGRAM_DATA_IMPORT_SUPPORTED)
55 class IACImporterAsync;
56 class IACImporterAsyncCB;
57 #endif
58 
59 class VPN_VPNAPI ClientIfcBase
60 {
61  friend class EventMgr;
62  friend class ClientIfcInternal;
63 
64 protected:
65 
66  ClientIfcBase();
67  virtual ~ClientIfcBase();
68 
69  /**
70  * Callback used to deliver new statistics related to the VPN
71  * connection.
72  *
73  * When a connection is active, a new set of statistics is
74  * delivered each second.
75  *
76  * @see resetStats(), stopStats() and startStats()
77  *
78  */
79  virtual void StatsCB(VPNStats &stats) = 0;
80 
81 
82  /**
83  * Callback used to deliver VPN state and state change string.
84  * The stateString delivered by this method is localized.
85  *
86  * See the ::VPNState enum found in api.h for set of valid states.
87  */
88  virtual void StateCB(const VPNState state,
89  const VPNSubState subState,
90  const tstring stateString) = 0;
91 
92 
93  /**
94  * If a banner needs to be acknowledged, this CB delivers the banner
95  * to the client.
96  *
97  * NOTE: Connection establishment will block until the method
98  * setBannerResponse() is called.
99  *
100  * In a GUI, a banner would typically be displayed in a modal dialog
101  * with an accept or decline button selection.
102  *
103  * @see setBannerResponse() to set the user response to the banner.
104  */
105  virtual void BannerCB(const tstring &banner) = 0;
106 
107  /**
108  * If a pre-connect reminder needs to be acknowledged, this CB delivers
109  * the pre-connect reminder to the client.
110  *
111  * NOTE: Connection establishment will block until the method
112  * setPreConnectReminderResponse() is called.
113  *
114  * In a GUI, a pre-connect reminder would typically be displayed in a modal
115  * dialog with an OK button selection.
116  *
117  * @see setPreConnectReminderResponse() to set the user acknowledgement to
118  * the pre-connect reminder message.
119  */
120  virtual void PreConnectReminderCB(const tstring &rtstrPreConnectReminder);
121 
122  /**
123  * Messages are delivered via the NoticeCB and can come from multiple
124  * sources. There are four message types (error, warning, info and
125  * status). See the ::MessageType enum in api.h for the list.
126  *
127  * Clients using the API as an embedded application (not
128  * user visible) might want to further characterize
129  * messages. One option here is to use the AnyConnect message
130  * catalog and assign message codes as the translations for
131  * various messages. An application could then track messages based
132  * on its own error code scheme.
133  */
134  virtual void NoticeCB(const tstring &notice,
135  const MessageType type,
136  const bool bSensitive = false) = 0;
137 
138 #if defined(PLATFORM_APPLE_SSLVPN) || defined(PLATFORM_ANDROID) || defined(PLATFORM_CHROMEBOOK)
139  virtual void CertBannerCB(const tstring &certBannerSummary,
140  const uint32_t nCertBannerCertLen,
141  const uint8_t *pCertBannerCertDer,
142  const std::list<tstring> &confirmReasons,
143  const std::list<CertConfirmReason> &confirmReasonEnums,
144  bool bImportAllowed = true) = 0;
145 #endif
146 
147  /**
148  * This CB would likely occur only during a connection when it was
149  * detected that the software needed to be upgraded, or when Start
150  * Before Logon (SBL) is being used.
151  *
152  * Unlike the other callback methods, this method provides a default
153  * implementation (calling the system's exit() function).
154  * If clients of the API wish to override this behavior, they are
155  * responsible for ensuring that the current running process exits with
156  * the return code specified by returnCode.
157  *
158  * <b>Caution</b>: IF YOU OVERRIDE THIS METHOD AND DO NOT EXIT WITH
159  * THE PROPER CODE SOFTWARE UPDATE FUNCTIONALITY IN YOUR CLIENT WILL
160  * BREAK
161  */
162  virtual void ExitNoticeCB(const tstring &tstrNotice,
163  const int returnCode);
164 
165 
166  /**
167  * Under normal operating conditions, this CB is called as soon
168  * as the attach method completes. In case the service (vpn agent)
169  * is not ready, this CB is not called until it is.
170  *
171  * Any API calls made prior to this CB being called will result in a
172  * NoticeCB error message.
173  */
174  virtual void ServiceReadyCB() = 0;
175 
176 
177 
178  /**
179  * This method supports prompting for single or multiple values. All
180  * prompts are considered mandatory.
181  *
182  * The ConnectPromptInfo object contains a list of PromptEntry
183  * instances. The labels and their default values (if any) can be
184  * found in these instances. After the data has been collected from the user
185  * it can be set into these same instances. When ready, the client
186  * application should call the method UserSubmit() to have the
187  * responses read by the API.
188  */
189  virtual void UserPromptCB(ConnectPromptInfo &ConnectPrompt) = 0;
190 
191 
192  /**
193  * Use this method to provide Window Manager hints to GUI
194  * applications. To receive these hints, the application must
195  * identify itself as a GUI in the attach method. In addition, this
196  * method should be overridden to receive any generated events.
197  *
198  * Event that can be received include those indicating that a user is
199  * starting a second instance of the GUI application. This information
200  * can be used to tell the already running application to un-minimize
201  * itself and let the new program know that it should Quit (since a GUI
202  * is already running).
203  */
204  virtual void WMHintCB(const WMHint hint,
205  const WMHintReason reason);
206 
207 
208  /**
209  * This method is useful when the connection to the secure gateway
210  * has been established as part of a web-launch of the VPN tunnel.
211  *
212  * If the client application wishes to be notified of the secure
213  * gateway to which the VPN has been established, this method should
214  * be overridden.
215  *
216  * If the client application is started and a tunnel is already active,
217  * this method also delivers the name of the secure gateway host.
218  */
219  virtual void deliverWebLaunchHostCB(const tstring &activeHost);
220 
221  /**
222  * This method is called when the preference to block untrusted
223  * servers is enabled and the current VPN server being connected
224  * to is untrusted. Clients should present an error to the user
225  * notifying them that the current connection to rtstrUntrustedServer
226  * is being blocked. The client should also provide a way for the
227  * user to change the preference to block untrusted servers.
228  *
229  * The user response must be indicated using setCertBlockedResponse
230  */
231  virtual void CertBlockedCB(const tstring &rtstrUntrustedServer) = 0;
232 
233  /**
234  * This method is called when connections to untrusted VPN servers
235  * is allowed by policies and the current VPN server being connected
236  * to is untrusted. Clients should present a warning to the user
237  * notifying them that the current connection to rtstrUntrustedServer
238  * is unsafe. The reason the VPN server is untrusted is provided in
239  * rltstrCertErrors. The client should provide a way for the user to
240  * connect once, connect and always trust or cancel the connection.
241  * If bAllowImport is set to false then the always trust option should
242  * not be presented to users.
243  *
244  * The user response must be indicated using setCertWarningResponse
245  */
246  virtual void CertWarningCB(const tstring &rtstrUntrustedServer,
247  const std::list<tstring> &rltstrCertErrors,
248  bool bAllowImport) = 0;
249 
250 #if defined(PLATFORM_WIN_APP)
251  /**
252  * Same as above but also passes the Server certificate DER for details display
253  */
254  virtual void CertWarningCB(const tstring &rtstrUntrustedServer,
255  const std::list<tstring> &rltstrCertErrors,
256  const std::vector<uint8_t> &rvServerCertDER,
257  bool bAllowImport) = 0;
258 #endif
259 
260  /**
261  * This method should be overridden by the client application to
262  * exercise some control over the delivery of events from the other
263  * protected methods in this class.
264  *
265  * This might be necessary in cases where a GUI/CLI is being written and
266  * the data from this API needs to be delivered in the GUI/CLI or main
267  * thread. In this case, you should override this method and when it
268  * is called by the API post an event to your event queue (message
269  * pump, etc.). After this event executes in your GUI/CLI or main thread,
270  * call the method ClientIfc::ProcessEvents to have events delivered
271  * to your client application.
272  */
273  virtual void EventAvailable();
274 
275 #if defined(MANUAL_PKCS12_IMPORT_SUPPORTED)
276  virtual void ImportPKCS12ResultCB(const std::vector<uint8_t> &certHash,
277  const tstring &tstrError);
278 #endif
279 #if defined(PLATFORM_ANDROID)
280  virtual void ClientCertificateCB(std::vector< std::pair<uint32_t, uint8_t*> > certList) = 0;
281  virtual void AgentDetachedCB();
282 #endif
283 
284 #if defined(VPNAPI_EVENT_NOTIFICATION_SUPPORTED)
285  /**
286  * Internal callback between ClientIfcBase and ClientIfc.
287  */
288  virtual void EventNotificationInternalCB(
289  const std::shared_ptr<CEventNotificationTlv>& spEventNtfctnTlv) = 0;
290 #endif
291 
292 
293  /**
294  * Internal methods for use by ClientIfc.
295  */
296 
297  void ResetQuarantinedReconnect();
298 
299  void ClientIfcTransmigration();
300 
301 public:
302 
303  bool attach(const ClientType clientType = ClientType_GUI,
304  const bool requestFullCapabilities = true,
305  const bool suppressAutoConnect = true,
306  const bool bSuppressEventAvailableCB = false);
307 
308  void detach();
309 
310  void ProcessEvents();
311 
312  bool hasFullCapabilities();
313 
314  bool isConnected(bool bSilent = false);
315 
316  bool isAvailable();
317 
318  std::list<tstring> getHostNames();
319 
320  std::list<HostEntry> getHostEntries();
321 
322  tstring getDefaultHostName();
323 
324  bool connect(
325 #if defined(HOST_DATA_SUPPORTED)
326  const IHostData& host);
327 #else
328  tstring host);
329 #endif
330 
331  bool connect(
332 #if defined(HOST_DATA_SUPPORTED)
333  const IHostData& host,
334 #else
335  tstring host,
336 #endif
337  unsigned int origin);
338 
339  bool setNewTunnelGroup(const tstring & group);
340 
341  void disconnect();
342 
343  void cancel();
344 
345  void resetStats();
346 
347  void getState();
348 
349  VPNState getCurrentVPNState();
350  VPNSubState getCurrentVPNSubState();
351  VPNSubState getPreviousVPNSubState();
352 
353  STATE getCurrentState();
354 
355  tstring getStateText();
356  static tstring getNoticeTypeText(MessageType msgType);
357 
358  static tstring getStateText(VPNState state,
359  VPNSubState subState = VPNSS_NORMAL,
360  NETENV_STATE netEnvState = NES_NETWORK_ACCESSIBLE,
361  const tstring& tstrConnectedHost = tstring());
362 
363  void setNetworkStates(NETENV_STATE netEnvState,
364  NETCTRL_STATE netCtrlState,
365  NETWORK_TYPE netType,
366  bool bACBrowserForCPRemediation,
367  bool bUpdateUI);
368  void refreshOperatingModeForCurrentNetStates();
369  NETENV_STATE getCurrentNetEnvState();
370  NETENV_STATE getPreviousNetEnvState();
371  NETCTRL_STATE getCurrentNetCtrlState();
372  NETWORK_TYPE getCurrentNetType();
373  bool isACBrowserForCPRemediation();
374 
375  static tstring getNetCtrlText(NETCTRL_STATE netCtrlState);
376  static tstring getNetEnvText(NETENV_STATE netEnvState,
377  bool bSimple = false);
378  static tstring getNetTypeText(NETWORK_TYPE netType);
379  static tstring getQuarantinedStatusText();
380  static tstring getNetworkStatusSimpleText(const NETENV_STATE netEnvState,
381  const NETCTRL_STATE netCtrlState);
382 
383  // can't be static due to requiring operating mode information
384  tstring getNetworkStatusText(const VPNState state,
385  const VPNSubState subState,
386  const NETENV_STATE netEnvState,
387  const NETCTRL_STATE netCtrlState);
388 
389  PreferenceInfo& getPreferences();
390 
391  bool savePreferences();
392 
393  void startStats();
394 
395  void stopStats();
396 
397  void UserSubmit();
398 
399  void setBanner(const tstring &banner);
400  void setBannerResponse(bool bResponse);
401 
402  void setPreConnectReminder(const tstring &tstrPreConnectReminder);
403  void setPreConnectReminderResponse();
404 
405  bool getUserResponse();
406  bool isUserResponseSet();
407 
408  void setCertBlocked(const tstring &tstrUntrustedServer);
409  void setCertWarning(const tstring &rtstrUntrustedServer,
410  const std::list<tstring> &rltstrCertErrors,
411  bool bAllowImport);
412 #if defined(PLATFORM_WIN_APP)
413  void setCertWarning(const tstring &rtstrUntrustedServer,
414  const std::list<tstring> &rltstrCertErrors,
415  const std::vector<uint8_t>& rvServerCertDER,
416  bool bAllowImport);
417 #endif
418  bool getCertImportResponse();
419 
420 #if defined(PLATFORM_APPLE_SSLVPN) || defined(PLATFORM_ANDROID) || defined(PLATFORM_CHROMEBOOK)
421  void setCertBanner(tstring tstrCertBannerSummary,
422  uint32_t nCertBannerCertLen,
423  const uint8_t *pCertBannerCertDer,
424  const std::list<tstring> &confirmReasons,
425  const std::list<CertConfirmReason> &confirmReasonEnums,
426  bool bImportAllowed);
427 
428  void setCertBannerResponse(bool bResponse, bool bImportCert);
429  void importServerCert(std::vector<uint8_t> certData);
430  bool setFipsMode(bool bEnableFips);
431 #if defined(PLATFORM_ANDROID)
432  bool setStrictMode(bool bEnableStrictMode);
433  bool setRevocationEnabled(bool bRevocationEnabled);
434  bool IsRevocationEnabled();
435 #endif // currently supported only for android
436 #endif
437 
438  void setUserPrompt(ConnectPromptInfo &ConnectPrompt);
439 
440 #if defined(PLATFORM_ANDROID)
441  void setClientCertResponse(std::vector< std::pair<uint32_t, uint8_t*> > &derList);
442  void setAgentDetached();
443  bool getClientCertificates();
444 #endif
445 
446 #if defined(PLATFORM_APPLE_SSLVPN) || defined(PLATFORM_ANDROID)
447  void setSCEPEnrollInProgress(bool bInProgress);
448  bool isSCEPEnrollInProgress();
449 #endif
450 
451 #if defined(MANUAL_PKCS12_IMPORT_SUPPORTED)
452  void setImportPKCS12Result(const std::vector<uint8_t> &certHash, const tstring &tstrError);
453  bool requestImportPKCS12(const std::vector<uint8_t> &data);
454  std::vector<uint8_t> importPKCS12WithPassword(const std::vector<uint8_t> &data, const tstring &password);
455 #endif
456 
457  void setCertBlockedResponse(bool bUnlock);
458  void setCertWarningResponse(bool bConnect, bool bImportCert);
459 
460  void insertStateToConnectPrompt(ConnectPromptInfo &ConnectPrompt);
461 
462  void ExitNotice(const tstring &tstrNotice, const int code = 0);
463 
464  void notice(const tstring &tstrNotice,
465  const MessageType type = MsgType_Info,
466  bool bClearLastMsg = false,
467  bool bForce = false,
468  bool bStateMsg = false,
469  bool bSensitiveMsg = false);
470 
471  void notice(MsgWithArg &notice,
472  const MessageType type = MsgType_Info,
473  bool bClearLastMsg = false,
474  bool bForce = false,
475  bool bStateMsg = false,
476  bool bSensitiveMsg = false);
477 
478  void getStats(void);
479 
480  void setStats(VPNStats &stats);
481 
482  void exportStats(const tstring &tstrFilePath);
483 
484  void initState(VPNState state,
485  VPNState previousState,
486  VPNSubState subState);
487 
488  void setState(VPNState state,
489  VPNState previousState,
490  VPNSubState subState = VPNSS_NORMAL,
491  bool bUpdateStateMsg = true,
492  bool bOnlyUpdateUI = false);
493 
494 #if defined(PROGRAM_DATA_IMPORT_SUPPORTED)
495  IACImporterAsync *createACImporter(IACImporterAsyncCB *pCallback);
496 #endif
497 
498  void setWMHint(WMHint hint,
499  WMHintReason reason);
500 
501  bool isLastConnectType (const ConnectPromptType connPromptType);
502 
503  bool isOperatingMode(OperatingMode opMode);
504  void setOperatingMode(OperatingMode opMode);
505  void unsetOperatingMode(OperatingMode opMode);
506 
507  bool CanRemediateCaptivePortal();
508  bool policyAllowsCaptivePortalRemediation();
509 
510  bool isEventShutdown();
511 
512  bool isUsingEventModel();
513 
514  time_t getLastDisconnectTime();
515 
516  ConnectPromptInfo getConnectPromptInfo();
517  void resetConnectPromptPasswordData();
518 
519  void setStandaloneConnection(bool isStandalone);
520 
521  void deliverActiveHost(const tstring &activeHost,
522  ConnectProtocolType vpnProtocol = PROTOCOL_TYPE_UNKNOWN,
523  bool bActiveHostFriendlyName = false);
524 
525  bool isVPNServiceReady();
526 
527  // reset last disconnect time indicator.
528  //
529  void resetLastDisconnectTime(time_t time = 1);
530 
531  void processMinimize();
532 
533  // cert enrollment
534  void setEnrollClientCert(CertObj* pCert);
535 
536  // Show user banner for cert import warning on linux
537  // SCEPIfc to ConnectMgr
538  void linuxCertImportWarnUser();
539 
540  // Response to cert warning on linux
541  // ConnectMgr to SCEPIfc
542  void linuxCertImportWarnUserResponse(bool bAccept);
543 
544  void setDefaultHost(tstring &host);
545 
546 #if defined(HOST_DATA_SUPPORTED)
547  void setDefaultHostProfile(const IHostData &hostProfile);
548  IHostData* getDefaultHostData();
549 #endif
550 
551  void setLastVpnError(VPNError vpnError);
552  VPNError getLastVpnError();
553 
554 #if defined(PLATFORM_ANDROID)
555  bool requestClientCertificates();
556 #endif
557 
558  bool requestImportLocalization(const tstring tstrLocale,
559  const std::vector<unsigned char> &MoFileData);
560 
561  // Start the Automatic Headend Selection operation
562  void startAHS(const unsigned int uiReason,
563  const ProxyIfc& proxy);
564  // statusReturnCode is a long to match the current type of STATUSCODE.
565  // It is not using a STATUSCODE directly so that we do not have to
566  // expose the header files for STATUSCODEs to ClientIfcBase.h
567  void AHSSelectedHost(const unsigned int uiReason,
568  const std::vector<tstring> &headendList,
569  const long statusReturnCode,
570  const tstring& extraInfo);
571  std::vector<tstring> getAHSHostList();
572  unsigned int getAHSState();
573  bool isAHSHasRun();
574  bool IsAHSCachingRestricted();
575 
576  bool suppressConnectionErrorPopups();
577 
578  tstring getCaptivePortalDetectedMsg();
579 
580  void setProxyAuthPrompts(ProxyIfc* pProxy,
581  const tstring& promptMsg);
582 
583 #if defined(INTERPROCESS_COMMUNICATION_SUPPORTED)
584  bool handleIpcMessage(CIpcMessage *pIpcMessage);
585 #if defined(VPNAPI_EVENT_NOTIFICATION_SUPPORTED)
586  void signalDisconnectedToEventNtfctnThread();
587 #endif
588 #endif
589  bool IsCsdTokenVerified() const;
590 
591 #if defined(PLATFORM_APPLE_SSLVPN) || defined(PLATFORM_ANDROID)
592  virtual void SCEPEnrollStartCB();
593  virtual void SCEPEnrollExitCB();
594 #endif
595 
596  void activateConnectMgrTunnelInitiationCompletionEvent();
597  bool isConnectRequestActive();
598  bool isConnectRequestCleanup();
599 #if defined(PLATFORM_ANDROID) || defined(PLATFORM_CHROMEBOOK)
600  bool deleteProfileByName(const tstring &profileName);
601  tstring getProfileContents(const tstring &profileName);
602  bool importProfile(const tstring &profileName, const tstring &profileContents);
603 #endif
604 
605  bool syncProfileChange(const tstring &profileName);
606 
607 #if defined(CREDENTIAL_PREFILL_SUPPORTED)
608  bool hasPrefilledCredentials();
609  bool prefillCredentials(ConnectPromptInfo &connectPrompt);
610  void setPrefilledCredentials(CredentialPrefill *prefill);
611 #endif
612 
613 #if defined(PLATFORM_ANDROID) || defined(PLATFORM_APPLE_SSLVPN)
614  std::list<ManagedCertificate *> enumerateCertificates(CertificateType certType);
615  bool deleteCertificates(CertificateType certType, const std::list<std::string> &idList);
616  bool deleteServerCertificates(const std::list<std::string> &idList);
617 #endif
618 
619 #if defined(ANYCONNECT_USE_SNAK) && !defined(PLATFORM_WIN_APP)
620  std::list<ManagedCertificate *> enumerateSNAKCertificates(SNAK_CertType certType);
621  SNAK_CertType getSNAKCertType(CertificateType certType);
622  bool deleteClientCertificates(const std::list<std::string> &idList);
623 #endif
624 
625 #if defined(PLATFORM_APPLE_SSLVPN)
626  bool canUseBackupServers();
627 #endif
628 
629  tstring getConnectHost();
630 
631  tstring getMgmtTunnelHostname();
632 
633  VPN_TUNNEL_SCOPE getVpnTunnelScope();
634 
635  bool isStandaloneConnection();
636 
637  void sendSSoLogoutPrompt(ConnectPromptInfo &cpi);
638 
639  void setExternalSSOLogoutUrlFromAgent(const tstring& logoutUrl);
640 
641 private:
642 
643  //
644  // Private Member Data
645  //
646 
647  std::unique_ptr<ClientIfcInternal> m_upClientIfcInternal;
648 
649 
650  //
651  // Private Member Methods
652  //
653 
654  // Prevent copying by declaring but not defining copy constructor and operator= methods.
655  //
656  ClientIfcBase(const ClientIfcBase& other);
657  ClientIfcBase& operator=(const ClientIfcBase& other);
658 };
659 
660 #endif // _CLIENTIFCBASE_
Definition: api.h:113
ConnectPromptType
Definition: api.h:233
Definition: PreferenceInfo.h:26
WMHintReason
Definition: api.h:209
VPNState
Definition: api.h:144
Definition: ClientIfcBase.h:59
#define tstring
Definition: api.h:35
WMHint
Definition: api.h:190
Definition: ConnectPromptInfo.h:37
MessageType
Definition: api.h:108
OperatingMode
Definition: api.h:536
VPNSubState
Definition: api.h:168
VPNError
Definition: api.h:588
Definition: VPNStats.h:35