| 1 |
/* |
| 2 |
* userpref.h |
| 3 |
* contains methods to access user specific certificates IDs and more. |
| 4 |
* |
| 5 |
* Copyright (c) 2013-2014 Martin Szulecki All Rights Reserved. |
| 6 |
* Copyright (c) 2008 Jonathan Beck All Rights Reserved. |
| 7 |
* |
| 8 |
* This library is free software; you can redistribute it and/or |
| 9 |
* modify it under the terms of the GNU Lesser General Public |
| 10 |
* License as published by the Free Software Foundation; either |
| 11 |
* version 2.1 of the License, or (at your option) any later version. |
| 12 |
* |
| 13 |
* This library is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
* Lesser General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General Public |
| 19 |
* License along with this library; if not, write to the Free Software |
| 20 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 |
*/ |
| 22 |
|
| 23 |
#ifndef __USERPREF_H |
| 24 |
#define __USERPREF_H |
| 25 |
|
| 26 |
#ifdef HAVE_CONFIG_H |
| 27 |
#include <config.h> |
| 28 |
#endif |
| 29 |
|
| 30 |
#if defined(HAVE_OPENSSL) || defined(HAVE_MBEDTLS) |
| 31 |
typedef struct { |
| 32 |
unsigned char *data; |
| 33 |
unsigned int size; |
| 34 |
} key_data_t; |
| 35 |
#else |
| 36 |
#include <gnutls/gnutls.h> |
| 37 |
typedef gnutls_datum_t key_data_t; |
| 38 |
#endif |
| 39 |
|
| 40 |
#include <stdint.h> |
| 41 |
#include <plist/plist.h> |
| 42 |
|
| 43 |
#define USERPREF_DEVICE_CERTIFICATE_KEY "DeviceCertificate" |
| 44 |
#define USERPREF_ESCROW_BAG_KEY "EscrowBag" |
| 45 |
#define USERPREF_HOST_CERTIFICATE_KEY "HostCertificate" |
| 46 |
#define USERPREF_ROOT_CERTIFICATE_KEY "RootCertificate" |
| 47 |
#define USERPREF_HOST_PRIVATE_KEY_KEY "HostPrivateKey" |
| 48 |
#define USERPREF_ROOT_PRIVATE_KEY_KEY "RootPrivateKey" |
| 49 |
#define USERPREF_HOST_ID_KEY "HostID" |
| 50 |
#define USERPREF_SYSTEM_BUID_KEY "SystemBUID" |
| 51 |
#define USERPREF_WIFI_MAC_ADDRESS_KEY "WiFiMACAddress" |
| 52 |
|
| 53 |
/** Error Codes */ |
| 54 |
typedef enum { |
| 55 |
USERPREF_E_SUCCESS = 0, |
| 56 |
USERPREF_E_INVALID_ARG = -1, |
| 57 |
USERPREF_E_NOENT = -2, |
| 58 |
USERPREF_E_INVALID_CONF = -3, |
| 59 |
USERPREF_E_SSL_ERROR = -4, |
| 60 |
USERPREF_E_READ_ERROR = -5, |
| 61 |
USERPREF_E_WRITE_ERROR = -6, |
| 62 |
USERPREF_E_UNKNOWN_ERROR = -256 |
| 63 |
} userpref_error_t; |
| 64 |
|
| 65 |
const char *userpref_get_config_dir(void); |
| 66 |
int userpref_read_system_buid(char **system_buid); |
| 67 |
userpref_error_t userpref_read_pair_record(const char *udid, plist_t *pair_record); |
| 68 |
userpref_error_t userpref_save_pair_record(const char *udid, uint32_t device_id, plist_t pair_record); |
| 69 |
userpref_error_t userpref_delete_pair_record(const char *udid); |
| 70 |
|
| 71 |
userpref_error_t pair_record_generate_keys_and_certs(plist_t pair_record, key_data_t public_key, unsigned int device_version); |
| 72 |
#if defined(HAVE_OPENSSL) || defined(HAVE_MBEDTLS) |
| 73 |
userpref_error_t pair_record_import_key_with_name(plist_t pair_record, const char* name, key_data_t* key); |
| 74 |
userpref_error_t pair_record_import_crt_with_name(plist_t pair_record, const char* name, key_data_t* cert); |
| 75 |
#else |
| 76 |
userpref_error_t pair_record_import_key_with_name(plist_t pair_record, const char* name, gnutls_x509_privkey_t key); |
| 77 |
userpref_error_t pair_record_import_crt_with_name(plist_t pair_record, const char* name, gnutls_x509_crt_t cert); |
| 78 |
#endif |
| 79 |
|
| 80 |
userpref_error_t pair_record_get_host_id(plist_t pair_record, char** host_id); |
| 81 |
userpref_error_t pair_record_set_host_id(plist_t pair_record, const char* host_id); |
| 82 |
userpref_error_t pair_record_get_item_as_key_data(plist_t pair_record, const char* name, key_data_t *value); |
| 83 |
userpref_error_t pair_record_set_item_from_key_data(plist_t pair_record, const char* name, key_data_t *value); |
| 84 |
|
| 85 |
/* deprecated */ |
| 86 |
userpref_error_t userpref_get_paired_udids(char ***list, unsigned int *count); |
| 87 |
int userpref_has_pair_record(const char *udid); |
| 88 |
|
| 89 |
#endif |