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