1 | \input texinfo @c -*-texinfo-*- |
---|
2 | @c @smallbook @c COMMENT THIS OUT w/CYGNUS FORMAT |
---|
3 | @finalout |
---|
4 | @setfilename kerb-API |
---|
5 | @ifinfo |
---|
6 | @emph{Cygnus Network Security Programmer's Guide---Applications |
---|
7 | Interface for Unix and PC's} by Cygnus Support. CNS includes |
---|
8 | documentation and software developed at the Massachusetts Institute of |
---|
9 | Technology, which includes this copyright information: Copyright |
---|
10 | @copyright{} 1989 by the Massachusetts Institute of Technology |
---|
11 | @quotation |
---|
12 | Export of software employing encryption from the United States of |
---|
13 | America is assumed to require a specific license from the United States |
---|
14 | Government. It is the responsibility of any person or organization |
---|
15 | contemplating export to obtain such a license before exporting. |
---|
16 | @end quotation |
---|
17 | WITHIN THAT CONSTRAINT, permission to use, copy, modify, and distribute |
---|
18 | this software and its documentation for any purpose and without fee is |
---|
19 | hereby granted, provided that the above copyright notice appear in all |
---|
20 | copies and that both that copyright notice and this permission notice |
---|
21 | appear in supporting documentation, and that the name of M.I.T. not be |
---|
22 | used in advertising or publicity pertaining to distribution of the |
---|
23 | software without specific, written prior permission. M.I.T. makes no |
---|
24 | representations about the suitability of this software for any purpose. |
---|
25 | It is provided ``as is'' without express or implied warranty. Copyright |
---|
26 | @copyright{} 1991, 1992, 1994, 1995 Cygnus Support. Permission is granted |
---|
27 | to make and distribute verbatim copies of this manual provided the |
---|
28 | copyright notice and this permission notice are preserved on all copies. |
---|
29 | @ignore |
---|
30 | Permission is granted to process this file through TeX and print the |
---|
31 | results, provided the printed document carries a copying permission |
---|
32 | notice identical to this one except for the removal of this paragraph |
---|
33 | (this paragraph not being relevant to the printed manual). |
---|
34 | @end ignore |
---|
35 | Permission is granted to copy and distribute modified versions of this |
---|
36 | manual under the conditions for verbatim copying, provided also that the |
---|
37 | entire resulting derived work is distributed under the terms of a |
---|
38 | permission notice identical to this one. Permission is granted to copy |
---|
39 | and distribute translations of this manual into another language, under |
---|
40 | the above conditions for modified versions. |
---|
41 | @end ifinfo |
---|
42 | @setchapternewpage odd |
---|
43 | @settitle CNS Programmer's Guide |
---|
44 | @titlepage |
---|
45 | @finalout |
---|
46 | @title Cygnus Network Security |
---|
47 | @subtitle Application Programmer's Interface |
---|
48 | @sp 2 |
---|
49 | @subtitle January 1995 |
---|
50 | @vfill |
---|
51 | @author John Gilmore -- Cygnus Support |
---|
52 | @page |
---|
53 | @vskip 0pt plus 1filll |
---|
54 | @emph{Cygnus Network Security Programmer's Guide---Applications |
---|
55 | Interface for Unix and PC's} by Cygnus Support. |
---|
56 | |
---|
57 | @emph{Cygnus Editor: John Gilmore} |
---|
58 | |
---|
59 | CNS includes man pages and software developed at the Massachusetts |
---|
60 | Institute of Technology, which includes this copyright information: |
---|
61 | |
---|
62 | Copyright @copyright{} 1989 by the Massachusetts Institute of Technology |
---|
63 | |
---|
64 | @quotation |
---|
65 | Export of software employing encryption from the United States of |
---|
66 | America is assumed to require a specific license from the United States |
---|
67 | Government. It is the responsibility of any person or organization |
---|
68 | contemplating export to obtain such a license before exporting. |
---|
69 | @end quotation |
---|
70 | |
---|
71 | WITHIN THAT CONSTRAINT, permission to use, copy, modify, and distribute |
---|
72 | this software and its documentation for any purpose and without fee is |
---|
73 | hereby granted, provided that the above copyright notice appear in all |
---|
74 | copies and that both that copyright notice and this permission notice |
---|
75 | appear in supporting documentation, and that the name of M.I.T. not be |
---|
76 | used in advertising or publicity pertaining to distribution of the |
---|
77 | software without specific, written prior permission. M.I.T. makes no |
---|
78 | representations about the suitability of this software for any purpose. |
---|
79 | It is provided ``as is'' without express or implied warranty. |
---|
80 | |
---|
81 | Copyright @copyright{} 1992, 1994, 1995 Cygnus Support. Permission is |
---|
82 | granted to make and distribute verbatim copies of this manual provided |
---|
83 | the copyright notice and this permission notice are preserved on all |
---|
84 | copies. |
---|
85 | |
---|
86 | Permission is granted to copy and distribute modified versions of this |
---|
87 | manual under the conditions for verbatim copying, provided also that the |
---|
88 | entire resulting derived work is distributed under the terms of a |
---|
89 | permission notice identical to this one. |
---|
90 | |
---|
91 | Permission is granted to copy and distribute translations of this manual |
---|
92 | into another language, under the above conditions for modified versions. |
---|
93 | |
---|
94 | @end titlepage |
---|
95 | |
---|
96 | |
---|
97 | @ifinfo |
---|
98 | @node Top |
---|
99 | @top CNS Programmer's Guide |
---|
100 | @menu |
---|
101 | * Introduction:: A brief introduction to CNS |
---|
102 | |
---|
103 | * Common Kerberos Library API:: Kerberos Library API for portability |
---|
104 | * Unix Library API:: Kerberos Library API for Unix |
---|
105 | * Macintosh Library API:: Kerberos Library API for Macintosh |
---|
106 | * MS-Windows Library API:: Kerberos Library API for MS-Windows |
---|
107 | * Function Index:: Index to functions |
---|
108 | @end menu |
---|
109 | @end ifinfo |
---|
110 | |
---|
111 | @node Introduction |
---|
112 | @chapter Introduction |
---|
113 | |
---|
114 | Cygnus Support developed Cygnus Network Security (CNS) to provide strong |
---|
115 | system access security, with minimal impact on users' ease of access. |
---|
116 | Using Kerberos Version 4 encryption and client-server technology, CNS |
---|
117 | assures that user identities can be checked securely without |
---|
118 | transmitting unencrypted passwords over the Net. |
---|
119 | |
---|
120 | This document describes the application programmer interface for CNS. |
---|
121 | The interface is identical on Unix, the MacOS, and MS-Windows. Some |
---|
122 | facilities beyond the common subset are available on some of these |
---|
123 | operating systems. These are documented in separate chapters. |
---|
124 | |
---|
125 | The reader is hereby warned that the U.S. Government may impose |
---|
126 | limits on the export of the software described herein. Check with |
---|
127 | a good lawyer before exporting the software or making it available |
---|
128 | to non-citizens. |
---|
129 | |
---|
130 | |
---|
131 | @node Common Kerberos Library API |
---|
132 | @chapter CNS Common Kerberos Library API |
---|
133 | |
---|
134 | @menu |
---|
135 | * Kerberos Principals:: How authenticatable things are named |
---|
136 | * krb.h---include file:: How to call Kerberos from your programs |
---|
137 | * Generic Operations:: Overall control and error handling |
---|
138 | * Configuration Suite:: Configuration functions |
---|
139 | * Credential Suite:: Credential functions |
---|
140 | * High-level Suite:: High-Level Kerberos functions |
---|
141 | * Transformation Suite:: Message Transformation functions |
---|
142 | * Encryption Suite:: Encryption functions |
---|
143 | * Stream Suite:: Stream functions |
---|
144 | @end menu |
---|
145 | |
---|
146 | This section describes the standard application programmer interface to |
---|
147 | Kerberos. It provides facilities for configuration, shared credentials, |
---|
148 | high-level operations, and transformation routines. Though most of the |
---|
149 | suites in this section are available on all platforms, there are a few |
---|
150 | that have not yet been ported to particular machines. This is noted |
---|
151 | where applicable. |
---|
152 | |
---|
153 | @node Kerberos Principals |
---|
154 | @section Kerberos Principals |
---|
155 | |
---|
156 | Kerberos @dfn{principals} are the users and application servers that act |
---|
157 | within Kerberos. Each principal has a Kerberos principal name. A |
---|
158 | Kerberos principal name contains three parts: name, instance and realm. |
---|
159 | |
---|
160 | For a user, the principal @dfn{name} is the user name. For an |
---|
161 | application server, the principal name is the name of the service being |
---|
162 | provided (e.g., the CNS @code{rlogin}, @code{rsh} and @code{rcp} |
---|
163 | programs use the principal name @code{rcmd}). |
---|
164 | |
---|
165 | A principal @dfn{instance} is usually null for users, though some users |
---|
166 | may have privileged instances such as @samp{root} or @samp{admin}. For |
---|
167 | an application server, the instance is the name of the machine on which |
---|
168 | it runs (e.g., the @code{rlogin} service running on the machine |
---|
169 | @samp{abc} uses the name @samp{rcmd.abc}, while on the machine |
---|
170 | @samp{xyz} it uses @samp{rcmd.xyz}). The instance name for an |
---|
171 | application server is not the complete domain name, but just the first |
---|
172 | element (that is, the machine @samp{abc.company.org} uses an instance |
---|
173 | name of just @samp{abc}). |
---|
174 | |
---|
175 | A principal @dfn{realm} is simply the Kerberos realm in which the |
---|
176 | principal is defined. |
---|
177 | |
---|
178 | The Kerberos principal name is separated from the instance (if not null) |
---|
179 | by a period. The realm (if not the local realm) follows the principal |
---|
180 | name and instance and is preceded by an `@@' sign. The following are |
---|
181 | examples of valid Kerberos names: |
---|
182 | |
---|
183 | @smallexample |
---|
184 | gumby |
---|
185 | ambar.admin |
---|
186 | eichin@@CYGNUS.COM |
---|
187 | raeburn.root@@CYGNUS.COM |
---|
188 | rcmd.oursun@@CYGNUS.COM |
---|
189 | @end smallexample |
---|
190 | |
---|
191 | It is possible for principals to be under-specified. If an |
---|
192 | @var{instance} is missing, it is assumed to be null. If @var{realm} is |
---|
193 | missing, it is assumed to be the local realm as determined by |
---|
194 | @ref{krb_realmofhost,,krb_get_lrealm}. The canonical form is a complete |
---|
195 | @var{name}[.@var{instance}][@@@var{realm}]. |
---|
196 | |
---|
197 | Principal names may not contain the `.' or `@@' characters. Instance |
---|
198 | names may not contain the `@@' character. |
---|
199 | |
---|
200 | @ignore |
---|
201 | @subsubheading SEE ALSO |
---|
202 | @table @ref |
---|
203 | @item kdestroy |
---|
204 | @item kinit |
---|
205 | @item klist |
---|
206 | @item kpasswd |
---|
207 | @item des_crypt |
---|
208 | @item Kerberos |
---|
209 | @item kadmin |
---|
210 | @end table |
---|
211 | @subsubheading BUGS |
---|
212 | @end ignore |
---|
213 | |
---|
214 | @node krb.h---include file |
---|
215 | @section krb.h---include file |
---|
216 | @smallexample |
---|
217 | #include "krb.h" |
---|
218 | @end smallexample |
---|
219 | |
---|
220 | This include file declares data structures and function prototypes for |
---|
221 | all Kerberos operations. Any program module that uses Kerberos |
---|
222 | facilities should @code{#include} this file. |
---|
223 | |
---|
224 | To provide application portability among Unix, Macintosh, and MS-Windows, |
---|
225 | @file{krb.h} can declare various other system interfaces in addition to |
---|
226 | the minimal Kerberos V4 interface. These interfaces are controlled by |
---|
227 | @code{#ifdef}s, which must be set in the application source code before |
---|
228 | the @code{#include "krb.h"}. They are: |
---|
229 | |
---|
230 | @table @code |
---|
231 | @item DEFINE_SOCKADDR |
---|
232 | Defines symbols necessary for network programming using sockets, |
---|
233 | including @code{struct sockaddr_in}. |
---|
234 | @item NEED_TIME_H |
---|
235 | Defines symbols necessary for getting time-of-day from the C library. |
---|
236 | @end table |
---|
237 | |
---|
238 | The network programming interface uses ordinary sockets on Unix, WinSock |
---|
239 | 1.1 on MS-Windows, and a fake socket implementation on Macintosh built |
---|
240 | on top of MacTCP. We defined some of our own infrastructure where |
---|
241 | putting the WinSock coding into a Unix program would not be appropriate. |
---|
242 | They are as follows: |
---|
243 | |
---|
244 | @table @code |
---|
245 | @item SOCKET_INITIALIZE() |
---|
246 | Must be called before any other socket calls. |
---|
247 | @item SOCKET_CLEANUP() |
---|
248 | Must be called after finishing socket calls. |
---|
249 | @item SOCKET_ERRNO |
---|
250 | Returns the error code from the last socket call. |
---|
251 | @item SOCKET_SET_ERRNO(x) |
---|
252 | Sets the error code to be returned by @code{SOCKET_ERRNO}. |
---|
253 | @item SOCKET_NFDS(f) |
---|
254 | Returns a suitable first argument for @code{select()}, given a file |
---|
255 | descriptor to be selected upon. |
---|
256 | @item SOCKET_READ(fd, b, l) |
---|
257 | Equivalent to Unix @code{read} on a socket. |
---|
258 | @item SOCKET_WRITE(fd, b, l) |
---|
259 | Equivalent to Unix @code{write} on a socket. |
---|
260 | @item SOCKET_EINTR |
---|
261 | The error code returned when an I/O operation was interrupted (equivalent |
---|
262 | to EINTR on Unix). |
---|
263 | @end table |
---|
264 | |
---|
265 | |
---|
266 | @node Generic Operations |
---|
267 | @section Generic Operations |
---|
268 | |
---|
269 | These operations deal with the overall operation of Kerberos, |
---|
270 | or with error handling. |
---|
271 | |
---|
272 | @menu |
---|
273 | * krb_start_session:: Begin Kerberos library operations |
---|
274 | * krb_end_session:: End Kerberos library operations |
---|
275 | * kname_parse:: Parse Kerberos names |
---|
276 | * krb_get_err_text:: Interpret errors for humans |
---|
277 | @end menu |
---|
278 | |
---|
279 | @node krb_start_session |
---|
280 | @subsection krb_start_session |
---|
281 | @findex krb_start_session |
---|
282 | @code{int |
---|
283 | krb_start_session(char *cache_name);} |
---|
284 | |
---|
285 | Begins a Kerberos session (an interaction with the ticket cache). |
---|
286 | In some implementations, the Kerberos support may destroy the tickets |
---|
287 | obtained by various applications when all the applications exit, |
---|
288 | for improved security on single-user machines. Applications should |
---|
289 | neither depend on this behavior nor depend on its absence. |
---|
290 | |
---|
291 | If @code{cache_name} is a null pointer, the default shared ticket cache |
---|
292 | is used (the usual case). If @code{cache_name} is non-null, then a |
---|
293 | named-ticket cache may be used. If an implementation |
---|
294 | does not implemented named |
---|
295 | caches, then the @code{cache_name} parameter is ignored. |
---|
296 | |
---|
297 | In some environments, krb_start_session also locates and initializes the |
---|
298 | Kerberos driver or library as well as preparing an interaction with the |
---|
299 | ticket cache. |
---|
300 | |
---|
301 | Each application should call @code{krb_start_session} once, and should |
---|
302 | also call @code{krb_end_session} before it ends. |
---|
303 | |
---|
304 | @node krb_end_session |
---|
305 | @subsection krb_end_session |
---|
306 | @findex krb_end_session |
---|
307 | @code{int |
---|
308 | krb_end_session(char *cache_name);} |
---|
309 | |
---|
310 | Ends a Kerberos session (an interaction with the ticket cache). |
---|
311 | In some implementations, the Kerberos support may destroy the tickets |
---|
312 | obtained by various applications when all the applications exit, |
---|
313 | for improved security on single-user machines. Applications should |
---|
314 | neither depend on this behavior nor depend on its absence. |
---|
315 | |
---|
316 | If @code{cache_name} is a null pointer, the default shared ticket cache |
---|
317 | session is ended (the usual case). If @code{cache_name} is non-null, |
---|
318 | then a named ticket cache session may be ended. If a driver does not |
---|
319 | implement named caches, then the @code{cache_name} parameter is |
---|
320 | ignored. |
---|
321 | |
---|
322 | @code{krb_end_session} must be called if and only if the |
---|
323 | application previously called @code{krb_start_session}. |
---|
324 | @code{krb_start_session} and @code{krb_end_session} must be called in |
---|
325 | pairs. |
---|
326 | |
---|
327 | @node kname_parse |
---|
328 | @subsection kname_parse |
---|
329 | @findex kname_parse |
---|
330 | @code{int |
---|
331 | kname_parse (char *name, char *instance, char *realm, char *fullname);} |
---|
332 | |
---|
333 | This routine parses @var{fullname} into the three fields @var{name}, |
---|
334 | @var{instance}, and @var{realm}, which should point to memory of sizes |
---|
335 | @code{ANAME_SZ}, @code{INST_SZ}, and @code{REALM_SZ} bytes respectively. |
---|
336 | These fields must be initialized by the caller, since each remains |
---|
337 | unchanged if @var{fullname} does not include that field. Callers |
---|
338 | typically initialize them to null strings or to the local realm name. |
---|
339 | |
---|
340 | It returns an error code based on the parse. Only the syntax of the |
---|
341 | name is checked, not its validity in a database or on the network. |
---|
342 | |
---|
343 | |
---|
344 | @node krb_get_err_text |
---|
345 | @subsection krb_get_err_text |
---|
346 | @findex krb_get_err_text |
---|
347 | @code{char * |
---|
348 | krb_get_err_text (int error_code);} |
---|
349 | |
---|
350 | This returns the ASCII text string description |
---|
351 | associated with a Kerberos error code, |
---|
352 | as returned by many Kerberos functions. |
---|
353 | |
---|
354 | |
---|
355 | |
---|
356 | |
---|
357 | @node Configuration Suite |
---|
358 | @section Configuration suite |
---|
359 | |
---|
360 | These routines deal with extracting configuration information stored |
---|
361 | in the system. This includes the default realm, Key Distribution Center |
---|
362 | (KDC) servers (@file{krb.conf}) and host/realm mappings (@file{krb.realms}). |
---|
363 | |
---|
364 | @menu |
---|
365 | * krb_get_lrealm:: |
---|
366 | * krb_realmofhost:: |
---|
367 | * krb_get_krbhst:: |
---|
368 | * krb_get_admhst:: |
---|
369 | * krb_get_default_user:: |
---|
370 | * krb_set_default_user:: |
---|
371 | |
---|
372 | @end menu |
---|
373 | |
---|
374 | |
---|
375 | @node krb_get_lrealm |
---|
376 | @subsection krb_get_lrealm |
---|
377 | @findex krb_get_lrealm |
---|
378 | @code{int |
---|
379 | krb_get_lrealm(char *realm, int n);} |
---|
380 | |
---|
381 | This operation fills in the name of the default or local realm. |
---|
382 | @var{realm} must be at least @code{REALM_SZ} (40) bytes long. The value |
---|
383 | of @var{n} must always be `1', for historical reasons. |
---|
384 | |
---|
385 | On Unix machines, this information is currently stored in a file called |
---|
386 | @file{/usr/kerberos/lib/krb.conf}. In MS-Windows, it is in |
---|
387 | @file{krb.conf}, in the directory @file{\windows\krb.rea}. On the |
---|
388 | Macintosh, it is stored in the ``Kerberos Client'' Preferences file. |
---|
389 | |
---|
390 | @node krb_realmofhost |
---|
391 | @subsection krb_realmofhost |
---|
392 | @findex krb_realmofhost |
---|
393 | @code{char * |
---|
394 | krb_realmofhost(char *host);} |
---|
395 | |
---|
396 | Returns the Kerberos realm of the host @var{host}. |
---|
397 | @var{host} should be the fully-qualified domain-style primary |
---|
398 | host name of the host in question. |
---|
399 | |
---|
400 | @var{realm} must be at least @code{REALM_SZ} (40) bytes long. |
---|
401 | |
---|
402 | On Unix machines, this information is currently stored in a file called |
---|
403 | @file{/usr/kerberos/lib/krb.realms}. In MS-Windows, it is stored in a |
---|
404 | file called @file{krb.rea}, whose name is contained in the |
---|
405 | @file{kerberos.ini} file. In Macintosh, it is stored in the ``Kerberos |
---|
406 | Client'' Preferences file. In order to prevent certain security |
---|
407 | attacks, this routine must either have @emph{a priori} knowledge of a |
---|
408 | host's realm, or obtain such information securely. |
---|
409 | |
---|
410 | The format of the translation file on Unix is described in the |
---|
411 | @emph{Cygnus Network Security---User and Administrator Documentation for |
---|
412 | CNS Version 1,} manual. If @var{host} exactly matches a host_name line, |
---|
413 | the corresponding realm is returned. Otherwise, if the domain portion |
---|
414 | of @var{host} matches a domain_name line, the corresponding realm is |
---|
415 | returned. If @var{host} contains a domain, but no translation is found, |
---|
416 | @var{host's} domain is converted to upper-case and returned. If |
---|
417 | @var{host} contains no discernible domain, or an error occurs, the local |
---|
418 | realm name, as supplied by @ref{krb_realmofhost,,krb_get_lrealm}, is |
---|
419 | returned. |
---|
420 | |
---|
421 | @node krb_get_krbhst |
---|
422 | @subsection krb_get_krbhst |
---|
423 | @findex krb_get_krbhst |
---|
424 | @code{int |
---|
425 | krb_get_krbhst(char *host, char *realm, int n);} |
---|
426 | |
---|
427 | @code{krb_get_krbhst} fills in @var{host} with the hostname of the |
---|
428 | @var{n}th host running a Kerberos key distribution center (KDC) for |
---|
429 | realm @var{realm}. @var{host} must be large enough to hold any hostname. |
---|
430 | (You can get a portable definition of @code{MAXHOSTNAMELEN} by using |
---|
431 | @code{#define DEFINE_SOCKADDR} before including @file{"krb.h"}). |
---|
432 | |
---|
433 | If the host is successfully filled in, the routine returns |
---|
434 | @code{KSUCCESS}. If the configuration information is unavailable, and |
---|
435 | @var{n} equals `1', then the routine fills in @var{host} with |
---|
436 | @samp{kerberos.@var{realm}} and returns @code{KSUCCESS}. If there are |
---|
437 | fewer than @var{n} hosts running a Kerberos KDC for the requested realm, |
---|
438 | or the configuration information is malformed, the routine returns |
---|
439 | @code{KFAILURE}. |
---|
440 | |
---|
441 | To locate all key distribution centers, the application |
---|
442 | can re-call with a larger @var{n} as long as the result continues to |
---|
443 | be @code{KSUCCESS}. |
---|
444 | |
---|
445 | On Unix machines, this information is currently stored in an ASCII |
---|
446 | configuration file called @file{/usr/kerberos/lib/krb.conf} and |
---|
447 | described in the @emph{Cygnus Network Security---User and Administrator |
---|
448 | Documentation for CNS Version 1,} manual. In MS-Windows, it is |
---|
449 | @file{krb.conf}. The default location for @file{krb.conf} is in |
---|
450 | @file{\windows\krb.rea}. Macintosh, it is stored in the ``Kerberos |
---|
451 | Client'' Preferences file. |
---|
452 | |
---|
453 | @node krb_get_admhst |
---|
454 | @subsection krb_get_admhst |
---|
455 | @findex krb_get_admhst |
---|
456 | @code{extern int |
---|
457 | krb_get_admhst(char *host, char *realm, int n);} |
---|
458 | |
---|
459 | @code{krb_get_admhst} fills in @var{host} with the hostname of the |
---|
460 | @var{n}th host running a Kerberos KDC database administration server |
---|
461 | for realm @var{realm}. If the configuration information is unavailable |
---|
462 | or is malformed, or there are fewer than @var{n} hosts running a |
---|
463 | Kerberos KDC database administration server, the routine returns |
---|
464 | @code{KFAILURE}. |
---|
465 | |
---|
466 | @var{host} must be large enough to hold any hostname |
---|
467 | (@code{MAXHOSTNAMELEN} from @file{<sys/param.h>}). |
---|
468 | |
---|
469 | On Unix machines, this information is currently stored in a file called |
---|
470 | @file{/usr/kerberos/lib/krb.conf}. In MS-Windows, it is |
---|
471 | @file{krb.conf}. The default location for @file{krb.conf} is in |
---|
472 | @file{\windows\krb.rea}. Macintosh, it is stored in the ``Kerberos |
---|
473 | Client'' Preferences file. |
---|
474 | |
---|
475 | @node krb_get_default_user |
---|
476 | @subsection krb_get_default_user |
---|
477 | @findex krb_get_default_user |
---|
478 | @code{char * |
---|
479 | krb_get_default_user(void);} |
---|
480 | |
---|
481 | Returns the default @var{user} as configured, if the Kerberos |
---|
482 | implementation has the concept of a default @var{user name}. The |
---|
483 | result may include a user name, an instance field, and possibly a |
---|
484 | realm name. |
---|
485 | |
---|
486 | On Unix machines, the result is the current logged-in user name. |
---|
487 | In MS-Windows and Macintosh, it is the last name set with |
---|
488 | @code{krb_set_default_user}. |
---|
489 | |
---|
490 | |
---|
491 | @node krb_set_default_user |
---|
492 | @subsection krb_set_default_user |
---|
493 | @findex krb_set_default_user |
---|
494 | @code{int |
---|
495 | krb_set_default_user(char *user);} |
---|
496 | |
---|
497 | Sets the default @var{user} name to be used in future Kerberos |
---|
498 | interactions with the user. This call can be used by applications to |
---|
499 | override the default @var{user} configured in the Kerberos |
---|
500 | implementation. On some platforms, this setting persists after |
---|
501 | reboots. |
---|
502 | |
---|
503 | |
---|
504 | @node Credential Suite |
---|
505 | @section Credential suite |
---|
506 | |
---|
507 | These routines give access to credentials which are saved for the |
---|
508 | duration of the user's interaction with their computer. The storage |
---|
509 | for these credentials is called the @samp{credentials cache}, or in |
---|
510 | older parlance inherited from the first implementation, a @samp{ticket file}. |
---|
511 | |
---|
512 | @menu |
---|
513 | * krb_get_cred:: Get a credential by matching service names. |
---|
514 | * krb_save_credentials:: Save a new credential in the cache |
---|
515 | * krb_get_num_cred:: Count how many credentials there are. |
---|
516 | * krb_get_nth_cred:: Get one credential, by number. |
---|
517 | * krb_get_tf_fullname:: Get the principal name of the current user. |
---|
518 | * dest_tkt:: Destroy all tickets in the cache. |
---|
519 | @end menu |
---|
520 | |
---|
521 | @node krb_get_cred |
---|
522 | @subsection krb_get_cred |
---|
523 | @findex krb_get_cred |
---|
524 | @code{int krb_get_cred (char *service, char *instance, char *realm, |
---|
525 | struct credentials *credp);} |
---|
526 | |
---|
527 | Retrieves a given credential (specified by the triple of @var{service}, |
---|
528 | @var{instance}, and @var{realm}) from the current ticket cache. The |
---|
529 | resulting credential is stored through the argument pointer @var{credp}. |
---|
530 | |
---|
531 | The result is an error code. |
---|
532 | |
---|
533 | @code{krb_get_cred} searches the caller's ticket cache for a ticket for |
---|
534 | the given service, instance, and realm; and, if a ticket is found, |
---|
535 | fills in the given @code{CREDENTIALS} structure with the ticket |
---|
536 | information. If the ticket is found, @code{krb_get_cred} returns |
---|
537 | @code{GC_OK}. If the ticket file cannot be found, cannot be read, does not |
---|
538 | belong to the user (other than @samp{root}), is not a regular file, or |
---|
539 | is in the wrong mode, the error @code{GC_TKFIL} is returned. |
---|
540 | |
---|
541 | |
---|
542 | @node krb_save_credentials |
---|
543 | @subsection krb_save_credentials |
---|
544 | @findex krb_save_credentials |
---|
545 | @code{ |
---|
546 | int |
---|
547 | krb_save_credentials ((char *service, char *instance, char *realm, |
---|
548 | C_Block session, int lifetime, int kvno, KTEXT ticket, |
---|
549 | long issue_date))} |
---|
550 | |
---|
551 | Saves the given credential into the current ticket cache. |
---|
552 | |
---|
553 | @node krb_get_num_cred |
---|
554 | @subsection krb_get_num_cred |
---|
555 | @findex krb_get_num_cred |
---|
556 | @code{int |
---|
557 | krb_get_num_cred(void)} |
---|
558 | |
---|
559 | Returns the number of credentials in the current ticket cache, or `-1' |
---|
560 | if an error occurs. |
---|
561 | |
---|
562 | @node krb_get_nth_cred |
---|
563 | @subsection krb_get_nth_cred |
---|
564 | @findex krb_get_nth_cred |
---|
565 | @code{int |
---|
566 | krb_get_nth_cred(char *name, char *instance, char *realm, int n)} |
---|
567 | |
---|
568 | Retrieves the @var{n}th (where @var{n} starts at zero) credential from |
---|
569 | the current ticket cache and returns its name, instance and realm |
---|
570 | through the supplied @samp{char *}s, which must point to memory areas at |
---|
571 | least @samp{NAME_SZ}, @samp{INST_SZ}, and @samp{REALM_SZ} bytes long. |
---|
572 | The result is a Kerberos error code or KSUCCESS. The full credential |
---|
573 | may then be obtained by using krb_get_cred. |
---|
574 | |
---|
575 | @node krb_get_tf_fullname |
---|
576 | @subsection krb_get_tf_fullname |
---|
577 | @findex krb_get_tf_fullname |
---|
578 | @code{int |
---|
579 | krb_get_tf_fullname (char *tktfile, char *name, char *instance, char *realm)} |
---|
580 | |
---|
581 | Returns the name, instance, and realm of the principal in the current |
---|
582 | credential cache (also known as a ticket file). The ticket file name |
---|
583 | is the first parameter. The default name is used if the argument |
---|
584 | is a null pointer. Name, instance, and realm must point to areas |
---|
585 | of memory at least |
---|
586 | @samp{NAME_SZ}, @samp{INST_SZ}, and @samp{REALM_SZ} bytes long. |
---|
587 | The result is KSUCCESS or a Kerberos error code. |
---|
588 | |
---|
589 | @node dest_tkt |
---|
590 | @subsection dest_tkt |
---|
591 | @findex dest_tkt |
---|
592 | @code{int |
---|
593 | dest_tkt(void);} |
---|
594 | |
---|
595 | Destroys all the credentials in the current ticket cache. |
---|
596 | The result is KSUCCESS or a Kerberos error code. |
---|
597 | |
---|
598 | |
---|
599 | |
---|
600 | @node High-level Suite |
---|
601 | @section High-level Suite |
---|
602 | |
---|
603 | This library supports network authentication and various related operations. |
---|
604 | The following calls form the high-level Kerberos suite. |
---|
605 | |
---|
606 | @menu |
---|
607 | * krb_mk_auth:: |
---|
608 | @end menu |
---|
609 | |
---|
610 | @node krb_mk_auth |
---|
611 | @subsection krb_mk_auth |
---|
612 | @findex krb_mk_auth |
---|
613 | |
---|
614 | @code{int krb_mk_auth(long options, KTEXT ticket, char *service, char |
---|
615 | *instance, char *realm, unsigned KRBINT32 checksum, char *version, KTEXT |
---|
616 | buf);} |
---|
617 | |
---|
618 | Generates an authenticator that is equivalent to that used by |
---|
619 | the standard Kerberos V4 @var{krb_sendauth} routine. |
---|
620 | |
---|
621 | Using initial tickets stored in the current ticket cache, it gets a |
---|
622 | ticket (authenticator) for the service @var{service} on the host |
---|
623 | @var{instance}, in the realm @var{realm}. @var{service} should be the |
---|
624 | single component name for the service (@code{pop}, @code{rcmd}, etc). |
---|
625 | @var{instance} should be the name of the application server host; |
---|
626 | @code{krb_mk_auth} normally canonicalizes it using @code{krb_get_phost}. |
---|
627 | |
---|
628 | The @var{options} available are |
---|
629 | @table @code |
---|
630 | @item KOPT_DONT_CANON |
---|
631 | Don't canonicalize instance as a hostname. (If this option is not |
---|
632 | chosen, @code{krb_get_phost} is called to canonicalize it.) |
---|
633 | @item KOPT_DONT_MK_REQ |
---|
634 | Don't request server ticket from Kerberos. A ticket must be supplied in |
---|
635 | the @var{ticket} argument. (If this option is not chosen, and there is no |
---|
636 | ticket for the given server in the ticket cache, one will be fetched |
---|
637 | using @code{krb_mk_req} and returned in @var{ticket}.) |
---|
638 | @item KOPT_DO_MUTUAL |
---|
639 | Do mutual authentication, requiring that the receiving server return the |
---|
640 | @var{checksum}@code{+1} encrypted in the session key. The mutual |
---|
641 | authentication is done using @code{krb_mk_priv} on the other side (see |
---|
642 | @file{recvauth.c}) and @code{krb_rd_priv} on this side. |
---|
643 | @end table |
---|
644 | |
---|
645 | @var{checksum} is an application-provided checksum that is cryptographically |
---|
646 | transmitted in the authenticator; if the application needs no checksum |
---|
647 | securely transferred, use zero. The @var{version} argument allows the |
---|
648 | client program to pass an application-specific version string that the |
---|
649 | server program can then match against its own version string. The |
---|
650 | resulting byte string, which should be transmitted to the application's |
---|
651 | server, is placed into the buffer @file{buf}. |
---|
652 | |
---|
653 | If doing mutual authentication, the application should then read a |
---|
654 | response from the application server, using application-dependent |
---|
655 | means, and call @code{krb_check_auth} to check its validity. |
---|
656 | |
---|
657 | To make a call that is compatible with the Unix @code{sendauth} and |
---|
658 | @code{recvauth} calls requires some work. See the source code in |
---|
659 | @file{lib/krb/sendauth.c} for full details. @code{sendauth} |
---|
660 | compatibility is deprecated because it involves sending binary data |
---|
661 | across an otherwise application-controlled TCP socket. Instead, the |
---|
662 | application should control the manner in which the authenticator gets |
---|
663 | from the client to the server, using a protocol harmonious with the rest |
---|
664 | of the traffic on that socket. |
---|
665 | |
---|
666 | @node Transformation Suite |
---|
667 | @section Transformation Suite |
---|
668 | |
---|
669 | These routines create authenticated messages which can be |
---|
670 | passed between clients and servers. |
---|
671 | |
---|
672 | The @code{KTEXT} structure is used to pass around text of varying |
---|
673 | lengths. It consists of a buffer for the data, and a length. |
---|
674 | @code{krb_rd_req} takes an argument of this type containing the |
---|
675 | authenticator, and @code{krb_mk_req} returns the authenticator in a |
---|
676 | structure of this type. @code{KTEXT} itself is really a pointer to the |
---|
677 | structure. The actual structure is of type @code{KTEXT_ST}. |
---|
678 | |
---|
679 | The @code{AUTH_DAT} structure is filled in by @code{krb_rd_req}. It |
---|
680 | must be allocated before calling @code{krb_rd_req}, and a pointer to it |
---|
681 | is passed. The structure is filled in with data obtained from |
---|
682 | Kerberos. The @code{MSG_DAT} structure is filled in by either |
---|
683 | @code{krb_rd_priv}, @code{krb_rd_safe}, or @code{krb_rd_err}. It must |
---|
684 | be allocated before the call and a pointer to it is passed. The |
---|
685 | structure is filled in with data obtained from Kerberos. |
---|
686 | |
---|
687 | Note that the caller of @code{krb_rd_req}, @code{krb_rd_priv}, and |
---|
688 | @code{krb_rd_safe} must check time order and for replay attempts. |
---|
689 | |
---|
690 | @menu |
---|
691 | * krb_mk_req:: |
---|
692 | * krb_rd_req:: |
---|
693 | * krb_mk_priv:: |
---|
694 | * krb_rd_priv:: |
---|
695 | * krb_mk_safe:: |
---|
696 | * krb_rd_safe:: |
---|
697 | @end menu |
---|
698 | |
---|
699 | @node krb_mk_req |
---|
700 | @subsection krb_mk_req |
---|
701 | @findex krb_mk_req |
---|
702 | |
---|
703 | @code{int |
---|
704 | krb_mk_req(KTEXT authent, char *service_name, |
---|
705 | char *instance, char *realm, long int xsum);} |
---|
706 | |
---|
707 | Generates an authenticator for the service @var{service_name} on the |
---|
708 | host @var{instance}, in realm @var{realm}. Using initial tickets stored |
---|
709 | in the default ticket cache, it connects to the Key Distribution Center |
---|
710 | to retrieve a service ticket. @var{service_name} should be the single |
---|
711 | component name for the service (@code{pop}, @code{discuss}, etc). |
---|
712 | @var{instance} should be the unqualified name of the application server |
---|
713 | host, perhaps as obtained by a call to @code{krb_get_phost}. @var{xsum} |
---|
714 | is a checksum that is cryptographically transmitted in the |
---|
715 | authenticator. |
---|
716 | |
---|
717 | @code{krb_mk_req} takes a pointer to a text structure in which an |
---|
718 | authenticator is to be built. It also takes the name, instance, and |
---|
719 | realm of the service to be used and an optional checksum. It is up to |
---|
720 | the application to decide how to generate the checksum. |
---|
721 | @code{krb_mk_req} then retrieves a ticket for the desired service and |
---|
722 | creates an authenticator. The authenticator is built in @var{authent} |
---|
723 | and is accessible to the calling procedure. It is up to the application |
---|
724 | to get the authenticator to the service where it is read by |
---|
725 | @code{krb_rd_req}. Unless an attacker possesses the session key |
---|
726 | contained in the ticket, it cannot modify the authenticator. Thus, the |
---|
727 | checksum can be used to verify the authenticity of the other data that |
---|
728 | pass through a connection. |
---|
729 | |
---|
730 | |
---|
731 | @node krb_rd_req |
---|
732 | @subsection krb_rd_req |
---|
733 | @findex krb_rd_req |
---|
734 | |
---|
735 | @code{int krb_rd_req(KTEXT @var{authent},char *@var{service}, |
---|
736 | char *@var{instance}, long @var{from_addr}, |
---|
737 | AUTH_DAT *@var{ad}, char *@var{filename})} |
---|
738 | |
---|
739 | @code{krb_rd_req} takes an authenticator of type @code{KTEXT}, a service |
---|
740 | name, an instance, the address of the host originating the request, and |
---|
741 | a pointer to a structure of type @code{AUTH_DAT} which is filled in with |
---|
742 | information obtained from the authenticator. Optionally, it also takes |
---|
743 | the name of the file in which it finds the secret key(s) for the |
---|
744 | service. If the supplied instance contains @samp{*}, then the first |
---|
745 | service key with the same service name found in the service key file is |
---|
746 | used, and the @var{instance} argument is filled in with the chosen |
---|
747 | instance. This means that the caller must provide space for such an |
---|
748 | instance name. |
---|
749 | |
---|
750 | If the last argument is an empty string, @code{krb_rd_req} uses the file |
---|
751 | @file{/etc/krb-srvtab} to find its keys. If the last argument is |
---|
752 | @code{NULL}, it assumes that the key in the authenticator has been set |
---|
753 | by @code{krb_set_key} and does not look further. |
---|
754 | |
---|
755 | This routine is used to find out information about the principal when a |
---|
756 | request has been made to a service. It is up to the application |
---|
757 | protocol to get the authenticator from the client to the service. The |
---|
758 | routine then passes the authenticator to @code{krb_rd_req} to extract |
---|
759 | the desired information. |
---|
760 | |
---|
761 | @code{krb_rd_req} returns zero (@code{RD_AP_OK}) upon successful |
---|
762 | authentication. If a packet were forged, modified, or replayed, |
---|
763 | authentication fails. If authentication fails, a non-zero value is |
---|
764 | returned indicating the particular problem encountered. See |
---|
765 | @file{krb.h} for the list of error codes. |
---|
766 | |
---|
767 | |
---|
768 | @node krb_mk_priv |
---|
769 | @subsection krb_mk_priv |
---|
770 | @findex krb_mk_priv |
---|
771 | @code{krb_mk_priv(char *in, char *out, unsigned KRB_INT32 in_length, |
---|
772 | Key_schedule schedule, C_Block *key, struct sockaddr_in *sender, struct |
---|
773 | sockaddr_in *receiver);} |
---|
774 | |
---|
775 | long krb_mk_priv(u_char *@var{in}, u_char *@var{out}, u_long |
---|
776 | @var{in_length}, |
---|
777 | des_cblock @var{key}, des_key_schedule @var{schedule}; struct |
---|
778 | sockaddr_in *@var{sender}, |
---|
779 | struct sockaddr_in *@var{receiver}); |
---|
780 | |
---|
781 | @code{krb_mk_priv} creates an encrypted, authenticated message from any |
---|
782 | arbitrary application data, pointed to by @var{in} and @var{in_length} |
---|
783 | bytes long. The private session key, pointed to by @var{key} and the |
---|
784 | key schedule, @var{schedule}, are used to encrypt the data and some |
---|
785 | header information using PCBC encryption. @var{sender} and |
---|
786 | @var{receiver} point to the Internet address of the two parties. In |
---|
787 | addition to providing privacy, this protocol message protects against |
---|
788 | modifications, insertions or replays. The encapsulated message and |
---|
789 | header are placed in the area pointed to by @var{out}, which should be |
---|
790 | able to hold @code{in_length + 32} bytes. The routine returns the |
---|
791 | length of the output, or `-1' indicating an error. |
---|
792 | |
---|
793 | |
---|
794 | @node krb_rd_priv |
---|
795 | @subsection krb_rd_priv |
---|
796 | @findex krb_rd_priv |
---|
797 | @code{int krb_rd_priv(char *in, unsigned KRB_INT32 in_length, char |
---|
798 | *schedule, char *key, struct sockaddr *sender, struct sockaddr |
---|
799 | *receiver, MSG_DAT *msg_data);} |
---|
800 | |
---|
801 | long krb_rd_priv(u_char *@var{in}, u_long @var{in_length}, |
---|
802 | Key_schedule @var{schedule}, des_cblock @var{key}, struct |
---|
803 | sockaddr_in *@var{sender}, |
---|
804 | struct sockaddr_in *@var{receiver}, |
---|
805 | MSG_DAT *@var{msg_data}); |
---|
806 | |
---|
807 | This routine is used to decrypt and authenticate a message created by |
---|
808 | @code{krb_mk_priv}. @var{in} points to the beginning of the received |
---|
809 | message, the length of which is specified in @var{in_length}. The |
---|
810 | private session key, pointed to by @var{key}, is used to decrypt and |
---|
811 | verify the received message. If @var{schedule} is non-null, |
---|
812 | @var{schedule} points to the calculated key schedule for the key. The |
---|
813 | routine fills in fields in the @var{msg_data} structure with information |
---|
814 | retrieved from the message. |
---|
815 | |
---|
816 | @code{krb_rd_priv} decrypts and authenticates a received |
---|
817 | @code{krb_mk_priv} message. The private session key, pointed to by |
---|
818 | @var{key}, and the key schedule, @var{schedule}, are used to decrypt and |
---|
819 | verify the received message. @var{msg_data} is a pointer to a |
---|
820 | @code{MSG_DAT} struct. The routine fills in the @code{app_data} field |
---|
821 | with a pointer to the decrypted application data, @code{app_length} with |
---|
822 | the length of the @code{app_data} field, @code{time_sec} and |
---|
823 | @code{time_5ms} with the timestamps in the message, and @code{swap} with |
---|
824 | a `1' if the byte order of the receiver is different than that of the |
---|
825 | sender. (The application must still determine if it is appropriate to |
---|
826 | byte-swap application data; the Kerberos protocol fields are already |
---|
827 | taken care of). The routine returns zero if okay, or a Kerberos error |
---|
828 | code. Modified messages and old messages cause errors, but the caller |
---|
829 | must check the time sequence of messages. |
---|
830 | |
---|
831 | |
---|
832 | @node krb_mk_safe |
---|
833 | @subsection krb_mk_safe |
---|
834 | @findex krb_mk_safe |
---|
835 | @code{krb_mk_safe(unsigned char *in, unsigned char *out, |
---|
836 | unsigned KRB_INT32 in_length, C_Block *key, struct sockaddr_in *sender, |
---|
837 | struct sockaddr_in *receiver);} |
---|
838 | |
---|
839 | long krb_mk_safe(u_char *@var{in}, u_char *@var{out}, u_long |
---|
840 | @var{in_length}, |
---|
841 | des_cblock @var{key}, |
---|
842 | struct sockaddr_in *@var{sender}, |
---|
843 | struct sockaddr_in *@var{receiver}); |
---|
844 | |
---|
845 | This routine makes an authenticated, but unencrypted message from any |
---|
846 | arbitrary application data, pointed to by @var{in} and @var{in_length} |
---|
847 | bytes long. The private session key, pointed to by @var{key}, is used |
---|
848 | to seed the @var{quad_cksum} checksum algorithm used as part of the |
---|
849 | authentication. @var{sender} and @var{receiver} point to the Internet |
---|
850 | addresses of the two parties. The encapsulated message and header are |
---|
851 | placed in the area pointed to by @var{out}. This area should be to hold |
---|
852 | @var{in_length + 32} bytes. The routine returns the length of the |
---|
853 | output, or `-1' indicating an error. |
---|
854 | |
---|
855 | This message does |
---|
856 | not provide privacy, but does protect (via detection) against |
---|
857 | modifications, insertions or replays. The |
---|
858 | authentication provided by this routine is not as strong as that |
---|
859 | provided by @code{krb_mk_priv} or by computing the checksum using |
---|
860 | @code{cbc_cksum} instead, both of which authenticate via DES. |
---|
861 | |
---|
862 | |
---|
863 | @node krb_rd_safe |
---|
864 | @subsection krb_rd_safe |
---|
865 | @findex krb_rd_safe |
---|
866 | @code{long krb_rd_safe(u_char *@var{in}, u_long @var{in_length}, |
---|
867 | des_cblock @var{key}, |
---|
868 | struct sockaddr_in *@var{sender}, |
---|
869 | struct sockaddr_in *@var{receiver}, |
---|
870 | MSG_DAT *@var{msg_data})} |
---|
871 | |
---|
872 | This routine is used to authenticate a message created by |
---|
873 | @code{krb_mk_safe}. @var{in} points to the beginning of the received |
---|
874 | message, whose length is specified in @var{in_length}. The private |
---|
875 | session key, pointed to by @var{key}, is used to verify the |
---|
876 | authentication checksum of the received message. |
---|
877 | |
---|
878 | @var{msg_data} is a pointer to a @code{MSG_DAT} struct, defined in |
---|
879 | @file{krb.h}. The routine fills in these @code{MSG_DAT} fields: the |
---|
880 | @code{app_data} field with a pointer to the application data, |
---|
881 | @code{app_length} with the length of the @code{app_data} field, |
---|
882 | @code{time_sec} and @code{time_5ms} with the timestamps in the message, |
---|
883 | and @code{swap} with a `1' if the byte order of the receiver is |
---|
884 | different than that of the sender. (The application must still |
---|
885 | determine if it is appropriate to byteswap application data; the |
---|
886 | Kerberos protocol fields are already taken care of). |
---|
887 | |
---|
888 | The routine returns zero if okay, or a Kerberos error code. Modified |
---|
889 | messages and old messages cause errors, but the caller must check the |
---|
890 | time sequence of messages. |
---|
891 | |
---|
892 | |
---|
893 | @node Encryption Suite |
---|
894 | @section Encryption suite |
---|
895 | |
---|
896 | The Kerberos library supports various DES encryption related |
---|
897 | operations. It differs from the @code{crypt}, @code{setkey}, and |
---|
898 | @code{encrypt} library routines in that it provides a true DES |
---|
899 | encryption, without modifying the algorithm, and executes much faster. |
---|
900 | |
---|
901 | For each key that may be simultaneously active, create a |
---|
902 | @code{des_key_schedule} struct. Next, create key schedules (from the |
---|
903 | 8-byte keys) as needed, via @code{des_key_sched}, prior to using the |
---|
904 | encryption or checksum routines. Then set up the input and output areas |
---|
905 | (lengths are restricted to be multiples of eight bytes). Finally, |
---|
906 | invoke the encryption/decryption routine, @code{des_cbc_encrypt} or |
---|
907 | @code{des_pcbc_encrypt}. |
---|
908 | |
---|
909 | A @code{des_cblock} struct is an 8-byte block used as the fundamental |
---|
910 | unit for DES data and keys, and is defined as: |
---|
911 | @smallexample |
---|
912 | typedef unsigned char des_cblock[8]; |
---|
913 | @end smallexample |
---|
914 | @noindent |
---|
915 | and a @code{des_key_schedule} is defined as: |
---|
916 | @smallexample |
---|
917 | typedef struct des_ks_struct |
---|
918 | @{des_cblock _;@} |
---|
919 | des_key_schedule[16]; |
---|
920 | @end smallexample |
---|
921 | |
---|
922 | @menu |
---|
923 | * des_key_sched:: |
---|
924 | * des_cbc_encrypt:: |
---|
925 | * des_string_to_key:: |
---|
926 | @end menu |
---|
927 | |
---|
928 | @node des_key_sched |
---|
929 | @subsection des_key_sched |
---|
930 | @findex des_key_sched |
---|
931 | @code{des_key_sched(des_cblock *key, des_key_schedule *schedule);} |
---|
932 | |
---|
933 | This routine calculates a key schedule from the input @var{key}, |
---|
934 | and outputs the schedule into @var{schedule}. The key schedule may then be |
---|
935 | used in subsequent encryption/decryption operations. |
---|
936 | The user must overwrite or clear all keys and |
---|
937 | schedules as soon as no longer needed, to discourage their disclosure |
---|
938 | in memory dumps. |
---|
939 | |
---|
940 | @node des_cbc_encrypt |
---|
941 | @subsection des_cbc_encrypt |
---|
942 | @findex des_cbc_encrypt |
---|
943 | |
---|
944 | @code{int des_cbc_encrypt(des_cblock *@var{input},des_cblock |
---|
945 | *@var{output}, long @var{length}, des_key_schedule @var{schedule}, |
---|
946 | des_cblock *@var{ivec}, int @var{encrypt})} |
---|
947 | |
---|
948 | This routine encrypts or decrypts data using @code{DES CBC} mode. The |
---|
949 | data pointed to by @var{data}, of length @var{data_len}, are encrypted |
---|
950 | with the pre-calculated key schedule @var{schedule} and initialization |
---|
951 | vector @var{ivec}, and placed in @var{data_out}. If @var{encrypt_flag} |
---|
952 | is zero, then decryption is performed. If @var{encrypt_flag} is |
---|
953 | `1', then encryption is performed. |
---|
954 | |
---|
955 | This routine encrypts or decrypts a block of data using the |
---|
956 | cipher-block-chaining (CBC) mode of DES. |
---|
957 | |
---|
958 | If the @var{encrypt} argument is non-zero, the routine CBC-encrypts the |
---|
959 | cleartext data pointed to by the @var{input} argument. This is done |
---|
960 | into the ciphertext pointed to by the @var{output} argument, using the |
---|
961 | key schedule provided by the @var{schedule} argument, and initialization |
---|
962 | vector provided by the @var{ivec} argument. If the @var{length} argument |
---|
963 | is not an integral multiple of eight bytes, the last block is zero |
---|
964 | filled (highest addresses). The output is always an integral multiple |
---|
965 | of eight bytes. |
---|
966 | |
---|
967 | If @var{encrypt} is zero, the routine CBC decrypts the ciphertext data |
---|
968 | pointed to by the @var{input} argument. The result is put into |
---|
969 | cleartext pointed to by the @var{output} argument. This is done using |
---|
970 | the key schedule provided by the @var{schedule} argument, and |
---|
971 | initialization vector provided by the @var{ivec} argument. Decryption |
---|
972 | always operates on integral multiples of 8 bytes, so it rounds the |
---|
973 | length provided up to the appropriate multiple. Consequently, it always |
---|
974 | produces the rounded-up number of bytes of output cleartext. The |
---|
975 | application must determine if the output cleartext was zero-padded due |
---|
976 | to original cleartext lengths that were not integral multiples of 8. |
---|
977 | |
---|
978 | No errors or meaningful values are returned. @code{void} is not used |
---|
979 | for compatibility with older compilers. |
---|
980 | |
---|
981 | A characteristic of CBC mode is that changing even a single bit of the |
---|
982 | cleartext affects all the subsequent ciphertext. This makes |
---|
983 | cryptanalysis much more difficult. However, modifying a single bit of |
---|
984 | the ciphertext, then decrypting, only affects the resulting cleartext |
---|
985 | from the modified block and the succeeding block. The |
---|
986 | @code{des_pcbc_encrypt} routine was designed to detect modifications. |
---|
987 | However, because of problems, CBC mode in no longer recommended. |
---|
988 | |
---|
989 | @node des_string_to_key |
---|
990 | @subsection des_string_to_key |
---|
991 | @findex des_string_to_key |
---|
992 | @code{int des_string_to_key (char *string, char *key);} |
---|
993 | |
---|
994 | This routine converts an arbitrary length null-terminated @var{string} |
---|
995 | to an 8-byte DES key @var{key}, with odd byte parity. A one-way |
---|
996 | function is used to convert the string to a key, making it very |
---|
997 | difficult to reconstruct the string from the key. No meaningful value |
---|
998 | is returned. @code{void} is not used for compatibility with older |
---|
999 | compilers. |
---|
1000 | |
---|
1001 | @c If options is @var{krb_afs_flag}, then a Transarc string to key |
---|
1002 | @c algorithm is used, and @var{realm} should be the realm name to be used |
---|
1003 | @c in the transformation. |
---|
1004 | |
---|
1005 | @node Stream Suite |
---|
1006 | @section Stream functions |
---|
1007 | |
---|
1008 | @menu |
---|
1009 | * Kstream Overview:: Overview |
---|
1010 | * Kstream implementation:: sample stream implementation |
---|
1011 | @end menu |
---|
1012 | |
---|
1013 | @node Kstream Overview |
---|
1014 | @subsection Kstream Overview |
---|
1015 | |
---|
1016 | The @code{kstream} suite provides similar functions to the Standard I/O |
---|
1017 | Library (@file{stdio}). It permits you to create encrypted and |
---|
1018 | plaintext (unencrypted) I/O streams. You can create a @code{kstream}, |
---|
1019 | read from it or write to it, and destroy it. You also have some control |
---|
1020 | of buffering. At this time, the @code{kstream} suite is not available |
---|
1021 | for the Mac. |
---|
1022 | |
---|
1023 | The encryption system used (if any) is determined at the time of |
---|
1024 | creation. There are several create routines provided. |
---|
1025 | @table @samp |
---|
1026 | @findex kstream_create_rlogin_from_fd |
---|
1027 | @item kstream_create_rlogin_from_fd |
---|
1028 | creates a @code{kstream} using the same encryption mechanism that the |
---|
1029 | CNS @code{rlogin} program uses on a file descriptor |
---|
1030 | passed as an argument |
---|
1031 | @findex kstream_create_rcp_from_fd |
---|
1032 | @item kstream_create_rcp_from_fd |
---|
1033 | is the same as the @code{rlogin} version except that @code{rcp} pads |
---|
1034 | short blocks in a different way than @code{rlogin}. |
---|
1035 | @findex kstream_create_from_fd |
---|
1036 | @item kstream_create_from_fd |
---|
1037 | is a generic creation routine which takes a |
---|
1038 | @samp{kstream_crypt_ctl_block} which is simply a vector of pointers to |
---|
1039 | functions for encryption, decryption, initialization, and cleanup. |
---|
1040 | |
---|
1041 | @end table |
---|
1042 | |
---|
1043 | After creating a @code{kstream}, you simply call @code{kstream_read} or |
---|
1044 | @code{kstream_write} just as you would normally call @code{read} or |
---|
1045 | @code{write}. @code{kstream_flush} explicitly flushes any buffered data |
---|
1046 | out to the underlying file descriptor. @code{kstream_set_buffer_mode} |
---|
1047 | is used to turn buffering on or off; it defaults to on, but interactive |
---|
1048 | applications such as @code{rlogin} explicitly turn it off. |
---|
1049 | |
---|
1050 | @example |
---|
1051 | kstream kstream_create_from_fd (int fd, |
---|
1052 | const struct kstream_crypt_ctl_block *ctl, |
---|
1053 | kstream_ptr data); |
---|
1054 | |
---|
1055 | kstream_create_rlogin_from_fd (int fd, void* sched, |
---|
1056 | unsigned char (*ivec)[8]); |
---|
1057 | kstream kstream_create_rcp_from_fd (int fd, void* sched, |
---|
1058 | unsigned char (*ivec)[8]); |
---|
1059 | |
---|
1060 | int kstream_write (kstream, void*, size_t); |
---|
1061 | int kstream_read (kstream, void*, size_t); |
---|
1062 | int kstream_flush (kstream); |
---|
1063 | int kstream_destroy (kstream); |
---|
1064 | void kstream_set_buffer_mode (kstream, int); |
---|
1065 | @end example |
---|
1066 | |
---|
1067 | @node Kstream implementation |
---|
1068 | @subsection Sample implementation of a stream encryption package |
---|
1069 | |
---|
1070 | First, a brief description of the stream protocols in use. |
---|
1071 | |
---|
1072 | The data stream consists of four bytes representing a net-order (MSB |
---|
1073 | first) integer, followed by enough data to produce that many cleartext |
---|
1074 | bytes. This means the size of those data must be rounded up to a |
---|
1075 | multiple of 8. For blocks of less than eight bytes, most software pads |
---|
1076 | on the @var{left} with random values. |
---|
1077 | |
---|
1078 | |
---|
1079 | There are some internal routines whose behavior should be considered |
---|
1080 | carefully. Start from the top, in the @code{kstream_crypt_ctl_block} |
---|
1081 | entries. |
---|
1082 | |
---|
1083 | @table @code |
---|
1084 | @item init |
---|
1085 | simply takes a @code{kstream} and @code{kstream_des_init_block} (which |
---|
1086 | is just a key and an 8 byte initialization vector) and stuffs them into |
---|
1087 | the private data of the @code{kstream}. The buffers and lengths are |
---|
1088 | initialized to zero, and @code{no_right_justify} is cleared. |
---|
1089 | @item rcp_init |
---|
1090 | is the same as @code{init} except @code{no_right_justify} is set, since |
---|
1091 | @code{rcp} and @code{rlogin} use subtly different protocols. |
---|
1092 | @item encrypt |
---|
1093 | gets a pair of @code{kstream_data_block}s (just a pointer and length) |
---|
1094 | for output and input. Since we can always encrypt and send the |
---|
1095 | data we have, this routine just comes up with padding and then calls |
---|
1096 | @code{do_encrypt} to put the data into the outgoing stream. It returns |
---|
1097 | the number of successfully encrypted bytes (in this case, all of them.) |
---|
1098 | @item decrypt |
---|
1099 | also gets a pair of @code{kstream_data_block}s. Here, we do not |
---|
1100 | necessarily have enough data to decrypt the block. We need at least |
---|
1101 | four bytes even to read the length (and if we do not get that, we ask |
---|
1102 | for at least 12 total just so we have a chance). If we are doing an |
---|
1103 | @code{rlogin}, we also filter out extra characters that can slip in |
---|
1104 | before the length. |
---|
1105 | @item destroy |
---|
1106 | frees the output buffer, wipes the private data and then frees that |
---|
1107 | memory also. |
---|
1108 | @item do_encrypt |
---|
1109 | is not in the vector. It does the actual encryption work. This routine |
---|
1110 | handles blocks of any size up to 16 bytes, or any multiple of 8 over |
---|
1111 | that. It makes the padding a little easier to write it this way. |
---|
1112 | Handling sizes between 8 and 16 is an annoyance, but @code{rlogin} |
---|
1113 | actually relies on being able to send 12 bytes in one block. |
---|
1114 | @end table |
---|
1115 | |
---|
1116 | @node Unix Library API |
---|
1117 | @chapter CNS Unix Applications Programming Interface |
---|
1118 | |
---|
1119 | On Unix systems, the full set of Common API functions are available. |
---|
1120 | In addition, the following Unix-specific (or server-specific) |
---|
1121 | functions are also available. |
---|
1122 | |
---|
1123 | These application programming interfaces are only available on |
---|
1124 | Unix. They are typically used to write servers, or have not yet |
---|
1125 | been ported to other platforms. |
---|
1126 | |
---|
1127 | @menu |
---|
1128 | * Access Control Lists:: |
---|
1129 | * Error Reporting:: |
---|
1130 | * Encryption:: |
---|
1131 | * Authentication:: |
---|
1132 | * Realms:: |
---|
1133 | * Ticket Files:: |
---|
1134 | * Other:: |
---|
1135 | @end menu |
---|
1136 | |
---|
1137 | @node Access Control Lists |
---|
1138 | @section Access Control Lists |
---|
1139 | @menu |
---|
1140 | * ACL overview:: |
---|
1141 | * acl_canonicalize_principal:: |
---|
1142 | * acl_check:: |
---|
1143 | * acl_exact_match:: |
---|
1144 | * acl_add:: |
---|
1145 | * acl_delete:: |
---|
1146 | * acl_initialize:: |
---|
1147 | * ACL concurrency note:: |
---|
1148 | @end menu |
---|
1149 | @node ACL overview |
---|
1150 | @subsection ACL overview |
---|
1151 | @smallexample |
---|
1152 | cc @var{files} -lacl -lkrb |
---|
1153 | #include "krb.h" |
---|
1154 | acl_canonicalize_principal(char *@var{principal}, char *@file{buf}) |
---|
1155 | acl_check(char *@var{acl}, char *@var{principal}) |
---|
1156 | acl_exact_match(char *@var{acl}, char *@var{principal}) |
---|
1157 | acl_add(char *@var{acl}, char *@var{principal}) |
---|
1158 | acl_delete(char *@var{acl}, char *@var{principal}) |
---|
1159 | acl_initialize(char *@var{acl_file}, int @var{mode}) |
---|
1160 | @end smallexample |
---|
1161 | @c @subsubheading DESCRIPTION |
---|
1162 | An access control list (ACL) is a list of principals. Each principal is |
---|
1163 | represented by a text string which cannot contain whitespace. The |
---|
1164 | library allows application programs to refer to named access control |
---|
1165 | lists to test membership and to atomically add and delete principals |
---|
1166 | using a natural and intuitive interface. At present, the names of |
---|
1167 | access control lists are required to be Unix filenames, and refer to |
---|
1168 | human-readable Unix files. @c ; in the future, when a |
---|
1169 | @c networked ACL server is implemented, the names may refer to a different |
---|
1170 | @c namespace specific to the ACL service. |
---|
1171 | |
---|
1172 | @node acl_canonicalize_principal |
---|
1173 | @subsection acl_canonicalize_principal |
---|
1174 | @findex acl_canonicalize_principal |
---|
1175 | @code{acl_canonicalize_principal} |
---|
1176 | stores the canonical form of principal in @file{buf}. @file{buf} must |
---|
1177 | contain enough space to store a principal, given the limits on the sizes |
---|
1178 | of @var{name}, @var{instance}, and @var{realm} specified as |
---|
1179 | @code{ANAME_SZ}, @code{INST_SZ}, and @code{REALM_SZ}, respectively, in |
---|
1180 | @file{/usr/kerberos/include/krb.h}. |
---|
1181 | |
---|
1182 | @node acl_check |
---|
1183 | @subsection acl_check |
---|
1184 | @findex acl_check |
---|
1185 | @code{acl_check} returns nonzero if @var{principal} appears in the ACL. |
---|
1186 | Returns zero if @var{principal} does not appear in ACL, or if an error |
---|
1187 | occurs. Canonicalizes @var{principal} before checking, and allows the |
---|
1188 | ACL to contain wildcards. The only supported wildcards are entries of |
---|
1189 | the form @samp{@var{name}.*@@@var{realm}}, @samp{*.*@@@var{realm}}, and |
---|
1190 | @samp{*.*@@*}. An asterisk matches any value in the component field. |
---|
1191 | For example, @samp{jtkohl.*@@*} would match principal @samp{jtkohl}, |
---|
1192 | with any @var{instance} and any @var{realm}. |
---|
1193 | |
---|
1194 | @node acl_exact_match |
---|
1195 | @subsection acl_exact_match |
---|
1196 | @findex acl_exact_match |
---|
1197 | @code{acl_exact_match} |
---|
1198 | performs like @code{acl_check}, but does no canonicalization or wildcard |
---|
1199 | matching. |
---|
1200 | |
---|
1201 | @node acl_add |
---|
1202 | @subsection acl_add |
---|
1203 | @findex acl_add |
---|
1204 | @code{acl_add} atomically adds @var{principal} to the ACL. Returns zero |
---|
1205 | if successful, nonzero if unsuccessful. It is considered a failure if |
---|
1206 | @var{principal} is already in the ACL. This routine canonicalizes |
---|
1207 | @var{principal}, but treats wildcards literally. |
---|
1208 | |
---|
1209 | @node acl_delete |
---|
1210 | @subsection acl_delete |
---|
1211 | @findex acl_delete |
---|
1212 | @code{acl_delete} atomically deletes @var{principal} from the ACL. |
---|
1213 | Returns zero if successful, nonzero if unsuccessful. It is considered a |
---|
1214 | failure if @var{principal} is not already in the ACL. This routine |
---|
1215 | canonicalizes @var{principal}, but treats wildcards literally. |
---|
1216 | |
---|
1217 | @node acl_initialize |
---|
1218 | @subsection acl_initialize |
---|
1219 | @findex acl_initialize |
---|
1220 | @code{acl_initialize} |
---|
1221 | initializes @var{acl_file}. If the file @var{acl_file} does not exist, |
---|
1222 | @code{acl_initialize} creates it with mode mode. If the file |
---|
1223 | @var{acl_file} exists, @code{acl_initialize} removes all |
---|
1224 | members. Returns zero if successful, nonzero unsuccessful. |
---|
1225 | @strong{WARNING:} @var{mode} argument is likely to change with the |
---|
1226 | eventual introduction of an ACL service. |
---|
1227 | |
---|
1228 | @node ACL concurrency note |
---|
1229 | @subsection ACL concurrency note |
---|
1230 | @c @subsubheading NOTES |
---|
1231 | If there is concurrency (two or more people using these functions), |
---|
1232 | there is a very small chance of @code{acl_add} or @code{acl_delete} |
---|
1233 | erroneously reporting an error. This is an unavoidable side effect when |
---|
1234 | using lock files for concurrency control rather than @code{flock}(2), |
---|
1235 | which is not supported by NFS. The current implementation caches ACLs |
---|
1236 | in memory in a hash table for increased efficiency in checking |
---|
1237 | membership; one effect of the caching scheme is that one file descriptor |
---|
1238 | is kept open for each ACL cached, up to a maximum of 8. |
---|
1239 | @ignore |
---|
1240 | @subsubheading SEE ALSO |
---|
1241 | @table @ref |
---|
1242 | @item Kerberos |
---|
1243 | @item krb_realmofhost,,krb_get_lrealm |
---|
1244 | @end table |
---|
1245 | @end ignore |
---|
1246 | @node Error Reporting |
---|
1247 | @section Error Reporting |
---|
1248 | @menu |
---|
1249 | * com_err:: com_err |
---|
1250 | * compile_et:: compile_et |
---|
1251 | @end menu |
---|
1252 | @node com_err |
---|
1253 | @subsection com_err |
---|
1254 | @findex com_err |
---|
1255 | @c @subsubheading SYNOPSIS |
---|
1256 | @smallexample |
---|
1257 | #include <com_err.h> |
---|
1258 | void com_err (const char @var{whoami}, long @var{code}, |
---|
1259 | const char *@var{format}, @dots{}); |
---|
1260 | @var{proc} = set_com_err_hook (@var{proc}); |
---|
1261 | void (* @var{proc} ) (const char *, long, const char *, |
---|
1262 | va_list); |
---|
1263 | @var{proc} = reset_com_err_hook (); |
---|
1264 | void initialize_@var{XXXX}_error_table (); |
---|
1265 | @end smallexample |
---|
1266 | @c @subsubheading DESCRIPTION |
---|
1267 | @code{com_err} displays an error message on the standard error stream |
---|
1268 | @code{stderr} (see @samp{stdio}(3S)) composed of the @var{whoami} |
---|
1269 | string, which should specify the program name or some sub-portion of a |
---|
1270 | program, followed by an error message generated from the code value |
---|
1271 | (derived from @ref{compile_et}), and a string produced using the string |
---|
1272 | and any following arguments, in the same style as @samp{fprintf}(3). |
---|
1273 | The behavior of @code{com_err} can be modified using |
---|
1274 | @code{set_com_err_hook}; this defines a procedure which is called with |
---|
1275 | the arguments passed to @code{com_err}, instead of the default internal |
---|
1276 | procedure which sends the formatted text to error output. Thus the |
---|
1277 | error messages from a program can all easily be diverted to another form |
---|
1278 | of diagnostic logging, such as @samp{syslog}(3). |
---|
1279 | @code{reset_com_err_hook} may be used to restore the behavior of |
---|
1280 | @code{com_err} to its default form. Both procedures return the previous |
---|
1281 | hook value. These hook procedures must have the declaration given for |
---|
1282 | @var{proc} above. The @code{initialize_@var{XXXX}_error_table} routine |
---|
1283 | is generated mechanically by @code{compile_et} (see @ref{compile_et}) |
---|
1284 | from a source file containing names and associated strings. Each table |
---|
1285 | has a name of up to four characters, which is used in place of the |
---|
1286 | @var{XXXX} in the name of the routine. These routines should be called |
---|
1287 | before any of the corresponding error codes are used, so that the |
---|
1288 | @file{com_err} library recognizes error codes from these tables when |
---|
1289 | they are used. The @file{com_err.h} header file should be included in |
---|
1290 | any source file that uses routines from the @file{com_err} library; |
---|
1291 | executable files must be linked using @code{-lcom_err} in order to cause |
---|
1292 | the @file{com_err} library to be included. |
---|
1293 | @ignore |
---|
1294 | @subsubheading SEE ALSO |
---|
1295 | @c @xref{compile_et}, @samp{syslog}(3). |
---|
1296 | Ken Raeburn, "A Common Error Description Library for UNIX". |
---|
1297 | @end ignore |
---|
1298 | @node compile_et |
---|
1299 | @subsection compile_et |
---|
1300 | @ignore |
---|
1301 | @c @subsubheading SYNOPSIS |
---|
1302 | @smallexample |
---|
1303 | compile_et @var{file} |
---|
1304 | @end smallexample |
---|
1305 | @c @subsubheading DESCRIPTION |
---|
1306 | @end ignore |
---|
1307 | @code{compile_et} converts a table listing error-code names and |
---|
1308 | associated messages into a C source file suitable for use with the |
---|
1309 | @file{com_err} library (see @ref{com_err}). The source file name must |
---|
1310 | end with a suffix of @file{.et}; the file consists of a declaration |
---|
1311 | supplying the name (up to four characters long) of the error-code table: |
---|
1312 | @smallexample |
---|
1313 | error_table @var{name} |
---|
1314 | @end smallexample |
---|
1315 | @noindent |
---|
1316 | followed by up to 256 entries of the form: |
---|
1317 | @smallexample |
---|
1318 | error_code @var{name}, "@var{string}" |
---|
1319 | @end smallexample |
---|
1320 | @noindent |
---|
1321 | and a final |
---|
1322 | @smallexample |
---|
1323 | end |
---|
1324 | @end smallexample |
---|
1325 | @noindent |
---|
1326 | to indicate the end of the table. The name of the table is used to |
---|
1327 | construct the name of a subroutine |
---|
1328 | @code{initialize_@var{XXXX}_error_table} which must be called in order |
---|
1329 | for the @file{com_err} library to recognize the error table. The |
---|
1330 | various error codes defined are assigned sequentially increasing numbers |
---|
1331 | (starting with a large number computed as a hash function of the name of |
---|
1332 | the table); thus for compatibility it is suggested that new codes be |
---|
1333 | added only to the end of an existing table, and that no codes be removed |
---|
1334 | from tables. The names defined in the table are placed into a C header |
---|
1335 | file with preprocessor directives defining them as integer constants of |
---|
1336 | up to 32 bits in magnitude. A C source file is also generated which |
---|
1337 | should be compiled and linked with the object files which reference |
---|
1338 | these error codes; it contains the text of the messages and the |
---|
1339 | initialization subroutine. Both C files have names derived from that of |
---|
1340 | the original source file, with the @file{.et} suffix replaced by |
---|
1341 | @file{.c} and @file{.h}. A @samp{#} in the source file is treated as a |
---|
1342 | comment character, and all remaining text to the end of the source line |
---|
1343 | is ignored. |
---|
1344 | @ignore |
---|
1345 | @subsubheading BUGS |
---|
1346 | Since @code{compile_et} uses a very simple parser based on |
---|
1347 | @code{yacc}(1), its error recovery leaves much to be desired. |
---|
1348 | @subsubheading SEE ALSO |
---|
1349 | @xref{com_err}. |
---|
1350 | Ken Raeburn, "A Common Error Description Library for UNIX". |
---|
1351 | @end ignore |
---|
1352 | |
---|
1353 | @node Encryption |
---|
1354 | @section Encryption |
---|
1355 | @menu |
---|
1356 | * Encryption overview:: |
---|
1357 | * des_read_password:: |
---|
1358 | * des_random_key:: |
---|
1359 | * des_set_key:: |
---|
1360 | * des_ecb_encrypt:: |
---|
1361 | * des_pcbc_encrypt:: |
---|
1362 | * des_cbc_cksum:: |
---|
1363 | * quad_cksum:: |
---|
1364 | * des_init_random_number_generator:: |
---|
1365 | * des_new_random_key:: |
---|
1366 | @end menu |
---|
1367 | |
---|
1368 | @node Encryption overview |
---|
1369 | @subsection Encryption overview |
---|
1370 | This library supports various DES encryption related operations. It |
---|
1371 | differs from the Unix @code{crypt}, @code{setkey}, and @code{encrypt} |
---|
1372 | library routines in that it provides a true DES encryption, without |
---|
1373 | modifying the algorithm, and executes much faster. To use, create a |
---|
1374 | @code{des_key_schedule} struct, defined in @file{des.h} for each key |
---|
1375 | that may be simultaneously active. Next, create key schedules (from the |
---|
1376 | 8-byte keys) as needed, via @code{des_set_key}, prior to using the |
---|
1377 | encryption or checksum routines. Then setup the input and output areas |
---|
1378 | (note that lengths are restricted to be multiples of eight |
---|
1379 | bytes). Finally, invoke the encryption/decryption routines, |
---|
1380 | @code{des_ecb_encrypt} or @code{des_cbc_encrypt} or |
---|
1381 | @code{des_pcbc_encrypt}, or, to generate a cryptographic checksum, use |
---|
1382 | @code{quad_cksum} (fast) or @code{des_cbc_cksum} (slow). |
---|
1383 | @smallexample |
---|
1384 | #include "des.h" |
---|
1385 | int des_read_password(des_cblock *@var{key}, char *@var{prompt}, int |
---|
1386 | @var{verify}) |
---|
1387 | int des_string_to_key(char *@var{str}, des_cblock @var{key}) |
---|
1388 | int des_random_key(des_cblock *@var{key}) |
---|
1389 | int des_set_key(des_cblock *@var{key}, des_key_schedule @var{schedule}) |
---|
1390 | int des_ecb_encrypt(des_cblock *@var{input},des_cblock *@var{output}, |
---|
1391 | des_key_schedule @var{schedule},int @var{encrypt}) |
---|
1392 | int des_pcbc_encrypt(des_cblock *@var{input},des_cblock *@var{output}, long |
---|
1393 | @var{length}, des_key_schedule @var{schedule}, |
---|
1394 | des_cblock *@var{ivec}, int @var{encrypt}) |
---|
1395 | unsigned long quad_cksum(des_cblock *@var{input},des_cblock *@var{output}, |
---|
1396 | long @var{length}, int @var{out_count}, |
---|
1397 | des_cblock *@var{seed}) |
---|
1398 | @end smallexample |
---|
1399 | |
---|
1400 | @node des_read_password |
---|
1401 | @subsection des_read_password |
---|
1402 | @findex des_read_password |
---|
1403 | @code{des_read_password} writes the string specified by @var{prompt} to |
---|
1404 | the standard output, turns off echo (if possible) and reads an input |
---|
1405 | string from standard input until terminated with a newline. If |
---|
1406 | @var{verify} is non-zero, it prompts and reads input again, for use in |
---|
1407 | applications such as changing a password; both versions are compared, |
---|
1408 | and the input is requested repeatedly until they match. Then |
---|
1409 | @code{des_read_password} converts the input string into a valid DES key, |
---|
1410 | internally using the @code{des_string_to_key} routine. The newly |
---|
1411 | created key is copied to the area pointed to by the @var{key} argument. |
---|
1412 | @code{des_read_password} returns a zero if no errors occurred, or a `-1' |
---|
1413 | indicating that an error occurred trying to manipulate the terminal |
---|
1414 | echo. |
---|
1415 | |
---|
1416 | @node des_random_key |
---|
1417 | @subsection des_random_key |
---|
1418 | @findex des_random_key |
---|
1419 | @code{des_random_key} generates a random DES encryption key (eight |
---|
1420 | bytes), set to odd parity per FIPS specifications. This routine uses |
---|
1421 | the current time, process ID, and a counter as a seed for the random |
---|
1422 | number generator. The caller must supply space for the output key, |
---|
1423 | pointed to by argument @var{key}, then after calling |
---|
1424 | @code{des_random_key} should call the @code{des_set_key} routine when |
---|
1425 | needed. No meaningful value is returned. @code{void} is not used for |
---|
1426 | historical reasons. |
---|
1427 | |
---|
1428 | This function is deprecated. @code{des_init_random_number_generator} |
---|
1429 | should be used to set a key for the @code{des_new_random_key} generator, |
---|
1430 | which is much stronger due to the use of DES and the use of a secret |
---|
1431 | key. (Programs that operate directly on the database can use the master |
---|
1432 | key; for client programs like @samp{ksrvutil} it may be sufficient to |
---|
1433 | use a current session key.) |
---|
1434 | |
---|
1435 | @node des_set_key |
---|
1436 | @subsection des_set_key |
---|
1437 | @findex des_set_key |
---|
1438 | @code{des_set_key} calculates a key schedule from all eight bytes of the |
---|
1439 | input key, pointed to by the @var{key} argument, and outputs the |
---|
1440 | schedule into the @code{des_key_schedule} indicated by the |
---|
1441 | @var{schedule} argument. You must pass a valid eight byte key; no |
---|
1442 | padding is done. The key schedule may then be used in subsequent |
---|
1443 | encryption/decryption/checksum operations. Many key schedules may be |
---|
1444 | cached for later use. The user must clear keys and schedules as soon as |
---|
1445 | no longer needed, to prevent their disclosure. The routine also checks |
---|
1446 | the key parity, and returns a zero if the key parity is correct (odd), a |
---|
1447 | `-1' indicating a key parity error, or a `-2' indicating use of a weak |
---|
1448 | key. If an error is returned, the key schedule was not created. |
---|
1449 | |
---|
1450 | @node des_ecb_encrypt |
---|
1451 | @subsection des_ecb_encrypt |
---|
1452 | @findex des_ecb_encrypt |
---|
1453 | @code{des_ecb_encrypt} is the basic DES encryption routine that |
---|
1454 | encrypts or decrypts a single 8-byte block in electronic code book |
---|
1455 | mode. It always transforms the input data, pointed to by @var{input}, |
---|
1456 | into the output data, pointed to by the @var{output} argument. If the |
---|
1457 | @var{encrypt} argument is non-zero, the input (cleartext) is encrypted |
---|
1458 | into the output (ciphertext) using the @code{key_schedule} specified by |
---|
1459 | the @var{schedule} argument, previously set via @code{des_set_key}. If |
---|
1460 | @var{encrypt} is zero, the input (now ciphertext) is decrypted into the |
---|
1461 | output (now cleartext). Input and output may overlap. No meaningful |
---|
1462 | value is returned. @code{void} is not used for historical reasons. |
---|
1463 | |
---|
1464 | @node des_pcbc_encrypt |
---|
1465 | @subsection des_pcbc_encrypt |
---|
1466 | @findex des_pcbc_encrypt |
---|
1467 | @code{des_pcbc_encrypt} encrypts/decrypts using a modified block |
---|
1468 | chaining mode. Its calling sequence is identical to |
---|
1469 | @code{des_cbc_encrypt}. It differs in its error propagation |
---|
1470 | characteristics. @code{des_pcbc_encrypt} is not recommended for most |
---|
1471 | encryption purposes. Modification of a single bit of the ciphertext |
---|
1472 | affects all the subsequent (decrypted) cleartext. Similarly, modifying |
---|
1473 | a single bit of the cleartext affects all the subsequent (encrypted) |
---|
1474 | ciphertext. `PCBC' mode, on encryption, `XORs' both the cleartext of |
---|
1475 | block @var{N} and the ciphertext resulting from block @var{N} with the |
---|
1476 | cleartext for block @var{N}+1 prior to encrypting block @var{N}+1. |
---|
1477 | However, this mode has been shown to have inherent weaknesses. |
---|
1478 | |
---|
1479 | @node des_cbc_cksum |
---|
1480 | @subsection des_cbc_cksum |
---|
1481 | @findex des_cbc_cksum |
---|
1482 | @code{des_cbc_cksum} produces an 8-byte cryptographic checksum by |
---|
1483 | cipher-block-chain encrypting the cleartext data pointed to by the |
---|
1484 | @var{input} argument. All of the ciphertext output is discarded, except |
---|
1485 | the last 8-byte ciphertext block, which is written into the area pointed |
---|
1486 | to by the @var{output} argument. It uses the key schedule, provided by |
---|
1487 | the @var{schedule} argument and initialization vector provided by the |
---|
1488 | @var{ivec} argument. If the @var{length} argument is not an integral |
---|
1489 | multiple of eight bytes, the last cleartext block is copied to a temp |
---|
1490 | and zero filled at the highest addresses. The output is ALWAYS eight |
---|
1491 | bytes. The routine also returns an @code{unsigned long}, which is the |
---|
1492 | last (highest address) half of the 8 byte checksum computed. This |
---|
1493 | result is probably byte-order dependent. |
---|
1494 | |
---|
1495 | @node quad_cksum |
---|
1496 | @subsection quad_cksum |
---|
1497 | @findex quad_cksum |
---|
1498 | @code{quad_cksum} produces a checksum by chaining quadratic operations |
---|
1499 | on the cleartext data pointed to by the @var{input} argument. The |
---|
1500 | @var{length} argument specifies the length of the input---only exactly |
---|
1501 | that many bytes are included for the checksum, without any padding. The |
---|
1502 | algorithm may be iterated over the same input data, if the |
---|
1503 | @var{out_count} argument is `2', `3' or `4', and the optional |
---|
1504 | @var{output} argument is a non-null pointer. The default is one |
---|
1505 | iteration, and it does not run more than four times. Multiple |
---|
1506 | iterations run more slowly, but provide a longer checksum, if desired. |
---|
1507 | The @var{seed} argument provides an 8-byte seed for the first |
---|
1508 | iteration. If multiple iterations are requested, the results of one |
---|
1509 | iteration are automatically used as the seed for the next iteration. It |
---|
1510 | returns both an @code{unsigned long} checksum value, and if the |
---|
1511 | @var{output} argument is not a null pointer, up to 16 bytes of the |
---|
1512 | computed checksum are written into the output. |
---|
1513 | |
---|
1514 | @node des_init_random_number_generator |
---|
1515 | @subsection des_init_random_number_generator |
---|
1516 | @findex des_init_random_number_generator |
---|
1517 | @code{des_init_random_number_generator} sets the key for the new random |
---|
1518 | number generator. It also sets the initial sequence number from a |
---|
1519 | microsecond clock, the host id, and process id if available. |
---|
1520 | |
---|
1521 | @node des_new_random_key |
---|
1522 | @subsection des_new_random_key |
---|
1523 | @findex des_new_random_key |
---|
1524 | @code{des_new_random_key} encrypts the sequence number with the |
---|
1525 | previously selected key and advances the sequence number. This produces |
---|
1526 | a key with strong unpredictablity (due to the use of DES and a secret |
---|
1527 | key.) This function will only generate valid non-weak keys. |
---|
1528 | |
---|
1529 | @node Authentication |
---|
1530 | @section Authentication |
---|
1531 | @menu |
---|
1532 | * Authentication overview:: |
---|
1533 | * krb_kntoln:: |
---|
1534 | * krb_set_key:: |
---|
1535 | * krb_mk_err:: |
---|
1536 | * krb_rd_err:: |
---|
1537 | * krb_sendauth:: |
---|
1538 | * krb_recvauth:: |
---|
1539 | * krb_net_write and krb_net_read:: |
---|
1540 | @end menu |
---|
1541 | @node Authentication overview |
---|
1542 | @subsection Authentication overview |
---|
1543 | @smallexample |
---|
1544 | #include "krb.h" |
---|
1545 | int krb_kntoln(AUTH_DAT *@var{ad}, char *@var{lname}); |
---|
1546 | int krb_set_key(char *@var{key}, int @var{cvt}); |
---|
1547 | int krb_get_cred(char *@var{service}, char *@var{instance}, char |
---|
1548 | *@var{realm}, CREDENTIALS *@var{c}); |
---|
1549 | long krb_mk_err(u_char *@var{out}, long @var{code}, char *@var{string}); |
---|
1550 | long krb_rd_err(u_char *@var{in}, u_long @var{length}, |
---|
1551 | long @var{code}, MSG_DAT *@var{msg_data}); |
---|
1552 | @end smallexample |
---|
1553 | |
---|
1554 | The following functions, which are built on top of the core Kerberos |
---|
1555 | library, provide a convenient means for client and server programs to |
---|
1556 | send authentication messages to one another through network connections. |
---|
1557 | |
---|
1558 | @smallexample |
---|
1559 | #define DEFINE_SOCKADDR |
---|
1560 | #include "krb.h" |
---|
1561 | int krb_sendauth(long @var{options}, int @var{fd}, KTEXT @var{ktext}, char |
---|
1562 | *@var{service}, char *@var{inst}, char *@var{realm}, u_long @var{checksum}, |
---|
1563 | MSG_DAT *msg_@var{data}, |
---|
1564 | CREDENTIALS *@var{cred}, |
---|
1565 | Key_schedule @var{schedule}, |
---|
1566 | struct sockaddr_in *@var{laddr}, |
---|
1567 | struct sockaddr_in *@var{faddr}, |
---|
1568 | char *@var{version}); |
---|
1569 | int krb_recvauth(long @var{options}, int @var{fd}, KTEXT @var{ktext}, char |
---|
1570 | *@var{service}, char *@var{inst}, |
---|
1571 | struct sockaddr_in *@var{laddr}, |
---|
1572 | struct sockaddr_in *@var{faddr}, |
---|
1573 | AUTH_DAT *@var{auth_data}, |
---|
1574 | char *@var{filename}, |
---|
1575 | Key_schedule @var{schedule}, |
---|
1576 | char *@var{version}); |
---|
1577 | int krb_net_write(int @var{fd}, char *@file{buf}, int @var{format}); |
---|
1578 | int krb_net_read(int @var{fd}, char *@file{buf}, int @var{format}); |
---|
1579 | @end smallexample |
---|
1580 | |
---|
1581 | @node krb_kntoln |
---|
1582 | @subsection krb_kntoln |
---|
1583 | @findex krb_kntoln |
---|
1584 | @code{krb_kntoln} converts a Kerberos name (supplied in an |
---|
1585 | @code{AUTH_DAT} structure) to a local Unix username. If the instance is |
---|
1586 | the null string and the realm is the local realm, then the name is |
---|
1587 | copied to the @var{lname} argument. If the realm is not the local realm |
---|
1588 | or the instance is non-null, or some error occurs, @code{KFAILURE} is |
---|
1589 | returned, otherwise @code{KSUCCESS} is returned. The local name |
---|
1590 | returned might be used by an application to change user IDs, |
---|
1591 | directories, or other parameters. This function is not an integral part |
---|
1592 | of Kerberos, but is instead provided to support the use of Kerberos in |
---|
1593 | existing utilities. |
---|
1594 | |
---|
1595 | @node krb_set_key |
---|
1596 | @subsection krb_set_key |
---|
1597 | @findex krb_set_key |
---|
1598 | @code{krb_set_key} takes as an argument a DES key. It then creates a |
---|
1599 | key schedule from it and saves the original key to be used as an |
---|
1600 | initialization vector. It is used to set the server's key which must be |
---|
1601 | used to decrypt tickets. If called with a non-zero second argument, |
---|
1602 | @code{krb_set_key} first converts the input from a string of arbitrary |
---|
1603 | length to a DES key by encrypting it with a one-way function. In most |
---|
1604 | cases it should not be necessary to call @code{krb_set_key}. The |
---|
1605 | necessary keys are usually obtained and set inside |
---|
1606 | @code{krb_rd_req}. @code{krb_set_key} is provided for those applications |
---|
1607 | that do not wish to place the application keys on disk. |
---|
1608 | |
---|
1609 | @node krb_mk_err |
---|
1610 | @subsection krb_mk_err |
---|
1611 | @findex krb_mk_err |
---|
1612 | @code{krb_mk_err} constructs an application level error message that |
---|
1613 | may be used along with @code{krb_mk_priv} or @code{krb_mk_safe}. |
---|
1614 | @var{out} is a pointer to the output buffer, @var{code} is an |
---|
1615 | application specific error code, and @var{string} is an application |
---|
1616 | specific error string. |
---|
1617 | |
---|
1618 | @node krb_rd_err |
---|
1619 | @subsection krb_rd_err |
---|
1620 | @findex krb_rd_err |
---|
1621 | @code{krb_rd_err} unpacks a received @code{krb_mk_err} message. |
---|
1622 | @var{in} points to the beginning of the received message, whose length |
---|
1623 | is specified in @var{in_length}. @var{code} is a pointer to a value to |
---|
1624 | be filled in with the error value provided by the application. |
---|
1625 | @var{msg_data} is a pointer to a @code{MSG_DAT} struct, defined in |
---|
1626 | @file{krb.h}. The routine fills in these @code{MSG_DAT} fields: the |
---|
1627 | @code{app_data} field with a pointer to the application error text, |
---|
1628 | @code{app_length} with the length of the @code{app_data} field, and |
---|
1629 | @code{swap} with a `1' if the byte order of the receiver is different |
---|
1630 | than that of the sender. (The application must still determine if it is |
---|
1631 | appropriate to byte-swap application data; the Kerberos protocol fields |
---|
1632 | are already taken care of). The routine returns zero if the error |
---|
1633 | message has been successfully received, or a Kerberos error code. |
---|
1634 | |
---|
1635 | @node krb_sendauth |
---|
1636 | |
---|
1637 | @subsection krb_sendauth |
---|
1638 | @findex krb_sendauth |
---|
1639 | |
---|
1640 | The @code{krb_sendauth} function sends an authenticated ticket from the |
---|
1641 | client program to the server program by writing the ticket to a network |
---|
1642 | socket. The @code{krb_recvauth} function receives the ticket from the |
---|
1643 | client by reading from a network socket. |
---|
1644 | |
---|
1645 | @code{krb_sendauth} |
---|
1646 | writes the ticket to the network socket specified by the file |
---|
1647 | descriptor @var{fd}, returning @code{KSUCCESS} if the write proceeds |
---|
1648 | successfully, and an error code if it does not. The @var{ktext} |
---|
1649 | argument should point to an allocated @code{KTEXT_ST} structure. The |
---|
1650 | @var{service}, @var{inst}, and @var{realm} arguments specify the server |
---|
1651 | program's Kerberos principal name, instance, and realm. If you are |
---|
1652 | writing a client that uses the local realm exclusively, you can set the |
---|
1653 | @var{realm} argument to NULL. The @var{version} argument allows the |
---|
1654 | client program to pass an application-specific version string that the |
---|
1655 | server program can then match against its own version string. The |
---|
1656 | version string can be up to @code{KSEND_VNO_LEN} (see @file{krb.h}) |
---|
1657 | characters in length. The @var{checksum} argument can be used to pass |
---|
1658 | checksum information to the server program. The client program is |
---|
1659 | responsible for specifying this information. This checksum information |
---|
1660 | is difficult to corrupt because @code{krb_sendauth} passes it over the |
---|
1661 | network in encrypted form. The checksum argument is passed as the |
---|
1662 | checksum argument to @code{krb_mk_req}. You can set |
---|
1663 | @code{krb_sendauth}'s other arguments to NULL unless you want the |
---|
1664 | client and server programs to mutually authenticate themselves. In the |
---|
1665 | case of mutual authentication, the client authenticates itself to the |
---|
1666 | server program, and demands that the server in turn authenticate itself |
---|
1667 | to the client. |
---|
1668 | |
---|
1669 | If you want mutual authentication, make sure that you read all pending |
---|
1670 | data from the local socket before calling @code{krb_sendauth}. Set |
---|
1671 | @code{krb_sendauth}'s options argument to @code{KOPT_DO_MUTUAL} (this |
---|
1672 | macro is defined in the @file{krb.h} file); make sure that the |
---|
1673 | @var{laddr} argument points to the address of the local socket, and that |
---|
1674 | @var{faddr} points to the foreign socket's network address. |
---|
1675 | @code{krb_sendauth} fills in the other arguments---@var{msg_data}, |
---|
1676 | @var{cred}, and @var{schedule}---before sending the ticket to the server |
---|
1677 | program. You must, however, allocate space for these arguments before |
---|
1678 | calling the function. @code{krb_sendauth} supports two other options: |
---|
1679 | @code{KOPT_DONT_MK_REQ}, and @code{KOPT_DONT_CANON}. If called with |
---|
1680 | options set as @code{KOPT_DONT_MK_REQ}, @code{krb_sendauth} does not use |
---|
1681 | the @code{krb_mk_req} function to retrieve the ticket from the Kerberos |
---|
1682 | server. The @var{ktext} argument must point to an existing ticket and |
---|
1683 | authenticator (such as would be created by @code{krb_mk_req}), and the |
---|
1684 | @var{service}, @var{inst}, and @var{realm} arguments can be set to NULL. |
---|
1685 | |
---|
1686 | @code{krb_sendauth} does not convert the service's instance to canonical |
---|
1687 | form using @ref{krb_realmofhost,,krb_get_phost}, if called with options |
---|
1688 | set as @code{KOPT_DONT_CANON}. If you want to call @code{krb_sendauth} |
---|
1689 | with a multiple options specification, construct options as a bitwise-OR |
---|
1690 | of the options you want to specify. |
---|
1691 | |
---|
1692 | Note that @code{krb_sendauth}, @code{krb_recvauth}, |
---|
1693 | @code{krb_net_write}, and @code{krb_net_read} do not work properly on |
---|
1694 | sockets set to non-blocking I/O mode. |
---|
1695 | |
---|
1696 | @node krb_recvauth |
---|
1697 | @subsection krb_recvauth |
---|
1698 | @findex krb_recvauth |
---|
1699 | The @code{krb_recvauth} function reads a |
---|
1700 | ticket/authenticator pair from the socket pointed to by the @var{fd} |
---|
1701 | argument. Set the @var{options} argument as a bitwise-OR of the options |
---|
1702 | desired. Currently only @code{KOPT_DO_MUTUAL} is useful to the |
---|
1703 | receiver. |
---|
1704 | |
---|
1705 | The @code{ktext} argument should point to an allocated @code{KTEXT_ST} |
---|
1706 | structure. @code{krb_recvauth} fills @code{ktext} with the |
---|
1707 | ticket/authenticator pair read from @var{fd}, then passes it to |
---|
1708 | @code{krb_rd_req}. The @var{service} and @var{inst} arguments specify |
---|
1709 | the expected service and instance for which the ticket was generated. |
---|
1710 | They are also passed to @code{krb_rd_req}. The @var{inst} argument may |
---|
1711 | be set to @samp{*} if the caller wishes @code{krb_mk_req} to fill in the |
---|
1712 | instance used (note that there must be space in the @var{inst} argument |
---|
1713 | to hold a full instance name, see @xref{krb_mk_req}.) The |
---|
1714 | @var{faddr} argument should point to the address of the peer which is |
---|
1715 | presenting the ticket. It is also passed to @code{krb_rd_req}. If the |
---|
1716 | client and server plan to mutually authenticate one another, the |
---|
1717 | @var{laddr} argument should point to the local address of the file |
---|
1718 | descriptor. Otherwise you can set this argument to NULL. |
---|
1719 | |
---|
1720 | The @var{auth_data} argument should point to an allocated |
---|
1721 | @code{AUTH_DAT} area. It is passed to and filled in by |
---|
1722 | @code{krb_rd_req}. The checksum passed to the corresponding |
---|
1723 | @code{krb_sendauth} is available as part of the filled-in |
---|
1724 | @code{AUTH_DAT} area. The @var{filename} argument specifies the |
---|
1725 | filename which the service program should use to obtain its service key. |
---|
1726 | @code{krb_recvauth} passes filename to the @code{krb_rd_req} function. |
---|
1727 | If you set this argument to null, @code{krb_rd_req} looks for the |
---|
1728 | service key in the file @file{/etc/krb-srvtab}. If the client and |
---|
1729 | server are performing mutual authentication, the schedule argument should |
---|
1730 | point to an allocated @code{Key_schedule}. Otherwise it is ignored and |
---|
1731 | may be NULL. The @var{version} argument should point to a character |
---|
1732 | array of at least @code{KSEND_VNO_LEN} characters. It is filled in with |
---|
1733 | the version string passed by the client to @code{krb_sendauth}. |
---|
1734 | |
---|
1735 | Note that @code{krb_sendauth}, @code{krb_recvauth}, |
---|
1736 | @code{krb_net_write}, and @code{krb_net_read} do not work properly on |
---|
1737 | sockets set to non-blocking I/O mode. |
---|
1738 | |
---|
1739 | @c |
---|
1740 | @c krb_rd_auth was never implmented, since it was used only by servers, |
---|
1741 | @c and all servers were done on Unix where sockets are file descriptors. |
---|
1742 | @c For completeness it should be done, but we ran out of time. |
---|
1743 | @c |
---|
1744 | @c @item krb_rd_auth |
---|
1745 | @c @smallexample |
---|
1746 | @c csCode= krbReadSendauthCode (2025) |
---|
1747 | @c transform.data = data [input] |
---|
1748 | @c transform.data_len = data_len [input] |
---|
1749 | @c transform.principal = service [input] |
---|
1750 | @c transform.instance = instance [input] |
---|
1751 | @c transform.from_addr = from_addr [input] |
---|
1752 | @c transform.key = service_key [input] |
---|
1753 | @c transform.auth_data = auth_data [output by ref] |
---|
1754 | @c transform.version = version [output by ref] |
---|
1755 | @c @end smallexample |
---|
1756 | @c |
---|
1757 | @c This routine is used to interpret and authenticate an authenticator that |
---|
1758 | @c is sent over the network using the @code{krb_sendauth} |
---|
1759 | @c routine. @var{data} points to the beginning of the received message, |
---|
1760 | @c whose length is specified by @var{data_len}. @var{service name} and |
---|
1761 | @c @var{instance} specify the Kerberos service being authenticated; |
---|
1762 | @c @var{from_addr} is the Internet address of the host originating the |
---|
1763 | @c request. This routine fills information obtained from the |
---|
1764 | @c authenticator, fills in the session key in @var{key}, and returns the |
---|
1765 | @c version information in @var{version}. @var{version} must point to an |
---|
1766 | @c area @code{KSEND_VNO_LEN} bytes long. |
---|
1767 | @c |
---|
1768 | @c This routine is similar to the original @code{krb_recvauth} routine, |
---|
1769 | @c except that it takes the authenticator as an argument instead of reading |
---|
1770 | @c a file descriptor, and @var{service key} as an argument instead of |
---|
1771 | @c reading a @file{srvtab} file. If mutual authentication is requested, |
---|
1772 | @c the application is responsible to use @code{KrbMakePrivate} to send back |
---|
1773 | @c the checksum + 1 in network byte order. |
---|
1774 | @node krb_net_write and krb_net_read |
---|
1775 | @subsection krb_net_write and krb_net_read |
---|
1776 | @findex krb_net_write |
---|
1777 | @findex krb_net_read |
---|
1778 | The @code{krb_net_write} function emulates the @code{write}(2) system |
---|
1779 | call, but guarantees that all data specified is written to @var{fd} |
---|
1780 | before returning, unless an error condition occurs. The |
---|
1781 | @code{krb_net_read} function emulates the @code{read}(2) system call, |
---|
1782 | but guarantees that the requested amount of data is read from @var{fd} |
---|
1783 | before returning, unless an error condition occurs. |
---|
1784 | |
---|
1785 | @c @subsubheading BUGS |
---|
1786 | Note that @code{krb_sendauth}, @code{krb_recvauth}, |
---|
1787 | @code{krb_net_write}, and @code{krb_net_read} do not work properly on |
---|
1788 | sockets set to non-blocking I/O mode. |
---|
1789 | @ignore |
---|
1790 | @subsubheading SEE ALSO |
---|
1791 | @table @ref |
---|
1792 | @item Kerberos,,krb_mk_req |
---|
1793 | @item Kerberos,,krb_rd_req |
---|
1794 | @item krb_realmofhost,,krb_get_phost |
---|
1795 | @end table |
---|
1796 | |
---|
1797 | @subsubheading RESTRICTIONS |
---|
1798 | Copyright 1988, Massachusetts Institute of Technology. For copying and |
---|
1799 | distribution information, please see the file @file{<mit-copyright.h>}. |
---|
1800 | @end ignore |
---|
1801 | |
---|
1802 | |
---|
1803 | @node Realms |
---|
1804 | @section Realms |
---|
1805 | @subsection krb_get_phost |
---|
1806 | @findex krb_get_phost |
---|
1807 | |
---|
1808 | @code{char *krb_get_phost(char *@var{alias})} |
---|
1809 | |
---|
1810 | @code{krb_get_phost} converts the hostname @var{alias} (which can be |
---|
1811 | either an official name or an alias) into the instance name to be used |
---|
1812 | in obtaining Kerberos tickets for most services, including the Berkeley |
---|
1813 | @code{rcmd} suite (@code{rlogin}, @code{rcp}, @code{rsh}). The current |
---|
1814 | convention is to return the first segment of the official domain-style |
---|
1815 | name after conversion to lower case. |
---|
1816 | |
---|
1817 | @node Ticket Files |
---|
1818 | @section Ticket Files |
---|
1819 | |
---|
1820 | These routines are the original interface to the credentials cache. |
---|
1821 | This interface worked poorly on non-Unix platforms, so it has been |
---|
1822 | superseded by the routines described in the Common API section. |
---|
1823 | |
---|
1824 | This group of routines is provided to manipulate a Kerberos ticket |
---|
1825 | file. A @dfn{ticket file} has the following layout: |
---|
1826 | |
---|
1827 | @itemize @bullet |
---|
1828 | @item principal's name (a null-terminated string) |
---|
1829 | @item principal's instance (a null-terminated string) |
---|
1830 | @item @var{CREDENTIAL_1} |
---|
1831 | @item @var{CREDENTIAL_2} |
---|
1832 | @item @dots{} |
---|
1833 | @item @var{CREDENTIAL_n} |
---|
1834 | @item EOF |
---|
1835 | @end itemize |
---|
1836 | |
---|
1837 | @var{CREDENTIAL_x} consists of the following fixed-length fields |
---|
1838 | from the @code{CREDENTIALS} structure (defined in @file{"krb.h"}): |
---|
1839 | |
---|
1840 | @smallexample |
---|
1841 | char service[ANAME_SZ] |
---|
1842 | char instance[INST_SZ] |
---|
1843 | char realm[REALM_SZ] |
---|
1844 | des_cblock session |
---|
1845 | int lifetime |
---|
1846 | int kvno |
---|
1847 | KTEXT_ST ticket_st |
---|
1848 | long issue_date |
---|
1849 | @end smallexample |
---|
1850 | |
---|
1851 | @menu |
---|
1852 | * tf_init:: |
---|
1853 | * tf_get_pname:: |
---|
1854 | * tf_get_pinst:: |
---|
1855 | * tf_get_cred:: |
---|
1856 | * tf_close:: |
---|
1857 | @end menu |
---|
1858 | |
---|
1859 | |
---|
1860 | @node tf_init |
---|
1861 | @subsection tf_init |
---|
1862 | @findex tf_init |
---|
1863 | @code{tf_init} must be called before the other ticket file routines. It |
---|
1864 | takes the name of the ticket file to use, and a read/write flag as an |
---|
1865 | argument. It tries to open the ticket file, checks the mode and if |
---|
1866 | everything is okay, locks the file. If it is opened for reading, the |
---|
1867 | lock is shared. If it is opened for writing, the lock is exclusive. |
---|
1868 | @code{KSUCCESS} is returned if all goes well, otherwise one of the |
---|
1869 | following messages is returned: |
---|
1870 | @table @code |
---|
1871 | @item NO_TKT_FIL |
---|
1872 | - file was not there |
---|
1873 | @item TKT_FIL_ACC |
---|
1874 | - file was in wrong mode, etc. |
---|
1875 | @item TKT_FIL_LCK |
---|
1876 | - could not lock the file, even after a retry |
---|
1877 | @end table |
---|
1878 | |
---|
1879 | @node tf_get_pname |
---|
1880 | @subsection tf_get_pname |
---|
1881 | @findex tf_get_pname |
---|
1882 | The @code{tf_get_pname} function reads the principal's name from a ticket |
---|
1883 | file. It should only be called after @code{tf_init} has been called. |
---|
1884 | The principal's name is filled into the @var{pname} parameter. If all |
---|
1885 | goes well, @code{KSUCCESS} is returned. If @code{tf_init} is not |
---|
1886 | called, @code{TKT_FIL_INI} is returned. If the principal's name is |
---|
1887 | null, or @code{EOF} is encountered, or the name is longer than |
---|
1888 | @code{ANAME_SZ}, @code{TKT_FIL_FMT} is returned. |
---|
1889 | |
---|
1890 | @node tf_get_pinst |
---|
1891 | @subsection tf_get_pinst |
---|
1892 | @findex tf_get_pinst |
---|
1893 | The |
---|
1894 | @code{tf_get_pinst} reads the principal's instance from a ticket file. |
---|
1895 | It should only be called after @code{tf_init} and @code{tf_get_pname} |
---|
1896 | are called. The principal's instance is filled into the |
---|
1897 | @var{pinst} parameter. If all goes well, @code{KSUCCESS} is returned. |
---|
1898 | If @code{tf_init} is not called, @code{TKT_FIL_INI} is returned. If |
---|
1899 | @code{EOF} is encountered, or the name is longer than @code{INST_SZ}, |
---|
1900 | @code{TKT_FIL_FMT} is returned. Note that, unlike the principal name, |
---|
1901 | the instance name may be null. |
---|
1902 | |
---|
1903 | @node tf_get_cred |
---|
1904 | @subsection tf_get_cred |
---|
1905 | @findex tf_get_cred |
---|
1906 | The @code{tf_get_cred} routine reads a |
---|
1907 | @var{CREDENTIALS} record from a ticket file and fills in the given |
---|
1908 | structure. It should only be called after @code{tf_init}, |
---|
1909 | @code{tf_get_pname}, and @code{tf_get_pinst} are called. If all |
---|
1910 | goes well, @code{KSUCCESS} is returned. Possible error codes are: |
---|
1911 | @table @code |
---|
1912 | @item TKT_FIL_INI |
---|
1913 | - @code{tf_init} was not called first |
---|
1914 | @item TKT_FIL_FMT |
---|
1915 | - bad format |
---|
1916 | @item EOF |
---|
1917 | - end of file encountered |
---|
1918 | @end table |
---|
1919 | |
---|
1920 | @node tf_close |
---|
1921 | @subsection tf_close |
---|
1922 | @findex tf_close |
---|
1923 | @code{tf_close} closes the ticket file and releases the lock on it. |
---|
1924 | @ignore |
---|
1925 | @subsubheading SEE ALSO |
---|
1926 | @xref{Kerberos}. |
---|
1927 | @subsubheading BUGS |
---|
1928 | The ticket file routines have to be called in a certain order. |
---|
1929 | @subsubheading RESTRICTIONS |
---|
1930 | Copyright 1987 Massachusetts Institute of Technology |
---|
1931 | @end ignore |
---|
1932 | |
---|
1933 | |
---|
1934 | @node Other |
---|
1935 | @section Other |
---|
1936 | @menu |
---|
1937 | * krb_set_tkt_string:: krb_set_tkt_string |
---|
1938 | * kuserok:: kuserok |
---|
1939 | @end menu |
---|
1940 | |
---|
1941 | |
---|
1942 | @node krb_set_tkt_string |
---|
1943 | @subsection krb_set_tkt_string |
---|
1944 | @findex krb_set_tkt_string |
---|
1945 | |
---|
1946 | @smallexample |
---|
1947 | #include "krb.h" |
---|
1948 | void krb_set_tkt_string(char *@var{filename}); |
---|
1949 | @end smallexample |
---|
1950 | |
---|
1951 | @code{krb_set_tkt_string} sets the name of the file that holds the |
---|
1952 | user's cache of Kerberos server tickets and associated session keys. |
---|
1953 | The string @var{filename} passed in is copied into local storage. Only |
---|
1954 | @code{MAXPATHLEN-1} characters of the filename are copied in for use as |
---|
1955 | the cache file name. This routine should be called during |
---|
1956 | initialization, before other Kerberos routines are called; otherwise the |
---|
1957 | routines which fetch the ticket cache file name may be called and return |
---|
1958 | an undesired ticket file name until this routine is called. The default |
---|
1959 | ticket file name (unless the environment variable @code{KRBTKFILE} is |
---|
1960 | set) is @file{/tmp/tkt@var{uid}}), where @var{uid} denotes the user's |
---|
1961 | ID, in decimal. |
---|
1962 | |
---|
1963 | |
---|
1964 | @node kuserok |
---|
1965 | @subsection kuserok |
---|
1966 | @findex kuserok |
---|
1967 | |
---|
1968 | @smallexample |
---|
1969 | #include "krb.h" |
---|
1970 | kuserok(AUTH_DAT *@var{auth_data}, char *@var{localuser}); |
---|
1971 | @end smallexample |
---|
1972 | |
---|
1973 | @code{kuserok} determines whether a Kerberos principal described by the |
---|
1974 | structure @var{auth_data} is authorized to login as user @var{localuser} |
---|
1975 | according to the authorization file (@file{~localuser/.klogin} by |
---|
1976 | default). It returns zero if authorized, `1' if not authorized. If |
---|
1977 | there is no account for @var{localuser} on the local machine, |
---|
1978 | authorization is not granted. If there is no authorization file, and |
---|
1979 | the Kerberos principal described by @var{auth_data} translates to |
---|
1980 | @var{localuser} (using @pxref{krb_kntoln}), authorization is granted. |
---|
1981 | If the authorization file can not be accessed, or the file is not owned |
---|
1982 | by @var{localuser}, authorization is denied. Otherwise, the file is |
---|
1983 | searched for a matching principal name, and realm. If a match is found, |
---|
1984 | authorization is granted, else authorization is denied. The file |
---|
1985 | entries are in the format: |
---|
1986 | @smallexample |
---|
1987 | @var{name}.@var{instance}@@@var{realm} |
---|
1988 | @end smallexample |
---|
1989 | @noindent |
---|
1990 | with one entry per line. |
---|
1991 | @ignore |
---|
1992 | @subsubheading SEE ALSO |
---|
1993 | @table @ref |
---|
1994 | @item Kerberos |
---|
1995 | @item Kerberos,,krb_kntoln |
---|
1996 | @end table |
---|
1997 | @code{ruserok}(3) |
---|
1998 | |
---|
1999 | @subsubheading FILES |
---|
2000 | @table @file |
---|
2001 | @item ~localuser/.klogin |
---|
2002 | authorization list |
---|
2003 | @end table |
---|
2004 | @end ignore |
---|
2005 | |
---|
2006 | |
---|
2007 | @node Macintosh Library API |
---|
2008 | @chapter CNS Macintosh Library API |
---|
2009 | |
---|
2010 | This chapter documents Macintosh-specific aspects of the Cygnus Network |
---|
2011 | Support Kerberos programming interface. |
---|
2012 | |
---|
2013 | On the Macintosh, the standard Kerberos API is available, as |
---|
2014 | documented in the common API section. These standard |
---|
2015 | routines are implemented as |
---|
2016 | glue code which in turn calls a driver. In the driver is more glue code |
---|
2017 | which then calls the real routines. |
---|
2018 | |
---|
2019 | @emph{We STRONGLY recommend that you write your programs to use the |
---|
2020 | ordinary Kerberos subroutine call API. The low-level Macintosh |
---|
2021 | interface is not |
---|
2022 | guaranteed to remain stable. It's a lot easier to program with |
---|
2023 | simple subroutine calls instead of I/O traps too.} |
---|
2024 | |
---|
2025 | Application programs which have unusual requirements can call the |
---|
2026 | driver directly, though this is discouraged. To call the driver |
---|
2027 | directly, examine the file @file{mac_stubs.c} in the source code |
---|
2028 | distribution of Cygnus Network Security, in the @file{src/lib/krb} |
---|
2029 | directory. |
---|
2030 | |
---|
2031 | The low-level Kerberos interface is designed to be compatible with the |
---|
2032 | @code{kclient} program from Cornell, and borrows some code from the |
---|
2033 | @code{kclient} and @code{kconfig} programs. Programs written to work |
---|
2034 | with the @code{kclient} Mac Kerberos driver will probably work with |
---|
2035 | Cygnus Network Security's driver as well. One feature of the @code{kclient} |
---|
2036 | program that is not implemented by CNS is multiple named credential caches. |
---|
2037 | Supporting this feature would have required changing the basic |
---|
2038 | API for several Kerberos functions. |
---|
2039 | |
---|
2040 | None of the CNS driver operations work asynchronously; the driver must |
---|
2041 | be called synchronously. |
---|
2042 | |
---|
2043 | |
---|
2044 | @menu |
---|
2045 | * Compiling and Linking your Macintosh Program:: |
---|
2046 | @end menu |
---|
2047 | |
---|
2048 | @node Compiling and Linking your Macintosh Program |
---|
2049 | @section Compiling and Linking your Macintosh Program |
---|
2050 | |
---|
2051 | The Macintosh Kerberos driver is installed into the @samp{Extensions} |
---|
2052 | folder in the @samp{System Folder} on the disk drive from which you boot. |
---|
2053 | It installs itself into the system at boot time, putting a small icon |
---|
2054 | along the bottom of the screen for a short time. By the time the system |
---|
2055 | comes up, the driver is ready for use. |
---|
2056 | |
---|
2057 | The preferred way to use the driver is to @code{#include "krb.h"} |
---|
2058 | in all of your source modules that call Kerberos routines. Make |
---|
2059 | sure that your program calls @code{krb_start_session} before calling any |
---|
2060 | other Kerberos routines. Compile and link your code with the |
---|
2061 | @file{mac_stubs.c} file, which provides the short `stub' routines |
---|
2062 | which translate the Common Kerberos Library API into the arcane calling |
---|
2063 | conventions of Macintosh drivers. |
---|
2064 | |
---|
2065 | If @code{krb_start_session} does not return @code{KSUCCESS}, it is |
---|
2066 | unable to locate or initialize a Kerberos driver in your Macintosh. |
---|
2067 | Check your Extensions folder to make sure that the driver is being |
---|
2068 | installed on each reboot. You must reboot after putting the driver in |
---|
2069 | the Extensions folder as well. |
---|
2070 | |
---|
2071 | @node MS-Windows Library API |
---|
2072 | @chapter MS-Windows Application Programmer Interface |
---|
2073 | |
---|
2074 | This chapter documents Microsoft Windows-specific aspects of the |
---|
2075 | Cygnus Network Support Kerberos programming interface. |
---|
2076 | |
---|
2077 | On MS-Windows, the standard Kerberos API is available, as |
---|
2078 | documented in the common API section. These standard |
---|
2079 | routines are implemented in a Dynamic Link Library called |
---|
2080 | @file{KERBEROS.DLL}. |
---|
2081 | |
---|
2082 | Due to the standard DLL calling conventions, |
---|
2083 | all pointers passed to or returned from the MS-Windows Kerberos |
---|
2084 | implementation are |
---|
2085 | FAR pointers. The interface file @file{kerberos.h}, which is included |
---|
2086 | by the usual @file{krb.h} include file, provides function |
---|
2087 | prototypes that cause any pointers arguments to be converted to |
---|
2088 | FAR pointers. You must ensure that any result values which are pointers |
---|
2089 | are handled properly as FAR pointers. |
---|
2090 | |
---|
2091 | Values which are specified as @code{int} are 16 bit numbers using |
---|
2092 | MS-Windows compilers. |
---|
2093 | |
---|
2094 | @menu |
---|
2095 | * Compiling and Linking your MS-Windows Program:: |
---|
2096 | * Password changing calls:: Interface for changing a user's password |
---|
2097 | * Ticket cache notification:: Finding out when the cache changes |
---|
2098 | * Timekeeping:: Time epochs and clock access |
---|
2099 | @end menu |
---|
2100 | |
---|
2101 | @node Compiling and Linking your MS-Windows Program |
---|
2102 | @section Compiling and Linking your MS-Windows Program |
---|
2103 | |
---|
2104 | The @file{KERBEROS.DLL} file can be installed anywhere on |
---|
2105 | the search path. |
---|
2106 | |
---|
2107 | The preferred way to use the driver is to @code{#include "krb.h"} in all |
---|
2108 | of your source modules that call Kerberos routines. Make sure that your |
---|
2109 | program calls @code{krb_start_session} before calling any other Kerberos |
---|
2110 | routines. Link your code with the @file{KERBEROS.LIB} file, which |
---|
2111 | causes calls to @file{KERBEROS.DLL} to occur when running the program. |
---|
2112 | |
---|
2113 | @node Password changing calls |
---|
2114 | @section Password changing calls |
---|
2115 | |
---|
2116 | Due to the need to formally externalize calls from a DLL, a number of |
---|
2117 | routines which are only used in @code{kpasswd} on UNIX are visible in |
---|
2118 | the MS-Windows interface. The routines are used by the @code{CNS} user |
---|
2119 | interface program on Windows. On Unix, these routines reside within the |
---|
2120 | @code{kadm} library; they are not usually called by users. |
---|
2121 | |
---|
2122 | @smallexample |
---|
2123 | int kadm_change_pw (des_cblock key); |
---|
2124 | |
---|
2125 | int kadm_change_pw2 (des_cblock key, char *password, |
---|
2126 | unsigned char **ret_st); |
---|
2127 | |
---|
2128 | int kadm_init_link (char *pwserv_name, char *krb_master, |
---|
2129 | char *realm); |
---|
2130 | @end smallexample |
---|
2131 | |
---|
2132 | @node Ticket cache notification |
---|
2133 | @section Ticket cache notification |
---|
2134 | |
---|
2135 | This MS-Windows-specific API call gives an interactive application |
---|
2136 | notification when the contents of the ticket cache change. The call |
---|
2137 | returns the number of the unique message which are sent to all top level |
---|
2138 | windows after the ticket cache changes. The @code{CNS} program uses |
---|
2139 | this message to keep its display current. The prototype is as follows: |
---|
2140 | |
---|
2141 | @smallexample |
---|
2142 | int krb_get_notification_message(void) |
---|
2143 | @end smallexample |
---|
2144 | |
---|
2145 | |
---|
2146 | @node Timekeeping |
---|
2147 | @section Timekeeping |
---|
2148 | |
---|
2149 | The Kerberos protocol uses timestamps based on an epoch |
---|
2150 | in which time begins at |
---|
2151 | 00:00 January 1, 1970. All times expected and returned by the |
---|
2152 | Kerberos API are in these |
---|
2153 | units, independent of what the C library returns. Note that Microsoft C 7.0 |
---|
2154 | starts time at January 1, 1900, though they backed that change out in |
---|
2155 | version 7.0.1. Our code can run in either environment. |
---|
2156 | |
---|
2157 | Kerberos reads time from the hardware clock using BIOS interrupt |
---|
2158 | 0x1A. This avoids problems with the software clock drifting as the |
---|
2159 | system runs. |
---|
2160 | |
---|
2161 | The local time zone is set by the @code{TZ} environment variable. |
---|
2162 | |
---|
2163 | @node Function Index |
---|
2164 | @chapter Function Index |
---|
2165 | |
---|
2166 | @printindex fn |
---|
2167 | |
---|
2168 | @contents |
---|
2169 | @c end of texinfo file |
---|
2170 | @bye |
---|
2171 | @c (modify-syntax-entry ?_ "w" para-mode-syntax-table) |
---|
2172 | @c (modify-syntax-entry ?- "w" para-mode-syntax-table) |
---|
2173 | @c (modify-syntax-entry ?/ "w" para-mode-syntax-table) |
---|