AnyConnect Secure Mobility Client 3.1.00495

include/ClientIfc.h

00001 /**************************************************************************
00002 *       Copyright (c) 2006, Cisco Systems, All Rights Reserved
00003 ***************************************************************************
00004 *
00005 *  File:    ClientIfc.h
00006 *  Date:    11/2006
00007 *
00008 ***************************************************************************
00009 *
00010 *   Client Interface class implementation for the Client API.
00011 *
00012 ***************************************************************************/
00013 
00014 #ifndef _CLIENTIFC_
00015 #define _CLIENTIFC_
00016 
00017 
00018 /**
00019 * This is the main interface class for applications that implement the
00020 * Cisco AnyConnect Secure Mobility VPN API.  A program wishing to use the API must create a
00021 * class that extends the ClientIfc class.  This new class is required to
00022 * provide implementations for the pure virtual methods found in the protected
00023 * section (for example, StatsCB).
00024 *
00025 * Finally, the public section contains methods that are available for
00026 * managing the API.  These include methods like attach and connect.
00027 *
00028 * A client must implement the CB (abstract) methods found in the protected
00029 * section of this interface.
00030 *
00031 */
00032 
00033 
00034 
00035 #include "api.h"
00036 #include "ClientIfcBase.h"
00037 #include "VPNStats.h"
00038 #include "ConnectPromptInfo.h"
00039 #include "Preference.h"
00040 #include "PreferenceInfo.h"
00041 
00042 class VPN_VPNAPI ClientIfc : protected ClientIfcBase
00043 {
00044     protected:
00045 
00046         /**
00047          * Callback used to deliver new statistics related to the VPN
00048          * connection.
00049          *
00050          * When a connection is active, a new set of statistics is
00051          * delivered each second.
00052          *
00053          * @see resetStats(), stopStats() and startStats()
00054          *
00055          */
00056         virtual void StatsCB(VPNStats &stats) = 0;
00057 
00058 
00059         /**
00060          * Callback used to deliver VPN state and state change string.
00061          * The stateString delivered by this method is localized.
00062          *
00063          * See the ::VPNState enum found in api.h for set of valid states.
00064          */
00065         virtual void StateCB(const VPNState state,
00066                              const tstring stateString) = 0;
00067 
00068 
00069         /**
00070          * If a banner needs to be acknowledged, this CB delivers the banner
00071          * to the client. 
00072          *
00073          * NOTE: Connection establishment will block until the method
00074          * setBannerResponse() is called.
00075          *
00076          * In a GUI, a banner would typically be displayed in a modal dialog
00077          * with an accept or decline button selection.
00078          *
00079          * @see setBannerResponse() to set the user response to the banner.
00080          */
00081         virtual void BannerCB(const tstring &banner) = 0;
00082 
00083 
00084         /**
00085          * Messages are delivered via the NoticeCB and can come from multiple
00086          * sources.  There are four message types (error, warning, info and
00087          * status).  See the ::MessageType enum in api.h for the list.
00088          *
00089          * Clients using the API as an embedded application (not
00090          * user visible) might want to further characterize
00091          * messages.  One option here is to use the AnyConnect message
00092          * catalog and assign message codes as the translations for
00093          * various messages.  An application could then track messages based
00094          * on its own error code scheme.
00095          */
00096         virtual void NoticeCB(const tstring notice,
00097                               const MessageType type) = 0;
00098 
00099 
00100         /**
00101          * This CB would likely occur only during a connection when it was
00102          * detected that the software needed to be upgraded, or when Start
00103          * Before Logon (SBL) is being used.
00104          *
00105          * Unlike the other callback methods, this method provides a default
00106          * implementation (calling the system's exit() function).
00107          * If clients of the API wish to override this behavior, they are
00108          * responsible for ensuring that the current running process exits with
00109          * the return code specified by returnCode.
00110          *
00111          * <b>Caution</b>: IF YOU OVERRIDE THIS METHOD AND DO NOT EXIT WITH
00112          * THE PROPER CODE SOFTWARE UPDATE FUNCTIONALITY IN YOUR CLIENT WILL
00113          * BREAK
00114          */
00115         virtual void ExitNoticeCB(const tstring &tstrNotice,
00116                                   const int returnCode);
00117 
00118 
00119         /**
00120          * Under normal operating conditions, this CB is called as soon
00121          * as the attach method completes.  In case the service (vpn agent)
00122          * is not ready, this CB is not called until it is.
00123          *
00124          * Any API calls made prior to this CB being called will result in a
00125          * NoticeCB error message.
00126          */
00127         virtual void ServiceReadyCB() = 0;
00128 
00129 
00130 
00131         /**
00132          * This method supports prompting for single or multiple values.  All
00133          * prompts are considered mandatory.
00134          *
00135          * The ConnectPromptInfo object contains a list of PromptEntry
00136          * instances.  The labels and their default values (if any) can be
00137          * found in these instances.  After the data has been collected from the user
00138          * it can be set into these same instances.  When ready, the client
00139          * application should call the method UserSubmit() to have the
00140          * responses read by the API.
00141          */
00142         virtual void UserPromptCB(ConnectPromptInfo &ConnectPrompt) = 0;
00143 
00144 
00145         /**
00146          * Use this method to provide Window Manager hints to GUI
00147          * applications.  To receive these hints, the application must
00148          * identify itself as a GUI in the attach method.  In addition, this
00149          * method should be overriden to receive any generated events.
00150          *
00151          * Event that can be received include those indicating that a user is
00152          * starting a second instance of the GUI application.  This information
00153          * can be used to tell the already running application to un-minimize
00154          * itself and let the new program know that it should Quit (since a GUI
00155          * is already running).
00156          */
00157         virtual void WMHintCB(const WMHint hint,
00158                               const WMHintReason reason);
00159 
00160 
00161         /**
00162          * This method is useful when the connection to the secure gateway
00163          * has been established as part of a web-launch of the VPN tunnel.
00164          *
00165          * If the client application wishes to be notified of the secure
00166          * gateway to which the VPN has been established, this method should
00167          * be overriden.
00168          *
00169          * If the client application is started and a tunnel is already active,
00170          * this method also delivers the name of the secure gateway host.
00171          */
00172         virtual void deliverWebLaunchHostCB(const tstring &activeHost);
00173 
00174         /**
00175          * This method is called when the result of a vpnapi_request_importpkcs12(..) 
00176          * call is known. If bResult is false then pszError will be an error string.
00177          */
00178         virtual void ImportPKCS12ResultCB(bool bResult, const tstring &strError);
00179 
00180         /**
00181          * This method is called when the preference to block untrusted
00182          * servers is enabled and the current VPN server being connected
00183          * to is untrusted. Clients should present an error to the user
00184          * notifying them that the current connection to rtstrUntrustedServer
00185          * is being blocked. The client should also provide a way for the
00186          * user to change the preference to block untrusted servers.
00187          *
00188          * The user response must be indicated using setCertBlockedReponse
00189         */
00190         virtual void CertBlockedCB(const tstring &rtstrUntrustedServer) = 0;
00191 
00192         /**
00193          * This method is called when connections to untrusted VPN servers
00194          * is allowed by policies and the current VPN server being connected
00195          * to is untrusted. Clients should present a warning to the user
00196          * notifying them that the current connection to rtstrUntrustedServer
00197          * is unsafe. The reason the VPN server is untrusted is provided in
00198          * rltstrCertErrors. The client should provide a way for the user to
00199          * connect once, connect and always trust or cancel the connection.
00200          *
00201          * The user response must be indicated using setCertWarningReponse
00202         */
00203         virtual void CertWarningCB(const tstring &rtstrUntrustedServer,
00204                                    const std::list<tstring> &rltstrCertErrors) = 0;
00205 
00206         /**
00207          * This method can be overriden if the client application wishes to
00208          * exercise some control over the delivery of events from the other
00209          * protected methods in this class.
00210          *
00211          * This might be necessary in cases where a GUI is being written and
00212          * the data from this API needs to be delivered in the GUI or main
00213          * thread.  In this case, you should override this method and when it
00214          * is called by the API post an event to your event queue (message
00215          * pump, etc.).  After this event executes in your GUI or main thread,
00216          * call the method ClientIfc::ProcessEvents to have events delivered
00217          * to your client application.
00218          */
00219         virtual void EventAvailable();
00220 
00221 
00222         ClientIfc();
00223 
00224 
00225     public:
00226 
00227         /**
00228          * After the ClientIfc class has been created, the client implementation
00229          * must invoke this method prior to attempting connections,
00230          * retrieving statistics, etc.  If successful, this method returns
00231          * true.  If not successful, it returns false and returns a notice error
00232          * message to the user.
00233          *
00234          * A single call to this method is all that is necessary.  If the
00235          * attach fails, a message indicating the VPN service is not available
00236          * is returned.  If the call succeeds, the ServiceReadyCB is
00237          * called and true is returned.
00238          *
00239          * \param SBL Start Before Logon
00240          * is a mode of operation where a GUI
00241          * can be launched prior to the normal windows logon sequence.  This
00242          * allows a VPN tunnel to be activated and used as part of the windows
00243          * logon sequence.  The SBL attribute should be set to true only when
00244          * it has been passed as an argument to the program by the VPN agent.
00245          *
00246          * \param isGUI indicates that the started program is a UI
00247          * application.  With this attribute set to true, the application will
00248          * now receive WMHints.
00249          *
00250          * \param requestFullCapabilities indicates that the client program is
00251          * requesting full API capabilities.  Full capabilities allows the
00252          * client program to connect, disconnect, receive statistics, etc.
00253          * When full capabilities are not requested or not available, the
00254          * client program will not be able to establish new VPN connections.
00255          * Only a client program with full capabilites can do this.  In
00256          * addition, only the first program requesting full capabilities will
00257          * be granted this level of access.  The attach method can succeed
00258          * even if full capabilities is requested but not granted.  To test
00259          * for this state, use the method ::hasFullCapabilities.
00260          *
00261          * \param suppressAutoConnect indicates that the client wishes to
00262          * override automatically initiating a connection to the last connected
00263          * secure gateway at startup.  Normally, this is determined by the 
00264          * value of the AutoConnectOnStart preference.  If this flag is true
00265          * then an automatic connection will never be initiated, even if 
00266          * AutoConnectOnStart is enabled.
00267          */
00268         bool attach(bool SBL = false, 
00269                     bool isGUI = true,
00270                     bool requestFullCapabilities = true,
00271                     bool suppressAutoConnect = true);
00272 
00273 
00274         /**
00275          * After the client program is done, call the detach method to do a
00276          * graceful cleanup.  This method stops the flow
00277          * of events and does general cleanup.
00278          */
00279         void detach();
00280 
00281 
00282         /**
00283          * When the method ClientIfc::EventAvailable has been overriden in the
00284          * client application, this method must be called to receive events.
00285          *
00286          * It is expected that GUI programs will use EventAvailable as a
00287          * signal, allowing them to set an event using their native event
00288          * handler.  When that event fires, the application can call
00289          * ProcessEvents, which causes the API to deliver events in the
00290          * client's main thread.
00291          */
00292         virtual void ProcessEvents();
00293 
00294 
00295         /**
00296          * Use this method to determine whether this application has full
00297          * capabilities.  Only one application (the first one started) can have
00298          * full capabilities.  If this is the first application started, this
00299          * method returns true.  When an application does not have full
00300          * capabilities, it cannot initiate connections.
00301          */
00302         bool hasFullCapabilities();
00303  
00304 
00305         /**
00306          * This method returns true if the client has an active VPN
00307          * connection with a secure gateway.
00308          */
00309         bool isConnected();
00310 
00311 
00312         /**
00313          * This method returns true if the client VPN is available for use.
00314          * If false is returned this means that VPN has been intentionally
00315          * disabled.  This would indicate a situation where other AnyConnect
00316          * services were in use but not VPN.
00317          */
00318         bool isAvailable();
00319 
00320 
00321         /**
00322          * This method returns true if the VPN service is available for
00323          * establishing VPN connections.
00324          */
00325         bool isVPNServiceAvailable();
00326 
00327 
00328         /**
00329          * This method returns true if the mode in which the client is
00330          * currently operating is enabled. For a list of all possible modes
00331          * of operation see the ::OperatingMode enum in api.h.
00332          */
00333         bool isOperatingMode(OperatingMode opMode);
00334 
00335         /**
00336          * This method returns a list of secure gateway host names found in an
00337          * AnyConnect profile.  If no profile is available, an empty
00338          * list is returned.
00339          */
00340         std::list<tstring> getHostNames();
00341 
00342 
00343         /**
00344          * This method returns any default Host name from User Preferences.
00345          *
00346          * A host can be returned here even if there are no profiles on the
00347          * system.  The host last connected to (via the connect method) is
00348          * returned by this method.
00349          *
00350          * If there is no previously connected-to host, the first host found
00351          * in an AnyConnect profile (if any) is returned.
00352          */
00353         tstring getDefaultHostName();
00354 
00355 
00356         /**
00357          * This method initiates a connection to the specified host.
00358          * The connection results in the presentation of authentication
00359          * credentials, as appropriate.  Any credentials returned by the secure
00360          * gateway are delivered via the #UserPromptCB method.
00361          *
00362          * See ConnectPromptInfo for more details on possible authentication
00363          * credentials.
00364          *
00365          * If the connection request is accepted, true is returned.  This does
00366          * not mean the connection succeeded.  If the connection succeeds, a
00367          * state of connect will be received via the #StateCB method.
00368          */
00369         bool connect(tstring host);
00370 
00371         /**
00372          * Use this method to change selected group after initial connection
00373          * request has been made and credentials were delivered. 
00374          *
00375          * Depending on secure gateway configuratiion, call to this method may
00376          * result in a new connection request and will update credentials 
00377          * required for the selected group. New credentials returned by the 
00378          * secure gateway are delivered via the #UserPromptCB method.
00379          */
00380         virtual bool setNewTunnelGroup(const tstring & group);
00381 
00382         /**
00383          * Use this method to initiate a disconnect of the active VPN
00384          * connection.
00385          *
00386          * An indication of VPN disconnect is received via the #StateCB
00387          * method.
00388          */
00389         void disconnect();
00390 
00391 
00392         /**
00393          * This method triggers the retrieval of the current VPN state.
00394          * After the client is conected to the VPN service via the #attach
00395          * method, both the current state and any changes in state are
00396          * automatically delivered to the client.  In general, this method
00397          * should not be needed.
00398          *
00399          * ::VPNState is delivered via #StateCB method.
00400          */
00401         void getState();
00402 
00403 
00404         /**
00405          * This method triggers the retrieval of the current VPN statistics.
00406          * This allows an UI to notify the API that it is ready to receive 
00407          * statistics.
00408          *
00409          * ::VPNState is delivered via #StatsCB method.
00410          */
00411         void getStats();
00412 
00413         /**
00414          * This method resets current VPN statistics counters.
00415          */
00416         void resetStats();
00417 
00418 
00419         /**
00420          * This method activates the retrieval of VPN statistics and other
00421          * related data.  By default, VPNStats are automatically delivered
00422          * via the method #StatsCB.
00423          *
00424          * If the #stopStats method is called to stop the delivery of
00425          * statistics, this method can be called to resume delivery.  
00426          */
00427         void startStats();
00428 
00429 
00430         /**
00431          * This method stops the delivery of VPN statistics and
00432          * other related data.  By default, VPNStats are automatically
00433          * delivered.  This method disables delivery.
00434          *
00435          * The method #startStats can be called to resume the delivery of
00436          * statistics.
00437          */
00438         void stopStats();
00439 
00440 
00441       /**
00442        * This method directs where and how to export the statistics
00443        */
00444         void exportStats(const tstring &tstrFilePath);
00445 
00446 
00447         /**
00448          * Call this method after a #BannerCB has been received to indicate 
00449          * that the user response to the banner can now be read.
00450          *
00451          * \param bAccepted
00452          * indicates if the user accepted or declined the banner.
00453          */
00454         void setBannerResponse(bool bAccepted);
00455 
00456         /*
00457          * Call this method after a #CertBlockedCB has been received to
00458          * indicate the user's response to the blocked untrusted VPN server
00459          * error message.
00460          *
00461          * \param bUnblock indicates if the user wants to disable the
00462          * preference to block untrusted servers
00463         */
00464         void setCertBlockedResponse(bool bUnblock);
00465 
00466         /*
00467          * Call this method after a #CertWarningCB has been received to
00468          * indicate the user's response to the server certificate error
00469          * warning
00470          *
00471          * \param bConnect indicates user wants to connect anyways
00472          * \param bImport inidicates user wants to permanently trust
00473          * the VPN server. This would result in no future certificate
00474          * error warning prompts. bImport is only valid if
00475          * bConnect is true.
00476         */
00477         void setCertWarningResponse(bool bConnect, bool bImportCert);
00478 
00479 
00480         /**
00481          * Call this method to indicate that authentication credential
00482          * requests values solicited by the #UserPromptCB method can now
00483          * be read from the ConnectPromptInfo instance.
00484          */
00485         void UserSubmit();
00486 
00487 
00488         /**
00489          * Method for retrieving the currently available user preferences.
00490          * This method returns an instance of the class PreferenceInfo. The 
00491          * instance contains a variable number of Preference object pointers.  
00492          * Each preference contains data identifying the specific preference, 
00493          * its current value, etc. For a list of all possible preferences see
00494          * the ::PreferenceId enum in api.h. Note that some of these
00495          * preferences are not available to the user.
00496          *
00497          * @see PreferenceInfo
00498          */
00499         PreferenceInfo &getPreferences();
00500 
00501 
00502         /**
00503          * This method stores the current set values of the preferences to the 
00504          * preferences file(s).  This method is a counterpart to the 
00505          * getPreferences() method. 
00506          */
00507         bool savePreferences();
00508 
00509         /**
00510          * This method is used to import a PKCS12 file from a byte array.
00511          * May incite UserPromptCB() to prompt for the p12 password.  Will
00512          * invoke ImportPKCS12ResultCB() to indicate the result.
00513          * Returns true if the request was acknowledged, false otherwise.
00514          */
00515         bool requestImportPKCS12(const std::vector<unsigned char> &der);
00516 
00517         /**
00518          * This method is used to import a gettext localization file from a
00519          * byte array, for the specified locale. Returns true if the locale
00520          * file was successfully imported, false otherwise. 
00521          * Note: successful import does not guarantee that the specified
00522          * locale will be used.
00523          */
00524         bool requestImportLocalization(const tstring tstrLocale,
00525                                        const std::vector<unsigned char> &MoFileData);
00526 
00527         virtual ~ClientIfc();
00528 
00529     private:
00530 
00531         ClientIfc(const ClientIfc& other);
00532         ClientIfc& operator=(const ClientIfc& other);
00533 
00534 };
00535 
00536 #endif //_CLIENTIFC_