bda740cc86229e70998f9f1f23455ea64e5742c0
[jelmer/samba4-debian.git] / source / auth / gensec / gensec.h
1 /* 
2    Unix SMB/CIFS implementation.
3  
4    Generic Authentication Interface
5
6    Copyright (C) Andrew Tridgell 2003
7    Copyright (C) Andrew Bartlett <abartlet@samba.org> 2004-2005
8    
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 3 of the License, or
12    (at your option) any later version.
13    
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18    
19    You should have received a copy of the GNU General Public License
20    along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 #ifndef __GENSEC_H__
24 #define __GENSEC_H__
25
26 #define GENSEC_OID_NTLMSSP "1.3.6.1.4.1.311.2.2.10"
27 #define GENSEC_OID_SPNEGO "1.3.6.1.5.5.2"
28 #define GENSEC_OID_KERBEROS5 "1.2.840.113554.1.2.2"
29 #define GENSEC_OID_KERBEROS5_OLD "1.2.840.48018.1.2.2"
30 #define GENSEC_OID_KERBEROS5_USER2USER "1.2.840.113554.1.2.2.3"
31
32 enum gensec_priority {
33         GENSEC_SPNEGO = 90,
34         GENSEC_GSSAPI = 80,
35         GENSEC_KRB5 = 70,
36         GENSEC_SCHANNEL = 60,
37         GENSEC_NTLMSSP = 50,
38         GENSEC_SASL = 20,
39         GENSEC_OTHER = 0
40 };
41
42 struct gensec_security;
43 struct gensec_target {
44         const char *principal;
45         const char *hostname;
46         const char *service;
47 };
48
49 #define GENSEC_FEATURE_SESSION_KEY      0x00000001
50 #define GENSEC_FEATURE_SIGN             0x00000002
51 #define GENSEC_FEATURE_SEAL             0x00000004
52 #define GENSEC_FEATURE_DCE_STYLE        0x00000008
53 #define GENSEC_FEATURE_ASYNC_REPLIES    0x00000010
54 #define GENSEC_FEATURE_DATAGRAM_MODE    0x00000020
55
56 /* GENSEC mode */
57 enum gensec_role
58 {
59         GENSEC_SERVER,
60         GENSEC_CLIENT
61 };
62
63 struct auth_session_info;
64 struct cli_credentials;
65
66 struct gensec_update_request {
67         struct gensec_security *gensec_security;
68         void *private_data;
69         DATA_BLOB in;
70         DATA_BLOB out;
71         NTSTATUS status;
72         struct {
73                 void (*fn)(struct gensec_update_request *req, void *private_data);
74                 void *private_data;
75         } callback;
76 };
77
78 struct gensec_security_ops {
79         const char *name;
80         const char *sasl_name;
81         uint8_t auth_type;  /* 0 if not offered on DCE-RPC */
82         const char **oid;  /* NULL if not offered by SPNEGO */
83         NTSTATUS (*client_start)(struct gensec_security *gensec_security);
84         NTSTATUS (*server_start)(struct gensec_security *gensec_security);
85         /**
86            Determine if a packet has the right 'magic' for this mechanism
87         */
88         NTSTATUS (*magic)(struct gensec_security *gensec_security, 
89                           const DATA_BLOB *first_packet);
90         NTSTATUS (*update)(struct gensec_security *gensec_security, TALLOC_CTX *out_mem_ctx,
91                            const DATA_BLOB in, DATA_BLOB *out);
92         NTSTATUS (*seal_packet)(struct gensec_security *gensec_security, TALLOC_CTX *sig_mem_ctx,
93                                 uint8_t *data, size_t length, 
94                                 const uint8_t *whole_pdu, size_t pdu_length, 
95                                 DATA_BLOB *sig);
96         NTSTATUS (*sign_packet)(struct gensec_security *gensec_security, TALLOC_CTX *sig_mem_ctx,
97                                 const uint8_t *data, size_t length, 
98                                 const uint8_t *whole_pdu, size_t pdu_length, 
99                                 DATA_BLOB *sig);
100         size_t   (*sig_size)(struct gensec_security *gensec_security, size_t data_size);
101         size_t   (*max_input_size)(struct gensec_security *gensec_security);
102         size_t   (*max_wrapped_size)(struct gensec_security *gensec_security);
103         NTSTATUS (*check_packet)(struct gensec_security *gensec_security, TALLOC_CTX *sig_mem_ctx, 
104                                  const uint8_t *data, size_t length, 
105                                  const uint8_t *whole_pdu, size_t pdu_length, 
106                                  const DATA_BLOB *sig);
107         NTSTATUS (*unseal_packet)(struct gensec_security *gensec_security, TALLOC_CTX *sig_mem_ctx,
108                                   uint8_t *data, size_t length, 
109                                   const uint8_t *whole_pdu, size_t pdu_length, 
110                                   const DATA_BLOB *sig);
111         NTSTATUS (*wrap)(struct gensec_security *gensec_security, 
112                                   TALLOC_CTX *mem_ctx, 
113                                   const DATA_BLOB *in, 
114                                   DATA_BLOB *out); 
115         NTSTATUS (*unwrap)(struct gensec_security *gensec_security, 
116                            TALLOC_CTX *mem_ctx, 
117                            const DATA_BLOB *in, 
118                            DATA_BLOB *out); 
119         NTSTATUS (*wrap_packets)(struct gensec_security *gensec_security, 
120                                  TALLOC_CTX *mem_ctx, 
121                                  const DATA_BLOB *in, 
122                                  DATA_BLOB *out,
123                                  size_t *len_processed); 
124         NTSTATUS (*unwrap_packets)(struct gensec_security *gensec_security, 
125                                    TALLOC_CTX *mem_ctx, 
126                                    const DATA_BLOB *in, 
127                                    DATA_BLOB *out,
128                                    size_t *len_processed); 
129         NTSTATUS (*packet_full_request)(struct gensec_security *gensec_security,
130                                         DATA_BLOB blob, size_t *size);
131         NTSTATUS (*session_key)(struct gensec_security *gensec_security, DATA_BLOB *session_key);
132         NTSTATUS (*session_info)(struct gensec_security *gensec_security, 
133                                  struct auth_session_info **session_info); 
134         bool (*have_feature)(struct gensec_security *gensec_security,
135                                     uint32_t feature); 
136         bool enabled;
137         bool kerberos;
138         enum gensec_priority priority;
139 };
140         
141 struct gensec_security_ops_wrapper {
142         const struct gensec_security_ops *op;
143         const char *oid;
144 };
145
146 #define GENSEC_INTERFACE_VERSION 0
147
148 struct gensec_security {
149         const struct gensec_security_ops *ops;
150         void *private_data;
151         struct cli_credentials *credentials;
152         struct gensec_target target;
153         enum gensec_role gensec_role;
154         bool subcontext;
155         uint32_t want_features;
156         struct event_context *event_ctx;
157         struct messaging_context *msg_ctx; /* only valid as server */
158         struct socket_address *my_addr, *peer_addr;
159 };
160
161 /* this structure is used by backends to determine the size of some critical types */
162 struct gensec_critical_sizes {
163         int interface_version;
164         int sizeof_gensec_security_ops;
165         int sizeof_gensec_security;
166 };
167
168 #include "auth/gensec/gensec_proto.h"
169
170 #endif /* __GENSEC_H__ */