2 * GSSAPI Security Extensions
3 * RPC Pipe client and server routines
4 * Copyright (C) Simo Sorce 2010.
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.
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.
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/>.
20 /* We support only GSSAPI/KRB5 here */
25 #if defined(HAVE_KRB5) \
26 && defined(HAVE_GSSAPI_GSSAPI_EXT_H) \
27 && defined(HAVE_GSS_WRAP_IOV) \
28 && defined(HAVE_GSS_GET_NAME_ATTRIBUTE)
33 #include <gssapi/gssapi.h>
34 #include <gssapi/gssapi_krb5.h>
35 #include <gssapi/gssapi_ext.h>
37 #ifndef GSS_KRB5_INQ_SSPI_SESSION_KEY_OID
38 #define GSS_KRB5_INQ_SSPI_SESSION_KEY_OID_LENGTH 11
39 #define GSS_KRB5_INQ_SSPI_SESSION_KEY_OID "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02\x05\x05"
42 gss_OID_desc gse_sesskey_inq_oid
= {
43 GSS_KRB5_INQ_SSPI_SESSION_KEY_OID_LENGTH
,
44 (void *)GSS_KRB5_INQ_SSPI_SESSION_KEY_OID
47 #ifndef GSS_KRB5_SESSION_KEY_ENCTYPE_OID
48 #define GSS_KRB5_SESSION_KEY_ENCTYPE_OID_LENGTH 10
49 #define GSS_KRB5_SESSION_KEY_ENCTYPE_OID "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02\x04"
52 gss_OID_desc gse_sesskeytype_oid
= {
53 GSS_KRB5_SESSION_KEY_ENCTYPE_OID_LENGTH
,
54 (void *)GSS_KRB5_SESSION_KEY_ENCTYPE_OID
57 #define GSE_EXTRACT_RELEVANT_AUTHZ_DATA_OID_LENGTH 12
58 /* EXTRACTION OID AUTHZ ID */
59 #define GSE_EXTRACT_RELEVANT_AUTHZ_DATA_OID "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02\x05\x0a" "\x01"
61 gss_OID_desc gse_authz_data_oid
= {
62 GSE_EXTRACT_RELEVANT_AUTHZ_DATA_OID_LENGTH
,
63 (void *)GSE_EXTRACT_RELEVANT_AUTHZ_DATA_OID
66 #ifndef GSS_KRB5_EXTRACT_AUTHTIME_FROM_SEC_CONTEXT_OID
67 #define GSS_KRB5_EXTRACT_AUTHTIME_FROM_SEC_CONTEXT_OID_LENGTH 11
68 #define GSS_KRB5_EXTRACT_AUTHTIME_FROM_SEC_CONTEXT_OID "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02\x05\x0c"
71 gss_OID_desc gse_authtime_oid
= {
72 GSS_KRB5_EXTRACT_AUTHTIME_FROM_SEC_CONTEXT_OID_LENGTH
,
73 (void *)GSS_KRB5_EXTRACT_AUTHTIME_FROM_SEC_CONTEXT_OID
76 static char *gse_errstr(TALLOC_CTX
*mem_ctx
, OM_uint32 maj
, OM_uint32 min
);
85 gss_OID_desc gss_mech
;
86 OM_uint32 gss_c_flags
;
88 gss_name_t server_name
;
92 gss_cred_id_t delegated_creds
;
93 gss_name_t client_name
;
99 /* free non talloc dependent contexts */
100 static int gse_context_destructor(void *ptr
)
102 struct gse_context
*gse_ctx
;
103 OM_uint32 gss_min
, gss_maj
;
105 gse_ctx
= talloc_get_type_abort(ptr
, struct gse_context
);
106 if (gse_ctx
->k5ctx
) {
107 if (gse_ctx
->ccache
) {
108 krb5_cc_close(gse_ctx
->k5ctx
, gse_ctx
->ccache
);
109 gse_ctx
->ccache
= NULL
;
111 if (gse_ctx
->keytab
) {
112 krb5_kt_close(gse_ctx
->k5ctx
, gse_ctx
->keytab
);
113 gse_ctx
->keytab
= NULL
;
115 krb5_free_context(gse_ctx
->k5ctx
);
116 gse_ctx
->k5ctx
= NULL
;
118 if (gse_ctx
->gss_ctx
!= GSS_C_NO_CONTEXT
) {
119 gss_maj
= gss_delete_sec_context(&gss_min
,
123 if (gse_ctx
->server_name
) {
124 gss_maj
= gss_release_name(&gss_min
,
125 &gse_ctx
->server_name
);
127 if (gse_ctx
->client_name
) {
128 gss_maj
= gss_release_name(&gss_min
,
129 &gse_ctx
->client_name
);
131 if (gse_ctx
->creds
) {
132 gss_maj
= gss_release_cred(&gss_min
,
135 if (gse_ctx
->delegated_creds
) {
136 gss_maj
= gss_release_cred(&gss_min
,
137 &gse_ctx
->delegated_creds
);
139 if (gse_ctx
->ret_mech
) {
140 gss_maj
= gss_release_oid(&gss_min
,
146 static NTSTATUS
gse_context_init(TALLOC_CTX
*mem_ctx
,
147 bool do_sign
, bool do_seal
,
148 const char *ccache_name
,
149 uint32_t add_gss_c_flags
,
150 struct gse_context
**_gse_ctx
)
152 struct gse_context
*gse_ctx
;
153 krb5_error_code k5ret
;
156 gse_ctx
= talloc_zero(mem_ctx
, struct gse_context
);
158 return NT_STATUS_NO_MEMORY
;
160 talloc_set_destructor((TALLOC_CTX
*)gse_ctx
, gse_context_destructor
);
162 memcpy(&gse_ctx
->gss_mech
, gss_mech_krb5
, sizeof(gss_OID_desc
));
164 gse_ctx
->gss_c_flags
= GSS_C_MUTUAL_FLAG
|
166 GSS_C_DELEG_POLICY_FLAG
|
170 gse_ctx
->gss_c_flags
|= GSS_C_INTEG_FLAG
;
173 gse_ctx
->gss_c_flags
|= GSS_C_CONF_FLAG
;
176 gse_ctx
->gss_c_flags
|= add_gss_c_flags
;
178 /* Initialize Kerberos Context */
179 initialize_krb5_error_table();
181 k5ret
= krb5_init_context(&gse_ctx
->k5ctx
);
183 DEBUG(0, ("Failed to initialize kerberos context! (%s)\n",
184 error_message(k5ret
)));
185 status
= NT_STATUS_INTERNAL_ERROR
;
190 ccache_name
= krb5_cc_default_name(gse_ctx
->k5ctx
);
192 k5ret
= krb5_cc_resolve(gse_ctx
->k5ctx
, ccache_name
,
195 DEBUG(1, ("Failed to resolve credential cache! (%s)\n",
196 error_message(k5ret
)));
197 status
= NT_STATUS_INTERNAL_ERROR
;
201 /* TODO: Should we enforce a enc_types list ?
202 ret = krb5_set_default_tgs_ktypes(gse_ctx->k5ctx, enc_types);
209 TALLOC_FREE(gse_ctx
);
213 NTSTATUS
gse_init_client(TALLOC_CTX
*mem_ctx
,
214 bool do_sign
, bool do_seal
,
215 const char *ccache_name
,
218 const char *username
,
219 const char *password
,
220 uint32_t add_gss_c_flags
,
221 struct gse_context
**_gse_ctx
)
223 struct gse_context
*gse_ctx
;
224 OM_uint32 gss_maj
, gss_min
;
225 gss_buffer_desc name_buffer
= {0, NULL
};
226 gss_OID_set_desc mech_set
;
229 if (!server
|| !service
) {
230 return NT_STATUS_INVALID_PARAMETER
;
233 status
= gse_context_init(mem_ctx
, do_sign
, do_seal
,
234 ccache_name
, add_gss_c_flags
,
236 if (!NT_STATUS_IS_OK(status
)) {
237 return NT_STATUS_NO_MEMORY
;
240 name_buffer
.value
= talloc_asprintf(gse_ctx
,
241 "%s@%s", service
, server
);
242 if (!name_buffer
.value
) {
243 status
= NT_STATUS_NO_MEMORY
;
246 name_buffer
.length
= strlen((char *)name_buffer
.value
);
247 gss_maj
= gss_import_name(&gss_min
, &name_buffer
,
248 GSS_C_NT_HOSTBASED_SERVICE
,
249 &gse_ctx
->server_name
);
251 DEBUG(0, ("gss_import_name failed for %s, with [%s]\n",
252 (char *)name_buffer
.value
,
253 gse_errstr(gse_ctx
, gss_maj
, gss_min
)));
254 status
= NT_STATUS_INTERNAL_ERROR
;
258 /* TODO: get krb5 ticket using username/password, if no valid
259 * one already available in ccache */
262 mech_set
.elements
= &gse_ctx
->gss_mech
;
264 gss_maj
= gss_acquire_cred(&gss_min
,
272 DEBUG(0, ("gss_acquire_creds failed for %s, with [%s]\n",
273 (char *)name_buffer
.value
,
274 gse_errstr(gse_ctx
, gss_maj
, gss_min
)));
275 status
= NT_STATUS_INTERNAL_ERROR
;
280 TALLOC_FREE(name_buffer
.value
);
284 TALLOC_FREE(name_buffer
.value
);
285 TALLOC_FREE(gse_ctx
);
289 NTSTATUS
gse_get_client_auth_token(TALLOC_CTX
*mem_ctx
,
290 struct gse_context
*gse_ctx
,
292 DATA_BLOB
*token_out
)
294 OM_uint32 gss_maj
, gss_min
;
295 gss_buffer_desc in_data
;
296 gss_buffer_desc out_data
;
297 DATA_BLOB blob
= data_blob_null
;
300 in_data
.value
= token_in
->data
;
301 in_data
.length
= token_in
->length
;
303 gss_maj
= gss_init_sec_context(&gss_min
,
306 gse_ctx
->server_name
,
308 gse_ctx
->gss_c_flags
,
309 0, GSS_C_NO_CHANNEL_BINDINGS
,
310 &in_data
, NULL
, &out_data
,
314 /* we are done with it */
315 gse_ctx
->more_processing
= false;
316 status
= NT_STATUS_OK
;
318 case GSS_S_CONTINUE_NEEDED
:
319 /* we will need a third leg */
320 gse_ctx
->more_processing
= true;
321 /* status = NT_STATUS_MORE_PROCESSING_REQUIRED; */
322 status
= NT_STATUS_OK
;
325 DEBUG(0, ("gss_init_sec_context failed with [%s]\n",
326 gse_errstr(talloc_tos(), gss_maj
, gss_min
)));
327 status
= NT_STATUS_INTERNAL_ERROR
;
331 blob
= data_blob_talloc(mem_ctx
, out_data
.value
, out_data
.length
);
333 status
= NT_STATUS_NO_MEMORY
;
336 gss_maj
= gss_release_buffer(&gss_min
, &out_data
);
343 NTSTATUS
gse_init_server(TALLOC_CTX
*mem_ctx
,
344 bool do_sign
, bool do_seal
,
345 uint32_t add_gss_c_flags
,
346 const char *keytab_name
,
347 struct gse_context
**_gse_ctx
)
349 struct gse_context
*gse_ctx
;
350 OM_uint32 gss_maj
, gss_min
;
351 gss_OID_set_desc mech_set
;
356 status
= gse_context_init(mem_ctx
, do_sign
, do_seal
,
357 NULL
, add_gss_c_flags
, &gse_ctx
);
358 if (!NT_STATUS_IS_OK(status
)) {
359 return NT_STATUS_NO_MEMORY
;
363 ret
= gse_krb5_get_server_keytab(gse_ctx
->k5ctx
,
366 status
= NT_STATUS_INTERNAL_ERROR
;
369 ret
= smb_krb5_keytab_name(gse_ctx
, gse_ctx
->k5ctx
,
370 gse_ctx
->keytab
, &ktname
);
372 status
= NT_STATUS_INTERNAL_ERROR
;
376 ktname
= keytab_name
;
380 * This call sets the default keytab for the whole server, not
381 * just for this context. Need to find a way that does not alter
382 * the state of the whole server ... */
383 ret
= gsskrb5_register_acceptor_identity(ktname
);
385 status
= NT_STATUS_INTERNAL_ERROR
;
390 mech_set
.elements
= &gse_ctx
->gss_mech
;
392 gss_maj
= gss_acquire_cred(&gss_min
,
400 DEBUG(0, ("gss_acquire_creds failed with [%s]\n",
401 gse_errstr(gse_ctx
, gss_maj
, gss_min
)));
402 status
= NT_STATUS_INTERNAL_ERROR
;
406 status
= NT_STATUS_OK
;
409 if (!NT_STATUS_IS_OK(status
)) {
410 TALLOC_FREE(gse_ctx
);
417 NTSTATUS
gse_get_server_auth_token(TALLOC_CTX
*mem_ctx
,
418 struct gse_context
*gse_ctx
,
420 DATA_BLOB
*token_out
)
422 OM_uint32 gss_maj
, gss_min
;
423 gss_buffer_desc in_data
;
424 gss_buffer_desc out_data
;
425 DATA_BLOB blob
= data_blob_null
;
428 in_data
.value
= token_in
->data
;
429 in_data
.length
= token_in
->length
;
431 gss_maj
= gss_accept_sec_context(&gss_min
,
435 GSS_C_NO_CHANNEL_BINDINGS
,
436 &gse_ctx
->client_name
,
439 &gse_ctx
->ret_flags
, NULL
,
440 &gse_ctx
->delegated_creds
);
443 /* we are done with it */
444 gse_ctx
->more_processing
= false;
445 gse_ctx
->authenticated
= true;
446 status
= NT_STATUS_OK
;
448 case GSS_S_CONTINUE_NEEDED
:
449 /* we will need a third leg */
450 gse_ctx
->more_processing
= true;
451 /* status = NT_STATUS_MORE_PROCESSING_REQUIRED; */
452 status
= NT_STATUS_OK
;
455 DEBUG(0, ("gss_init_sec_context failed with [%s]\n",
456 gse_errstr(talloc_tos(), gss_maj
, gss_min
)));
458 if (gse_ctx
->gss_ctx
) {
459 gss_delete_sec_context(&gss_min
,
464 status
= NT_STATUS_INTERNAL_ERROR
;
468 /* we may be told to return nothing */
469 if (out_data
.length
) {
470 blob
= data_blob_talloc(mem_ctx
, out_data
.value
, out_data
.length
);
472 status
= NT_STATUS_NO_MEMORY
;
474 gss_maj
= gss_release_buffer(&gss_min
, &out_data
);
483 NTSTATUS
gse_verify_server_auth_flags(struct gse_context
*gse_ctx
)
485 if (!gse_ctx
->authenticated
) {
486 return NT_STATUS_INVALID_HANDLE
;
489 if (memcmp(gse_ctx
->ret_mech
,
490 gss_mech_krb5
, sizeof(gss_OID_desc
)) != 0) {
491 return NT_STATUS_ACCESS_DENIED
;
494 /* GSS_C_MUTUAL_FLAG */
495 if (gse_ctx
->gss_c_flags
& GSS_C_MUTUAL_FLAG
) {
496 if (!(gse_ctx
->ret_flags
& GSS_C_MUTUAL_FLAG
)) {
497 return NT_STATUS_ACCESS_DENIED
;
501 /* GSS_C_DELEG_FLAG */
502 /* GSS_C_DELEG_POLICY_FLAG */
503 /* GSS_C_REPLAY_FLAG */
504 /* GSS_C_SEQUENCE_FLAG */
506 /* GSS_C_INTEG_FLAG */
507 if (gse_ctx
->gss_c_flags
& GSS_C_INTEG_FLAG
) {
508 if (!(gse_ctx
->ret_flags
& GSS_C_INTEG_FLAG
)) {
509 return NT_STATUS_ACCESS_DENIED
;
513 /* GSS_C_CONF_FLAG */
514 if (gse_ctx
->gss_c_flags
& GSS_C_CONF_FLAG
) {
515 if (!(gse_ctx
->ret_flags
& GSS_C_CONF_FLAG
)) {
516 return NT_STATUS_ACCESS_DENIED
;
523 static char *gse_errstr(TALLOC_CTX
*mem_ctx
, OM_uint32 maj
, OM_uint32 min
)
525 OM_uint32 gss_min
, gss_maj
;
526 gss_buffer_desc msg_min
;
527 gss_buffer_desc msg_maj
;
528 OM_uint32 msg_ctx
= 0;
532 ZERO_STRUCT(msg_min
);
533 ZERO_STRUCT(msg_maj
);
535 gss_maj
= gss_display_status(&gss_min
, maj
, GSS_C_GSS_CODE
,
536 GSS_C_NO_OID
, &msg_ctx
, &msg_maj
);
540 gss_maj
= gss_display_status(&gss_min
, min
, GSS_C_MECH_CODE
,
541 (gss_OID
)discard_const(gss_mech_krb5
),
547 errstr
= talloc_strndup(mem_ctx
,
548 (char *)msg_maj
.value
,
553 errstr
= talloc_strdup_append_buffer(errstr
, ": ");
557 errstr
= talloc_strndup_append_buffer(errstr
,
558 (char *)msg_min
.value
,
566 gss_maj
= gss_release_buffer(&gss_min
, &msg_min
);
569 gss_maj
= gss_release_buffer(&gss_min
, &msg_maj
);
574 bool gse_require_more_processing(struct gse_context
*gse_ctx
)
576 return gse_ctx
->more_processing
;
579 DATA_BLOB
gse_get_session_key(TALLOC_CTX
*mem_ctx
,
580 struct gse_context
*gse_ctx
)
582 OM_uint32 gss_min
, gss_maj
;
583 gss_buffer_set_t set
= GSS_C_NO_BUFFER_SET
;
586 gss_maj
= gss_inquire_sec_context_by_oid(
587 &gss_min
, gse_ctx
->gss_ctx
,
588 &gse_sesskey_inq_oid
, &set
);
590 DEBUG(0, ("gss_inquire_sec_context_by_oid failed [%s]\n",
591 gse_errstr(talloc_tos(), gss_maj
, gss_min
)));
592 return data_blob_null
;
595 if ((set
== GSS_C_NO_BUFFER_SET
) ||
597 (memcmp(set
->elements
[1].value
,
598 gse_sesskeytype_oid
.elements
,
599 gse_sesskeytype_oid
.length
) != 0)) {
600 DEBUG(0, ("gss_inquire_sec_context_by_oid returned unknown "
601 "OID for data in results:\n"));
602 dump_data(1, (uint8_t *)set
->elements
[1].value
,
603 set
->elements
[1].length
);
604 return data_blob_null
;
607 ret
= data_blob_talloc(mem_ctx
, set
->elements
[0].value
,
608 set
->elements
[0].length
);
610 gss_maj
= gss_release_buffer_set(&gss_min
, &set
);
614 NTSTATUS
gse_get_client_name(struct gse_context
*gse_ctx
,
615 TALLOC_CTX
*mem_ctx
, char **cli_name
)
617 OM_uint32 gss_min
, gss_maj
;
618 gss_buffer_desc name_buffer
;
620 if (!gse_ctx
->authenticated
) {
621 return NT_STATUS_ACCESS_DENIED
;
624 if (!gse_ctx
->client_name
) {
625 return NT_STATUS_NOT_FOUND
;
628 /* TODO: check OID matches KRB5 Principal Name OID ? */
630 gss_maj
= gss_display_name(&gss_min
,
631 gse_ctx
->client_name
,
634 DEBUG(0, ("gss_display_name failed [%s]\n",
635 gse_errstr(talloc_tos(), gss_maj
, gss_min
)));
636 return NT_STATUS_INTERNAL_ERROR
;
639 *cli_name
= talloc_strndup(talloc_tos(),
640 (char *)name_buffer
.value
,
643 gss_maj
= gss_release_buffer(&gss_min
, &name_buffer
);
646 return NT_STATUS_NO_MEMORY
;
652 NTSTATUS
gse_get_authz_data(struct gse_context
*gse_ctx
,
653 TALLOC_CTX
*mem_ctx
, DATA_BLOB
*pac
)
655 OM_uint32 gss_min
, gss_maj
;
656 gss_buffer_set_t set
= GSS_C_NO_BUFFER_SET
;
658 if (!gse_ctx
->authenticated
) {
659 return NT_STATUS_ACCESS_DENIED
;
662 gss_maj
= gss_inquire_sec_context_by_oid(
663 &gss_min
, gse_ctx
->gss_ctx
,
664 &gse_authz_data_oid
, &set
);
666 DEBUG(0, ("gss_inquire_sec_context_by_oid failed [%s]\n",
667 gse_errstr(talloc_tos(), gss_maj
, gss_min
)));
668 return NT_STATUS_NOT_FOUND
;
671 if (set
== GSS_C_NO_BUFFER_SET
) {
672 DEBUG(0, ("gss_inquire_sec_context_by_oid returned unknown "
673 "data in results.\n"));
674 return NT_STATUS_INTERNAL_ERROR
;
677 /* for now we just hope it is the first value */
678 *pac
= data_blob_talloc(mem_ctx
,
679 set
->elements
[0].value
,
680 set
->elements
[0].length
);
682 gss_maj
= gss_release_buffer_set(&gss_min
, &set
);
687 NTSTATUS
gse_get_pac_blob(struct gse_context
*gse_ctx
,
688 TALLOC_CTX
*mem_ctx
, DATA_BLOB
*pac_blob
)
690 OM_uint32 gss_min
, gss_maj
;
692 * gss_get_name_attribute() in MIT krb5 1.10.0 can return unintialized pac_display_buffer
693 * and later gss_release_buffer() will crash on attempting to release it.
695 * So always initialize the buffer descriptors.
697 * See following links for more details:
698 * http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=658514
699 * http://krbdev.mit.edu/rt/Ticket/Display.html?user=guest&pass=guest&id=7087
701 gss_buffer_desc pac_buffer
= {
705 gss_buffer_desc pac_display_buffer
= {
709 gss_buffer_desc pac_name
= {
710 .value
= discard_const_p(char, "urn:mspac:"),
711 .length
= sizeof("urn:mspac:") - 1
714 int authenticated
= false;
715 int complete
= false;
718 if (!gse_ctx
->authenticated
) {
719 return NT_STATUS_ACCESS_DENIED
;
722 gss_maj
= gss_get_name_attribute(&gss_min
,
723 gse_ctx
->client_name
, &pac_name
,
724 &authenticated
, &complete
,
725 &pac_buffer
, &pac_display_buffer
,
729 DEBUG(0, ("obtaining PAC via GSSAPI gss_get_name_attribute "
731 gse_errstr(mem_ctx
, gss_maj
, gss_min
)));
732 return NT_STATUS_ACCESS_DENIED
;
735 if (authenticated
&& complete
) {
736 /* The PAC blob is returned directly */
737 *pac_blob
= data_blob_talloc(mem_ctx
,
740 if (!pac_blob
->data
) {
741 status
= NT_STATUS_NO_MEMORY
;
743 status
= NT_STATUS_OK
;
746 gss_maj
= gss_release_buffer(&gss_min
, &pac_buffer
);
747 gss_maj
= gss_release_buffer(&gss_min
, &pac_display_buffer
);
752 DEBUG(0, ("obtaining PAC via GSSAPI failed: authenticated: %s, "
753 "complete: %s, more: %s\n",
754 authenticated
? "true" : "false",
755 complete
? "true" : "false",
756 more
? "true" : "false"));
758 return NT_STATUS_ACCESS_DENIED
;
761 size_t gse_get_signature_length(struct gse_context
*gse_ctx
,
762 int seal
, size_t payload_size
)
764 OM_uint32 gss_min
, gss_maj
;
765 gss_iov_buffer_desc iov
[2];
766 uint8_t fakebuf
[payload_size
];
769 iov
[0].type
= GSS_IOV_BUFFER_TYPE_HEADER
;
770 iov
[0].buffer
.value
= NULL
;
771 iov
[0].buffer
.length
= 0;
772 iov
[1].type
= GSS_IOV_BUFFER_TYPE_DATA
;
773 iov
[1].buffer
.value
= fakebuf
;
774 iov
[1].buffer
.length
= payload_size
;
776 gss_maj
= gss_wrap_iov_length(&gss_min
, gse_ctx
->gss_ctx
,
777 seal
, GSS_C_QOP_DEFAULT
,
780 DEBUG(0, ("gss_wrap_iov_length failed with [%s]\n",
781 gse_errstr(talloc_tos(), gss_maj
, gss_min
)));
785 return iov
[0].buffer
.length
;
788 NTSTATUS
gse_seal(TALLOC_CTX
*mem_ctx
, struct gse_context
*gse_ctx
,
789 DATA_BLOB
*data
, DATA_BLOB
*signature
)
791 OM_uint32 gss_min
, gss_maj
;
792 gss_iov_buffer_desc iov
[2];
793 int req_seal
= 1; /* setting to 1 means we request sign+seal */
797 /* allocate the memory ourselves so we do not need to talloc_memdup */
798 signature
->length
= gse_get_signature_length(gse_ctx
, 1, data
->length
);
799 if (!signature
->length
) {
800 return NT_STATUS_INTERNAL_ERROR
;
802 signature
->data
= (uint8_t *)talloc_size(mem_ctx
, signature
->length
);
803 if (!signature
->data
) {
804 return NT_STATUS_NO_MEMORY
;
806 iov
[0].type
= GSS_IOV_BUFFER_TYPE_HEADER
;
807 iov
[0].buffer
.value
= signature
->data
;
808 iov
[0].buffer
.length
= signature
->length
;
810 /* data is encrypted in place, which is ok */
811 iov
[1].type
= GSS_IOV_BUFFER_TYPE_DATA
;
812 iov
[1].buffer
.value
= data
->data
;
813 iov
[1].buffer
.length
= data
->length
;
815 gss_maj
= gss_wrap_iov(&gss_min
, gse_ctx
->gss_ctx
,
816 req_seal
, GSS_C_QOP_DEFAULT
,
819 DEBUG(0, ("gss_wrap_iov failed with [%s]\n",
820 gse_errstr(talloc_tos(), gss_maj
, gss_min
)));
821 status
= NT_STATUS_ACCESS_DENIED
;
826 DEBUG(0, ("gss_wrap_iov says data was not sealed!\n"));
827 status
= NT_STATUS_ACCESS_DENIED
;
831 status
= NT_STATUS_OK
;
833 DEBUG(10, ("Sealed %d bytes, and got %d bytes header/signature.\n",
834 (int)iov
[1].buffer
.length
, (int)iov
[0].buffer
.length
));
840 NTSTATUS
gse_unseal(TALLOC_CTX
*mem_ctx
, struct gse_context
*gse_ctx
,
841 DATA_BLOB
*data
, DATA_BLOB
*signature
)
843 OM_uint32 gss_min
, gss_maj
;
844 gss_iov_buffer_desc iov
[2];
848 iov
[0].type
= GSS_IOV_BUFFER_TYPE_HEADER
;
849 iov
[0].buffer
.value
= signature
->data
;
850 iov
[0].buffer
.length
= signature
->length
;
852 /* data is decrypted in place, which is ok */
853 iov
[1].type
= GSS_IOV_BUFFER_TYPE_DATA
;
854 iov
[1].buffer
.value
= data
->data
;
855 iov
[1].buffer
.length
= data
->length
;
857 gss_maj
= gss_unwrap_iov(&gss_min
, gse_ctx
->gss_ctx
,
858 &sealed
, NULL
, iov
, 2);
860 DEBUG(0, ("gss_unwrap_iov failed with [%s]\n",
861 gse_errstr(talloc_tos(), gss_maj
, gss_min
)));
862 status
= NT_STATUS_ACCESS_DENIED
;
867 DEBUG(0, ("gss_unwrap_iov says data is not sealed!\n"));
868 status
= NT_STATUS_ACCESS_DENIED
;
872 status
= NT_STATUS_OK
;
874 DEBUG(10, ("Unsealed %d bytes, with %d bytes header/signature.\n",
875 (int)iov
[1].buffer
.length
, (int)iov
[0].buffer
.length
));
881 NTSTATUS
gse_sign(TALLOC_CTX
*mem_ctx
, struct gse_context
*gse_ctx
,
882 DATA_BLOB
*data
, DATA_BLOB
*signature
)
884 OM_uint32 gss_min
, gss_maj
;
885 gss_buffer_desc in_data
= { 0, NULL
};
886 gss_buffer_desc out_data
= { 0, NULL
};
889 in_data
.value
= data
->data
;
890 in_data
.length
= data
->length
;
892 gss_maj
= gss_get_mic(&gss_min
, gse_ctx
->gss_ctx
,
894 &in_data
, &out_data
);
896 DEBUG(0, ("gss_get_mic failed with [%s]\n",
897 gse_errstr(talloc_tos(), gss_maj
, gss_min
)));
898 status
= NT_STATUS_ACCESS_DENIED
;
902 *signature
= data_blob_talloc(mem_ctx
,
903 out_data
.value
, out_data
.length
);
904 if (!signature
->data
) {
905 status
= NT_STATUS_NO_MEMORY
;
909 status
= NT_STATUS_OK
;
912 if (out_data
.value
) {
913 gss_maj
= gss_release_buffer(&gss_min
, &out_data
);
918 NTSTATUS
gse_sigcheck(TALLOC_CTX
*mem_ctx
, struct gse_context
*gse_ctx
,
919 DATA_BLOB
*data
, DATA_BLOB
*signature
)
921 OM_uint32 gss_min
, gss_maj
;
922 gss_buffer_desc in_data
= { 0, NULL
};
923 gss_buffer_desc in_token
= { 0, NULL
};
926 in_data
.value
= data
->data
;
927 in_data
.length
= data
->length
;
928 in_token
.value
= signature
->data
;
929 in_token
.length
= signature
->length
;
931 gss_maj
= gss_verify_mic(&gss_min
, gse_ctx
->gss_ctx
,
932 &in_data
, &in_token
, NULL
);
934 DEBUG(0, ("gss_verify_mic failed with [%s]\n",
935 gse_errstr(talloc_tos(), gss_maj
, gss_min
)));
936 status
= NT_STATUS_ACCESS_DENIED
;
940 status
= NT_STATUS_OK
;
948 NTSTATUS
gse_init_client(TALLOC_CTX
*mem_ctx
,
949 bool do_sign
, bool do_seal
,
950 const char *ccache_name
,
953 const char *username
,
954 const char *password
,
955 uint32_t add_gss_c_flags
,
956 struct gse_context
**_gse_ctx
)
958 return NT_STATUS_NOT_IMPLEMENTED
;
961 NTSTATUS
gse_get_client_auth_token(TALLOC_CTX
*mem_ctx
,
962 struct gse_context
*gse_ctx
,
964 DATA_BLOB
*token_out
)
966 return NT_STATUS_NOT_IMPLEMENTED
;
969 NTSTATUS
gse_init_server(TALLOC_CTX
*mem_ctx
,
970 bool do_sign
, bool do_seal
,
971 uint32_t add_gss_c_flags
,
973 struct gse_context
**_gse_ctx
)
975 return NT_STATUS_NOT_IMPLEMENTED
;
978 NTSTATUS
gse_get_server_auth_token(TALLOC_CTX
*mem_ctx
,
979 struct gse_context
*gse_ctx
,
981 DATA_BLOB
*token_out
)
983 return NT_STATUS_NOT_IMPLEMENTED
;
986 NTSTATUS
gse_verify_server_auth_flags(struct gse_context
*gse_ctx
)
988 return NT_STATUS_NOT_IMPLEMENTED
;
991 bool gse_require_more_processing(struct gse_context
*gse_ctx
)
996 DATA_BLOB
gse_get_session_key(TALLOC_CTX
*mem_ctx
,
997 struct gse_context
*gse_ctx
)
999 return data_blob_null
;
1002 NTSTATUS
gse_get_client_name(struct gse_context
*gse_ctx
,
1003 TALLOC_CTX
*mem_ctx
, char **cli_name
)
1005 return NT_STATUS_NOT_IMPLEMENTED
;
1008 NTSTATUS
gse_get_authz_data(struct gse_context
*gse_ctx
,
1009 TALLOC_CTX
*mem_ctx
, DATA_BLOB
*pac
)
1011 return NT_STATUS_NOT_IMPLEMENTED
;
1014 NTSTATUS
gse_get_pac_blob(struct gse_context
*gse_ctx
,
1015 TALLOC_CTX
*mem_ctx
, DATA_BLOB
*pac
)
1017 return NT_STATUS_NOT_IMPLEMENTED
;
1020 size_t gse_get_signature_length(struct gse_context
*gse_ctx
,
1021 int seal
, size_t payload_size
)
1026 NTSTATUS
gse_seal(TALLOC_CTX
*mem_ctx
, struct gse_context
*gse_ctx
,
1027 DATA_BLOB
*data
, DATA_BLOB
*signature
)
1029 return NT_STATUS_NOT_IMPLEMENTED
;
1032 NTSTATUS
gse_unseal(TALLOC_CTX
*mem_ctx
, struct gse_context
*gse_ctx
,
1033 DATA_BLOB
*data
, DATA_BLOB
*signature
)
1035 return NT_STATUS_NOT_IMPLEMENTED
;
1038 NTSTATUS
gse_sign(TALLOC_CTX
*mem_ctx
, struct gse_context
*gse_ctx
,
1039 DATA_BLOB
*data
, DATA_BLOB
*signature
)
1041 return NT_STATUS_NOT_IMPLEMENTED
;
1044 NTSTATUS
gse_sigcheck(TALLOC_CTX
*mem_ctx
, struct gse_context
*gse_ctx
,
1045 DATA_BLOB
*data
, DATA_BLOB
*signature
)
1047 return NT_STATUS_NOT_IMPLEMENTED
;
1050 #endif /* HAVE_KRB5 && HAVE_GSSAPI_EXT_H && HAVE_GSS_WRAP_IOV */