7b3c4780a3f87d677fb200c786ef83ed49f17388
[metze/heimdal/wip.git] / lib / gssapi / sanon / sanon_locl.h
1 /*
2  * Copyright (c) 2019-2020, AuriStor, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * - Redistributions of source code must retain the above copyright
10  *   notice, this list of conditions and the following disclaimer.
11  *
12  * - Redistributions in binary form must reproduce the above copyright
13  *   notice, this list of conditions and the following disclaimer in
14  *   the documentation and/or other materials provided with the
15  *   distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28  * OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  */
31
32 #ifndef SANON_LOCL_H
33 #define SANON_LOCL_H 1
34
35 #include <config.h>
36
37 #include <krb5_locl.h> /* for _krb5_SP800_108_HMAC_KDF() */
38
39 #include <hcrypto/x25519_ref10.h>
40
41 #include <gssapi.h>
42 #include <gkrb5_err.h> /* for GSS_KRB5_S_XXX */
43
44 #include "mech/mech_locl.h"
45
46 typedef struct sanon_ctx_desc {
47     /* X25519 ECDH secret key */
48     uint8_t sk[crypto_scalarmult_curve25519_BYTES];
49     /* X25519 ECDH public key */
50     uint8_t pk[crypto_scalarmult_curve25519_BYTES];
51     /* krb5 context for message protection/PRF */
52     gss_ctx_id_t rfc4121;
53     int is_initiator : 1;
54 } *sanon_ctx;
55
56 extern gss_name_t _gss_sanon_anonymous_identity;
57 extern gss_name_t _gss_sanon_non_anonymous_identity;
58
59 extern gss_cred_id_t _gss_sanon_anonymous_cred;
60 extern gss_cred_id_t _gss_sanon_non_anonymous_cred;
61
62 #include "sanon-private.h"
63
64 #define SANON_WELLKNOWN_USER_NAME               "WELLKNOWN/ANONYMOUS@WELLKNOWN:ANONYMOUS"
65 #define SANON_WELLKNOWN_USER_NAME_LEN           (sizeof(SANON_WELLKNOWN_USER_NAME) - 1)
66
67 extern gss_buffer_t _gss_sanon_wellknown_user_name;
68
69 #define SANON_WELLKNOWN_SERVICE_NAME            "WELLKNOWN@ANONYMOUS"
70 #define SANON_WELLKNOWN_SERVICE_NAME_LEN        (sizeof(SANON_WELLKNOWN_SERVICE_NAME) - 1)
71
72 extern gss_buffer_t _gss_sanon_wellknown_service_name;
73
74 static inline int
75 buffer_equal_p(gss_const_buffer_t b1, gss_const_buffer_t b2)
76 {
77     return b1->length == b2->length &&
78         memcmp(b1->value, b2->value, b2->length) == 0;
79 }
80
81 /* flags that are valid to be sent from a SAnon initiator in the flags field */
82 #define SANON_PROTOCOL_FLAG_MASK ( GSS_C_DCE_STYLE | GSS_C_IDENTIFY_FLAG | GSS_C_EXTENDED_ERROR_FLAG )
83
84 #endif /* SANON_LOCL_H */