s3-librpc Remove layer around struct gensec_security
[gd/samba-autobuild/.git] / source3 / librpc / crypto / spnego.h
1 /*
2  *  SPNEGO Encapsulation
3  *  RPC Pipe client routines
4  *  Copyright (C) Simo Sorce 2010.
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 3 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #ifndef _CLI_SPNEGO_H_
21 #define _CLI_SPENGO_H_
22
23 enum spnego_mech {
24         SPNEGO_NONE = 0,
25         SPNEGO_KRB5,
26         SPNEGO_NTLMSSP
27 };
28
29 struct spnego_context {
30         enum spnego_mech mech;
31
32         struct gensec_security *gensec_security;
33
34         char *oid_list[ASN1_MAX_OIDS];
35         char *mech_oid;
36
37         enum {
38                 SPNEGO_CONV_INIT = 0,
39                 SPNEGO_CONV_NEGO,
40                 SPNEGO_CONV_AUTH_MORE,
41                 SPNEGO_CONV_AUTH_CONFIRM,
42                 SPNEGO_CONV_AUTH_DONE
43         } state;
44
45         bool do_sign;
46         bool do_seal;
47         bool is_dcerpc;
48
49         struct tsocket_address *remote_address;
50
51         bool more_processing; /* Current mech state requires more processing */
52 };
53
54 NTSTATUS spnego_generic_init_client(TALLOC_CTX *mem_ctx,
55                                     const char *oid,
56                                     bool do_sign, bool do_seal,
57                                     bool is_dcerpc,
58                                     const char *server,
59                                     const char *target_service,
60                                     const char *domain,
61                                     const char *username,
62                                     const char *password,
63                                     struct spnego_context **spnego_ctx);
64
65 NTSTATUS spnego_get_client_auth_token(TALLOC_CTX *mem_ctx,
66                                       struct spnego_context *sp_ctx,
67                                       DATA_BLOB *spnego_in,
68                                       DATA_BLOB *spnego_out);
69
70 bool spnego_require_more_processing(struct spnego_context *sp_ctx);
71
72 NTSTATUS spnego_get_negotiated_mech(struct spnego_context *sp_ctx,
73                                     struct gensec_security **auth_context);
74
75 DATA_BLOB spnego_get_session_key(TALLOC_CTX *mem_ctx,
76                                  struct spnego_context *sp_ctx);
77
78 NTSTATUS spnego_sign(TALLOC_CTX *mem_ctx,
79                         struct spnego_context *sp_ctx,
80                         DATA_BLOB *data, DATA_BLOB *full_data,
81                         DATA_BLOB *signature);
82 NTSTATUS spnego_sigcheck(TALLOC_CTX *mem_ctx,
83                          struct spnego_context *sp_ctx,
84                          DATA_BLOB *data, DATA_BLOB *full_data,
85                          DATA_BLOB *signature);
86 NTSTATUS spnego_seal(TALLOC_CTX *mem_ctx,
87                         struct spnego_context *sp_ctx,
88                         DATA_BLOB *data, DATA_BLOB *full_data,
89                         DATA_BLOB *signature);
90 NTSTATUS spnego_unseal(TALLOC_CTX *mem_ctx,
91                         struct spnego_context *sp_ctx,
92                         DATA_BLOB *data, DATA_BLOB *full_data,
93                         DATA_BLOB *signature);
94
95 #endif /* _CLI_SPENGO_H_ */