sshgss.h 6.9 KB

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