2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
15 #ifdef IGNORE_SOME_GCC_WARNINGS
16 # pragma GCC diagnostic warning "-Wdeprecated-declarations"
20 #include <afs/pthread_glock.h>
21 #include <sys/types.h>
27 #include <netinet/in.h>
34 #include <hcrypto/des.h>
39 #include "cellconfig.h"
44 /* return a null security object if nothing else can be done */
46 QuickAuth(struct rx_securityClass **astr, afs_int32 *aindex)
48 struct rx_securityClass *tc;
49 tc = rxnull_NewClientSecurityObject();
51 *aindex = RX_SECIDX_NULL;
56 /* Return an appropriate security class and index */
58 afsconf_ServerAuth(void *arock,
59 struct rx_securityClass **astr,
62 struct afsconf_dir *adir = (struct afsconf_dir *) arock;
63 struct rx_securityClass *tclass;
66 tclass = (struct rx_securityClass *)
67 rxkad_NewServerSecurityObject(0, adir, afsconf_GetKey, NULL);
70 *aindex = RX_SECIDX_KAD;
78 #endif /* !defined(UKERNEL) */
81 GenericAuth(struct afsconf_dir *adir,
82 struct rx_securityClass **astr,
87 struct ktc_encryptionKey key, session;
88 struct rx_securityClass *tclass;
93 /* first, find the right key and kvno to use */
94 code = afsconf_GetLatestKey(adir, &kvno, &key);
96 return QuickAuth(astr, aindex);
99 /* next create random session key, using key for seed to good random */
100 DES_init_random_number_generator((DES_cblock *) &key);
101 code = DES_new_random_key((DES_cblock *) &session);
103 return QuickAuth(astr, aindex);
106 /* now create the actual ticket */
107 ticketLen = sizeof(tbuffer);
108 memset(tbuffer, '\0', sizeof(tbuffer));
110 tkt_MakeTicket(tbuffer, &ticketLen, &key, AUTH_SUPERUSER, "", "", 0,
111 0xffffffff, &session, 0, "afs", "");
112 /* parms were buffer, ticketlen, key to seal ticket with, principal
113 * name, instance and cell, start time, end time, session key to seal
114 * in ticket, inet host, server name and server instance */
116 return QuickAuth(astr, aindex);
119 /* Next, we have ticket, kvno and session key, authenticate the connection.
120 * We use a magic # instead of a constant because of basic compilation
121 * order when compiling the system from scratch (rx/rxkad.h isn't installed
123 tclass = (struct rx_securityClass *)
124 rxkad_NewClientSecurityObject(enclevel, &session, kvno, ticketLen,
127 *aindex = RX_SECIDX_KAD;
131 /* build a fake ticket for 'afs' using keys from adir, returning an
132 * appropriate security class and index
135 afsconf_ClientAuth(void *arock, struct rx_securityClass ** astr,
138 struct afsconf_dir * adir = (struct afsconf_dir *) arock;
142 rc = GenericAuth(adir, astr, aindex, rxkad_clear);
147 /* build a fake ticket for 'afs' using keys from adir, returning an
148 * appropriate security class and index. This one, unlike the above,
149 * tells rxkad to encrypt the data, too.
152 afsconf_ClientAuthSecure(void *arock,
153 struct rx_securityClass **astr,
156 struct afsconf_dir *adir = (struct afsconf_dir *) arock;
160 rc = GenericAuth(adir, astr, aindex, rxkad_crypt);
166 * Build a security class from the user's current tokens
168 * This function constructs an RX security class from a user's current
171 * @param[in] info The cell information structure
172 * @param[in] flags Security flags describing the desired mechanism
173 * @param[out] sc The selected security class
174 * @param[out] scIndex The index of the selected class
175 * @parma[out] expires The expiry time of the tokens used to build the class
177 * Only the AFSCONF_SECOPTS_ALWAYSENCRYPT flag will modify the behaviour of
178 * this function - it determines whether a cleartext, or encrypting, security
182 * 0 on success, non-zero on failure. An error code of
183 * AFSCONF_NO_SECURITY_CLASS indicates that were were unable to build a
184 * security class using the selected tokens.
188 afsconf_ClientAuthToken(struct afsconf_cell *info,
189 afsconf_secflags flags,
190 struct rx_securityClass **sc,
194 struct ktc_setTokenData *tokenSet = NULL;
195 struct ktc_token ttoken;
200 *scIndex = RX_SECIDX_NULL;
202 code = ktc_GetTokenEx(info->name, &tokenSet);
206 code = token_extractRxkad(tokenSet, &ttoken, NULL, NULL);
208 /* XXX - We should think about how to handle this */
209 if (ttoken.kvno < 0 || ttoken.kvno > 256) {
211 "funny kvno (%d) in ticket, proceeding\n",
214 if (flags & AFSCONF_SECOPTS_ALWAYSENCRYPT)
215 encryptLevel = rxkad_crypt;
217 encryptLevel = rxkad_clear;
218 *sc = rxkad_NewClientSecurityObject(encryptLevel,
223 *scIndex = RX_SECIDX_KAD;
225 *expires = ttoken.endTime;
229 token_FreeSet(&tokenSet);
232 return AFSCONF_NO_SECURITY_CLASS;
238 * Build a set of security classes suitable for a server accepting
239 * incoming connections
241 #if !defined(UKERNEL)
243 afsconf_BuildServerSecurityObjects(struct afsconf_dir *dir,
245 struct rx_securityClass ***classes,
246 afs_int32 *numClasses)
248 if (flags & AFSCONF_SEC_OBJS_RXKAD_CRYPT)
253 *classes = calloc(*numClasses, sizeof(**classes));
255 (*classes)[0] = rxnull_NewServerSecurityObject();
256 (*classes)[1] = NULL;
257 (*classes)[2] = rxkad_NewServerSecurityObject(0, dir,
258 afsconf_GetKey, NULL);
259 if (flags & AFSCONF_SEC_OBJS_RXKAD_CRYPT)
260 (*classes)[3] = rxkad_NewServerSecurityObject(rxkad_crypt, dir,
261 afsconf_GetKey, NULL);
266 * Pick a security class to use for an outgoing connection
268 * This function selects an RX security class to use for an outgoing
269 * connection, based on the set of security flags provided.
272 * The configuration directory structure for this cell. If NULL,
273 * no classes requiring local configuration will be returned.
275 * A set of flags to determine the properties of the security class which
277 * - AFSCONF_SECOPTS_NOAUTH - return an anonymous secirty class
278 * - AFSCONF_SECOPTS_LOCALAUTH - use classes which have local key
279 * material available.
280 * - AFSCONF_SECOPTS_ALWAYSENCRYPT - use classes in encrypting, rather
281 * than authentication or integrity modes.
282 * - AFSCONF_SECOPTS_FALLBACK_NULL - if no suitable class can be found,
283 * then fallback to the rxnull security class.
285 * The cell information structure for the current cell. If this is NULL,
286 * then use a version locally obtained using the cellName.
287 * @param[in] cellName
288 * The cellName to use when obtaining cell information (may be NULL if
291 * The selected security class
292 * @param[out] scIndex
293 * The index of the selected security class
294 * @param[out] expires
295 * The expiry time of the tokens used to construct the class. Will be
296 * NEVER_DATE if the class has an unlimited lifetime. If NULL, the
297 * function won't store the expiry date.
300 * Returns 0 on success, or a com_err error code on failure.
303 afsconf_PickClientSecObj(struct afsconf_dir *dir, afsconf_secflags flags,
304 struct afsconf_cell *info,
305 char *cellName, struct rx_securityClass **sc,
306 afs_int32 *scIndex, time_t *expires) {
307 struct afsconf_cell localInfo;
311 *scIndex = RX_SECIDX_NULL;
315 if ( !(flags & AFSCONF_SECOPTS_NOAUTH) ) {
317 return AFSCONF_NOCELLDB;
319 if (flags & AFSCONF_SECOPTS_LOCALAUTH) {
320 code = afsconf_GetLatestKey(dir, 0, 0);
324 if (flags & AFSCONF_SECOPTS_ALWAYSENCRYPT)
325 code = afsconf_ClientAuthSecure(dir, sc, scIndex);
327 code = afsconf_ClientAuth(dir, sc, scIndex);
333 *expires = NEVERDATE;
336 code = afsconf_GetCellInfo(dir, cellName, NULL, &localInfo);
342 code = afsconf_ClientAuthToken(info, flags, sc, scIndex, expires);
343 if (code && !(flags & AFSCONF_SECOPTS_FALLBACK_NULL))
346 /* If we didn't get a token, we'll just run anonymously */
351 *sc = rxnull_NewClientSecurityObject();
352 *scIndex = RX_SECIDX_NULL;
354 *expires = NEVERDATE;