sshgss.h 5.5 KB

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