r1022: add the session_info() call to the dcerpc server auth backends
[nivanova/samba-autobuild/.git] / source4 / rpc_server / dcesrv_crypto.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    server side dcerpc authentication code - crypto support
5
6    Copyright (C) Andrew Tridgell 2004
7    Copyright (C) Stefan (metze) Metzmacher 2004
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 /*
25   this provides a crypto interface to the various backends (such as
26   NTLMSSP and SCHANNEL) for the rpc server code
27 */
28
29 #include "includes.h"
30
31 /*
32   startup the cryptographic side of an authenticated dcerpc server
33 */
34 NTSTATUS dcesrv_crypto_select_type(struct dcesrv_connection *dce_conn,
35                                struct dcesrv_auth *auth)
36 {
37         if (auth->auth_info->auth_level != DCERPC_AUTH_LEVEL_INTEGRITY &&
38             auth->auth_info->auth_level != DCERPC_AUTH_LEVEL_PRIVACY) {
39                 DEBUG(2,("auth_level %d not supported in dcesrv auth\n", 
40                          auth->auth_info->auth_level));
41                 return NT_STATUS_INVALID_PARAMETER;
42         }
43
44         if (auth->crypto_ctx.ops != NULL) {
45                 /* TODO:
46                  * this this function should not be called
47                  * twice per dcesrv_connection!
48                  * 
49                  * so we need to find out the right
50                  * dcerpc error to return
51                  */
52         }
53
54         /*
55          * TODO:
56          * maybe a dcesrv_crypto_find_backend_by_type() whould be better here
57          * to make thinks more generic
58          */
59         auth->crypto_ctx.ops = dcesrv_crypto_backend_bytype(auth->auth_info->auth_type);
60         if (auth->crypto_ctx.ops == NULL) {
61                 DEBUG(2,("dcesrv auth_type %d not supported\n", auth->auth_info->auth_type));
62                 return NT_STATUS_INVALID_PARAMETER;
63         }
64
65         return NT_STATUS_OK;
66 }
67
68 /*
69   start crypto state
70 */
71 NTSTATUS dcesrv_crypto_start(struct dcesrv_auth *auth) 
72 {
73         return auth->crypto_ctx.ops->start(auth);
74 }
75
76 /*
77   update crypto state
78 */
79 NTSTATUS dcesrv_crypto_update(struct dcesrv_auth *auth, 
80                               TALLOC_CTX *out_mem_ctx, 
81                               const DATA_BLOB in, DATA_BLOB *out) 
82 {
83         return auth->crypto_ctx.ops->update(auth, out_mem_ctx, in, out);
84 }
85
86 /*
87   get auth_session_info state
88 */
89 NTSTATUS dcesrv_crypto_session_info(struct dcesrv_auth *auth, struct auth_session_info **session_info) 
90 {
91         return auth->crypto_ctx.ops->session_info(auth, session_info);
92 }
93
94 /*
95   seal a packet
96 */
97 NTSTATUS dcesrv_crypto_seal(struct dcesrv_auth *auth, TALLOC_CTX *sig_mem_ctx,
98                                 uint8_t *data, size_t length, DATA_BLOB *sig)
99 {
100         return auth->crypto_ctx.ops->seal(auth, sig_mem_ctx, data, length, sig);
101 }
102
103 /*
104   sign a packet
105 */
106 NTSTATUS dcesrv_crypto_sign(struct dcesrv_auth *auth, TALLOC_CTX *sig_mem_ctx,
107                                 const uint8_t *data, size_t length, DATA_BLOB *sig) 
108 {
109         return auth->crypto_ctx.ops->sign(auth, sig_mem_ctx, data, length, sig);
110 }
111
112 /*
113   check a packet signature
114 */
115 NTSTATUS dcesrv_crypto_check_sig(struct dcesrv_auth *auth, TALLOC_CTX *sig_mem_ctx,
116                                 const uint8_t *data, size_t length, const DATA_BLOB *sig)
117 {
118         return auth->crypto_ctx.ops->check_sig(auth, sig_mem_ctx, data, length, sig);
119 }
120
121 /*
122   unseal a packet
123 */
124 NTSTATUS dcesrv_crypto_unseal(struct dcesrv_auth *auth, TALLOC_CTX *sig_mem_ctx,
125                                 uint8_t *data, size_t length, DATA_BLOB *sig)
126 {
127         return auth->crypto_ctx.ops->unseal(auth, sig_mem_ctx, data, length, sig);
128 }
129
130 /*
131   end crypto state
132 */
133 void dcesrv_crypto_end(struct dcesrv_auth *auth) 
134 {
135         auth->crypto_ctx.ops->end(auth);
136 }
137
138 const struct dcesrv_crypto_ops *dcesrv_crypto_backend_bytype(uint8_t auth_type)
139 {
140         switch (auth_type) {
141 #if 0
142                 case DCERPC_AUTH_TYPE_SCHANNEL:
143                         return dcesrv_crypto_schannel_get_ops();
144 #endif
145                 case DCERPC_AUTH_TYPE_NTLMSSP:
146                         return dcesrv_crypto_ntlmssp_get_ops();
147         }
148
149         return NULL;
150 }