pgssapi.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. #ifndef PUTTY_PGSSAPI_H
  2. #define PUTTY_PGSSAPI_H
  3. #include "putty.h"
  4. #ifndef NO_GSSAPI
  5. /*
  6. * On Unix, if we're statically linking against GSSAPI, we leave the
  7. * declaration of all this lot to the official header. If we're
  8. * dynamically linking, we declare it ourselves, because that avoids
  9. * us needing the official header at compile time.
  10. *
  11. * However, we still need the function pointer types, because even
  12. * with statically linked GSSAPI we use the ssh_gss_library wrapper.
  13. */
  14. #ifdef STATIC_GSSAPI
  15. #include <gssapi/gssapi.h>
  16. typedef gss_OID const_gss_OID; /* for our prototypes below */
  17. #else /* STATIC_GSSAPI */
  18. /*******************************************************************************
  19. * GSSAPI Definitions, taken from RFC 2744
  20. ******************************************************************************/
  21. /* GSSAPI Type Definitions */
  22. typedef uint32_t OM_uint32;
  23. typedef struct gss_OID_desc_struct {
  24. OM_uint32 length;
  25. void *elements;
  26. } gss_OID_desc;
  27. typedef const gss_OID_desc *const_gss_OID;
  28. typedef gss_OID_desc *gss_OID;
  29. typedef struct gss_OID_set_desc_struct {
  30. size_t count;
  31. gss_OID elements;
  32. } gss_OID_set_desc;
  33. typedef const gss_OID_set_desc *const_gss_OID_set;
  34. typedef gss_OID_set_desc *gss_OID_set;
  35. typedef struct gss_buffer_desc_struct {
  36. size_t length;
  37. void *value;
  38. } gss_buffer_desc, *gss_buffer_t;
  39. typedef struct gss_channel_bindings_struct {
  40. OM_uint32 initiator_addrtype;
  41. gss_buffer_desc initiator_address;
  42. OM_uint32 acceptor_addrtype;
  43. gss_buffer_desc acceptor_address;
  44. gss_buffer_desc application_data;
  45. } *gss_channel_bindings_t;
  46. typedef void *gss_ctx_id_t;
  47. typedef void *gss_name_t;
  48. typedef void *gss_cred_id_t;
  49. typedef OM_uint32 gss_qop_t;
  50. typedef int gss_cred_usage_t;
  51. /* Flag bits for context-level services. */
  52. #define GSS_C_DELEG_FLAG 1
  53. #define GSS_C_MUTUAL_FLAG 2
  54. #define GSS_C_REPLAY_FLAG 4
  55. #define GSS_C_SEQUENCE_FLAG 8
  56. #define GSS_C_CONF_FLAG 16
  57. #define GSS_C_INTEG_FLAG 32
  58. #define GSS_C_ANON_FLAG 64
  59. #define GSS_C_PROT_READY_FLAG 128
  60. #define GSS_C_TRANS_FLAG 256
  61. /* Credential usage options */
  62. #define GSS_C_BOTH 0
  63. #define GSS_C_INITIATE 1
  64. #define GSS_C_ACCEPT 2
  65. /*-
  66. * RFC 2744 Page 86
  67. * Expiration time of 2^32-1 seconds means infinite lifetime for a
  68. * credential or security context
  69. */
  70. #define GSS_C_INDEFINITE 0xfffffffful
  71. /* Status code types for gss_display_status */
  72. #define GSS_C_GSS_CODE 1
  73. #define GSS_C_MECH_CODE 2
  74. /* The constant definitions for channel-bindings address families */
  75. #define GSS_C_AF_UNSPEC 0
  76. #define GSS_C_AF_LOCAL 1
  77. #define GSS_C_AF_INET 2
  78. #define GSS_C_AF_IMPLINK 3
  79. #define GSS_C_AF_PUP 4
  80. #define GSS_C_AF_CHAOS 5
  81. #define GSS_C_AF_NS 6
  82. #define GSS_C_AF_NBS 7
  83. #define GSS_C_AF_ECMA 8
  84. #define GSS_C_AF_DATAKIT 9
  85. #define GSS_C_AF_CCITT 10
  86. #define GSS_C_AF_SNA 11
  87. #define GSS_C_AF_DECnet 12
  88. #define GSS_C_AF_DLI 13
  89. #define GSS_C_AF_LAT 14
  90. #define GSS_C_AF_HYLINK 15
  91. #define GSS_C_AF_APPLETALK 16
  92. #define GSS_C_AF_BSC 17
  93. #define GSS_C_AF_DSS 18
  94. #define GSS_C_AF_OSI 19
  95. #define GSS_C_AF_X25 21
  96. #define GSS_C_AF_NULLADDR 255
  97. /* Various Null values */
  98. #define GSS_C_NO_NAME ((gss_name_t) 0)
  99. #define GSS_C_NO_BUFFER ((gss_buffer_t) 0)
  100. #define GSS_C_NO_OID ((gss_OID) 0)
  101. #define GSS_C_NO_OID_SET ((gss_OID_set) 0)
  102. #define GSS_C_NO_CONTEXT ((gss_ctx_id_t) 0)
  103. #define GSS_C_NO_CREDENTIAL ((gss_cred_id_t) 0)
  104. #define GSS_C_NO_CHANNEL_BINDINGS ((gss_channel_bindings_t) 0)
  105. #define GSS_C_EMPTY_BUFFER {0, NULL}
  106. /* Major status codes */
  107. #define GSS_S_COMPLETE 0
  108. /* Some "helper" definitions to make the status code macros obvious. */
  109. #define GSS_C_CALLING_ERROR_OFFSET 24
  110. #define GSS_C_ROUTINE_ERROR_OFFSET 16
  111. #define GSS_C_SUPPLEMENTARY_OFFSET 0
  112. #define GSS_C_CALLING_ERROR_MASK 0377ul
  113. #define GSS_C_ROUTINE_ERROR_MASK 0377ul
  114. #define GSS_C_SUPPLEMENTARY_MASK 0177777ul
  115. /*
  116. * The macros that test status codes for error conditions.
  117. * Note that the GSS_ERROR() macro has changed slightly from
  118. * the V1 GSS-API so that it now evaluates its argument
  119. * only once.
  120. */
  121. #define GSS_CALLING_ERROR(x) \
  122. (x & (GSS_C_CALLING_ERROR_MASK << GSS_C_CALLING_ERROR_OFFSET))
  123. #define GSS_ROUTINE_ERROR(x) \
  124. (x & (GSS_C_ROUTINE_ERROR_MASK << GSS_C_ROUTINE_ERROR_OFFSET))
  125. #define GSS_SUPPLEMENTARY_INFO(x) \
  126. (x & (GSS_C_SUPPLEMENTARY_MASK << GSS_C_SUPPLEMENTARY_OFFSET))
  127. #define GSS_ERROR(x) \
  128. (x & ((GSS_C_CALLING_ERROR_MASK << GSS_C_CALLING_ERROR_OFFSET) | \
  129. (GSS_C_ROUTINE_ERROR_MASK << GSS_C_ROUTINE_ERROR_OFFSET)))
  130. /* Now the actual status code definitions */
  131. /* Calling errors: */
  132. #define GSS_S_CALL_INACCESSIBLE_READ \
  133. (1ul << GSS_C_CALLING_ERROR_OFFSET)
  134. #define GSS_S_CALL_INACCESSIBLE_WRITE \
  135. (2ul << GSS_C_CALLING_ERROR_OFFSET)
  136. #define GSS_S_CALL_BAD_STRUCTURE \
  137. (3ul << GSS_C_CALLING_ERROR_OFFSET)
  138. /* Routine errors: */
  139. #define GSS_S_BAD_MECH (1ul << \
  140. GSS_C_ROUTINE_ERROR_OFFSET)
  141. #define GSS_S_BAD_NAME (2ul << \
  142. GSS_C_ROUTINE_ERROR_OFFSET)
  143. #define GSS_S_BAD_NAMETYPE (3ul << \
  144. GSS_C_ROUTINE_ERROR_OFFSET)
  145. #define GSS_S_BAD_BINDINGS (4ul << \
  146. GSS_C_ROUTINE_ERROR_OFFSET)
  147. #define GSS_S_BAD_STATUS (5ul << \
  148. GSS_C_ROUTINE_ERROR_OFFSET)
  149. #define GSS_S_BAD_SIG (6ul << \
  150. GSS_C_ROUTINE_ERROR_OFFSET)
  151. #define GSS_S_BAD_MIC GSS_S_BAD_SIG
  152. #define GSS_S_NO_CRED (7ul << \
  153. GSS_C_ROUTINE_ERROR_OFFSET)
  154. #define GSS_S_NO_CONTEXT (8ul << \
  155. GSS_C_ROUTINE_ERROR_OFFSET)
  156. #define GSS_S_DEFECTIVE_TOKEN (9ul << \
  157. GSS_C_ROUTINE_ERROR_OFFSET)
  158. #define GSS_S_DEFECTIVE_CREDENTIAL (10ul << \
  159. GSS_C_ROUTINE_ERROR_OFFSET)
  160. #define GSS_S_CREDENTIALS_EXPIRED (11ul << \
  161. GSS_C_ROUTINE_ERROR_OFFSET)
  162. #define GSS_S_CONTEXT_EXPIRED (12ul << \
  163. GSS_C_ROUTINE_ERROR_OFFSET)
  164. #define GSS_S_FAILURE (13ul << \
  165. GSS_C_ROUTINE_ERROR_OFFSET)
  166. #define GSS_S_BAD_QOP (14ul << \
  167. GSS_C_ROUTINE_ERROR_OFFSET)
  168. #define GSS_S_UNAUTHORIZED (15ul << \
  169. GSS_C_ROUTINE_ERROR_OFFSET)
  170. #define GSS_S_UNAVAILABLE (16ul << \
  171. GSS_C_ROUTINE_ERROR_OFFSET)
  172. #define GSS_S_DUPLICATE_ELEMENT (17ul << \
  173. GSS_C_ROUTINE_ERROR_OFFSET)
  174. #define GSS_S_NAME_NOT_MN (18ul << \
  175. GSS_C_ROUTINE_ERROR_OFFSET)
  176. /* Supplementary info bits: */
  177. #define GSS_S_CONTINUE_NEEDED \
  178. (1ul << (GSS_C_SUPPLEMENTARY_OFFSET + 0))
  179. #define GSS_S_DUPLICATE_TOKEN \
  180. (1ul << (GSS_C_SUPPLEMENTARY_OFFSET + 1))
  181. #define GSS_S_OLD_TOKEN \
  182. (1ul << (GSS_C_SUPPLEMENTARY_OFFSET + 2))
  183. #define GSS_S_UNSEQ_TOKEN \
  184. (1ul << (GSS_C_SUPPLEMENTARY_OFFSET + 3))
  185. #define GSS_S_GAP_TOKEN \
  186. (1ul << (GSS_C_SUPPLEMENTARY_OFFSET + 4))
  187. extern const_gss_OID GSS_C_NT_USER_NAME;
  188. extern const_gss_OID GSS_C_NT_MACHINE_UID_NAME;
  189. extern const_gss_OID GSS_C_NT_STRING_UID_NAME;
  190. extern const_gss_OID GSS_C_NT_HOSTBASED_SERVICE_X;
  191. extern const_gss_OID GSS_C_NT_HOSTBASED_SERVICE;
  192. extern const_gss_OID GSS_C_NT_ANONYMOUS;
  193. extern const_gss_OID GSS_C_NT_EXPORT_NAME;
  194. #endif /* STATIC_GSSAPI */
  195. extern const gss_OID GSS_MECH_KRB5;
  196. /* GSSAPI functions we use.
  197. * TODO: Replace with all GSSAPI functions from RFC?
  198. */
  199. /* Calling convention, just in case we need one. */
  200. #ifndef GSS_CC
  201. #define GSS_CC
  202. #endif /*GSS_CC*/
  203. typedef OM_uint32 (GSS_CC *t_gss_release_cred)
  204. (OM_uint32 * /*minor_status*/,
  205. gss_cred_id_t * /*cred_handle*/);
  206. typedef OM_uint32 (GSS_CC *t_gss_init_sec_context)
  207. (OM_uint32 * /*minor_status*/,
  208. const gss_cred_id_t /*initiator_cred_handle*/,
  209. gss_ctx_id_t * /*context_handle*/,
  210. const gss_name_t /*target_name*/,
  211. const gss_OID /*mech_type*/,
  212. OM_uint32 /*req_flags*/,
  213. OM_uint32 /*time_req*/,
  214. const gss_channel_bindings_t /*input_chan_bindings*/,
  215. const gss_buffer_t /*input_token*/,
  216. gss_OID * /*actual_mech_type*/,
  217. gss_buffer_t /*output_token*/,
  218. OM_uint32 * /*ret_flags*/,
  219. OM_uint32 * /*time_rec*/);
  220. typedef OM_uint32 (GSS_CC *t_gss_delete_sec_context)
  221. (OM_uint32 * /*minor_status*/,
  222. gss_ctx_id_t * /*context_handle*/,
  223. gss_buffer_t /*output_token*/);
  224. typedef OM_uint32 (GSS_CC *t_gss_get_mic)
  225. (OM_uint32 * /*minor_status*/,
  226. const gss_ctx_id_t /*context_handle*/,
  227. gss_qop_t /*qop_req*/,
  228. const gss_buffer_t /*message_buffer*/,
  229. gss_buffer_t /*msg_token*/);
  230. typedef OM_uint32 (GSS_CC *t_gss_verify_mic)
  231. (OM_uint32 * /*minor_status*/,
  232. const gss_ctx_id_t /*context_handle*/,
  233. const gss_buffer_t /*message_buffer*/,
  234. const gss_buffer_t /*msg_token*/,
  235. gss_qop_t * /*qop_state*/);
  236. typedef OM_uint32 (GSS_CC *t_gss_display_status)
  237. (OM_uint32 * /*minor_status*/,
  238. OM_uint32 /*status_value*/,
  239. int /*status_type*/,
  240. const gss_OID /*mech_type*/,
  241. OM_uint32 * /*message_context*/,
  242. gss_buffer_t /*status_string*/);
  243. typedef OM_uint32 (GSS_CC *t_gss_import_name)
  244. (OM_uint32 * /*minor_status*/,
  245. const gss_buffer_t /*input_name_buffer*/,
  246. const_gss_OID /*input_name_type*/,
  247. gss_name_t * /*output_name*/);
  248. typedef OM_uint32 (GSS_CC *t_gss_release_name)
  249. (OM_uint32 * /*minor_status*/,
  250. gss_name_t * /*name*/);
  251. typedef OM_uint32 (GSS_CC *t_gss_release_buffer)
  252. (OM_uint32 * /*minor_status*/,
  253. gss_buffer_t /*buffer*/);
  254. typedef OM_uint32 (GSS_CC *t_gss_acquire_cred)
  255. (OM_uint32 * /*minor_status*/,
  256. const gss_name_t /*desired_name*/,
  257. OM_uint32 /*time_req*/,
  258. const gss_OID_set /*desired_mechs*/,
  259. gss_cred_usage_t /*cred_usage*/,
  260. gss_cred_id_t * /*output_cred_handle*/,
  261. gss_OID_set * /*actual_mechs*/,
  262. OM_uint32 * /*time_rec*/);
  263. typedef OM_uint32 (GSS_CC *t_gss_inquire_cred_by_mech)
  264. (OM_uint32 * /*minor_status*/,
  265. const gss_cred_id_t /*cred_handle*/,
  266. const gss_OID /*mech_type*/,
  267. gss_name_t * /*name*/,
  268. OM_uint32 * /*initiator_lifetime*/,
  269. OM_uint32 * /*acceptor_lifetime*/,
  270. gss_cred_usage_t * /*cred_usage*/);
  271. struct gssapi_functions {
  272. t_gss_delete_sec_context delete_sec_context;
  273. t_gss_display_status display_status;
  274. t_gss_get_mic get_mic;
  275. t_gss_verify_mic verify_mic;
  276. t_gss_import_name import_name;
  277. t_gss_init_sec_context init_sec_context;
  278. t_gss_release_buffer release_buffer;
  279. t_gss_release_cred release_cred;
  280. t_gss_release_name release_name;
  281. t_gss_acquire_cred acquire_cred;
  282. t_gss_inquire_cred_by_mech inquire_cred_by_mech;
  283. };
  284. #endif /* NO_GSSAPI */
  285. #endif /* PUTTY_PGSSAPI_H */