Add rxgk_util.c
[openafs.git] / src / rxgk / rxgk_private.h
1 /* src/rxgk/rxgk_private.h - Declarations of RXGK-internal routines */
2 /*
3  * Copyright (C) 2013, 2014 by the Massachusetts Institute of Technology.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  *   notice, this list of conditions and the following disclaimer.
12  *
13  * * Redistributions in binary form must reproduce the above copyright
14  *   notice, this list of conditions and the following disclaimer in
15  *   the documentation and/or other materials provided with the
16  *   distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29  * OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31
32 /*
33  * Prototypes for routines internal to RXGK.
34  */
35
36 #ifndef RXGK_PRIVATE_H
37 #define RXGK_PRIVATE_H
38
39 /* RX-internal headers we depend on. */
40 #include <rx/rx_identity.h>
41
42 /** Statistics about a connection.  Bytes and packets sent/received. */
43 struct rxgkStats {
44     afs_uint32 brecv;
45     afs_uint32 bsent;
46     afs_uint32 precv;
47     afs_uint32 psent;
48 };
49
50 /* The packet pseudoheader used for auth and crypt connections. */
51 struct rxgk_header {
52     afs_uint32 epoch;
53     afs_uint32 cid;
54     afs_uint32 callNumber;
55     afs_uint32 seq;
56     afs_uint32 index;
57     afs_uint32 length;
58 } __attribute__((packed));
59
60 /*
61  * rgxk_server.c
62  */
63
64 /**
65  * Security Object private data for the server.
66  *
67  * Per-connection flags, and a way to get a decryption key for what the client
68  * sends us.
69  */
70 struct rxgk_sprivate {
71     afs_int32 flags;
72     void *rock;
73     rxgk_getkey_func getkey;
74 };
75 /**
76  * Per-connection security data for the server.
77  *
78  * Security level, authentication state, expiration, the current challenge
79  * nonce, status, the connection start time and current key derivation key
80  * number.  Cache both the user identity and callback identity presented
81  * in the token, for later use.
82  */
83 struct rxgk_sconn {
84     RXGK_Level level;
85     unsigned char tried_auth;
86     unsigned char auth;
87     rxgkTime expiration;
88     unsigned char challenge[RXGK_CHALLENGE_NONCE_LEN];
89     struct rxgkStats stats;
90     rxgkTime start_time;
91     struct rx_identity *client;
92     afs_uint32 key_number;
93     rxgk_key k0;
94     RXGK_Data cb_tok;
95     rxgk_key cb_key;
96 };
97
98 /*
99  * rxgk_client.c
100  */
101
102 /**
103  * Security Object private data for client.
104  *
105  * The session key ("token master key"), plust the enctype of the
106  * token and the token itself.
107  * UUIDs for both the client (cache manager) and target server.  This is
108  * doable because the token is either a db server (the target has no UUID)
109  * or tied to a particular file server (which does have a UUID).
110  */
111 struct rxgk_cprivate {
112     afs_int32 flags;
113     rxgk_key k0;
114     afs_int32 enctype;
115     RXGK_Level level;
116     RXGK_Data token;
117     afsUUID *client_uuid;
118     afsUUID *target_uuid;
119 };
120 /**
121  * Per-connection security data for client.
122  *
123  * The start time of the connection and connection key number are used
124  * for key derivation, information about the callback key to be presented in
125  * the authenticator for the connection, and the requisite connection
126  * statistics.
127  */
128 struct rxgk_cconn {
129     rxgkTime start_time;
130     afs_uint32 key_number;
131     RXGK_Data cb_tok;
132     RXGK_Data cb_k0;
133     afs_int32 cb_enctype;
134     struct rxgkStats stats;
135 };
136
137 /* rxgk_crypto_IMPL.c (currently rfc3961 is the only IMPL) */
138 ssize_t rxgk_etype_to_len(int etype);
139
140 /* rxgk_token.c */
141 afs_int32 rxgk_extract_token(RXGK_Data *tc, RXGK_Token *out,
142                              rxgk_getkey_func getkey, void *rock)
143                             AFS_NONNULL((1,2,3));
144
145 /* rxgk_util.c */
146 afs_int32 rxgk_security_overhead(struct rx_connection *aconn, RXGK_Level level,
147                                  rxgk_key k0);
148 afs_int32 rxgk_key_number(afs_uint16 wire, afs_uint32 local, afs_uint32 *real);
149
150 /* rxgk_packet.c */
151 int rxgk_check_mic_packet(rxgk_key tk, afs_int32 keyusage,
152                           struct rx_connection *aconn,
153                           struct rx_packet *apacket);
154 int rxgk_decrypt_packet(rxgk_key tk, afs_int32 keyusage,
155                         struct rx_connection *aconn, struct rx_packet *apacket);
156 int rxgk_mic_packet(rxgk_key tk, afs_int32 keyusage,
157                     struct rx_connection *aconn, struct rx_packet *apacket);
158 int rxgk_enc_packet(rxgk_key tk, afs_int32 keyusage,
159                     struct rx_connection *aconn, struct rx_packet *apacket);
160
161 #endif /* RXGK_PRIVATE_H */