plugin_keyring.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /* Copyright (c) 2016, 2017 Oracle and/or its affiliates. All rights reserved.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License, version 2.0,
  4. as published by the Free Software Foundation.
  5. This program is also distributed with certain software (including
  6. but not limited to OpenSSL) that is licensed under separate terms,
  7. as designated in a particular file or component or in included license
  8. documentation. The authors of MySQL hereby grant you an additional
  9. permission to link the program and your derivative works with the
  10. separately licensed software that they have included with MySQL.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License, version 2.0, for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  18. #ifndef MYSQL_PLUGIN_KEYRING_INCLUDED
  19. #define MYSQL_PLUGIN_KEYRING_INCLUDED
  20. /**
  21. API for keyring plugin. (MYSQL_KEYRING_PLUGIN)
  22. */
  23. #include "plugin.h"
  24. #define MYSQL_KEYRING_INTERFACE_VERSION 0x0101
  25. /**
  26. The descriptor structure for the plugin, that is referred from
  27. st_mysql_plugin.
  28. */
  29. struct st_mysql_keyring
  30. {
  31. int interface_version;
  32. /*!
  33. Add key to the keyring.
  34. Obfuscates and adds the key to the keyring. The key is associated with
  35. key_id and user_id (unique key identifier).
  36. @param[in] key_id id of the key to store
  37. @param[in] key_type type of the key to store
  38. @param[in] user_id id of the owner of the key
  39. @param[in] key the key itself to be stored. The memory of the key is
  40. copied by the keyring, thus the key itself can be freed
  41. after it was stored in the keyring.
  42. @param[in] key_len the length of the key to be stored
  43. @return Operation status
  44. @retval 0 OK
  45. @retval 1 ERROR
  46. */
  47. my_bool (*mysql_key_store)(const char *key_id, const char *key_type,
  48. const char* user_id, const void *key, size_t key_len);
  49. /*!
  50. Fetches key from the keyring.
  51. De-obfuscates and retrieves key associated with key_id and user_id from the
  52. keyring.
  53. @param[in] key_id id of the key to fetch
  54. @param[out] key_type type of the fetched key
  55. @param[in] user_id id of the owner of the key
  56. @param[out] key the fetched key itself. The memory for this key is
  57. allocated by the keyring and needs to be freed by the
  58. user when no longer needed. Prior to freeing the memory
  59. it needs to be obfuscated or zeroed.
  60. @param[out] key_len the length of the fetched key
  61. @return Operation status
  62. @retval 0 OK
  63. @retval 1 ERROR
  64. */
  65. my_bool (*mysql_key_fetch)(const char *key_id, char **key_type,
  66. const char *user_id, void **key, size_t *key_len);
  67. /*!
  68. Removes key from the keyring.
  69. Removes the key associated with key_id and user_id from the
  70. keyring.
  71. @param[in] key_id id of the key to remove
  72. @param[in] user_id id of the owner of the key to remove
  73. @return Operation status
  74. @retval 0 OK
  75. @retval 1 ERROR
  76. */
  77. my_bool (*mysql_key_remove)(const char *key_id, const char *user_id);
  78. /*!
  79. Generates and stores the key.
  80. Generates a random key of length key_len, associates it with key_id, user_id
  81. and stores it in the keyring.
  82. @param[in] key_id id of the key to generate
  83. @param[in] key_type type of the key to generate
  84. @param[in] user_id id of the owner of the generated key
  85. @param[in] key_len length of the key to generate
  86. @return Operation status
  87. @retval 0 OK
  88. @retval 1 ERROR
  89. */
  90. my_bool (*mysql_key_generate)(const char *key_id, const char *key_type,
  91. const char *user_id, size_t key_len);
  92. /**
  93. Keys_iterator object refers to an iterator which is used to iterate
  94. on a list which refers to Key_metadata. Key_metadata hold information
  95. about individual keys keyd_id and user_id. Keys_iterator should be used
  96. in following sequence only.
  97. void* iterator_ptr;
  98. char key_id[64]= { 0 };
  99. char user_id[64]= { 0 };
  100. plugin_handle->mysql_key_iterator_init(&iterator_ptr);
  101. if (iterator_ptr == NULL)
  102. report error;
  103. while (!(plugin_handle->mysql_key_iterator_get_key(iterator_ptr,
  104. key_id, user_id)))
  105. {
  106. Fetch the keys.
  107. Perform operations on the fetched keys.
  108. ..
  109. }
  110. plugin_handle->mysql_key_iterator_deinit(iterator_ptr);
  111. init() method accepts a void pointer which is the made to point to
  112. Keys_iterator instance. Keys_iterator instance internal pointer points
  113. to Key_metadata list. This list holds information about all keys stored
  114. in the backed end data store of keyring plugin. After call to init()
  115. please check iterator_ptr.
  116. get_key() method accepts the above iterator_ptr as IN param and then
  117. fills the passes in key_id and user_id with valid values. This can be
  118. used to fetch actual key information. Every call to this method will
  119. change internal pointers to advance to next position, so that the next
  120. call will fetch the next key.
  121. deinit() method frees all internal pointers along with iterator_ptr.
  122. */
  123. /**
  124. Initialize an iterator.
  125. @param[out] key_iterator Iterator used to fetch individual keys
  126. from key_container.
  127. @return VOID
  128. */
  129. void (*mysql_key_iterator_init)(void** key_iterator);
  130. /**
  131. Deinitialize an iterator.
  132. @param[in] key_iterator Iterator used to fetch individual keys
  133. from key_container.
  134. @return VOID
  135. */
  136. void (*mysql_key_iterator_deinit)(void* key_iterator);
  137. /**
  138. Get details of key. Every call to this service will change
  139. internal pointers to advance to next position, so that the next call
  140. will fetch the next key. In case iterator moves to the end, this service
  141. will return error.
  142. @param[in] key_iterator Iterator used to fetch individual keys
  143. from key_container.
  144. @param[out] key_id id of the key
  145. @param[out] user_id id of the owner
  146. @return Operation status
  147. @retval 0 OK
  148. @retval 1 ERROR
  149. */
  150. bool (*mysql_key_iterator_get_key)(void* key_iterator, char *key_id, char *user_id);
  151. };
  152. #endif