Clone of PhatAC @ https://github.com/floaterxk/PhatAC

plugin_keyring.h 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* Copyright (c) 2016, 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 as published by
  4. the Free Software Foundation; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with this program; if not, write to the Free Software
  11. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  12. #ifndef MYSQL_PLUGIN_KEYRING_INCLUDED
  13. #define MYSQL_PLUGIN_KEYRING_INCLUDED
  14. /**
  15. API for keyring plugin. (MYSQL_KEYRING_PLUGIN)
  16. */
  17. #include "plugin.h"
  18. #define MYSQL_KEYRING_INTERFACE_VERSION 0x0100
  19. /**
  20. The descriptor structure for the plugin, that is referred from
  21. st_mysql_plugin.
  22. */
  23. struct st_mysql_keyring
  24. {
  25. int interface_version;
  26. /*!
  27. Add key to the keyring.
  28. Obfuscates and adds the key to the keyring. The key is associated with
  29. key_id and user_id (unique key identifier).
  30. @param[in] key_id id of the key to store
  31. @param[in] key_type type of the key to store
  32. @param[in] user_id id of the owner of the key
  33. @param[in] key the key itself to be stored. The memory of the key is
  34. copied by the keyring, thus the key itself can be freed
  35. after it was stored in the keyring.
  36. @param[in] key_len the length of the key to be stored
  37. @return Operation status
  38. @retval 0 OK
  39. @retval 1 ERROR
  40. */
  41. my_bool (*mysql_key_store)(const char *key_id, const char *key_type,
  42. const char* user_id, const void *key, size_t key_len);
  43. /*!
  44. Fetches key from the keyring.
  45. De-obfuscates and retrieves key associated with key_id and user_id from the
  46. keyring.
  47. @param[in] key_id id of the key to fetch
  48. @param[out] key_type type of the fetched key
  49. @param[in] user_id id of the owner of the key
  50. @param[out] key the fetched key itself. The memory for this key is
  51. allocated by the keyring and needs to be freed by the
  52. user when no longer needed. Prior to freeing the memory
  53. it needs to be obfuscated or zeroed.
  54. @param[out] key_len the length of the fetched key
  55. @return Operation status
  56. @retval 0 OK
  57. @retval 1 ERROR
  58. */
  59. my_bool (*mysql_key_fetch)(const char *key_id, char **key_type,
  60. const char *user_id, void **key, size_t *key_len);
  61. /*!
  62. Removes key from the keyring.
  63. Removes the key associated with key_id and user_id from the
  64. keyring.
  65. @param[in] key_id id of the key to remove
  66. @param[in] user_id id of the owner of the key to remove
  67. @return Operation status
  68. @retval 0 OK
  69. @retval 1 ERROR
  70. */
  71. my_bool (*mysql_key_remove)(const char *key_id, const char *user_id);
  72. /*!
  73. Generates and stores the key.
  74. Generates a random key of length key_len, associates it with key_id, user_id
  75. and stores it in the keyring.
  76. @param[in] key_id id of the key to generate
  77. @param[in] key_type type of the key to generate
  78. @param[in] user_id id of the owner of the generated key
  79. @param[in] key_len length of the key to generate
  80. @return Operation status
  81. @retval 0 OK
  82. @retval 1 ERROR
  83. */
  84. my_bool (*mysql_key_generate)(const char *key_id, const char *key_type,
  85. const char *user_id, size_t key_len);
  86. };
  87. #endif