gssapi_mechanism_base.hpp 3.73 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 28
#include <gssapi/gssapi_generic.h>
#include <gssapi/gssapi_krb5.h>
29 30 31

#include "mechanism.hpp"
#include "options.hpp"
32

33 34 35 36 37
namespace zmq
{

    class msg_t;

38
    /// Commonalities between clients and servers are captured here.
Mike Gatny's avatar
Mike Gatny committed
39 40 41
    /// 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).
42 43
    class gssapi_mechanism_base_t:
        public mechanism_t
44 45
    {
    public:
46
        gssapi_mechanism_base_t (const options_t &options_);
47 48 49
        virtual ~gssapi_mechanism_base_t () = 0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

}
Chris Laws's avatar
Chris Laws committed
117

118
#endif
119

Chris Laws's avatar
Chris Laws committed
120
#endif