death-to-dos-win95-20060802
[openafs.git] / src / rxgk / rxgk_locl.h
1 /*
2  * Copyright (c) 1995 - 1998, 2002 Kungliga Tekniska Högskolan
3  * (Royal Institute of Technology, Stockholm, Sweden).
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  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 
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.
16  * 
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.
20  * 
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
31  * SUCH DAMAGE.
32  */
33
34 /* $Id$ */
35
36 #ifndef __RXGK_LOCL_H
37 #define __RXGK_LOCL_H
38
39 #ifdef HAVE_CONFIG_H
40 #include <config.h>
41 #endif
42
43 #include <stdlib.h>
44 #include <string.h>
45 #include <limits.h>
46
47 #include <sys/types.h>
48 #include <netinet/in.h>
49
50 #include <krb5.h>
51 #include "rxgk_proto.h"
52
53 #ifdef NDEBUG
54 #ifndef assert
55 #define assert(e) ((void)0)
56 #endif
57 #else
58 #ifndef assert
59 #define assert(e) ((e) ? (void)0 : (void)osi_Panic("assert(%s) failed: file %s, line %d\n", #e, __FILE__, __LINE__, #e))
60 #endif
61 #endif
62
63 #undef RCSID
64 #include <rx/rx.h>
65 #include <rx/rx_null.h>
66 #undef RCSID
67 #define RCSID(msg) \
68 static /**/const char *const rcsid[] = { (char *)rcsid, "\100(#)" msg }
69
70 extern int rx_epoch, rx_nextCid;
71
72 #include "rxgk.h"
73
74 #define rxgk_disipline 3
75
76 #define rxgk_unallocated 1
77 #define rxgk_authenticated 2
78 #define rxgk_expired 4
79 #define rxgk_checksummed 8
80
81 typedef struct key_stuff {
82     krb5_context        ks_context;
83     krb5_keyblock       ks_key;
84     uint32_t            ks_recv_seqnum;
85     krb5_keyblock       ks_skey;
86     krb5_crypto         ks_crypto;      /* rx session key */
87     krb5_crypto         ks_scrypto;     /* rx stream key */
88 } key_stuff;
89
90 typedef struct end_stuff {
91     /* need 64 bit counters */
92     uint32_t bytesReceived, packetsReceived, bytesSent, packetsSent;
93 } end_stuff;
94
95 extern int rxgk_key_contrib_size;
96
97 int
98 rxgk_prepare_packet(struct rx_packet *pkt, struct rx_connection *con,
99                      int level, key_stuff *k, end_stuff *e);
100
101 int
102 rxgk_check_packet(struct rx_packet *pkt, struct rx_connection *con,
103                    int level, key_stuff *k, end_stuff *e);
104
105 /* Per connection specific server data */
106 typedef struct serv_con_data {
107   end_stuff e;
108   key_stuff k;
109   uint32_t expires;
110   uint32_t nonce;
111   rxgk_level cur_level; /* Starts at min_level and can only increase */
112   char authenticated;
113 } serv_con_data;
114
115 /* rxgk */
116
117 int
118 rxgk5_get_auth_token(krb5_context context, uint32_t addr, int port, 
119                      uint32_t serviceId,
120                      RXGK_Token *token,
121                      RXGK_Token *auth_token, krb5_keyblock *key,
122                      krb5_keyblock *skey,
123                      int32_t *kvno);
124
125 int
126 rxk5_mutual_auth_client_generate(krb5_context context, krb5_keyblock *key,
127                                  uint32_t number,
128                                  RXGK_Token *challage_token);
129 int
130 rxk5_mutual_auth_client_check(krb5_context context, krb5_keyblock *key,
131                               uint32_t number,
132                               const RXGK_Token *reply_token,
133                               krb5_keyblock *rxsession_key);
134 int
135 rxk5_mutual_auth_server(krb5_context context, krb5_keyblock *key,
136                         const RXGK_Token *challage_token,
137                         int *enctype, 
138                         void **session_key, size_t *session_key_size,
139                         RXGK_Token *reply_token);
140
141 int
142 rxgk_set_conn(struct rx_connection *, int, int);
143
144 int
145 rxgk_decode_auth_token(void *data, size_t len, struct RXGK_AUTH_CRED *c);
146
147 void
148 rxgk_getheader(struct rx_packet *pkt, struct rxgk_header_data *h);
149
150 int
151 rxgk_server_init(void);
152
153 #if 0
154 int
155 rxgk_derive_transport_key(krb5_context context,
156                           krb5_keyblock *rx_conn_key,
157                           RXGK_rxtransport_key *keycontrib,
158                           krb5_keyblock *rkey);
159 #endif
160
161 int
162 rxgk_random_to_key(int, void *, int, krb5_keyblock *);
163
164 #endif /* __RXGK_LOCL_H */