AnyConnect Secure Mobility Client  5.1.19.1862
ClientIfc.h
1 /**************************************************************************
2 * Copyright (c) 2006, 2022-2023, 2025 Cisco Systems, Inc.
3 * All Rights Reserved. Cisco Highly Confidential.
4 ***************************************************************************
5 *
6 * File: ClientIfc.h
7 * Date: 11/2006
8 *
9 ***************************************************************************
10 * Client Interface class implementation for the Client API.
11 ***************************************************************************/
12 
13 #ifndef _CLIENTIFC_
14 #define _CLIENTIFC_
15 
16 
17 /**
18 * This is the main interface class for applications that implement the
19 * Cisco AnyConnect Secure Mobility VPN API. A program wishing to use the API must create a
20 * class that extends the ClientIfc class. This new class is required to
21 * provide implementations for the pure virtual methods found in the protected
22 * section (for example, StatsCB).
23 *
24 * Finally, the public section contains methods that are available for
25 * managing the API. These include methods like attach and connect.
26 *
27 * A client must implement the CB (abstract) methods found in the protected
28 * section of this interface.
29 *
30 */
31 
32 #include "ClientIfcCommon.h"
33 #include "api.h"
34 #include "ClientIfcBase.h"
35 #include "VPNStats.h"
36 #include "ConnectPromptInfo.h"
37 #include "Preference.h"
38 #include "PreferenceInfo.h"
39 
40 class ClientIfcData;
41 
42 class VPN_VPNAPI ClientIfc :
43  protected ClientIfcBase
44 {
45  friend class ClientIfcData;
46 
47  protected:
48 
49  ClientIfc();
50 
51  virtual ~ClientIfc();
52 
53  /**
54  * Callback Declarations inherited from ClientIfcBase.
55  *
56  * Virtual Abstract Callback Method Declarations:
57  * StatsCB
58  * StateCB
59  * BannerCB
60  * NoticeCB
61  * CertBannerCB
62  * ServiceReadyCB
63  * UserPromptCB
64  * CertBlockedCB
65  * CertWarningCB (2 signatures)
66  * ClientCertificateCB
67  * ServiceStatusCB
68  *
69  * Virtual Callback Method Declarations:
70  * PreConnectReminderCB
71  * ExitNoticeCB
72  * WMHintCB
73  * deliverWebLaunchHostCB
74  * EventAvailable
75  * ImportPKCS12ResultCB
76  * AgentDetachedCB
77  */
78 
79  public:
80 
81  /**
82  * After the ClientIfc class has been created, the client implementation
83  * must invoke this method prior to attempting connections,
84  * retrieving statistics, etc. If successful, this method returns
85  * true. If not successful, it returns false and returns a notice error
86  * message to the user.
87  *
88  * A single call to this method is all that is necessary. If the
89  * attach fails, a message indicating the VPN service is not available
90  * is returned. If the call succeeds, the ServiceReadyCB is
91  * called and true is returned.
92  *
93  * \param ClientType clientType (default ClientType_GUI)
94  * Other options: ClientType_GUI_SBL, ClientType_CLI, ClientType_MGMT.
95  * ClientType_GUI: indicates that the started program is a GUI
96  * application. With this attribute set to true, the application will
97  * now receive WMHints.
98  * ClientType_GUI_SBL: SBL (Start Before Logon) is a mode of operation
99  * where a GUI can be launched prior to the normal windows logon sequence.
100  * This allows a VPN tunnel to be activated and used as part of the windows
101  * logon sequence. This value is applicable only when a corresponding
102  * argument has been passed to the program by the VPN agent.
103  * ClientType_CLI: indicates that the started program is a CLI application.
104  * ClientType_MGMT: indicates that the started program is used to initiate
105  * an AnyConnect management VPN tunnel. This value is
106  * applicable only to a client launched by AnyConnect VPN agent.
107  *
108  * \param requestFullCapabilities indicates that the client program is
109  * requesting full API capabilities. Full capabilities allows the
110  * client program to connect, disconnect, receive statistics, etc.
111  * When full capabilities are not requested or not available, the
112  * client program will not be able to establish new VPN connections.
113  * Only a client program with full capabilites can do this. In
114  * addition, only the first program requesting full capabilities will
115  * be granted this level of access. The attach method can succeed
116  * even if full capabilities is requested but not granted. To test
117  * for this state, use the method ::hasFullCapabilities.
118  *
119  * \param suppressAutoConnect indicates that the client wishes to
120  * override automatically initiating a connection to the last connected
121  * secure gateway at startup. Normally, this is determined by the
122  * value of the AutoConnectOnStart preference. If this flag is true
123  * then an automatic connection will never be initiated, even if
124  * AutoConnectOnStart is enabled.
125  */
126  bool attach(ClientType clientType = ClientType_GUI,
127  bool requestFullCapabilities = true,
128  bool suppressAutoConnect = true);
129 
130 
131  /**
132  * After the client program is done, call the detach method to do a
133  * graceful cleanup. This method stops the flow
134  * of events and does general cleanup.
135  */
136  void detach();
137 
138 
139  /**
140  * When the method ClientIfc::EventAvailable has been overridden in the
141  * client application, this method must be called to receive events.
142  *
143  * It is expected that GUI programs will use EventAvailable as a
144  * signal, allowing them to set an event using their native event
145  * handler. When that event fires, the application can call
146  * ProcessEvents, which causes the API to deliver events in the
147  * client's main thread.
148  */
149  void ProcessEvents();
150 
151 
152  /**
153  * Use this method to determine whether this application has full
154  * capabilities. Only one application (the first one started) can have
155  * full capabilities. If this is the first application started, this
156  * method returns true. When an application has full capabilities,
157  * it can initiate connections, as well as offer UI capabilities.
158  */
159  bool hasFullCapabilities();
160 
161 
162  /**
163  * This method returns true if the client has an active VPN
164  * connection with a secure gateway.
165  */
166  bool isConnected(bool bSilent = false);
167 
168 
169  /**
170  * This method returns true if the client VPN is available for use.
171  * If false is returned this means that VPN has been intentionally
172  * disabled. This would indicate a situation where other AnyConnect
173  * services were in use but not VPN.
174  */
175  bool isAvailable();
176 
177 
178  /**
179  * This method returns true if the VPN service is available for
180  * establishing VPN connections.
181  */
182  bool isVPNServiceAvailable();
183 
184 
185  /**
186  * This method returns true if the mode in which the client is
187  * currently operating is enabled. For a list of all possible modes
188  * of operation see the ::OperatingMode enum in api.h.
189  */
190  bool isOperatingMode(OperatingMode opMode);
191 
192  /**
193  * This method returns a list of secure gateway host names found in an
194  * AnyConnect profile. If no profile is available, an empty
195  * list is returned.
196  */
197  std::list<tstring> getHostNames();
198 
199 
200  /**
201  * This method returns any default Host name from User Preferences.
202  *
203  * A host can be returned here even if there are no profiles on the
204  * system. The host last connected to (via the connect method) is
205  * returned by this method.
206  *
207  * If there is no previously connected-to host, the first host found
208  * in an AnyConnect profile (if any) is returned.
209  */
210  tstring getDefaultHostName();
211 
212 
213  /**
214  * This method initiates a connection to the specified host.
215  * The connection results in the presentation of authentication
216  * credentials, as appropriate. Any credentials returned by the secure
217  * gateway are delivered via the #UserPromptCB method.
218  *
219  * See ConnectPromptInfo for more details on possible authentication
220  * credentials.
221  *
222  * If the connection request is accepted, true is returned. This does
223  * not mean the connection succeeded. If the connection succeeds, a
224  * state of connect will be received via the #StateCB method.
225  */
226  bool connect(
227  tstring host);
228 
229 #if defined(HOST_DATA_SUPPORTED)
230  bool connect(
231  const IHostData& host);
232 #endif
233 
234  bool connect(
235 #if defined(HOST_DATA_SUPPORTED)
236  const IHostData& host,
237 #else
238  tstring host,
239 #endif
240  unsigned int origin);
241 
242  /**
243  * Use this method to change selected group after initial connection
244  * request has been made and credentials were delivered.
245  *
246  * Depending on secure gateway configuratiion, call to this method may
247  * result in a new connection request and will update credentials
248  * required for the selected group. New credentials returned by the
249  * secure gateway are delivered via the #UserPromptCB method.
250  */
251  bool setNewTunnelGroup(const tstring & group);
252 
253  /**
254  * Use this method to initiate a disconnect of the active VPN
255  * connection.
256  *
257  * An indication of VPN disconnect is received via the #StateCB
258  * method.
259  */
260  void disconnect();
261 
262  /**
263  * Use this method to initiate a disconnect of the active VPN
264  * connection. This function consumes a VPNDisconnectReason to specify
265  * why the disconnect is occurring.
266  *
267  * An indication of VPN disconnect is received via the #StateCB
268  * method.
269  */
270  void disconnect(VPNDisconnectReason disconnectEvent);
271 
272  /**
273  * Use this method to cancel the user authentication. VPN tunnel is not connected
274  * at the moment. This function is used to cancel SSO authentication.
275  *
276  * An indication of VPN disconnect is received via the #StateCB
277  * method.
278  */
279  void cancel();
280 
281  /**
282  * This method triggers the retrieval of the current VPN state.
283  * After the client is conected to the VPN service via the #attach
284  * method, both the current state and any changes in state are
285  * automatically delivered to the client. In general, this method
286  * should not be needed.
287  *
288  * ::VPNState is delivered via #StateCB method.
289  */
290  void getState();
291 
292 
293  /**
294  * This method triggers the retrieval of the current VPN statistics.
295  * This allows an UI to notify the API that it is ready to receive
296  * statistics.
297  *
298  * ::VPNState is delivered via #StatsCB method.
299  */
300  void getStats();
301 
302  /**
303  * This method resets current VPN statistics counters.
304  */
305  void resetStats();
306 
307 
308  /**
309  * This method activates the retrieval of VPN statistics and other
310  * related data. By default, VPNStats are automatically delivered
311  * via the method #StatsCB.
312  *
313  * If the #stopStats method is called to stop the delivery of
314  * statistics, this method can be called to resume delivery.
315  */
316  void startStats();
317 
318 
319  /**
320  * This method stops the delivery of VPN statistics and
321  * other related data. By default, VPNStats are automatically
322  * delivered. This method disables delivery.
323  *
324  * The method #startStats can be called to resume the delivery of
325  * statistics.
326  */
327  void stopStats();
328 
329 
330  /**
331  * This method directs where and how to export the statistics
332  */
333  void exportStats(const tstring &tstrFilePath);
334 
335 
336  /**
337  * Call this method after a #BannerCB has been received to indicate
338  * that the user response to the banner can now be read.
339  *
340  * \param bAccepted
341  * indicates if the user accepted or declined the banner.
342  */
343  void setBannerResponse(bool bAccepted);
344 
345  /**
346  * Call this method after a #PreConnectReminderCB has been received
347  * to indicate that user has acknowledged pre-connect reminder message.
348  *
349  * NOTE : Ignoring the response from user (for example, closing the modal
350  * dialog instead of clicking OK button). Old AnyConnect client (v3.1)
351  * ignored the response too.
352  */
353  void setPreConnectReminderResponse();
354 
355  /*
356  * Call this method after a #CertBlockedCB has been received to
357  * indicate the user's response to the blocked untrusted VPN server
358  * error message.
359  *
360  * \param bUnblock indicates if the user wants to disable the
361  * preference to block untrusted servers
362  */
363  void setCertBlockedResponse(bool bUnblock);
364 
365  /*
366  * Call this method after a #CertWarningCB has been received to
367  * indicate the user's response to the server certificate error
368  * warning
369  *
370  * \param bConnect indicates user wants to connect anyways
371  * \param bImport inidicates user wants to permanently trust
372  * the VPN server. This would result in no future certificate
373  * error warning prompts. bImport is only valid if
374  * bConnect is true and bAllowImport is true when a CertWarningCB
375  * was given.
376  */
377  void setCertWarningResponse(bool bConnect, bool bImportCert);
378 
379 
380  /**
381  * Call this method to indicate that authentication credential
382  * requests values solicited by the #UserPromptCB method can now
383  * be read from the ConnectPromptInfo instance.
384  */
385  void UserSubmit();
386 
387 
388  /**
389  * Method for retrieving the currently available user preferences.
390  * This method returns a instance of the class PreferenceInfo. The class
391  * instance is a deep copy and therefore independent of any VPN API
392  * object instances. It contains a variable number of Preference class
393  * instance pointers. Each preference contains data identifying the
394  * specific preference, its current value, etc. For a list of all
395  * possible preferences see the PreferenceId enum in api.h. Note that
396  * some of these preferences are not available to the user.
397  *
398  * @see PreferenceInfo
399  */
400  std::shared_ptr<PreferenceInfo> getPreferences();
401 
402  /**
403  * Method for retrieving the current number of available user preferences.
404  * This method provides an optimized means of determining if there are any available user
405  * preferences. An application may have no need to retrieve the user preferences if there are
406  * no user preferences available, and invoking getPreferences() incurs the cost of a deep
407  * copy of the internal PreferenceInfo class instance, possibly causing many memory
408  * allocations, even when there are no avaiable user preferences, which could result in poor
409  * user interface responsiveness.
410  *
411  * @see PreferenceInfo
412  */
413  unsigned int getPreferencesCount();
414 
415  /**
416  * This method stores the current set values of the preferences to the
417  * preferences file(s). This method is a counterpart to the
418  * getPreferences() method.
419  */
420  bool savePreferences(const std::shared_ptr<PreferenceInfo>& spPreferenceInfo);
421 
422  /**
423  * This is called from the credential dialog in the GUI to get the correct
424  * friendly name for the dialog title.
425  */
426  tstring getConnectHost();
427 
428  /**
429  * This method sets the last VPN error seen during this connection
430  * attempt for reporting purposes. This VPN error should be cleared for
431  * each connection attempt.
432  */
433  void setLastVpnError(VPNError vpnError);
434 
435 
436  /**
437  * This method gets the last VPN error seen during this connection
438  * attempt for reporting purposes. This VPN error should be cleared for
439  * each connection attempt.
440  */
441  VPNError getLastVpnError();
442 
443  /**
444  * This method indicates if a request to connect has been initiated and the SG is being
445  * contacted. Note: the connect request is not active while waiting for the user to enter
446  * credentials.
447  */
448  bool isConnectRequestActive();
449 
450  private:
451 
452  //
453  //
454  // Private Member Methods
455  //
456  //
457 
458  // Prevent copying by declaring but not defining copy constructor and operator= methods.
459  //
460  ClientIfc(const ClientIfc& other);
461  ClientIfc& operator=(const ClientIfc& other);
462 
463 #if defined(VPNAPI_EVENT_NOTIFICATION_SUPPORTED)
464  virtual void EventNotificationInternalCB(
465  const std::shared_ptr<CEventNotificationTlv>& spEventNtfctnTlv);
466 #endif
467 
468  using ClientIfcBase::ClientIfcTransmigration;
469 
470  //
471  //
472  // Private Member Data
473  //
474  //
475 
476  ClientIfcData* const m_pClientIfcData;
477 };
478 
479 #endif //_CLIENTIFC_
VPNDisconnectReason
Definition: api.h:188
Definition: ClientIfcBase.h:66
#define tstring
Definition: api.h:35
Definition: ClientIfc.h:42
OperatingMode
Definition: api.h:545
VPNError
Definition: api.h:597