summaryrefslogtreecommitdiffstats
path: root/common/userpref.h
diff options
context:
space:
mode:
Diffstat (limited to 'common/userpref.h')
-rw-r--r--common/userpref.h89
1 files changed, 89 insertions, 0 deletions
diff --git a/common/userpref.h b/common/userpref.h
new file mode 100644
index 0000000..9a1832c
--- /dev/null
+++ b/common/userpref.h
@@ -0,0 +1,89 @@
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)
31typedef struct {
32 unsigned char *data;
33 unsigned int size;
34} key_data_t;
35#else
36#include <gnutls/gnutls.h>
37typedef 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 */
54typedef 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
65const char *userpref_get_config_dir(void);
66int userpref_read_system_buid(char **system_buid);
67userpref_error_t userpref_read_pair_record(const char *udid, plist_t *pair_record);
68userpref_error_t userpref_save_pair_record(const char *udid, uint32_t device_id, plist_t pair_record);
69userpref_error_t userpref_delete_pair_record(const char *udid);
70
71userpref_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)
73userpref_error_t pair_record_import_key_with_name(plist_t pair_record, const char* name, key_data_t* key);
74userpref_error_t pair_record_import_crt_with_name(plist_t pair_record, const char* name, key_data_t* cert);
75#else
76userpref_error_t pair_record_import_key_with_name(plist_t pair_record, const char* name, gnutls_x509_privkey_t key);
77userpref_error_t pair_record_import_crt_with_name(plist_t pair_record, const char* name, gnutls_x509_crt_t cert);
78#endif
79
80userpref_error_t pair_record_get_host_id(plist_t pair_record, char** host_id);
81userpref_error_t pair_record_set_host_id(plist_t pair_record, const char* host_id);
82userpref_error_t pair_record_get_item_as_key_data(plist_t pair_record, const char* name, key_data_t *value);
83userpref_error_t pair_record_set_item_from_key_data(plist_t pair_record, const char* name, key_data_t *value);
84
85/* deprecated */
86userpref_error_t userpref_get_paired_udids(char ***list, unsigned int *count);
87int userpref_has_pair_record(const char *udid);
88
89#endif