gssapi_mechanism_base.hpp 3.76 KB
Newer Older
1
/*
2
    Copyright (c) 2007-2014 Contributors as noted in the AUTHORS file
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

    This file is part of 0MQ.

    0MQ is free software; you can redistribute it and/or modify it under
    the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    0MQ is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __ZMQ_GSSAPI_MECHANISM_BASE_HPP_INCLUDED__
#define __ZMQ_GSSAPI_MECHANISM_BASE_HPP_INCLUDED__

Chris Laws's avatar
Chris Laws committed
23 24 25 26
#include "platform.hpp"

#ifdef HAVE_LIBGSSAPI_KRB5

27
#ifndef ZMQ_HAVE_FREEBSD
28
#include <gssapi/gssapi_generic.h>
29
#endif
30
#include <gssapi/gssapi_krb5.h>
31 32 33

#include "mechanism.hpp"
#include "options.hpp"
34

35 36 37 38 39
namespace zmq
{

    class msg_t;

40
    /// Commonalities between clients and servers are captured here.
Mike Gatny's avatar
Mike Gatny committed
41 42 43
    /// For example, clients and servers both need to produce and
    /// process context-level GSSAPI tokens (via INITIATE commands)
    /// and per-message GSSAPI tokens (via MESSAGE commands).
44 45
    class gssapi_mechanism_base_t:
        public mechanism_t
46 47
    {
    public:
48
        gssapi_mechanism_base_t (const options_t &options_);
49 50 51
        virtual ~gssapi_mechanism_base_t () = 0;

    protected:
Mike Gatny's avatar
Mike Gatny committed
52 53
        //  Produce a context-level GSSAPI token (INITIATE command)
        //  during security context initialization.
54
        int produce_initiate (msg_t *msg_, void *data_, size_t data_len_);
Chris Laws's avatar
Chris Laws committed
55

Mike Gatny's avatar
Mike Gatny committed
56 57
        //  Process a context-level GSSAPI token (INITIATE command)
        //  during security context initialization.
58
        int process_initiate (msg_t *msg_, void **data_, size_t &data_len_);
59 60

        // Produce a metadata ready msg (READY) to conclude handshake
61
        int produce_ready (msg_t *msg_);
62 63 64

        // Process a metadata ready msg (READY)
        int process_ready (msg_t *msg_);
Chris Laws's avatar
Chris Laws committed
65

Mike Gatny's avatar
Mike Gatny committed
66 67
        //  Encode a per-message GSSAPI token (MESSAGE command) using
        //  the established security context.
68
        int encode_message (msg_t *msg_);
Chris Laws's avatar
Chris Laws committed
69

Mike Gatny's avatar
Mike Gatny committed
70 71
        //  Decode a per-message GSSAPI token (MESSAGE command) using
        //  the  established security context.
72
        int decode_message (msg_t *msg_);
Chris Laws's avatar
Chris Laws committed
73

Mike Gatny's avatar
Mike Gatny committed
74 75
        //  Acquire security context credentials from the
        //  underlying mechanism.
Chris Busbey's avatar
Chris Busbey committed
76
        static int acquire_credentials (char * principal_name_,
77
                                        gss_cred_id_t * cred_);
78 79

    protected:
Mike Gatny's avatar
Mike Gatny committed
80
        //  Opaque GSSAPI token for outgoing data
81
        gss_buffer_desc send_tok;
Chris Laws's avatar
Chris Laws committed
82

Mike Gatny's avatar
Mike Gatny committed
83
        //  Opaque GSSAPI token for incoming data
84
        gss_buffer_desc recv_tok;
Chris Laws's avatar
Chris Laws committed
85

Chris Busbey's avatar
Chris Busbey committed
86
        //  Opaque GSSAPI representation of principal
87
        gss_name_t target_name;
Chris Laws's avatar
Chris Laws committed
88

89
        //  Human-readable principal name
Chris Busbey's avatar
Chris Busbey committed
90
        char * principal_name;
91

Mike Gatny's avatar
Mike Gatny committed
92
        //  Status code returned by GSSAPI functions
93
        OM_uint32 maj_stat;
94

Mike Gatny's avatar
Mike Gatny committed
95
        //  Status code returned by the underlying mechanism
96
        OM_uint32 min_stat;
97

Mike Gatny's avatar
Mike Gatny committed
98 99
        //  Status code returned by the underlying mechanism
        //  during context initialization
100
        OM_uint32 init_sec_min_stat;
101

Mike Gatny's avatar
Mike Gatny committed
102
        //  Flags returned by GSSAPI (ignored)
103
        OM_uint32 ret_flags;
Chris Laws's avatar
Chris Laws committed
104

Mike Gatny's avatar
Mike Gatny committed
105
        //  Flags returned by GSSAPI (ignored)
106
        OM_uint32 gss_flags;
Chris Laws's avatar
Chris Laws committed
107

Mike Gatny's avatar
Mike Gatny committed
108
        //  Credentials used to establish security context
109
        gss_cred_id_t cred;
110

Mike Gatny's avatar
Mike Gatny committed
111
        //  Opaque GSSAPI representation of the security context
112
        gss_ctx_id_t context;
113 114 115

        //  If true, use gss to encrypt messages. If false, only utilize gss for auth.
        bool do_encryption;
116 117 118
    };

}
Chris Laws's avatar
Chris Laws committed
119

120
#endif
121

Chris Laws's avatar
Chris Laws committed
122
#endif