userpref.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #ifndef __USERPREF_H
  23. #define __USERPREF_H
  24. #ifdef HAVE_CONFIG_H
  25. #include <config.h>
  26. #endif
  27. #ifdef HAVE_OPENSSL
  28. typedef struct {
  29. unsigned char *data;
  30. unsigned int size;
  31. } key_data_t;
  32. #else
  33. #include <gnutls/gnutls.h>
  34. typedef gnutls_datum_t key_data_t;
  35. #endif
  36. #include <stdint.h>
  37. #include <plist/plist.h>
  38. #define USERPREF_DEVICE_CERTIFICATE_KEY "DeviceCertificate"
  39. #define USERPREF_ESCROW_BAG_KEY "EscrowBag"
  40. #define USERPREF_HOST_CERTIFICATE_KEY "HostCertificate"
  41. #define USERPREF_ROOT_CERTIFICATE_KEY "RootCertificate"
  42. #define USERPREF_HOST_PRIVATE_KEY_KEY "HostPrivateKey"
  43. #define USERPREF_ROOT_PRIVATE_KEY_KEY "RootPrivateKey"
  44. #define USERPREF_HOST_ID_KEY "HostID"
  45. #define USERPREF_SYSTEM_BUID_KEY "SystemBUID"
  46. #define USERPREF_WIFI_MAC_ADDRESS_KEY "WiFiMACAddress"
  47. /** Error Codes */
  48. typedef enum {
  49. USERPREF_E_SUCCESS = 0,
  50. USERPREF_E_INVALID_ARG = -1,
  51. USERPREF_E_INVALID_CONF = -2,
  52. USERPREF_E_SSL_ERROR = -3,
  53. USERPREF_E_READ_ERROR = -4,
  54. USERPREF_E_WRITE_ERROR = -5,
  55. USERPREF_E_UNKNOWN_ERROR = -256
  56. } userpref_error_t;
  57. const char *userpref_get_config_dir(void);
  58. int userpref_read_system_buid(char **system_buid);
  59. userpref_error_t userpref_read_pair_record(const char *udid, plist_t *pair_record);
  60. userpref_error_t userpref_save_pair_record(const char *udid, plist_t pair_record);
  61. userpref_error_t userpref_delete_pair_record(const char *udid);
  62. userpref_error_t pair_record_generate_keys_and_certs(plist_t pair_record, key_data_t public_key);
  63. #ifdef HAVE_OPENSSL
  64. userpref_error_t pair_record_import_key_with_name(plist_t pair_record, const char* name, key_data_t* key);
  65. userpref_error_t pair_record_import_crt_with_name(plist_t pair_record, const char* name, key_data_t* cert);
  66. #else
  67. userpref_error_t pair_record_import_key_with_name(plist_t pair_record, const char* name, gnutls_x509_privkey_t key);
  68. userpref_error_t pair_record_import_crt_with_name(plist_t pair_record, const char* name, gnutls_x509_crt_t cert);
  69. #endif
  70. userpref_error_t pair_record_get_host_id(plist_t pair_record, char** host_id);
  71. userpref_error_t pair_record_set_host_id(plist_t pair_record, const char* host_id);
  72. userpref_error_t pair_record_get_item_as_key_data(plist_t pair_record, const char* name, key_data_t *value);
  73. userpref_error_t pair_record_set_item_from_key_data(plist_t pair_record, const char* name, key_data_t *value);
  74. /* deprecated */
  75. userpref_error_t userpref_get_paired_udids(char ***list, unsigned int *count);
  76. int userpref_has_pair_record(const char *udid);
  77. #endif