AnyConnect Secure Mobility Client  5.1.7.80
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 getCurrentState();
350  VPNSubState getCurrentSubState();
351  VPNSubState getPreviousSubState();
352 
353  tstring getStateText();
354  static tstring getNoticeTypeText(MessageType msgType);
355 
356  static tstring getStateText(VPNState state,
357  VPNSubState subState = VPNSS_NORMAL,
358  NETENV_STATE netEnvState = NES_NETWORK_ACCESSIBLE,
359  const tstring& tstrConnectedHost = tstring());
360 
361  void setNetworkStates(NETENV_STATE netEnvState,
362  NETCTRL_STATE netCtrlState,
363  NETWORK_TYPE netType,
364  bool bACBrowserForCPRemediation,
365  bool bUpdateUI);
366  void refreshOperatingModeForCurrentNetStates();
367  NETENV_STATE getCurrentNetEnvState();
368  NETENV_STATE getPreviousNetEnvState();
369  NETCTRL_STATE getCurrentNetCtrlState();
370  NETWORK_TYPE getCurrentNetType();
371  bool isACBrowserForCPRemediation();
372 
373  static tstring getNetCtrlText(NETCTRL_STATE netCtrlState);
374  static tstring getNetEnvText(NETENV_STATE netEnvState,
375  bool bSimple = false);
376  static tstring getNetTypeText(NETWORK_TYPE netType);
377  static tstring getQuarantinedStatusText();
378  static tstring getNetworkStatusSimpleText(const NETENV_STATE netEnvState,
379  const NETCTRL_STATE netCtrlState);
380 
381  // can't be static due to requiring operating mode information
382  tstring getNetworkStatusText(const VPNState state,
383  const VPNSubState subState,
384  const NETENV_STATE netEnvState,
385  const NETCTRL_STATE netCtrlState);
386 
387  PreferenceInfo& getPreferences();
388 
389  bool savePreferences();
390 
391  void startStats();
392 
393  void stopStats();
394 
395  void UserSubmit();
396 
397  void setBanner(const tstring &banner);
398  void setBannerResponse(bool bResponse);
399 
400  void setPreConnectReminder(const tstring &tstrPreConnectReminder);
401  void setPreConnectReminderResponse();
402 
403  bool getUserResponse();
404  bool isUserResponseSet();
405 
406  void setCertBlocked(const tstring &tstrUntrustedServer);
407  void setCertWarning(const tstring &rtstrUntrustedServer,
408  const std::list<tstring> &rltstrCertErrors,
409  bool bAllowImport);
410 #if defined(PLATFORM_WIN_APP)
411  void setCertWarning(const tstring &rtstrUntrustedServer,
412  const std::list<tstring> &rltstrCertErrors,
413  const std::vector<uint8_t>& rvServerCertDER,
414  bool bAllowImport);
415 #endif
416  bool getCertImportResponse();
417 
418 #if defined(PLATFORM_APPLE_SSLVPN) || defined(PLATFORM_ANDROID) || defined(PLATFORM_CHROMEBOOK)
419  void setCertBanner(tstring tstrCertBannerSummary,
420  uint32_t nCertBannerCertLen,
421  const uint8_t *pCertBannerCertDer,
422  const std::list<tstring> &confirmReasons,
423  const std::list<CertConfirmReason> &confirmReasonEnums,
424  bool bImportAllowed);
425 
426  void setCertBannerResponse(bool bResponse, bool bImportCert);
427  void importServerCert(std::vector<uint8_t> certData);
428  bool setFipsMode(bool bEnableFips);
429 #if defined(PLATFORM_ANDROID)
430  bool setStrictMode(bool bEnableStrictMode);
431  bool setRevocationEnabled(bool bRevocationEnabled);
432  bool IsRevocationEnabled();
433 #endif // currently supported only for android
434 #endif
435 
436  void setUserPrompt(ConnectPromptInfo &ConnectPrompt);
437 
438 #if defined(PLATFORM_ANDROID)
439  void setClientCertResponse(std::vector< std::pair<uint32_t, uint8_t*> > &derList);
440  void setAgentDetached();
441  bool getClientCertificates();
442 #endif
443 
444 #if defined(PLATFORM_APPLE_SSLVPN) || defined(PLATFORM_ANDROID)
445  void setSCEPEnrollInProgress(bool bInProgress);
446  bool isSCEPEnrollInProgress();
447 #endif
448 
449 #if defined(MANUAL_PKCS12_IMPORT_SUPPORTED)
450  void setImportPKCS12Result(const std::vector<uint8_t> &certHash, const tstring &tstrError);
451  bool requestImportPKCS12(const std::vector<uint8_t> &data);
452  std::vector<uint8_t> importPKCS12WithPassword(const std::vector<uint8_t> &data, const tstring &password);
453 #endif
454 
455  void setCertBlockedResponse(bool bUnlock);
456  void setCertWarningResponse(bool bConnect, bool bImportCert);
457 
458  void insertStateToConnectPrompt(ConnectPromptInfo &ConnectPrompt);
459 
460  void ExitNotice(const tstring &tstrNotice, const int code = 0);
461 
462  void notice(const tstring &tstrNotice,
463  const MessageType type = MsgType_Info,
464  bool bClearLastMsg = false,
465  bool bForce = false,
466  bool bStateMsg = false,
467  bool bSensitiveMsg = false);
468 
469  void notice(MsgWithArg &notice,
470  const MessageType type = MsgType_Info,
471  bool bClearLastMsg = false,
472  bool bForce = false,
473  bool bStateMsg = false,
474  bool bSensitiveMsg = false);
475 
476  void getStats(void);
477 
478  void setStats(VPNStats &stats);
479 
480  void exportStats(const tstring &tstrFilePath);
481 
482  void initState(VPNState state,
483  VPNState previousState,
484  VPNSubState subState);
485 
486  void setState(VPNState state,
487  VPNState previousState,
488  VPNSubState subState = VPNSS_NORMAL,
489  bool bUpdateStateMsg = true,
490  bool bOnlyUpdateUI = false);
491 
492 #if defined(PROGRAM_DATA_IMPORT_SUPPORTED)
493  IACImporterAsync *createACImporter(IACImporterAsyncCB *pCallback);
494 #endif
495 
496  void setWMHint(WMHint hint,
497  WMHintReason reason);
498 
499  bool isLastConnectType (const ConnectPromptType connPromptType);
500 
501  bool isOperatingMode(OperatingMode opMode);
502  void setOperatingMode(OperatingMode opMode);
503  void unsetOperatingMode(OperatingMode opMode);
504 
505  bool CanRemediateCaptivePortal();
506  bool policyAllowsCaptivePortalRemediation();
507 
508  bool isEventShutdown();
509 
510  bool isUsingEventModel();
511 
512  time_t getLastDisconnectTime();
513 
514  ConnectPromptInfo getConnectPromptInfo();
515  void resetConnectPromptPasswordData();
516 
517  void setStandaloneConnection(bool isStandalone);
518 
519  void deliverActiveHost(const tstring &activeHost,
520  ConnectProtocolType vpnProtocol = PROTOCOL_TYPE_UNKNOWN,
521  bool bActiveHostFriendlyName = false);
522 
523  bool isVPNServiceReady();
524 
525  // reset last disconnect time indicator.
526  //
527  void resetLastDisconnectTime(time_t time = 1);
528 
529  void processMinimize();
530 
531  // cert enrollment
532  void setEnrollClientCert(CertObj* pCert);
533 
534  // Show user banner for cert import warning on linux
535  // SCEPIfc to ConnectMgr
536  void linuxCertImportWarnUser();
537 
538  // Response to cert warning on linux
539  // ConnectMgr to SCEPIfc
540  void linuxCertImportWarnUserResponse(bool bAccept);
541 
542  void setDefaultHost(tstring &host);
543 
544 #if defined(HOST_DATA_SUPPORTED)
545  void setDefaultHostProfile(const IHostData &hostProfile);
546  IHostData* getDefaultHostData();
547 #endif
548 
549  void setLastVpnError(VPNError vpnError);
550  VPNError getLastVpnError();
551 
552 #if defined(PLATFORM_ANDROID)
553  bool requestClientCertificates();
554 #endif
555 
556  bool requestImportLocalization(const tstring tstrLocale,
557  const std::vector<unsigned char> &MoFileData);
558 
559  // Start the Automatic Headend Selection operation
560  void startAHS(const unsigned int uiReason,
561  const ProxyIfc& proxy);
562  // statusReturnCode is a long to match the current type of STATUSCODE.
563  // It is not using a STATUSCODE directly so that we do not have to
564  // expose the header files for STATUSCODEs to ClientIfcBase.h
565  void AHSSelectedHost(const unsigned int uiReason,
566  const std::vector<tstring> &headendList,
567  const long statusReturnCode,
568  const tstring& extraInfo);
569  std::vector<tstring> getAHSHostList();
570  unsigned int getAHSState();
571  bool isAHSHasRun();
572  bool IsAHSCachingRestricted();
573 
574  bool suppressConnectionErrorPopups();
575 
576  tstring getCaptivePortalDetectedMsg();
577 
578  void setProxyAuthPrompts(ProxyIfc* pProxy,
579  const tstring& promptMsg);
580 
581 #if defined(INTERPROCESS_COMMUNICATION_SUPPORTED)
582  bool handleIpcMessage(CIpcMessage *pIpcMessage);
583 #endif
584  bool IsCsdTokenVerified() const;
585 
586 #if defined(PLATFORM_APPLE_SSLVPN) || defined(PLATFORM_ANDROID)
587  virtual void SCEPEnrollStartCB();
588  virtual void SCEPEnrollExitCB();
589 #endif
590 
591  void activateConnectMgrTunnelInitiationCompletionEvent();
592  bool isConnectRequestActive();
593  bool isConnectRequestCleanup();
594 #if defined(PLATFORM_ANDROID) || defined(PLATFORM_CHROMEBOOK)
595  bool deleteProfileByName(const tstring &profileName);
596  tstring getProfileContents(const tstring &profileName);
597  bool importProfile(const tstring &profileName, const tstring &profileContents);
598 #endif
599 
600  bool syncProfileChange(const tstring &profileName);
601 
602 #if defined(CREDENTIAL_PREFILL_SUPPORTED)
603  bool hasPrefilledCredentials();
604  bool prefillCredentials(ConnectPromptInfo &connectPrompt);
605  void setPrefilledCredentials(CredentialPrefill *prefill);
606 #endif
607 
608 #if defined(PLATFORM_ANDROID) || defined(PLATFORM_APPLE_SSLVPN)
609  std::list<ManagedCertificate *> enumerateCertificates(CertificateType certType);
610  bool deleteCertificates(CertificateType certType, const std::list<std::string> &idList);
611  bool deleteServerCertificates(const std::list<std::string> &idList);
612 #endif
613 
614 #if defined(ANYCONNECT_USE_SNAK) && !defined(PLATFORM_WIN_APP)
615  std::list<ManagedCertificate *> enumerateSNAKCertificates(SNAK_CertType certType);
616  SNAK_CertType getSNAKCertType(CertificateType certType);
617  bool deleteClientCertificates(const std::list<std::string> &idList);
618 #endif
619 
620 #if defined(PLATFORM_APPLE_SSLVPN)
621  bool canUseBackupServers();
622 #endif
623 
624  tstring getConnectHost();
625 
626  tstring getMgmtTunnelHostname();
627 
628  VPN_TUNNEL_SCOPE getVpnTunnelScope();
629 
630  bool isStandaloneConnection();
631 
632  void sendSSoLogoutPrompt(ConnectPromptInfo &cpi);
633 
634  void setExternalSSOLogoutUrlFromAgent(const tstring& logoutUrl);
635 
636 private:
637 
638  //
639  // Private Member Data
640  //
641 
642  std::unique_ptr<ClientIfcInternal> m_upClientIfcInternal;
643 
644 
645  //
646  // Private Member Methods
647  //
648 
649  // Prevent copying by declaring but not defining copy constructor and operator= methods.
650  //
651  ClientIfcBase(const ClientIfcBase& other);
652  ClientIfcBase& operator=(const ClientIfcBase& other);
653 };
654 
655 #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