2 * Copyright (c) 2006 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include "krb5_locl.h"
35 __RCSID("$Heimdal: digest.c 22156 2007-12-04 20:02:49Z lha $"
37 #include "digest_asn1.h"
39 struct krb5_digest_data
{
44 DigestInitReply initReply
;
45 DigestRequest request
;
46 DigestResponse response
;
50 krb5_digest_alloc(krb5_context context
, krb5_digest
*digest
)
54 d
= calloc(1, sizeof(*d
));
57 krb5_set_error_string(context
, "out of memory");
66 krb5_digest_free(krb5_digest digest
)
70 free_DigestInit(&digest
->init
);
71 free_DigestInitReply(&digest
->initReply
);
72 free_DigestRequest(&digest
->request
);
73 free_DigestResponse(&digest
->response
);
74 memset(digest
, 0, sizeof(*digest
));
80 krb5_digest_set_server_cb(krb5_context context
,
85 if (digest
->init
.channel
) {
86 krb5_set_error_string(context
, "server channel binding already set");
89 digest
->init
.channel
= calloc(1, sizeof(*digest
->init
.channel
));
90 if (digest
->init
.channel
== NULL
)
93 digest
->init
.channel
->cb_type
= strdup(type
);
94 if (digest
->init
.channel
->cb_type
== NULL
)
97 digest
->init
.channel
->cb_binding
= strdup(binding
);
98 if (digest
->init
.channel
->cb_binding
== NULL
)
102 if (digest
->init
.channel
) {
103 free(digest
->init
.channel
->cb_type
);
104 free(digest
->init
.channel
->cb_binding
);
105 free(digest
->init
.channel
);
106 digest
->init
.channel
= NULL
;
108 krb5_set_error_string(context
, "out of memory");
113 krb5_digest_set_type(krb5_context context
,
117 if (digest
->init
.type
) {
118 krb5_set_error_string(context
, "client type already set");
121 digest
->init
.type
= strdup(type
);
122 if (digest
->init
.type
== NULL
) {
123 krb5_set_error_string(context
, "out of memory");
130 krb5_digest_set_hostname(krb5_context context
,
132 const char *hostname
)
134 if (digest
->init
.hostname
) {
135 krb5_set_error_string(context
, "server hostname already set");
138 digest
->init
.hostname
= malloc(sizeof(*digest
->init
.hostname
));
139 if (digest
->init
.hostname
== NULL
) {
140 krb5_set_error_string(context
, "out of memory");
143 *digest
->init
.hostname
= strdup(hostname
);
144 if (*digest
->init
.hostname
== NULL
) {
145 krb5_set_error_string(context
, "out of memory");
146 free(digest
->init
.hostname
);
147 digest
->init
.hostname
= NULL
;
154 krb5_digest_get_server_nonce(krb5_context context
,
157 return digest
->initReply
.nonce
;
161 krb5_digest_set_server_nonce(krb5_context context
,
165 if (digest
->request
.serverNonce
) {
166 krb5_set_error_string(context
, "nonce already set");
169 digest
->request
.serverNonce
= strdup(nonce
);
170 if (digest
->request
.serverNonce
== NULL
) {
171 krb5_set_error_string(context
, "out of memory");
178 krb5_digest_get_opaque(krb5_context context
,
181 return digest
->initReply
.opaque
;
185 krb5_digest_set_opaque(krb5_context context
,
189 if (digest
->request
.opaque
) {
190 krb5_set_error_string(context
, "opaque already set");
193 digest
->request
.opaque
= strdup(opaque
);
194 if (digest
->request
.opaque
== NULL
) {
195 krb5_set_error_string(context
, "out of memory");
202 krb5_digest_get_identifier(krb5_context context
,
205 if (digest
->initReply
.identifier
== NULL
)
207 return *digest
->initReply
.identifier
;
211 krb5_digest_set_identifier(krb5_context context
,
215 if (digest
->request
.identifier
) {
216 krb5_set_error_string(context
, "identifier already set");
219 digest
->request
.identifier
= calloc(1, sizeof(*digest
->request
.identifier
));
220 if (digest
->request
.identifier
== NULL
) {
221 krb5_set_error_string(context
, "out of memory");
224 *digest
->request
.identifier
= strdup(id
);
225 if (*digest
->request
.identifier
== NULL
) {
226 krb5_set_error_string(context
, "out of memory");
227 free(digest
->request
.identifier
);
228 digest
->request
.identifier
= NULL
;
234 static krb5_error_code
235 digest_request(krb5_context context
,
238 krb5_key_usage usage
,
239 const DigestReqInner
*ireq
,
240 DigestRepInner
*irep
)
245 krb5_data data
, data2
;
247 krb5_crypto crypto
= NULL
;
248 krb5_auth_context ac
= NULL
;
249 krb5_principal principal
= NULL
;
250 krb5_ccache id
= NULL
;
253 krb5_data_zero(&data
);
254 krb5_data_zero(&data2
);
255 memset(&req
, 0, sizeof(req
));
256 memset(&rep
, 0, sizeof(rep
));
258 if (ccache
== NULL
) {
259 ret
= krb5_cc_default(context
, &id
);
266 ret
= krb5_get_default_realm(context
, &r
);
276 ret
= krb5_make_principal(context
, &principal
,
277 r
, KRB5_DIGEST_NAME
, r
, NULL
);
281 ASN1_MALLOC_ENCODE(DigestReqInner
, data
.data
, data
.length
,
284 krb5_set_error_string(context
,
285 "Failed to encode digest inner request");
288 if (size
!= data
.length
)
289 krb5_abortx(context
, "ASN.1 internal encoder error");
291 ret
= krb5_mk_req_exact(context
, &ac
,
292 AP_OPTS_USE_SUBKEY
|AP_OPTS_MUTUAL_REQUIRED
,
293 principal
, NULL
, id
, &req
.apReq
);
300 ret
= krb5_auth_con_getlocalsubkey(context
, ac
, &key
);
304 krb5_set_error_string(context
, "Digest failed to get local subkey");
309 ret
= krb5_crypto_init(context
, key
, 0, &crypto
);
310 krb5_free_keyblock (context
, key
);
315 ret
= krb5_encrypt_EncryptedData(context
, crypto
, usage
,
316 data
.data
, data
.length
, 0,
321 krb5_data_free(&data
);
323 ASN1_MALLOC_ENCODE(DigestREQ
, data
.data
, data
.length
,
326 krb5_set_error_string(context
, "Failed to encode DigestREQest");
329 if (size
!= data
.length
)
330 krb5_abortx(context
, "ASN.1 internal encoder error");
332 ret
= krb5_sendto_kdc(context
, &data
, &r
, &data2
);
336 ret
= decode_DigestREP(data2
.data
, data2
.length
, &rep
, NULL
);
338 krb5_set_error_string(context
, "Failed to parse digest response");
343 krb5_ap_rep_enc_part
*repl
;
345 ret
= krb5_rd_rep(context
, ac
, &rep
.apRep
, &repl
);
349 krb5_free_ap_rep_enc_part(context
, repl
);
354 ret
= krb5_auth_con_getremotesubkey(context
, ac
, &key
);
359 krb5_set_error_string(context
,
360 "Digest reply have no remote subkey");
364 krb5_crypto_destroy(context
, crypto
);
365 ret
= krb5_crypto_init(context
, key
, 0, &crypto
);
366 krb5_free_keyblock (context
, key
);
371 krb5_data_free(&data
);
372 ret
= krb5_decrypt_EncryptedData(context
, crypto
, usage
,
373 &rep
.innerRep
, &data
);
377 ret
= decode_DigestRepInner(data
.data
, data
.length
, irep
, NULL
);
379 krb5_set_error_string(context
, "Failed to decode digest inner reply");
384 if (ccache
== NULL
&& id
)
385 krb5_cc_close(context
, id
);
386 if (realm
== NULL
&& r
)
389 krb5_crypto_destroy(context
, crypto
);
391 krb5_auth_con_free(context
, ac
);
393 krb5_free_principal(context
, principal
);
395 krb5_data_free(&data
);
396 krb5_data_free(&data2
);
398 free_DigestREQ(&req
);
399 free_DigestREP(&rep
);
405 krb5_digest_init_request(krb5_context context
,
414 memset(&ireq
, 0, sizeof(ireq
));
415 memset(&irep
, 0, sizeof(irep
));
417 if (digest
->init
.type
== NULL
) {
418 krb5_set_error_string(context
, "Type missing from init req");
422 ireq
.element
= choice_DigestReqInner_init
;
423 ireq
.u
.init
= digest
->init
;
425 ret
= digest_request(context
, realm
, ccache
,
426 KRB5_KU_DIGEST_ENCRYPT
, &ireq
, &irep
);
430 if (irep
.element
== choice_DigestRepInner_error
) {
431 krb5_set_error_string(context
, "Digest init error: %s",
432 irep
.u
.error
.reason
);
433 ret
= irep
.u
.error
.code
;
437 if (irep
.element
!= choice_DigestRepInner_initReply
) {
438 krb5_set_error_string(context
, "digest reply not an initReply");
443 ret
= copy_DigestInitReply(&irep
.u
.initReply
, &digest
->initReply
);
445 krb5_set_error_string(context
, "Failed to copy initReply");
450 free_DigestRepInner(&irep
);
457 krb5_digest_set_client_nonce(krb5_context context
,
461 if (digest
->request
.clientNonce
) {
462 krb5_set_error_string(context
, "clientNonce already set");
465 digest
->request
.clientNonce
=
466 calloc(1, sizeof(*digest
->request
.clientNonce
));
467 if (digest
->request
.clientNonce
== NULL
) {
468 krb5_set_error_string(context
, "out of memory");
471 *digest
->request
.clientNonce
= strdup(nonce
);
472 if (*digest
->request
.clientNonce
== NULL
) {
473 krb5_set_error_string(context
, "out of memory");
474 free(digest
->request
.clientNonce
);
475 digest
->request
.clientNonce
= NULL
;
482 krb5_digest_set_digest(krb5_context context
,
486 if (digest
->request
.digest
) {
487 krb5_set_error_string(context
, "digest already set");
490 digest
->request
.digest
= strdup(dgst
);
491 if (digest
->request
.digest
== NULL
) {
492 krb5_set_error_string(context
, "out of memory");
499 krb5_digest_set_username(krb5_context context
,
501 const char *username
)
503 if (digest
->request
.username
) {
504 krb5_set_error_string(context
, "username already set");
507 digest
->request
.username
= strdup(username
);
508 if (digest
->request
.username
== NULL
) {
509 krb5_set_error_string(context
, "out of memory");
516 krb5_digest_set_authid(krb5_context context
,
520 if (digest
->request
.authid
) {
521 krb5_set_error_string(context
, "authid already set");
524 digest
->request
.authid
= malloc(sizeof(*digest
->request
.authid
));
525 if (digest
->request
.authid
== NULL
) {
526 krb5_set_error_string(context
, "out of memory");
529 *digest
->request
.authid
= strdup(authid
);
530 if (*digest
->request
.authid
== NULL
) {
531 krb5_set_error_string(context
, "out of memory");
532 free(digest
->request
.authid
);
533 digest
->request
.authid
= NULL
;
540 krb5_digest_set_authentication_user(krb5_context context
,
542 krb5_principal authentication_user
)
546 if (digest
->request
.authentication_user
) {
547 krb5_set_error_string(context
, "authentication_user already set");
550 ret
= krb5_copy_principal(context
,
552 &digest
->request
.authentication_user
);
553 if (digest
->request
.authentication_user
== NULL
) {
554 krb5_set_error_string(context
, "out of memory");
561 krb5_digest_set_realm(krb5_context context
,
565 if (digest
->request
.realm
) {
566 krb5_set_error_string(context
, "realm already set");
569 digest
->request
.realm
= malloc(sizeof(*digest
->request
.realm
));
570 if (digest
->request
.realm
== NULL
) {
571 krb5_set_error_string(context
, "out of memory");
574 *digest
->request
.realm
= strdup(realm
);
575 if (*digest
->request
.realm
== NULL
) {
576 krb5_set_error_string(context
, "out of memory");
577 free(digest
->request
.realm
);
578 digest
->request
.realm
= NULL
;
585 krb5_digest_set_method(krb5_context context
,
589 if (digest
->request
.method
) {
590 krb5_set_error_string(context
, "method already set");
593 digest
->request
.method
= malloc(sizeof(*digest
->request
.method
));
594 if (digest
->request
.method
== NULL
) {
595 krb5_set_error_string(context
, "out of memory");
598 *digest
->request
.method
= strdup(method
);
599 if (*digest
->request
.method
== NULL
) {
600 krb5_set_error_string(context
, "out of memory");
601 free(digest
->request
.method
);
602 digest
->request
.method
= NULL
;
609 krb5_digest_set_uri(krb5_context context
,
613 if (digest
->request
.uri
) {
614 krb5_set_error_string(context
, "uri already set");
617 digest
->request
.uri
= malloc(sizeof(*digest
->request
.uri
));
618 if (digest
->request
.uri
== NULL
) {
619 krb5_set_error_string(context
, "out of memory");
622 *digest
->request
.uri
= strdup(uri
);
623 if (*digest
->request
.uri
== NULL
) {
624 krb5_set_error_string(context
, "out of memory");
625 free(digest
->request
.uri
);
626 digest
->request
.uri
= NULL
;
633 krb5_digest_set_nonceCount(krb5_context context
,
635 const char *nonce_count
)
637 if (digest
->request
.nonceCount
) {
638 krb5_set_error_string(context
, "nonceCount already set");
641 digest
->request
.nonceCount
=
642 malloc(sizeof(*digest
->request
.nonceCount
));
643 if (digest
->request
.nonceCount
== NULL
) {
644 krb5_set_error_string(context
, "out of memory");
647 *digest
->request
.nonceCount
= strdup(nonce_count
);
648 if (*digest
->request
.nonceCount
== NULL
) {
649 krb5_set_error_string(context
, "out of memory");
650 free(digest
->request
.nonceCount
);
651 digest
->request
.nonceCount
= NULL
;
658 krb5_digest_set_qop(krb5_context context
,
662 if (digest
->request
.qop
) {
663 krb5_set_error_string(context
, "qop already set");
666 digest
->request
.qop
= malloc(sizeof(*digest
->request
.qop
));
667 if (digest
->request
.qop
== NULL
) {
668 krb5_set_error_string(context
, "out of memory");
671 *digest
->request
.qop
= strdup(qop
);
672 if (*digest
->request
.qop
== NULL
) {
673 krb5_set_error_string(context
, "out of memory");
674 free(digest
->request
.qop
);
675 digest
->request
.qop
= NULL
;
682 krb5_digest_set_responseData(krb5_context context
,
684 const char *response
)
686 digest
->request
.responseData
= strdup(response
);
687 if (digest
->request
.responseData
== NULL
) {
688 krb5_set_error_string(context
, "out of memory");
695 krb5_digest_request(krb5_context context
,
704 memset(&ireq
, 0, sizeof(ireq
));
705 memset(&irep
, 0, sizeof(irep
));
707 ireq
.element
= choice_DigestReqInner_digestRequest
;
708 ireq
.u
.digestRequest
= digest
->request
;
710 if (digest
->request
.type
== NULL
) {
711 if (digest
->init
.type
== NULL
) {
712 krb5_set_error_string(context
, "Type missing from req");
715 ireq
.u
.digestRequest
.type
= digest
->init
.type
;
718 if (ireq
.u
.digestRequest
.digest
== NULL
)
719 ireq
.u
.digestRequest
.digest
= "md5";
721 ret
= digest_request(context
, realm
, ccache
,
722 KRB5_KU_DIGEST_ENCRYPT
, &ireq
, &irep
);
726 if (irep
.element
== choice_DigestRepInner_error
) {
727 krb5_set_error_string(context
, "Digest response error: %s",
728 irep
.u
.error
.reason
);
729 ret
= irep
.u
.error
.code
;
733 if (irep
.element
!= choice_DigestRepInner_response
) {
734 krb5_set_error_string(context
, "digest reply not an DigestResponse");
739 ret
= copy_DigestResponse(&irep
.u
.response
, &digest
->response
);
741 krb5_set_error_string(context
, "Failed to copy initReply");
746 free_DigestRepInner(&irep
);
752 krb5_digest_rep_get_status(krb5_context context
,
755 return digest
->response
.success
? TRUE
: FALSE
;
759 krb5_digest_get_rsp(krb5_context context
,
762 if (digest
->response
.rsp
== NULL
)
764 return *digest
->response
.rsp
;
768 krb5_digest_get_tickets(krb5_context context
,
778 krb5_digest_get_client_binding(krb5_context context
,
783 if (digest
->response
.channel
) {
784 *type
= strdup(digest
->response
.channel
->cb_type
);
785 *binding
= strdup(digest
->response
.channel
->cb_binding
);
786 if (*type
== NULL
|| *binding
== NULL
) {
789 krb5_set_error_string(context
, "out of memory");
800 krb5_digest_get_session_key(krb5_context context
,
806 krb5_data_zero(data
);
807 if (digest
->response
.session_key
== NULL
)
809 ret
= der_copy_octet_string(digest
->response
.session_key
, data
);
811 krb5_clear_error_string(context
);
816 struct krb5_ntlm_data
{
818 NTLMInitReply initReply
;
820 NTLMResponse response
;
824 krb5_ntlm_alloc(krb5_context context
,
827 *ntlm
= calloc(1, sizeof(**ntlm
));
829 krb5_set_error_string(context
, "out of memory");
836 krb5_ntlm_free(krb5_context context
, krb5_ntlm ntlm
)
838 free_NTLMInit(&ntlm
->init
);
839 free_NTLMInitReply(&ntlm
->initReply
);
840 free_NTLMRequest(&ntlm
->request
);
841 free_NTLMResponse(&ntlm
->response
);
842 memset(ntlm
, 0, sizeof(*ntlm
));
849 krb5_ntlm_init_request(krb5_context context
,
854 const char *hostname
,
855 const char *domainname
)
861 memset(&ireq
, 0, sizeof(ireq
));
862 memset(&irep
, 0, sizeof(irep
));
864 ntlm
->init
.flags
= flags
;
866 ALLOC(ntlm
->init
.hostname
, 1);
867 *ntlm
->init
.hostname
= strdup(hostname
);
870 ALLOC(ntlm
->init
.domain
, 1);
871 *ntlm
->init
.domain
= strdup(domainname
);
874 ireq
.element
= choice_DigestReqInner_ntlmInit
;
875 ireq
.u
.ntlmInit
= ntlm
->init
;
877 ret
= digest_request(context
, realm
, ccache
,
878 KRB5_KU_DIGEST_ENCRYPT
, &ireq
, &irep
);
882 if (irep
.element
== choice_DigestRepInner_error
) {
883 krb5_set_error_string(context
, "Digest init error: %s",
884 irep
.u
.error
.reason
);
885 ret
= irep
.u
.error
.code
;
889 if (irep
.element
!= choice_DigestRepInner_ntlmInitReply
) {
890 krb5_set_error_string(context
, "ntlm reply not an initReply");
895 ret
= copy_NTLMInitReply(&irep
.u
.ntlmInitReply
, &ntlm
->initReply
);
897 krb5_set_error_string(context
, "Failed to copy initReply");
902 free_DigestRepInner(&irep
);
908 krb5_ntlm_init_get_flags(krb5_context context
,
912 *flags
= ntlm
->initReply
.flags
;
917 krb5_ntlm_init_get_challange(krb5_context context
,
919 krb5_data
*challange
)
923 ret
= der_copy_octet_string(&ntlm
->initReply
.challange
, challange
);
925 krb5_clear_error_string(context
);
931 krb5_ntlm_init_get_opaque(krb5_context context
,
937 ret
= der_copy_octet_string(&ntlm
->initReply
.opaque
, opaque
);
939 krb5_clear_error_string(context
);
945 krb5_ntlm_init_get_targetname(krb5_context context
,
949 *name
= strdup(ntlm
->initReply
.targetname
);
951 krb5_clear_error_string(context
);
958 krb5_ntlm_init_get_targetinfo(krb5_context context
,
964 if (ntlm
->initReply
.targetinfo
== NULL
) {
965 krb5_data_zero(data
);
969 ret
= krb5_data_copy(data
,
970 ntlm
->initReply
.targetinfo
->data
,
971 ntlm
->initReply
.targetinfo
->length
);
973 krb5_clear_error_string(context
);
981 krb5_ntlm_request(krb5_context context
,
990 memset(&ireq
, 0, sizeof(ireq
));
991 memset(&irep
, 0, sizeof(irep
));
993 ireq
.element
= choice_DigestReqInner_ntlmRequest
;
994 ireq
.u
.ntlmRequest
= ntlm
->request
;
996 ret
= digest_request(context
, realm
, ccache
,
997 KRB5_KU_DIGEST_ENCRYPT
, &ireq
, &irep
);
1001 if (irep
.element
== choice_DigestRepInner_error
) {
1002 krb5_set_error_string(context
, "NTLM response error: %s",
1003 irep
.u
.error
.reason
);
1004 ret
= irep
.u
.error
.code
;
1008 if (irep
.element
!= choice_DigestRepInner_ntlmResponse
) {
1009 krb5_set_error_string(context
, "NTLM reply not an NTLMResponse");
1014 ret
= copy_NTLMResponse(&irep
.u
.ntlmResponse
, &ntlm
->response
);
1016 krb5_set_error_string(context
, "Failed to copy NTLMResponse");
1021 free_DigestRepInner(&irep
);
1027 krb5_ntlm_req_set_flags(krb5_context context
,
1031 ntlm
->request
.flags
= flags
;
1036 krb5_ntlm_req_set_username(krb5_context context
,
1038 const char *username
)
1040 ntlm
->request
.username
= strdup(username
);
1041 if (ntlm
->request
.username
== NULL
) {
1042 krb5_set_error_string(context
, "out of memory");
1049 krb5_ntlm_req_set_targetname(krb5_context context
,
1051 const char *targetname
)
1053 ntlm
->request
.targetname
= strdup(targetname
);
1054 if (ntlm
->request
.targetname
== NULL
) {
1055 krb5_set_error_string(context
, "out of memory");
1062 krb5_ntlm_req_set_lm(krb5_context context
,
1064 void *hash
, size_t len
)
1066 ntlm
->request
.lm
.data
= malloc(len
);
1067 if (ntlm
->request
.lm
.data
== NULL
) {
1068 krb5_set_error_string(context
, "out of memory");
1071 ntlm
->request
.lm
.length
= len
;
1072 memcpy(ntlm
->request
.lm
.data
, hash
, len
);
1077 krb5_ntlm_req_set_ntlm(krb5_context context
,
1079 void *hash
, size_t len
)
1081 ntlm
->request
.ntlm
.data
= malloc(len
);
1082 if (ntlm
->request
.ntlm
.data
== NULL
) {
1083 krb5_set_error_string(context
, "out of memory");
1086 ntlm
->request
.ntlm
.length
= len
;
1087 memcpy(ntlm
->request
.ntlm
.data
, hash
, len
);
1092 krb5_ntlm_req_set_opaque(krb5_context context
,
1096 ntlm
->request
.opaque
.data
= malloc(opaque
->length
);
1097 if (ntlm
->request
.opaque
.data
== NULL
) {
1098 krb5_set_error_string(context
, "out of memory");
1101 ntlm
->request
.opaque
.length
= opaque
->length
;
1102 memcpy(ntlm
->request
.opaque
.data
, opaque
->data
, opaque
->length
);
1107 krb5_ntlm_req_set_session(krb5_context context
,
1109 void *sessionkey
, size_t length
)
1111 ntlm
->request
.sessionkey
= calloc(1, sizeof(*ntlm
->request
.sessionkey
));
1112 if (ntlm
->request
.sessionkey
== NULL
) {
1113 krb5_set_error_string(context
, "out of memory");
1116 ntlm
->request
.sessionkey
->data
= malloc(length
);
1117 if (ntlm
->request
.sessionkey
->data
== NULL
) {
1118 krb5_set_error_string(context
, "out of memory");
1121 memcpy(ntlm
->request
.sessionkey
->data
, sessionkey
, length
);
1122 ntlm
->request
.sessionkey
->length
= length
;
1127 krb5_ntlm_rep_get_status(krb5_context context
,
1130 return ntlm
->response
.success
? TRUE
: FALSE
;
1134 krb5_ntlm_rep_get_sessionkey(krb5_context context
,
1138 if (ntlm
->response
.sessionkey
== NULL
) {
1139 krb5_set_error_string(context
, "no ntlm session key");
1142 krb5_clear_error_string(context
);
1143 return krb5_data_copy(data
,
1144 ntlm
->response
.sessionkey
->data
,
1145 ntlm
->response
.sessionkey
->length
);
1149 * Get the supported/allowed mechanism for this principal.
1151 * @param context A Keberos context.
1152 * @param realm The realm of the KDC.
1153 * @param ccache The credential cache to use when talking to the KDC.
1154 * @param flags The supported mechanism.
1156 * @return Return an error code or 0.
1158 * @ingroup krb5_digest
1162 krb5_digest_probe(krb5_context context
,
1167 DigestReqInner ireq
;
1168 DigestRepInner irep
;
1169 krb5_error_code ret
;
1171 memset(&ireq
, 0, sizeof(ireq
));
1172 memset(&irep
, 0, sizeof(irep
));
1174 ireq
.element
= choice_DigestReqInner_supportedMechs
;
1176 ret
= digest_request(context
, realm
, ccache
,
1177 KRB5_KU_DIGEST_ENCRYPT
, &ireq
, &irep
);
1181 if (irep
.element
== choice_DigestRepInner_error
) {
1182 krb5_set_error_string(context
, "Digest probe error: %s",
1183 irep
.u
.error
.reason
);
1184 ret
= irep
.u
.error
.code
;
1188 if (irep
.element
!= choice_DigestRepInner_supportedMechs
) {
1189 krb5_set_error_string(context
, "Digest reply not an probe");
1194 *flags
= DigestTypes2int(irep
.u
.supportedMechs
);
1197 free_DigestRepInner(&irep
);