]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/net/sunrpc/gss_krb5_unseal.c | |
3 | * | |
4 | * Adapted from MIT Kerberos 5-1.2.1 lib/gssapi/krb5/k5unseal.c | |
5 | * | |
6 | * Copyright (c) 2000 The Regents of the University of Michigan. | |
7 | * All rights reserved. | |
8 | * | |
9 | * Andy Adamson <andros@umich.edu> | |
10 | */ | |
11 | ||
12 | /* | |
13 | * Copyright 1993 by OpenVision Technologies, Inc. | |
14 | * | |
15 | * Permission to use, copy, modify, distribute, and sell this software | |
16 | * and its documentation for any purpose is hereby granted without fee, | |
17 | * provided that the above copyright notice appears in all copies and | |
18 | * that both that copyright notice and this permission notice appear in | |
19 | * supporting documentation, and that the name of OpenVision not be used | |
20 | * in advertising or publicity pertaining to distribution of the software | |
21 | * without specific, written prior permission. OpenVision makes no | |
22 | * representations about the suitability of this software for any | |
23 | * purpose. It is provided "as is" without express or implied warranty. | |
24 | * | |
25 | * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, | |
26 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO | |
27 | * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR | |
28 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF | |
29 | * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | |
30 | * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | |
31 | * PERFORMANCE OF THIS SOFTWARE. | |
32 | */ | |
33 | ||
34 | /* | |
35 | * Copyright (C) 1998 by the FundsXpress, INC. | |
36 | * | |
37 | * All rights reserved. | |
38 | * | |
39 | * Export of this software from the United States of America may require | |
40 | * a specific license from the United States Government. It is the | |
41 | * responsibility of any person or organization contemplating export to | |
42 | * obtain such a license before exporting. | |
43 | * | |
44 | * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and | |
45 | * distribute this software and its documentation for any purpose and | |
46 | * without fee is hereby granted, provided that the above copyright | |
47 | * notice appear in all copies and that both that copyright notice and | |
48 | * this permission notice appear in supporting documentation, and that | |
49 | * the name of FundsXpress. not be used in advertising or publicity pertaining | |
50 | * to distribution of the software without specific, written prior | |
51 | * permission. FundsXpress makes no representations about the suitability of | |
52 | * this software for any purpose. It is provided "as is" without express | |
53 | * or implied warranty. | |
54 | * | |
55 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
56 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
57 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
58 | */ | |
59 | ||
60 | #include <linux/types.h> | |
1da177e4 LT |
61 | #include <linux/jiffies.h> |
62 | #include <linux/sunrpc/gss_krb5.h> | |
63 | #include <linux/crypto.h> | |
64 | ||
65 | #ifdef RPC_DEBUG | |
66 | # define RPCDBG_FACILITY RPCDBG_AUTH | |
67 | #endif | |
68 | ||
69 | ||
bfa91516 BF |
70 | /* read_token is a mic token, and message_buffer is the data that the mic was |
71 | * supposedly taken over. */ | |
1da177e4 | 72 | |
1da177e4 | 73 | u32 |
a0857d03 BF |
74 | gss_verify_mic_kerberos(struct gss_ctx *gss_ctx, |
75 | struct xdr_buf *message_buffer, struct xdr_netobj *read_token) | |
1da177e4 | 76 | { |
a0857d03 | 77 | struct krb5_ctx *ctx = gss_ctx->internal_ctx_id; |
1da177e4 LT |
78 | int signalg; |
79 | int sealalg; | |
9e57b302 BF |
80 | char cksumdata[16]; |
81 | struct xdr_netobj md5cksum = {.len = 0, .data = cksumdata}; | |
1da177e4 LT |
82 | s32 now; |
83 | int direction; | |
5743d65c | 84 | u32 seqnum; |
1da177e4 LT |
85 | unsigned char *ptr = (unsigned char *)read_token->data; |
86 | int bodysize; | |
1da177e4 | 87 | |
8885cb36 | 88 | dprintk("RPC: krb5_read_token\n"); |
1da177e4 LT |
89 | |
90 | if (g_verify_token_header(&ctx->mech_used, &bodysize, &ptr, | |
91 | read_token->len)) | |
39a21dd1 | 92 | return GSS_S_DEFECTIVE_TOKEN; |
1da177e4 | 93 | |
d00953a5 KC |
94 | if ((ptr[0] != ((KG_TOK_MIC_MSG >> 8) & 0xff)) || |
95 | (ptr[1] != (KG_TOK_MIC_MSG & 0xff))) | |
39a21dd1 | 96 | return GSS_S_DEFECTIVE_TOKEN; |
1da177e4 LT |
97 | |
98 | /* XXX sanity-check bodysize?? */ | |
99 | ||
d00953a5 | 100 | signalg = ptr[2] + (ptr[3] << 8); |
94efa934 | 101 | if (signalg != SGN_ALG_DES_MAC_MD5) |
39a21dd1 | 102 | return GSS_S_DEFECTIVE_TOKEN; |
1da177e4 | 103 | |
d00953a5 | 104 | sealalg = ptr[4] + (ptr[5] << 8); |
94efa934 | 105 | if (sealalg != SEAL_ALG_NONE) |
39a21dd1 | 106 | return GSS_S_DEFECTIVE_TOKEN; |
94efa934 | 107 | |
d00953a5 | 108 | if ((ptr[6] != 0xff) || (ptr[7] != 0xff)) |
39a21dd1 | 109 | return GSS_S_DEFECTIVE_TOKEN; |
1da177e4 | 110 | |
d00953a5 | 111 | if (make_checksum("md5", ptr, 8, message_buffer, 0, &md5cksum)) |
39a21dd1 | 112 | return GSS_S_FAILURE; |
5eb064f9 | 113 | |
39a21dd1 BF |
114 | if (krb5_encrypt(ctx->seq, NULL, md5cksum.data, md5cksum.data, 16)) |
115 | return GSS_S_FAILURE; | |
1da177e4 | 116 | |
d00953a5 | 117 | if (memcmp(md5cksum.data + 8, ptr + GSS_KRB5_TOK_HDR_LEN, 8)) |
39a21dd1 | 118 | return GSS_S_BAD_SIG; |
1da177e4 LT |
119 | |
120 | /* it got through unscathed. Make sure the context is unexpired */ | |
121 | ||
1da177e4 LT |
122 | now = get_seconds(); |
123 | ||
1da177e4 | 124 | if (now > ctx->endtime) |
39a21dd1 | 125 | return GSS_S_CONTEXT_EXPIRED; |
1da177e4 LT |
126 | |
127 | /* do sequencing checks */ | |
128 | ||
d00953a5 | 129 | if (krb5_get_seq_num(ctx->seq, ptr + GSS_KRB5_TOK_HDR_LEN, ptr + 8, &direction, &seqnum)) |
39a21dd1 | 130 | return GSS_S_FAILURE; |
1da177e4 LT |
131 | |
132 | if ((ctx->initiate && direction != 0xff) || | |
133 | (!ctx->initiate && direction != 0)) | |
39a21dd1 | 134 | return GSS_S_BAD_SIG; |
1da177e4 | 135 | |
39a21dd1 | 136 | return GSS_S_COMPLETE; |
1da177e4 | 137 | } |