r12804: This patch reworks the Samba4 sockets layer to use a socket_address
[amitay/samba.git] / source4 / 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 2 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, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 #define GENSEC_OID_NTLMSSP "1 3 6 1 4 1 311 2 2 10"
25 #define GENSEC_OID_SPNEGO "1 3 6 1 5 5 2"
26 #define GENSEC_OID_KERBEROS5 "1 2 840 113554 1 2 2"
27 #define GENSEC_OID_KERBEROS5_OLD "1 2 840 48018 1 2 2"
28 #define GENSEC_OID_KERBEROS5_USER2USER "1 2 840 113554 1 2 2 3"
29
30 struct gensec_security;
31 struct gensec_target {
32         const char *principal;
33         const char *hostname;
34         const char *service;
35 };
36
37 #define GENSEC_FEATURE_SESSION_KEY      0x00000001
38 #define GENSEC_FEATURE_SIGN             0x00000002
39 #define GENSEC_FEATURE_SEAL             0x00000004
40 #define GENSEC_FEATURE_DCE_STYLE        0x00000008
41 #define GENSEC_FEATURE_ASYNC_REPLIES    0x00000010
42 #define GENSEC_FEATURE_DATAGRAM_MODE    0x00000020
43
44 /* GENSEC mode */
45 enum gensec_role
46 {
47         GENSEC_SERVER,
48         GENSEC_CLIENT
49 };
50
51 struct auth_session_info;
52
53 struct gensec_security_ops {
54         const char *name;
55         const char *sasl_name;
56         uint8_t auth_type;  /* 0 if not offered on DCE-RPC */
57         const char **oid;  /* NULL if not offered by SPNEGO */
58         NTSTATUS (*client_start)(struct gensec_security *gensec_security);
59         NTSTATUS (*server_start)(struct gensec_security *gensec_security);
60         /**
61            Determine if a packet has the right 'magic' for this mechanism
62         */
63         NTSTATUS (*magic)(struct gensec_security *gensec_security, 
64                           const DATA_BLOB *first_packet);
65         NTSTATUS (*update)(struct gensec_security *gensec_security, TALLOC_CTX *out_mem_ctx,
66                            const DATA_BLOB in, DATA_BLOB *out);
67         NTSTATUS (*seal_packet)(struct gensec_security *gensec_security, TALLOC_CTX *sig_mem_ctx,
68                                 uint8_t *data, size_t length, 
69                                 const uint8_t *whole_pdu, size_t pdu_length, 
70                                 DATA_BLOB *sig);
71         NTSTATUS (*sign_packet)(struct gensec_security *gensec_security, TALLOC_CTX *sig_mem_ctx,
72                                 const uint8_t *data, size_t length, 
73                                 const uint8_t *whole_pdu, size_t pdu_length, 
74                                 DATA_BLOB *sig);
75         size_t   (*sig_size)(struct gensec_security *gensec_security, size_t data_size);
76         NTSTATUS (*check_packet)(struct gensec_security *gensec_security, TALLOC_CTX *sig_mem_ctx, 
77                                  const uint8_t *data, size_t length, 
78                                  const uint8_t *whole_pdu, size_t pdu_length, 
79                                  const DATA_BLOB *sig);
80         NTSTATUS (*unseal_packet)(struct gensec_security *gensec_security, TALLOC_CTX *sig_mem_ctx,
81                                   uint8_t *data, size_t length, 
82                                   const uint8_t *whole_pdu, size_t pdu_length, 
83                                   const DATA_BLOB *sig);
84         NTSTATUS (*wrap)(struct gensec_security *gensec_security, 
85                                   TALLOC_CTX *mem_ctx, 
86                                   const DATA_BLOB *in, 
87                                   DATA_BLOB *out); 
88         NTSTATUS (*unwrap)(struct gensec_security *gensec_security, 
89                                   TALLOC_CTX *mem_ctx, 
90                                   const DATA_BLOB *in, 
91                                   DATA_BLOB *out); 
92         NTSTATUS (*session_key)(struct gensec_security *gensec_security, DATA_BLOB *session_key);
93         NTSTATUS (*session_info)(struct gensec_security *gensec_security, 
94                                  struct auth_session_info **session_info); 
95         BOOL (*have_feature)(struct gensec_security *gensec_security,
96                                     uint32_t feature); 
97         BOOL enabled;
98 };
99         
100 struct gensec_security_ops_wrapper {
101         const struct gensec_security_ops *op;
102         const char *oid;
103 };
104
105 #define GENSEC_INTERFACE_VERSION 0
106
107 struct gensec_security {
108         const struct gensec_security_ops *ops;
109         void *private_data;
110         struct cli_credentials *credentials;
111         struct gensec_target target;
112         enum gensec_role gensec_role;
113         BOOL subcontext;
114         uint32_t want_features;
115         struct event_context *event_ctx;
116         struct socket_address *my_addr, *peer_addr;
117 };
118
119 /* this structure is used by backends to determine the size of some critical types */
120 struct gensec_critical_sizes {
121         int interface_version;
122         int sizeof_gensec_security_ops;
123         int sizeof_gensec_security;
124 };
125
126 #include "gensec_proto.h"