pubkeyapi.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Dropbear - a SSH2 server
  3. *
  4. * Copyright (c) 2002,2003 Matt Johnston
  5. * All rights reserved.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy
  8. * of this software and associated documentation files (the "Software"), to deal
  9. * in the Software without restriction, including without limitation the rights
  10. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. * SOFTWARE. */
  24. #ifndef DROPBEAR_PUBKEY_H
  25. #define DROPBEAR_PUBKEY_H
  26. /* External Public Key API (EPKA) Plug-in Interface
  27. *
  28. * See:
  29. * https://github.com/fabriziobertocci/dropbear-epka
  30. * for additional information and examples about this API
  31. *
  32. */
  33. struct PluginInstance;
  34. struct PluginSession;
  35. /* API VERSION INFORMATION -
  36. * Dropbear will:
  37. * - Reject any plugin with a major version mismatch
  38. * - Load and print a warning if the plugin's minor version is HIGHER than
  39. * dropbear's minor version (assumes properties are added at the end of
  40. * PluginInstance or PluginSession). This is a case of plugin newer than dropbear.
  41. * - Reject if the plugin minor version is SMALLER than dropbear one (case
  42. * of plugin older than dropbear).
  43. * - Load (with no warnings) if version match.
  44. */
  45. #define DROPBEAR_PLUGIN_VERSION_MAJOR 1
  46. #define DROPBEAR_PLUGIN_VERSION_MINOR 0
  47. /* Creates an instance of the plugin.
  48. *
  49. * This is the main entry point of the plug-in and should be IMMUTABLE across
  50. * different API versions. Dropbear will check the version number
  51. * returned in the api_version to match the version it understands and reject
  52. * any plugin for which API major version does not match.
  53. *
  54. * If the version MINOR is different, dropbear will allow the plugin to run
  55. * only if: plugin_MINOR > dropbear_MINOR
  56. *
  57. * If plugin_MINOR < dropbear_MINOR or if the MAJOR version is different
  58. * dropbear will reject the plugin and terminate the execution.
  59. *
  60. * addrstring is the IP address of the client.
  61. *
  62. * Returns NULL in case of failure, otherwise a void * of the instance that need
  63. * to be passed to all the subsequent call to the plugin
  64. */
  65. typedef struct PluginInstance *(* PubkeyExtPlugin_newFn)(int verbose,
  66. const char *options,
  67. const char *addrstring);
  68. #define DROPBEAR_PUBKEY_PLUGIN_FNNAME_NEW "plugin_new"
  69. /* Validate a client through public key authentication
  70. *
  71. * If session has not been already created, creates it and store it
  72. * in *sessionInOut.
  73. * If session is a non-NULL, it will reuse it.
  74. *
  75. * Returns DROPBEAR_SUCCESS (0) if success or DROPBEAR_FAILURE (-1) if
  76. * authentication fails
  77. */
  78. typedef int (* PubkeyExtPlugin_checkPubKeyFn)(struct PluginInstance *PluginInstance,
  79. struct PluginSession **sessionInOut,
  80. const char* algo,
  81. unsigned int algolen,
  82. const unsigned char* keyblob,
  83. unsigned int keybloblen,
  84. const char *username);
  85. /* Notify the plugin that auth completed (after signature verification)
  86. */
  87. typedef void (* PubkeyExtPlugin_authSuccessFn)(struct PluginSession *session);
  88. /* Deletes a session
  89. * TODO: Add a reason why the session is terminated. See svr_dropbear_exit (in svr-session.c)
  90. */
  91. typedef void (* PubkeyExtPlugin_sessionDeleteFn)(struct PluginSession *session);
  92. /* Deletes the plugin instance */
  93. typedef void (* PubkeyExtPlugin_deleteFn)(struct PluginInstance *PluginInstance);
  94. /* The PluginInstance object - A simple container of the pointer to the functions used
  95. * by Dropbear.
  96. *
  97. * A plug-in can extend it to add its own properties
  98. *
  99. * The instance is created from the call to the plugin_new() function of the
  100. * shared library.
  101. * The delete_plugin function should delete the object.
  102. */
  103. struct PluginInstance {
  104. int api_version[2]; /* 0=Major, 1=Minor */
  105. PubkeyExtPlugin_checkPubKeyFn checkpubkey; /* mandatory */
  106. PubkeyExtPlugin_authSuccessFn auth_success; /* optional */
  107. PubkeyExtPlugin_sessionDeleteFn delete_session; /* mandatory */
  108. PubkeyExtPlugin_deleteFn delete_plugin; /* mandatory */
  109. };
  110. /*****************************************************************************
  111. * SESSION
  112. ****************************************************************************/
  113. /* Returns the options from the session.
  114. * The returned buffer will be destroyed when the session is deleted.
  115. * Option buffer string NULL-terminated
  116. */
  117. typedef char * (* PubkeyExtPlugin_getOptionsFn)(struct PluginSession *session);
  118. /* An SSH Session. Created during pre-auth and reused during the authentication.
  119. * The plug-in should delete this object (or any object extending it) from
  120. * the delete_session() function.
  121. *
  122. * Extend it to cache user and authentication information that can be
  123. * reused between pre-auth and auth (and to store whatever session-specific
  124. * variable you need to keep).
  125. *
  126. * Store any optional auth options in the auth_options property of the session.
  127. */
  128. struct PluginSession {
  129. struct PluginInstance * plugin_instance;
  130. PubkeyExtPlugin_getOptionsFn get_options;
  131. };
  132. #endif