Client Event Listener
The ClientEventListener class exposes a number of events that are fired at certain points during the SDK's operation. Below is a list of the available events:
DataPacketIn
Fired when receiving a data packet from the server.class MyClientEventListener: ClientEventListener {
...
func onDataPacketIn(_ dataPacket: Data) {
//...
}
...
}
This event fires when a packet is received. The entire data packet (including all framing and error detection characters) is contained in the dataPacket parameter. This parameter may be inspected for advanced troubleshooting, or to extract additional response properties beyond the scope of the SDK.
DataPacketOut
Fired when sending a data packet to the server.class MyClientEventListener: ClientEventListener {
...
func onDataPacketOut(_ dataPacket: Data) {
//...
}
...
}
This event fires right before each data packet is sent. The entire data packet (including all framing and error detection characters) is contained in the dataPacket parameter. This parameter may be inspected for advanced troubleshooting.
Log
Fires once for each log message.class MyClientEventListener: ClientEventListener {
...
func onLog(_ logLevel: Int32, _ message: String, _ logType: String) {
print("[\(logType)]\(message)")
}
...
}
Logging is handled through the Log event. This will fire any time a message is built or a response is parsed, including error messages.
When the Log event is fired, the message in question is made available via the message event parameter. The other event arguments are logType and logLevel.
The logType parameter indicates the type of the log entry. Possible values are:
- Info
- RequestHeaders
- ResponseHeaders
- RequestBody
- ResponseBody
- ProxyRequest
- ProxyResponse
- FirewallRequest
- FirewallResponse
- CReq
- CRes
- Erro
- EphemeralKey
- DeviceParams
- SW
A logType of SW indicates a Security Warning. When this value is present, the message parameter will contain a code to indicate a more specific cause of the warning. Below is a list of possible warning message values and their meanings:
SW Message Value | Description |
01 | Tampered; installed from Ad-Hoc or XCode |
02 | Tampered; invalid info dictionary |
03 | Tampered; Info.plist was modified after the app was built |
04 | Tampered; Bundle ID mismatch |
05, XX | Jailbroken; suspicious jailbreak files present on the device |
06, XX | Jailbroken; suspicious jailbreak library loaded |
07, XX | Jailbroken; write permissions enabled on system directories |
08 | Jailbroken; app has permission to fork |
09, XX | Jailbroken; app can query jailbreak URL schemes |
10 | Debugging; p_trace flag detected |
11 | Debugging; internal error: cannot find sysctl |
12 | Debugging; internal error: cannot find getpid |
13 | Debugging; invalid PID |
14, XX | Debugging; reverse engineering tool detected on the device |
15, XX | Debugging; suspicious TCP port detected |
The logLevel parameter in the event indicates the log level to which the current message belongs. Possible values are:
- 0 - None
- 1 - Info
- 2 - Verbose
- 3 - Debug
It is recommended to output all messages raised in this event to a file for record keeping or troubleshooting purposes.
SSLServerAuthentication
Fired after the server presents its certificate to the client.class MyClientEventListener: ClientEventListener {
...
func onSSLServerAuthentication(_ certEncoded: Data, _ certSubject: String, _ certIssuer: String, _ status: String, _ accept: UnsafeMutablePointer<Int32>) {
//...
}
...
}
This event fires when establishing a TLS connection and provides information about the server's certificate. The accept parameter indicates whether the certificate is trusted by default.
When accept is False, status shows why the verification failed (otherwise, status contains the string "OK"). If it is decided to continue, you can override and accept the certificate by setting the accept parameter to True.
SSLStatus
Shows the progress of the secure connection.class MyClientEventListener: ClientEventListener {
...
func onSSLStatus(_ message: String) {
//...
}
...
}
The event is fired for informational and logging purposes only. Used to track the progress of the connection.