gssapi_mechanism_base.hpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
  3. This file is part of libzmq, the ZeroMQ core engine in C++.
  4. libzmq is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU Lesser General Public License (LGPL) as published
  6. by the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. As a special exception, the Contributors give you permission to link
  9. this library with independent modules to produce an executable,
  10. regardless of the license terms of these independent modules, and to
  11. copy and distribute the resulting executable under terms of your choice,
  12. provided that you also meet, for each linked independent module, the
  13. terms and conditions of the license of that module. An independent
  14. module is a module which is not derived from or based on this library.
  15. If you modify this library, you must extend this exception to your
  16. version of the library.
  17. libzmq is distributed in the hope that it will be useful, but WITHOUT
  18. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  19. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  20. License for more details.
  21. You should have received a copy of the GNU Lesser General Public License
  22. along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. #ifndef __ZMQ_GSSAPI_MECHANISM_BASE_HPP_INCLUDED__
  25. #define __ZMQ_GSSAPI_MECHANISM_BASE_HPP_INCLUDED__
  26. #ifdef HAVE_LIBGSSAPI_KRB5
  27. #if HAVE_GSSAPI_GSSAPI_GENERIC_H
  28. #include <gssapi/gssapi_generic.h>
  29. #endif
  30. #include <gssapi/gssapi_krb5.h>
  31. #include "mechanism_base.hpp"
  32. #include "options.hpp"
  33. namespace zmq
  34. {
  35. class msg_t;
  36. /// Commonalities between clients and servers are captured here.
  37. /// For example, clients and servers both need to produce and
  38. /// process context-level GSSAPI tokens (via INITIATE commands)
  39. /// and per-message GSSAPI tokens (via MESSAGE commands).
  40. class gssapi_mechanism_base_t : public virtual mechanism_base_t
  41. {
  42. public:
  43. gssapi_mechanism_base_t (session_base_t *session_,
  44. const options_t &options_);
  45. ~gssapi_mechanism_base_t () ZMQ_OVERRIDE = 0;
  46. protected:
  47. // Produce a context-level GSSAPI token (INITIATE command)
  48. // during security context initialization.
  49. int produce_initiate (msg_t *msg_, void *data_, size_t data_len_);
  50. // Process a context-level GSSAPI token (INITIATE command)
  51. // during security context initialization.
  52. int process_initiate (msg_t *msg_, void **data_, size_t &data_len_);
  53. // Produce a metadata ready msg (READY) to conclude handshake
  54. int produce_ready (msg_t *msg_);
  55. // Process a metadata ready msg (READY)
  56. int process_ready (msg_t *msg_);
  57. // Encode a per-message GSSAPI token (MESSAGE command) using
  58. // the established security context.
  59. int encode_message (msg_t *msg_);
  60. // Decode a per-message GSSAPI token (MESSAGE command) using
  61. // the established security context.
  62. int decode_message (msg_t *msg_);
  63. // Convert ZMQ_GSSAPI_NT values to GSSAPI name_type
  64. static const gss_OID convert_nametype (int zmq_name_type_);
  65. // Acquire security context credentials from the
  66. // underlying mechanism.
  67. static int acquire_credentials (char *principal_name_,
  68. gss_cred_id_t *cred_,
  69. gss_OID name_type_);
  70. protected:
  71. // Opaque GSSAPI token for outgoing data
  72. gss_buffer_desc send_tok;
  73. // Opaque GSSAPI token for incoming data
  74. gss_buffer_desc recv_tok;
  75. // Opaque GSSAPI representation of principal
  76. gss_name_t target_name;
  77. // Human-readable principal name
  78. char *principal_name;
  79. // Status code returned by GSSAPI functions
  80. OM_uint32 maj_stat;
  81. // Status code returned by the underlying mechanism
  82. OM_uint32 min_stat;
  83. // Status code returned by the underlying mechanism
  84. // during context initialization
  85. OM_uint32 init_sec_min_stat;
  86. // Flags returned by GSSAPI (ignored)
  87. OM_uint32 ret_flags;
  88. // Flags returned by GSSAPI (ignored)
  89. OM_uint32 gss_flags;
  90. // Credentials used to establish security context
  91. gss_cred_id_t cred;
  92. // Opaque GSSAPI representation of the security context
  93. gss_ctx_id_t context;
  94. // If true, use gss to encrypt messages. If false, only utilize gss for auth.
  95. bool do_encryption;
  96. };
  97. }
  98. #endif
  99. #endif