/* Copyright (c) 2011 Samuel Lidén Borell Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef _BACKEND_H_ #define _BACKEND_H_ typedef struct palt_request palt_request_t; typedef struct palt_token palt_token_t; typedef struct palt_tokenlist palt_tokenlist_t; struct palt_tokenlist { /** * This pointer can be used for any purpose. It's ignored by the backend. */ void *tag; /** * Called when a token has been added. */ void (*added)(palt_tokenlist_t *tokenlist, palt_token_t *token); /** * Called when a token has changed in some way, for example if it's name * has been changed. Optional (may be NULL). */ void (*updated)(palt_tokenlist_t *tokenlist, palt_token_t *token); /** * Called when a token has been removed. After this callback has returned, * the token will be free'd automatically. */ void (*removed)(palt_tokenlist_t *tokenlist, palt_token_t *token); /** * Called when a scan starts and finishes. You should change the user * interface so the user can see that a scan is in progress. */ void (*scan_status_changed)(palt_tokenlist_t *tokenlist); }; typedef enum { /* No error (does not imply completion) */ PALT_NO_ERROR_SO_FAR = 0, /* User aborted */ PALT_USER_ABORTED, /* Errors */ PALT_INVALID_CARD, PALT_INVALID_PIN, PALT_INVALID_PASSWORD, } palt_error_t; typedef enum { /* Request status */ PALT_REQUEST_FINISHED = 1 << 0, /* Card status */ PALT_PIN_LOCKED = 1 << 10, /* User action required */ PALT_NEED_CARD = 1 << 21, PALT_NEED_PIN = 1 << 22, PALT_NEED_PASSWORD = 1 << 23, PALT_NEED_CONFIRMATION = 1 << 24, } palt_status_t; typedef void (palt_notifyfunc_t)(palt_request_t *request); struct palt_request { /* Input */ const palt_token_t *token; const char *url; const char *nonce; const char *password; void *tag; palt_notifyfunc_t *notify_func; union { /** Input */ struct { /** Public key fingerprint */ const unsigned char *fingerprint; size_t fplen; /** Encrypted data, if sent during key generation */ const unsigned char *encrypted; size_t enclen; } in; /** Output */ struct { /** Public key */ unsigned char **pubkey; size_t *publen; /** Encrypted data (optional). This can be the private key */ unsigned char **encrypted; size_t *enclen; } out; } keypair; /** Resulting signature */ unsigned char *signature; size_t siglen; palt_error_t error; palt_status_t status; }; /** * Returns a name of a token, or NULL if the token doesn't have a name. */ char *palt_get_token_name(const palt_token_t *token); /** * Registers a token list. PAlt calls the specified callbacks when the list * of tokens changes, and also initially when this function is called. */ void palt_register_tokenlist(palt_tokenlist_t *tokenlist); /** * Unregisters a token list. */ void palt_unregister_tokenlist(palt_tokenlist_t *tokenlist); /** * Manually scans for available tokens. This is done asynchronously. */ void palt_scan_tokens(); /** * Generates a new key pair for a user and a URL. The private key is * encrypted. */ void palt_generate(palt_request_t *req); /** * Generates a signature from the key pair for a user and a URL. */ void palt_auth(palt_request_t *req); #endif