Ziti C SDK
|
#include "externs.h"
#include "errors.h"
#include <stdint.h>
#include "ziti_model.h"
#include <netinet/in.h>
Go to the source code of this file.
Macros | |
#define | ZITI_INVALID_HANDLE ((ziti_handle_t)-1) |
Typedefs | |
typedef uint32_t | ziti_handle_t |
typedef int | ziti_socket_t |
Functions | |
void | Ziti_lib_init (void) |
Initialize Ziti library. | |
int | Ziti_last_error (void) |
return Ziti error code for last failed operation. | |
int | Ziti_enroll_identity (const char *jwt, const char *key, const char *cert, char **id_json, unsigned long *id_json_len) |
enroll a new Ziti identity | |
int | Ziti_load_context (ziti_handle_t *h, const char *identity) |
Load Ziti identity. | |
ziti_jwt_signer_array | Ziti_get_ext_signers (ziti_handle_t ztx) |
Get external signers available for authentication. | |
char * | Ziti_login_external (ziti_handle_t ztx, const char *signer_name) |
Start external login process. | |
int | Ziti_login_totp (ziti_handle_t ztx, const char *code) |
Login with TOTP code. | |
int | Ziti_wait_for_auth (ziti_handle_t ztx, int timeout_ms) |
Wait for authentication to complete. | |
ziti_socket_t | Ziti_socket (int type) |
creates a socket handle(Windows) or file descriptor(*nix) suitable for connecting to a Ziti service | |
int | Ziti_close (ziti_socket_t socket) |
close the given socket handle/file descriptor. | |
int | Ziti_check_socket (ziti_socket_t socket) |
Check if the given socket handle/fd is attached to a Ziti connection via Ziti_connect() /Ziti_bind() | |
int | Ziti_connect (ziti_socket_t socket, ziti_handle_t ztx, const char *service, const char *terminator) |
Connect socket to a Ziti service. | |
int | Ziti_connect_addr (ziti_socket_t socket, const char *host, unsigned int port) |
Connect socket to a Ziti service with the given intercept address. | |
int | Ziti_bind (ziti_socket_t socket, ziti_handle_t ztx, const char *service, const char *terminator) |
Bind socket to a Ziti service. | |
int | Ziti_listen (ziti_socket_t socket, int backlog) |
marks the [socket] as a socket able to accept incoming connections | |
ziti_socket_t | Ziti_accept (ziti_socket_t socket, char *caller, int caller_len) |
accept a client Ziti connection as a socket | |
void | Ziti_lib_shutdown (void) |
Shutdown Ziti library. | |
#define ZITI_INVALID_HANDLE ((ziti_handle_t)-1) |
typedef uint32_t ziti_handle_t |
typedef int ziti_socket_t |
ziti_socket_t Ziti_accept | ( | ziti_socket_t | socket, |
char * | caller, | ||
int | caller_len | ||
) |
accept a client Ziti connection as a socket
Extracts the first [ziti_connection] from pending queue, accepts it, and opens a new socket fd for it.
If no pending connection requests are present, behavior depends on whether [socket] is marked non-blocking.
socket | socket created with [Ziti_socket()], bound to a service with [Ziti_bind()] or [Ziti_bind_addr()], and is listening after [Ziti_listen()] |
caller | buffer to store caller ID (dialing identity name) |
caller_len | length of the [caller] buffer |
int Ziti_bind | ( | ziti_socket_t | socket, |
ziti_handle_t | ztx, | ||
const char * | service, | ||
const char * | terminator | ||
) |
Bind socket to a Ziti service.
socket | socket handle created with [Ziti_socket()] |
ztx | Ziti context |
service | service name provided by [ztx] |
terminator | (optional) create specific terminator |
int Ziti_check_socket | ( | ziti_socket_t | socket | ) |
Check if the given socket handle/fd is attached to a Ziti connection via Ziti_connect()
/Ziti_bind()
socket |
int Ziti_close | ( | ziti_socket_t | socket | ) |
close the given socket handle/file descriptor.
This method facilitates faster cleanup of Ziti socket. Calling standard close()/closesocket() methods still works but may lead to race conditions.
socket |
int Ziti_connect | ( | ziti_socket_t | socket, |
ziti_handle_t | ztx, | ||
const char * | service, | ||
const char * | terminator | ||
) |
Connect socket to a Ziti service.
socket | socket handle created with [Ziti_socket()] |
ztx | Ziti context handle |
service | service name provided by [ztx] |
terminator | (optional) specific terminator to connect to |
int Ziti_connect_addr | ( | ziti_socket_t | socket, |
const char * | host, | ||
unsigned int | port | ||
) |
Connect socket to a Ziti service with the given intercept address.
socket | socket handle created with [Ziti_socket()] |
host | target hostname |
port | target port |
int Ziti_enroll_identity | ( | const char * | jwt, |
const char * | key, | ||
const char * | cert, | ||
char ** | id_json, | ||
unsigned long * | id_json_len | ||
) |
enroll a new Ziti identity
jwt | enrollment token |
key | private key (required for third party CA enrollment, otherwise optional) |
cert | identity x.509 certificate (required for third party CA enrollment, otherwise ignored) |
id_json | (output) identity in JSON format, caller is responsible for freeing it |
id_json_len | (output) length of id_json |
ziti_jwt_signer_array Ziti_get_ext_signers | ( | ziti_handle_t | ztx | ) |
Get external signers available for authentication.
The result must be freed with [free_ziti_jwt_signer_array].
int Ziti_last_error | ( | void | ) |
return Ziti error code for last failed operation.
Use [ziti_errorstr] to get error message.
void Ziti_lib_init | ( | void | ) |
Initialize Ziti library.
Creates a background processing thread for Ziti processing.
void Ziti_lib_shutdown | ( | void | ) |
Shutdown Ziti library.
All loaded contexts are shutdown and background thread is terminated.
int Ziti_listen | ( | ziti_socket_t | socket, |
int | backlog | ||
) |
marks the [socket] as a socket able to accept incoming connections
socket | a file descriptor created with [Ziti_socket()] and bound to a service with [Ziti_bind] or [Ziti_bind_addr] |
backlog | maximum size of the queue of pending connections. |
int Ziti_load_context | ( | ziti_handle_t * | h, |
const char * | identity | ||
) |
Load Ziti identity.
First it tries to parse [identity] as identity Json. if that fails it tries to load it from file using [identity] as the path.
Ziti identity handle is returned to [h] on success or if additional authentication is required if passed [identity] parameter is deemed invalid the handle is set to [ZITI_INVALID_HANDLE] and error code is returned.
h | pointer to ziti_handle_t to be initialized |
identity | identity config JSON or path to a file. |
char * Ziti_login_external | ( | ziti_handle_t | ztx, |
const char * | signer_name | ||
) |
Start external login process.
This method is used to start the external login process for the given Ziti context. It will return a URL that the application should prompt user to open in their browser to complete the authentication.
the returned URL must be freed with free().
ztx | Ziti context handle |
signer_name | name of the external JWT signer to use |
int Ziti_login_totp | ( | ziti_handle_t | ztx, |
const char * | code | ||
) |
Login with TOTP code.
This method is used to complete the authentication process by providing a TOTP code. It should be called after the user has entered their TOTP code.
ztx | Ziti context handle |
code | TOTP code provided by the user |
ziti_socket_t Ziti_socket | ( | int | type | ) |
creates a socket handle(Windows) or file descriptor(*nix) suitable for connecting to a Ziti service
type | socket type which defines communication semantics, only SOCK_STREAM and SOCK_DGRAM are supported at this time (see socket(2)) |
int Ziti_wait_for_auth | ( | ziti_handle_t | ztx, |
int | timeout_ms | ||
) |
Wait for authentication to complete.
This method blocks until the authentication is completed or the timeout is reached. If the authentication is successful, it returns 0, otherwise it returns a negative error code.
ztx | Ziti context handle |
timeout_ms | timeout in milliseconds, 0 means no timeout |