gss.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. #ifndef PUTTY_SSHGSS_H
  2. #define PUTTY_SSHGSS_H
  3. #include "putty.h"
  4. #include "pgssapi.h"
  5. /* This struct is defined even in NO_GSSAPI mode, so that stubs/no-gss.c can
  6. * return an instance of it containing no libraries */
  7. struct ssh_gss_liblist {
  8. struct ssh_gss_library *libraries;
  9. int nlibraries;
  10. };
  11. #ifndef NO_GSSAPI
  12. #define SSH2_GSS_OIDTYPE 0x06
  13. typedef void *Ssh_gss_ctx;
  14. typedef enum Ssh_gss_stat {
  15. SSH_GSS_OK = 0,
  16. SSH_GSS_S_CONTINUE_NEEDED,
  17. SSH_GSS_NO_MEM,
  18. SSH_GSS_BAD_HOST_NAME,
  19. SSH_GSS_BAD_MIC,
  20. SSH_GSS_NO_CREDS,
  21. SSH_GSS_FAILURE
  22. } Ssh_gss_stat;
  23. #define SSH_GSS_S_COMPLETE SSH_GSS_OK
  24. #define SSH_GSS_CLEAR_BUF(buf) do { \
  25. (*buf).length = 0; \
  26. (*buf).value = NULL; \
  27. } while (0)
  28. typedef gss_buffer_desc Ssh_gss_buf;
  29. typedef gss_name_t Ssh_gss_name;
  30. #define GSS_NO_EXPIRATION ((time_t)-1)
  31. #define GSS_DEF_REKEY_MINS 2 /* Default minutes between GSS cache checks */
  32. /* Functions, provided by either {windows,unix}/gss.c or gssc.c */
  33. struct ssh_gss_library;
  34. /*
  35. * Prepare a collection of GSSAPI libraries for use in a single SSH
  36. * connection. Returns a structure containing a list of libraries,
  37. * with their ids (see struct ssh_gss_library below) filled in so
  38. * that the client can go through them in the SSH user's preferred
  39. * order.
  40. *
  41. * Must always return non-NULL. (Even if no libraries are available,
  42. * it must return an empty structure.)
  43. *
  44. * The free function cleans up the structure, and its associated
  45. * libraries (if any).
  46. */
  47. struct ssh_gss_liblist *ssh_gss_setup(Conf *conf);
  48. void ssh_gss_cleanup(struct ssh_gss_liblist *list);
  49. /*
  50. * Fills in buf with a string describing the GSSAPI mechanism in
  51. * use. buf->data is not dynamically allocated.
  52. */
  53. typedef Ssh_gss_stat (*t_ssh_gss_indicate_mech)(struct ssh_gss_library *lib,
  54. Ssh_gss_buf *buf);
  55. /*
  56. * Converts a name such as a hostname into a GSSAPI internal form,
  57. * which is placed in "out". The result should be freed by
  58. * ssh_gss_release_name().
  59. */
  60. typedef Ssh_gss_stat (*t_ssh_gss_import_name)(struct ssh_gss_library *lib,
  61. char *in, Ssh_gss_name *out);
  62. /*
  63. * Frees the contents of an Ssh_gss_name structure filled in by
  64. * ssh_gss_import_name().
  65. */
  66. typedef Ssh_gss_stat (*t_ssh_gss_release_name)(struct ssh_gss_library *lib,
  67. Ssh_gss_name *name);
  68. /*
  69. * The main GSSAPI security context setup function. The "out"
  70. * parameter will need to be freed by ssh_gss_free_tok.
  71. */
  72. typedef Ssh_gss_stat (*t_ssh_gss_init_sec_context)
  73. (struct ssh_gss_library *lib,
  74. Ssh_gss_ctx *ctx, Ssh_gss_name name, int delegate,
  75. Ssh_gss_buf *in, Ssh_gss_buf *out, time_t *expiry,
  76. unsigned long *lifetime);
  77. /*
  78. * Frees the contents of an Ssh_gss_buf filled in by
  79. * ssh_gss_init_sec_context(). Do not accidentally call this on
  80. * something filled in by ssh_gss_get_mic() (which requires a
  81. * different free function) or something filled in by any other
  82. * way.
  83. */
  84. typedef Ssh_gss_stat (*t_ssh_gss_free_tok)(struct ssh_gss_library *lib,
  85. Ssh_gss_buf *);
  86. /*
  87. * Acquires the credentials to perform authentication in the first
  88. * place. Needs to be freed by ssh_gss_release_cred().
  89. */
  90. typedef Ssh_gss_stat (*t_ssh_gss_acquire_cred)(struct ssh_gss_library *lib,
  91. Ssh_gss_ctx *,
  92. time_t *expiry);
  93. /*
  94. * Frees the contents of an Ssh_gss_ctx filled in by
  95. * ssh_gss_acquire_cred().
  96. */
  97. typedef Ssh_gss_stat (*t_ssh_gss_release_cred)(struct ssh_gss_library *lib,
  98. Ssh_gss_ctx *);
  99. /*
  100. * Gets a MIC for some input data. "out" needs to be freed by
  101. * ssh_gss_free_mic().
  102. */
  103. typedef Ssh_gss_stat (*t_ssh_gss_get_mic)(struct ssh_gss_library *lib,
  104. Ssh_gss_ctx ctx, Ssh_gss_buf *in,
  105. Ssh_gss_buf *out);
  106. /*
  107. * Validates an input MIC for some input data.
  108. */
  109. typedef Ssh_gss_stat (*t_ssh_gss_verify_mic)(struct ssh_gss_library *lib,
  110. Ssh_gss_ctx ctx,
  111. Ssh_gss_buf *in_data,
  112. Ssh_gss_buf *in_mic);
  113. /*
  114. * Frees the contents of an Ssh_gss_buf filled in by
  115. * ssh_gss_get_mic(). Do not accidentally call this on something
  116. * filled in by ssh_gss_init_sec_context() (which requires a
  117. * different free function) or something filled in by any other
  118. * way.
  119. */
  120. typedef Ssh_gss_stat (*t_ssh_gss_free_mic)(struct ssh_gss_library *lib,
  121. Ssh_gss_buf *);
  122. /*
  123. * Return an error message after authentication failed. The
  124. * message string is returned in "buf", with buf->len giving the
  125. * number of characters of printable message text and buf->data
  126. * containing one more character which is a trailing NUL.
  127. * buf->data should be manually freed by the caller.
  128. */
  129. typedef Ssh_gss_stat (*t_ssh_gss_display_status)(struct ssh_gss_library *lib,
  130. Ssh_gss_ctx, Ssh_gss_buf *buf);
  131. struct ssh_gss_library {
  132. /*
  133. * Identifying number in the enumeration used by the
  134. * configuration code to specify a preference order.
  135. */
  136. int id;
  137. /*
  138. * Filled in at initialisation time, if there's anything
  139. * interesting to say about how GSSAPI was initialised (e.g.
  140. * which of a number of alternative libraries was used).
  141. */
  142. const char *gsslogmsg;
  143. /*
  144. * Function pointers implementing the SSH wrapper layer on top
  145. * of GSSAPI. (Defined in sshgssc, typically, though Windows
  146. * provides an alternative layer to sit on top of the annoyingly
  147. * different SSPI.)
  148. */
  149. t_ssh_gss_indicate_mech indicate_mech;
  150. t_ssh_gss_import_name import_name;
  151. t_ssh_gss_release_name release_name;
  152. t_ssh_gss_init_sec_context init_sec_context;
  153. t_ssh_gss_free_tok free_tok;
  154. t_ssh_gss_acquire_cred acquire_cred;
  155. t_ssh_gss_release_cred release_cred;
  156. t_ssh_gss_get_mic get_mic;
  157. t_ssh_gss_verify_mic verify_mic;
  158. t_ssh_gss_free_mic free_mic;
  159. t_ssh_gss_display_status display_status;
  160. /*
  161. * Additional data for the wrapper layers.
  162. */
  163. union {
  164. struct gssapi_functions gssapi;
  165. /*
  166. * The SSPI wrappers don't need to store their Windows API
  167. * function pointers in this structure, because there can't
  168. * be more than one set of them available.
  169. */
  170. } u;
  171. /*
  172. * Wrapper layers will often also need to store a library handle
  173. * of some sort for cleanup time.
  174. */
  175. void *handle;
  176. };
  177. /*
  178. * State that has to be shared between all GSSAPI-using parts of the
  179. * same SSH connection, in particular between GSS key exchange and the
  180. * subsequent trivial userauth method that reuses its output.
  181. */
  182. struct ssh_connection_shared_gss_state {
  183. struct ssh_gss_liblist *libs;
  184. struct ssh_gss_library *lib;
  185. Ssh_gss_name srv_name;
  186. Ssh_gss_ctx ctx;
  187. };
  188. #endif /* NO_GSSAPI */
  189. #endif /*PUTTY_SSHGSS_H*/