2 * Modifications for Lustre
4 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
6 * Copyright (c) 2011, 2015, Intel Corporation.
8 * Author: Eric Mei <ericm@clusterfs.com>
12 * linux/net/sunrpc/gss_krb5_mech.c
13 * linux/net/sunrpc/gss_krb5_crypto.c
14 * linux/net/sunrpc/gss_krb5_seal.c
15 * linux/net/sunrpc/gss_krb5_seqnum.c
16 * linux/net/sunrpc/gss_krb5_unseal.c
18 * Copyright (c) 2001 The Regents of the University of Michigan.
19 * All rights reserved.
21 * Andy Adamson <andros@umich.edu>
22 * J. Bruce Fields <bfields@umich.edu>
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
28 * 1. Redistributions of source code must retain the above copyright
29 * notice, this list of conditions and the following disclaimer.
30 * 2. Redistributions in binary form must reproduce the above copyright
31 * notice, this list of conditions and the following disclaimer in the
32 * documentation and/or other materials provided with the distribution.
33 * 3. Neither the name of the University nor the names of its
34 * contributors may be used to endorse or promote products derived
35 * from this software without specific prior written permission.
37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
39 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
41 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
42 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
43 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
44 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
45 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
46 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
47 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51 #define DEBUG_SUBSYSTEM S_SEC
52 #include <linux/init.h>
53 #include <linux/module.h>
54 #include <linux/slab.h>
55 #include <linux/crypto.h>
56 #include <linux/mutex.h>
59 #include <obd_class.h>
60 #include <obd_support.h>
61 #include <lustre_net.h>
62 #include <lustre_import.h>
63 #include <lustre_sec.h>
66 #include "gss_internal.h"
70 #include "gss_crypto.h"
72 static spinlock_t krb5_seq_lock;
76 char *ke_enc_name; /* linux tfm name */
77 char *ke_hash_name; /* linux tfm name */
78 int ke_enc_mode; /* linux tfm mode */
79 int ke_hash_size; /* checksum size */
80 int ke_conf_size; /* confounder size */
81 unsigned int ke_hash_hmac:1; /* is hmac? */
85 * NOTE: for aes128-cts and aes256-cts, MIT implementation use CTS encryption.
86 * but currently we simply CBC with padding, because linux doesn't support CTS
87 * yet. this need to be fixed in the future.
89 static struct krb5_enctype enctypes[] = {
90 [ENCTYPE_DES_CBC_RAW] = { /* des-cbc-md5 */
91 .ke_dispname = "des-cbc-md5",
92 .ke_enc_name = "cbc(des)",
93 .ke_hash_name = "md5",
97 [ENCTYPE_DES3_CBC_RAW] = { /* des3-hmac-sha1 */
98 .ke_dispname = "des3-hmac-sha1",
99 .ke_enc_name = "cbc(des3_ede)",
100 .ke_hash_name = "hmac(sha1)",
105 [ENCTYPE_AES128_CTS_HMAC_SHA1_96] = { /* aes128-cts */
106 .ke_dispname = "aes128-cts-hmac-sha1-96",
107 .ke_enc_name = "cbc(aes)",
108 .ke_hash_name = "hmac(sha1)",
113 [ENCTYPE_AES256_CTS_HMAC_SHA1_96] = { /* aes256-cts */
114 .ke_dispname = "aes256-cts-hmac-sha1-96",
115 .ke_enc_name = "cbc(aes)",
116 .ke_hash_name = "hmac(sha1)",
121 [ENCTYPE_ARCFOUR_HMAC] = { /* arcfour-hmac-md5 */
122 .ke_dispname = "arcfour-hmac-md5",
123 .ke_enc_name = "ecb(arc4)",
124 .ke_hash_name = "hmac(md5)",
131 #define MAX_ENCTYPES sizeof(enctypes)/sizeof(struct krb5_enctype)
133 static const char * enctype2str(__u32 enctype)
135 if (enctype < MAX_ENCTYPES && enctypes[enctype].ke_dispname)
136 return enctypes[enctype].ke_dispname;
142 int krb5_init_keys(struct krb5_ctx *kctx)
144 struct krb5_enctype *ke;
146 if (kctx->kc_enctype >= MAX_ENCTYPES ||
147 enctypes[kctx->kc_enctype].ke_hash_size == 0) {
148 CERROR("unsupported enctype %x\n", kctx->kc_enctype);
152 ke = &enctypes[kctx->kc_enctype];
154 /* tfm arc4 is stateful, user should alloc-use-free by his own */
155 if (kctx->kc_enctype != ENCTYPE_ARCFOUR_HMAC &&
156 gss_keyblock_init(&kctx->kc_keye, ke->ke_enc_name, ke->ke_enc_mode))
159 /* tfm hmac is stateful, user should alloc-use-free by his own */
160 if (ke->ke_hash_hmac == 0 &&
161 gss_keyblock_init(&kctx->kc_keyi, ke->ke_enc_name, ke->ke_enc_mode))
163 if (ke->ke_hash_hmac == 0 &&
164 gss_keyblock_init(&kctx->kc_keyc, ke->ke_enc_name, ke->ke_enc_mode))
171 void delete_context_kerberos(struct krb5_ctx *kctx)
173 rawobj_free(&kctx->kc_mech_used);
175 gss_keyblock_free(&kctx->kc_keye);
176 gss_keyblock_free(&kctx->kc_keyi);
177 gss_keyblock_free(&kctx->kc_keyc);
181 __u32 import_context_rfc1964(struct krb5_ctx *kctx, char *p, char *end)
183 unsigned int tmp_uint, keysize;
186 if (gss_get_bytes(&p, end, &tmp_uint, sizeof(tmp_uint)))
188 kctx->kc_seed_init = (tmp_uint != 0);
191 if (gss_get_bytes(&p, end, kctx->kc_seed, sizeof(kctx->kc_seed)))
194 /* sign/seal algorithm, not really used now */
195 if (gss_get_bytes(&p, end, &tmp_uint, sizeof(tmp_uint)) ||
196 gss_get_bytes(&p, end, &tmp_uint, sizeof(tmp_uint)))
199 /* end time. While kc_endtime might be 64 bit the krb5 API
200 * still uses 32 bits. To delay the 2038 bug see the incoming
201 * value as a u32 which give us until 2106. See the link for details:
203 * http://web.mit.edu/kerberos/www/krb5-current/doc/appdev/y2038.html
205 if (gss_get_bytes(&p, end, &kctx->kc_endtime, sizeof(u32)))
209 if (gss_get_bytes(&p, end, &tmp_uint, sizeof(tmp_uint)))
211 kctx->kc_seq_send = tmp_uint;
214 if (gss_get_rawobj(&p, end, &kctx->kc_mech_used))
217 /* old style enc/seq keys in format:
221 * we decompose them to fit into the new context
225 if (gss_get_bytes(&p, end, &kctx->kc_enctype, sizeof(kctx->kc_enctype)))
228 if (gss_get_bytes(&p, end, &keysize, sizeof(keysize)))
231 if (gss_get_keyblock(&p, end, &kctx->kc_keye, keysize))
235 if (gss_get_bytes(&p, end, &tmp_uint, sizeof(tmp_uint)) ||
236 tmp_uint != kctx->kc_enctype)
239 if (gss_get_bytes(&p, end, &tmp_uint, sizeof(tmp_uint)) ||
243 if (gss_get_keyblock(&p, end, &kctx->kc_keyc, keysize))
246 /* old style fallback */
247 if (gss_keyblock_dup(&kctx->kc_keyi, &kctx->kc_keyc))
253 CDEBUG(D_SEC, "successfully imported rfc1964 context\n");
256 return GSS_S_FAILURE;
259 /* Flags for version 2 context flags */
260 #define KRB5_CTX_FLAG_INITIATOR 0x00000001
261 #define KRB5_CTX_FLAG_CFX 0x00000002
262 #define KRB5_CTX_FLAG_ACCEPTOR_SUBKEY 0x00000004
265 __u32 import_context_rfc4121(struct krb5_ctx *kctx, char *p, char *end)
267 unsigned int tmp_uint, keysize;
269 /* end time. While kc_endtime might be 64 bit the krb5 API
270 * still uses 32 bits. To delay the 2038 bug see the incoming
271 * value as a u32 which give us until 2106. See the link for details:
273 * http://web.mit.edu/kerberos/www/krb5-current/doc/appdev/y2038.html
275 if (gss_get_bytes(&p, end, &kctx->kc_endtime, sizeof(u32)))
279 if (gss_get_bytes(&p, end, &tmp_uint, sizeof(tmp_uint)))
282 if (tmp_uint & KRB5_CTX_FLAG_INITIATOR)
283 kctx->kc_initiate = 1;
284 if (tmp_uint & KRB5_CTX_FLAG_CFX)
286 if (tmp_uint & KRB5_CTX_FLAG_ACCEPTOR_SUBKEY)
287 kctx->kc_have_acceptor_subkey = 1;
290 if (gss_get_bytes(&p, end, &kctx->kc_seq_send,
291 sizeof(kctx->kc_seq_send)))
295 if (gss_get_bytes(&p, end, &kctx->kc_enctype, sizeof(kctx->kc_enctype)))
298 /* size of each key */
299 if (gss_get_bytes(&p, end, &keysize, sizeof(keysize)))
302 /* number of keys - should always be 3 */
303 if (gss_get_bytes(&p, end, &tmp_uint, sizeof(tmp_uint)))
307 CERROR("Invalid number of keys: %u\n", tmp_uint);
312 if (gss_get_keyblock(&p, end, &kctx->kc_keye, keysize))
315 if (gss_get_keyblock(&p, end, &kctx->kc_keyi, keysize))
318 if (gss_get_keyblock(&p, end, &kctx->kc_keyc, keysize))
321 CDEBUG(D_SEC, "successfully imported v2 context\n");
324 return GSS_S_FAILURE;
328 * The whole purpose here is trying to keep user level gss context parsing
329 * from nfs-utils unchanged as possible as we can, they are not quite mature
330 * yet, and many stuff still not clear, like heimdal etc.
333 __u32 gss_import_sec_context_kerberos(rawobj_t *inbuf,
334 struct gss_ctx *gctx)
336 struct krb5_ctx *kctx;
337 char *p = (char *)inbuf->data;
338 char *end = (char *)(inbuf->data + inbuf->len);
339 unsigned int tmp_uint, rc;
341 if (gss_get_bytes(&p, end, &tmp_uint, sizeof(tmp_uint))) {
342 CERROR("Fail to read version\n");
343 return GSS_S_FAILURE;
346 /* only support 0, 1 for the moment */
348 CERROR("Invalid version %u\n", tmp_uint);
349 return GSS_S_FAILURE;
354 return GSS_S_FAILURE;
356 if (tmp_uint == 0 || tmp_uint == 1) {
357 kctx->kc_initiate = tmp_uint;
358 rc = import_context_rfc1964(kctx, p, end);
360 rc = import_context_rfc4121(kctx, p, end);
364 rc = krb5_init_keys(kctx);
367 delete_context_kerberos(kctx);
370 return GSS_S_FAILURE;
373 gctx->internal_ctx_id = kctx;
374 return GSS_S_COMPLETE;
378 __u32 gss_copy_reverse_context_kerberos(struct gss_ctx *gctx,
379 struct gss_ctx *gctx_new)
381 struct krb5_ctx *kctx = gctx->internal_ctx_id;
382 struct krb5_ctx *knew;
386 return GSS_S_FAILURE;
388 knew->kc_initiate = kctx->kc_initiate ? 0 : 1;
389 knew->kc_cfx = kctx->kc_cfx;
390 knew->kc_seed_init = kctx->kc_seed_init;
391 knew->kc_have_acceptor_subkey = kctx->kc_have_acceptor_subkey;
392 knew->kc_endtime = kctx->kc_endtime;
394 memcpy(knew->kc_seed, kctx->kc_seed, sizeof(kctx->kc_seed));
395 knew->kc_seq_send = kctx->kc_seq_recv;
396 knew->kc_seq_recv = kctx->kc_seq_send;
397 knew->kc_enctype = kctx->kc_enctype;
399 if (rawobj_dup(&knew->kc_mech_used, &kctx->kc_mech_used))
402 if (gss_keyblock_dup(&knew->kc_keye, &kctx->kc_keye))
404 if (gss_keyblock_dup(&knew->kc_keyi, &kctx->kc_keyi))
406 if (gss_keyblock_dup(&knew->kc_keyc, &kctx->kc_keyc))
408 if (krb5_init_keys(knew))
411 gctx_new->internal_ctx_id = knew;
412 CDEBUG(D_SEC, "successfully copied reverse context\n");
413 return GSS_S_COMPLETE;
416 delete_context_kerberos(knew);
418 return GSS_S_FAILURE;
422 __u32 gss_inquire_context_kerberos(struct gss_ctx *gctx,
425 struct krb5_ctx *kctx = gctx->internal_ctx_id;
427 *endtime = kctx->kc_endtime;
428 return GSS_S_COMPLETE;
432 void gss_delete_sec_context_kerberos(void *internal_ctx)
434 struct krb5_ctx *kctx = internal_ctx;
436 delete_context_kerberos(kctx);
441 * compute (keyed/keyless) checksum against the plain text which appended
442 * with krb5 wire token header.
445 __s32 krb5_make_checksum(__u32 enctype,
446 struct gss_keyblock *kb,
447 struct krb5_header *khdr,
448 int msgcnt, rawobj_t *msgs,
449 int iovcnt, lnet_kiov_t *iovs,
452 struct krb5_enctype *ke = &enctypes[enctype];
453 struct crypto_hash *tfm;
455 __u32 code = GSS_S_FAILURE;
458 if (!(tfm = crypto_alloc_hash(ke->ke_hash_name, 0, 0))) {
459 CERROR("failed to alloc TFM: %s\n", ke->ke_hash_name);
460 return GSS_S_FAILURE;
463 cksum->len = crypto_hash_digestsize(tfm);
464 OBD_ALLOC_LARGE(cksum->data, cksum->len);
470 hdr.data = (__u8 *)khdr;
471 hdr.len = sizeof(*khdr);
473 if (ke->ke_hash_hmac)
474 rc = gss_digest_hmac(tfm, &kb->kb_key,
475 &hdr, msgcnt, msgs, iovcnt, iovs, cksum);
477 rc = gss_digest_norm(tfm, kb,
478 &hdr, msgcnt, msgs, iovcnt, iovs, cksum);
481 code = GSS_S_COMPLETE;
483 crypto_free_hash(tfm);
487 static void fill_krb5_header(struct krb5_ctx *kctx,
488 struct krb5_header *khdr,
491 unsigned char acceptor_flag;
493 acceptor_flag = kctx->kc_initiate ? 0 : FLAG_SENDER_IS_ACCEPTOR;
496 khdr->kh_tok_id = cpu_to_be16(KG_TOK_WRAP_MSG);
497 khdr->kh_flags = acceptor_flag | FLAG_WRAP_CONFIDENTIAL;
498 khdr->kh_ec = cpu_to_be16(0);
499 khdr->kh_rrc = cpu_to_be16(0);
501 khdr->kh_tok_id = cpu_to_be16(KG_TOK_MIC_MSG);
502 khdr->kh_flags = acceptor_flag;
503 khdr->kh_ec = cpu_to_be16(0xffff);
504 khdr->kh_rrc = cpu_to_be16(0xffff);
507 khdr->kh_filler = 0xff;
508 spin_lock(&krb5_seq_lock);
509 khdr->kh_seq = cpu_to_be64(kctx->kc_seq_send++);
510 spin_unlock(&krb5_seq_lock);
513 static __u32 verify_krb5_header(struct krb5_ctx *kctx,
514 struct krb5_header *khdr,
517 unsigned char acceptor_flag;
518 __u16 tok_id, ec_rrc;
520 acceptor_flag = kctx->kc_initiate ? FLAG_SENDER_IS_ACCEPTOR : 0;
523 tok_id = KG_TOK_WRAP_MSG;
526 tok_id = KG_TOK_MIC_MSG;
531 if (be16_to_cpu(khdr->kh_tok_id) != tok_id) {
532 CERROR("bad token id\n");
533 return GSS_S_DEFECTIVE_TOKEN;
535 if ((khdr->kh_flags & FLAG_SENDER_IS_ACCEPTOR) != acceptor_flag) {
536 CERROR("bad direction flag\n");
537 return GSS_S_BAD_SIG;
539 if (privacy && (khdr->kh_flags & FLAG_WRAP_CONFIDENTIAL) == 0) {
540 CERROR("missing confidential flag\n");
541 return GSS_S_BAD_SIG;
543 if (khdr->kh_filler != 0xff) {
544 CERROR("bad filler\n");
545 return GSS_S_DEFECTIVE_TOKEN;
547 if (be16_to_cpu(khdr->kh_ec) != ec_rrc ||
548 be16_to_cpu(khdr->kh_rrc) != ec_rrc) {
549 CERROR("bad EC or RRC\n");
550 return GSS_S_DEFECTIVE_TOKEN;
552 return GSS_S_COMPLETE;
556 __u32 gss_get_mic_kerberos(struct gss_ctx *gctx,
563 struct krb5_ctx *kctx = gctx->internal_ctx_id;
564 struct krb5_enctype *ke = &enctypes[kctx->kc_enctype];
565 struct krb5_header *khdr;
566 rawobj_t cksum = RAWOBJ_EMPTY;
568 /* fill krb5 header */
569 LASSERT(token->len >= sizeof(*khdr));
570 khdr = (struct krb5_header *)token->data;
571 fill_krb5_header(kctx, khdr, 0);
574 if (krb5_make_checksum(kctx->kc_enctype, &kctx->kc_keyc,
575 khdr, msgcnt, msgs, iovcnt, iovs, &cksum))
576 return GSS_S_FAILURE;
578 LASSERT(cksum.len >= ke->ke_hash_size);
579 LASSERT(token->len >= sizeof(*khdr) + ke->ke_hash_size);
580 memcpy(khdr + 1, cksum.data + cksum.len - ke->ke_hash_size,
583 token->len = sizeof(*khdr) + ke->ke_hash_size;
585 return GSS_S_COMPLETE;
589 __u32 gss_verify_mic_kerberos(struct gss_ctx *gctx,
596 struct krb5_ctx *kctx = gctx->internal_ctx_id;
597 struct krb5_enctype *ke = &enctypes[kctx->kc_enctype];
598 struct krb5_header *khdr;
599 rawobj_t cksum = RAWOBJ_EMPTY;
602 if (token->len < sizeof(*khdr)) {
603 CERROR("short signature: %u\n", token->len);
604 return GSS_S_DEFECTIVE_TOKEN;
607 khdr = (struct krb5_header *)token->data;
609 major = verify_krb5_header(kctx, khdr, 0);
610 if (major != GSS_S_COMPLETE) {
611 CERROR("bad krb5 header\n");
615 if (token->len < sizeof(*khdr) + ke->ke_hash_size) {
616 CERROR("short signature: %u, require %d\n",
617 token->len, (int) sizeof(*khdr) + ke->ke_hash_size);
618 return GSS_S_FAILURE;
621 if (krb5_make_checksum(kctx->kc_enctype, &kctx->kc_keyc,
622 khdr, msgcnt, msgs, iovcnt, iovs, &cksum)) {
623 CERROR("failed to make checksum\n");
624 return GSS_S_FAILURE;
627 LASSERT(cksum.len >= ke->ke_hash_size);
628 if (memcmp(khdr + 1, cksum.data + cksum.len - ke->ke_hash_size,
630 CERROR("checksum mismatch\n");
632 return GSS_S_BAD_SIG;
636 return GSS_S_COMPLETE;
640 * if adj_nob != 0, we adjust desc->bd_nob to the actual cipher text size.
643 int krb5_encrypt_bulk(struct crypto_blkcipher *tfm,
644 struct krb5_header *khdr,
646 struct ptlrpc_bulk_desc *desc,
650 struct blkcipher_desc ciph_desc;
651 __u8 local_iv[16] = {0};
652 struct scatterlist src, dst;
653 struct sg_table sg_src, sg_dst;
654 int blocksize, i, rc, nob = 0;
656 LASSERT(ptlrpc_is_bulk_desc_kiov(desc->bd_type));
657 LASSERT(desc->bd_iov_count);
658 LASSERT(GET_ENC_KIOV(desc));
660 blocksize = crypto_blkcipher_blocksize(tfm);
661 LASSERT(blocksize > 1);
662 LASSERT(cipher->len == blocksize + sizeof(*khdr));
665 ciph_desc.info = local_iv;
668 /* encrypt confounder */
669 rc = gss_setup_sgtable(&sg_src, &src, confounder, blocksize);
673 rc = gss_setup_sgtable(&sg_dst, &dst, cipher->data, blocksize);
675 gss_teardown_sgtable(&sg_src);
679 rc = crypto_blkcipher_encrypt_iv(&ciph_desc, sg_dst.sgl,
680 sg_src.sgl, blocksize);
682 gss_teardown_sgtable(&sg_dst);
683 gss_teardown_sgtable(&sg_src);
686 CERROR("error to encrypt confounder: %d\n", rc);
690 /* encrypt clear pages */
691 for (i = 0; i < desc->bd_iov_count; i++) {
692 sg_init_table(&src, 1);
693 sg_set_page(&src, BD_GET_KIOV(desc, i).kiov_page,
694 (BD_GET_KIOV(desc, i).kiov_len +
697 BD_GET_KIOV(desc, i).kiov_offset);
700 sg_init_table(&dst, 1);
701 sg_set_page(&dst, BD_GET_ENC_KIOV(desc, i).kiov_page,
702 src.length, src.offset);
704 BD_GET_ENC_KIOV(desc, i).kiov_offset = dst.offset;
705 BD_GET_ENC_KIOV(desc, i).kiov_len = dst.length;
707 rc = crypto_blkcipher_encrypt_iv(&ciph_desc, &dst, &src,
710 CERROR("error to encrypt page: %d\n", rc);
715 /* encrypt krb5 header */
716 rc = gss_setup_sgtable(&sg_src, &src, khdr, sizeof(*khdr));
720 rc = gss_setup_sgtable(&sg_dst, &dst, cipher->data + blocksize,
723 gss_teardown_sgtable(&sg_src);
727 rc = crypto_blkcipher_encrypt_iv(&ciph_desc, sg_dst.sgl, sg_src.sgl,
730 gss_teardown_sgtable(&sg_dst);
731 gss_teardown_sgtable(&sg_src);
734 CERROR("error to encrypt krb5 header: %d\n", rc);
745 * desc->bd_nob_transferred is the size of cipher text received.
746 * desc->bd_nob is the target size of plain text supposed to be.
748 * if adj_nob != 0, we adjust each page's kiov_len to the actual
750 * - for client read: we don't know data size for each page, so
751 * bd_iov[]->kiov_len is set to PAGE_SIZE, but actual data received might
752 * be smaller, so we need to adjust it according to
753 * bd_u.bd_kiov.bd_enc_vec[]->kiov_len.
754 * this means we DO NOT support the situation that server send an odd size
755 * data in a page which is not the last one.
756 * - for server write: we knows exactly data size for each page being expected,
757 * thus kiov_len is accurate already, so we should not adjust it at all.
758 * and bd_u.bd_kiov.bd_enc_vec[]->kiov_len should be
759 * round_up(bd_iov[]->kiov_len) which
760 * should have been done by prep_bulk().
763 int krb5_decrypt_bulk(struct crypto_blkcipher *tfm,
764 struct krb5_header *khdr,
765 struct ptlrpc_bulk_desc *desc,
770 struct blkcipher_desc ciph_desc;
771 __u8 local_iv[16] = {0};
772 struct scatterlist src, dst;
773 struct sg_table sg_src, sg_dst;
774 int ct_nob = 0, pt_nob = 0;
775 int blocksize, i, rc;
777 LASSERT(ptlrpc_is_bulk_desc_kiov(desc->bd_type));
778 LASSERT(desc->bd_iov_count);
779 LASSERT(GET_ENC_KIOV(desc));
780 LASSERT(desc->bd_nob_transferred);
782 blocksize = crypto_blkcipher_blocksize(tfm);
783 LASSERT(blocksize > 1);
784 LASSERT(cipher->len == blocksize + sizeof(*khdr));
787 ciph_desc.info = local_iv;
790 if (desc->bd_nob_transferred % blocksize) {
791 CERROR("odd transferred nob: %d\n", desc->bd_nob_transferred);
795 /* decrypt head (confounder) */
796 rc = gss_setup_sgtable(&sg_src, &src, cipher->data, blocksize);
800 rc = gss_setup_sgtable(&sg_dst, &dst, plain->data, blocksize);
802 gss_teardown_sgtable(&sg_src);
806 rc = crypto_blkcipher_decrypt_iv(&ciph_desc, sg_dst.sgl,
807 sg_src.sgl, blocksize);
809 gss_teardown_sgtable(&sg_dst);
810 gss_teardown_sgtable(&sg_src);
813 CERROR("error to decrypt confounder: %d\n", rc);
817 for (i = 0; i < desc->bd_iov_count && ct_nob < desc->bd_nob_transferred;
819 if (BD_GET_ENC_KIOV(desc, i).kiov_offset % blocksize
821 BD_GET_ENC_KIOV(desc, i).kiov_len % blocksize
823 CERROR("page %d: odd offset %u len %u, blocksize %d\n",
824 i, BD_GET_ENC_KIOV(desc, i).kiov_offset,
825 BD_GET_ENC_KIOV(desc, i).kiov_len,
831 if (ct_nob + BD_GET_ENC_KIOV(desc, i).kiov_len >
832 desc->bd_nob_transferred)
833 BD_GET_ENC_KIOV(desc, i).kiov_len =
834 desc->bd_nob_transferred - ct_nob;
836 BD_GET_KIOV(desc, i).kiov_len =
837 BD_GET_ENC_KIOV(desc, i).kiov_len;
838 if (pt_nob + BD_GET_ENC_KIOV(desc, i).kiov_len >
840 BD_GET_KIOV(desc, i).kiov_len =
841 desc->bd_nob - pt_nob;
843 /* this should be guaranteed by LNET */
844 LASSERT(ct_nob + BD_GET_ENC_KIOV(desc, i).
846 desc->bd_nob_transferred);
847 LASSERT(BD_GET_KIOV(desc, i).kiov_len <=
848 BD_GET_ENC_KIOV(desc, i).kiov_len);
851 if (BD_GET_ENC_KIOV(desc, i).kiov_len == 0)
854 sg_init_table(&src, 1);
855 sg_set_page(&src, BD_GET_ENC_KIOV(desc, i).kiov_page,
856 BD_GET_ENC_KIOV(desc, i).kiov_len,
857 BD_GET_ENC_KIOV(desc, i).kiov_offset);
859 if (BD_GET_KIOV(desc, i).kiov_len % blocksize == 0)
861 BD_GET_KIOV(desc, i).kiov_page);
863 rc = crypto_blkcipher_decrypt_iv(&ciph_desc, &dst, &src,
866 CERROR("error to decrypt page: %d\n", rc);
870 if (BD_GET_KIOV(desc, i).kiov_len % blocksize != 0) {
871 memcpy(page_address(BD_GET_KIOV(desc, i).kiov_page) +
872 BD_GET_KIOV(desc, i).kiov_offset,
873 page_address(BD_GET_ENC_KIOV(desc, i).
875 BD_GET_KIOV(desc, i).kiov_offset,
876 BD_GET_KIOV(desc, i).kiov_len);
879 ct_nob += BD_GET_ENC_KIOV(desc, i).kiov_len;
880 pt_nob += BD_GET_KIOV(desc, i).kiov_len;
883 if (unlikely(ct_nob != desc->bd_nob_transferred)) {
884 CERROR("%d cipher text transferred but only %d decrypted\n",
885 desc->bd_nob_transferred, ct_nob);
889 if (unlikely(!adj_nob && pt_nob != desc->bd_nob)) {
890 CERROR("%d plain text expected but only %d received\n",
891 desc->bd_nob, pt_nob);
895 /* if needed, clear up the rest unused iovs */
897 while (i < desc->bd_iov_count)
898 BD_GET_KIOV(desc, i++).kiov_len = 0;
900 /* decrypt tail (krb5 header) */
901 rc = gss_setup_sgtable(&sg_src, &src, cipher->data + blocksize,
906 rc = gss_setup_sgtable(&sg_dst, &dst, cipher->data + blocksize,
909 gss_teardown_sgtable(&sg_src);
913 rc = crypto_blkcipher_decrypt_iv(&ciph_desc, sg_dst.sgl, sg_src.sgl,
916 gss_teardown_sgtable(&sg_src);
917 gss_teardown_sgtable(&sg_dst);
920 CERROR("error to decrypt tail: %d\n", rc);
924 if (memcmp(cipher->data + blocksize, khdr, sizeof(*khdr))) {
925 CERROR("krb5 header doesn't match\n");
933 __u32 gss_wrap_kerberos(struct gss_ctx *gctx,
939 struct krb5_ctx *kctx = gctx->internal_ctx_id;
940 struct krb5_enctype *ke = &enctypes[kctx->kc_enctype];
941 struct krb5_header *khdr;
943 rawobj_t cksum = RAWOBJ_EMPTY;
944 rawobj_t data_desc[3], cipher;
945 __u8 conf[GSS_MAX_CIPHER_BLOCK];
946 __u8 local_iv[16] = {0};
950 LASSERT(ke->ke_conf_size <= GSS_MAX_CIPHER_BLOCK);
951 LASSERT(kctx->kc_keye.kb_tfm == NULL ||
953 crypto_blkcipher_blocksize(kctx->kc_keye.kb_tfm));
956 * final token format:
957 * ---------------------------------------------------
958 * | krb5 header | cipher text | checksum (16 bytes) |
959 * ---------------------------------------------------
962 /* fill krb5 header */
963 LASSERT(token->len >= sizeof(*khdr));
964 khdr = (struct krb5_header *)token->data;
965 fill_krb5_header(kctx, khdr, 1);
967 /* generate confounder */
968 cfs_get_random_bytes(conf, ke->ke_conf_size);
970 /* get encryption blocksize. note kc_keye might not associated with
971 * a tfm, currently only for arcfour-hmac */
972 if (kctx->kc_enctype == ENCTYPE_ARCFOUR_HMAC) {
973 LASSERT(kctx->kc_keye.kb_tfm == NULL);
976 LASSERT(kctx->kc_keye.kb_tfm);
977 blocksize = crypto_blkcipher_blocksize(kctx->kc_keye.kb_tfm);
979 LASSERT(blocksize <= ke->ke_conf_size);
981 /* padding the message */
982 if (gss_add_padding(msg, msg_buflen, blocksize))
983 return GSS_S_FAILURE;
986 * clear text layout for checksum:
987 * ------------------------------------------------------
988 * | confounder | gss header | clear msgs | krb5 header |
989 * ------------------------------------------------------
991 data_desc[0].data = conf;
992 data_desc[0].len = ke->ke_conf_size;
993 data_desc[1].data = gsshdr->data;
994 data_desc[1].len = gsshdr->len;
995 data_desc[2].data = msg->data;
996 data_desc[2].len = msg->len;
998 /* compute checksum */
999 if (krb5_make_checksum(kctx->kc_enctype, &kctx->kc_keyi,
1000 khdr, 3, data_desc, 0, NULL, &cksum))
1001 return GSS_S_FAILURE;
1002 LASSERT(cksum.len >= ke->ke_hash_size);
1005 * clear text layout for encryption:
1006 * -----------------------------------------
1007 * | confounder | clear msgs | krb5 header |
1008 * -----------------------------------------
1010 data_desc[0].data = conf;
1011 data_desc[0].len = ke->ke_conf_size;
1012 data_desc[1].data = msg->data;
1013 data_desc[1].len = msg->len;
1014 data_desc[2].data = (__u8 *) khdr;
1015 data_desc[2].len = sizeof(*khdr);
1017 /* cipher text will be directly inplace */
1018 cipher.data = (__u8 *)(khdr + 1);
1019 cipher.len = token->len - sizeof(*khdr);
1020 LASSERT(cipher.len >= ke->ke_conf_size + msg->len + sizeof(*khdr));
1022 if (kctx->kc_enctype == ENCTYPE_ARCFOUR_HMAC) {
1024 struct crypto_blkcipher *arc4_tfm;
1026 if (krb5_make_checksum(ENCTYPE_ARCFOUR_HMAC, &kctx->kc_keyi,
1027 NULL, 1, &cksum, 0, NULL, &arc4_keye)) {
1028 CERROR("failed to obtain arc4 enc key\n");
1029 GOTO(arc4_out, rc = -EACCES);
1032 arc4_tfm = crypto_alloc_blkcipher("ecb(arc4)", 0, 0);
1033 if (IS_ERR(arc4_tfm)) {
1034 CERROR("failed to alloc tfm arc4 in ECB mode\n");
1035 GOTO(arc4_out_key, rc = -EACCES);
1038 if (crypto_blkcipher_setkey(arc4_tfm, arc4_keye.data,
1040 CERROR("failed to set arc4 key, len %d\n",
1042 GOTO(arc4_out_tfm, rc = -EACCES);
1045 rc = gss_crypt_rawobjs(arc4_tfm, NULL, 3, data_desc,
1048 crypto_free_blkcipher(arc4_tfm);
1050 rawobj_free(&arc4_keye);
1052 do {} while(0); /* just to avoid compile warning */
1054 rc = gss_crypt_rawobjs(kctx->kc_keye.kb_tfm, local_iv, 3,
1055 data_desc, &cipher, 1);
1059 rawobj_free(&cksum);
1060 return GSS_S_FAILURE;
1063 /* fill in checksum */
1064 LASSERT(token->len >= sizeof(*khdr) + cipher.len + ke->ke_hash_size);
1065 memcpy((char *)(khdr + 1) + cipher.len,
1066 cksum.data + cksum.len - ke->ke_hash_size,
1068 rawobj_free(&cksum);
1070 /* final token length */
1071 token->len = sizeof(*khdr) + cipher.len + ke->ke_hash_size;
1072 return GSS_S_COMPLETE;
1076 __u32 gss_prep_bulk_kerberos(struct gss_ctx *gctx,
1077 struct ptlrpc_bulk_desc *desc)
1079 struct krb5_ctx *kctx = gctx->internal_ctx_id;
1082 LASSERT(ptlrpc_is_bulk_desc_kiov(desc->bd_type));
1083 LASSERT(desc->bd_iov_count);
1084 LASSERT(GET_ENC_KIOV(desc));
1085 LASSERT(kctx->kc_keye.kb_tfm);
1087 blocksize = crypto_blkcipher_blocksize(kctx->kc_keye.kb_tfm);
1089 for (i = 0; i < desc->bd_iov_count; i++) {
1090 LASSERT(BD_GET_ENC_KIOV(desc, i).kiov_page);
1092 * offset should always start at page boundary of either
1093 * client or server side.
1095 if (BD_GET_KIOV(desc, i).kiov_offset & blocksize) {
1096 CERROR("odd offset %d in page %d\n",
1097 BD_GET_KIOV(desc, i).kiov_offset, i);
1098 return GSS_S_FAILURE;
1101 BD_GET_ENC_KIOV(desc, i).kiov_offset =
1102 BD_GET_KIOV(desc, i).kiov_offset;
1103 BD_GET_ENC_KIOV(desc, i).kiov_len =
1104 (BD_GET_KIOV(desc, i).kiov_len +
1105 blocksize - 1) & (~(blocksize - 1));
1108 return GSS_S_COMPLETE;
1112 __u32 gss_wrap_bulk_kerberos(struct gss_ctx *gctx,
1113 struct ptlrpc_bulk_desc *desc,
1114 rawobj_t *token, int adj_nob)
1116 struct krb5_ctx *kctx = gctx->internal_ctx_id;
1117 struct krb5_enctype *ke = &enctypes[kctx->kc_enctype];
1118 struct krb5_header *khdr;
1120 rawobj_t cksum = RAWOBJ_EMPTY;
1121 rawobj_t data_desc[1], cipher;
1122 __u8 conf[GSS_MAX_CIPHER_BLOCK];
1125 LASSERT(ptlrpc_is_bulk_desc_kiov(desc->bd_type));
1127 LASSERT(ke->ke_conf_size <= GSS_MAX_CIPHER_BLOCK);
1130 * final token format:
1131 * --------------------------------------------------
1132 * | krb5 header | head/tail cipher text | checksum |
1133 * --------------------------------------------------
1136 /* fill krb5 header */
1137 LASSERT(token->len >= sizeof(*khdr));
1138 khdr = (struct krb5_header *)token->data;
1139 fill_krb5_header(kctx, khdr, 1);
1141 /* generate confounder */
1142 cfs_get_random_bytes(conf, ke->ke_conf_size);
1144 /* get encryption blocksize. note kc_keye might not associated with
1145 * a tfm, currently only for arcfour-hmac */
1146 if (kctx->kc_enctype == ENCTYPE_ARCFOUR_HMAC) {
1147 LASSERT(kctx->kc_keye.kb_tfm == NULL);
1150 LASSERT(kctx->kc_keye.kb_tfm);
1151 blocksize = crypto_blkcipher_blocksize(kctx->kc_keye.kb_tfm);
1155 * we assume the size of krb5_header (16 bytes) must be n * blocksize.
1156 * the bulk token size would be exactly (sizeof(krb5_header) +
1157 * blocksize + sizeof(krb5_header) + hashsize)
1159 LASSERT(blocksize <= ke->ke_conf_size);
1160 LASSERT(sizeof(*khdr) >= blocksize && sizeof(*khdr) % blocksize == 0);
1161 LASSERT(token->len >= sizeof(*khdr) + blocksize + sizeof(*khdr) + 16);
1164 * clear text layout for checksum:
1165 * ------------------------------------------
1166 * | confounder | clear pages | krb5 header |
1167 * ------------------------------------------
1169 data_desc[0].data = conf;
1170 data_desc[0].len = ke->ke_conf_size;
1172 /* compute checksum */
1173 if (krb5_make_checksum(kctx->kc_enctype, &kctx->kc_keyi,
1175 desc->bd_iov_count, GET_KIOV(desc),
1177 return GSS_S_FAILURE;
1178 LASSERT(cksum.len >= ke->ke_hash_size);
1181 * clear text layout for encryption:
1182 * ------------------------------------------
1183 * | confounder | clear pages | krb5 header |
1184 * ------------------------------------------
1186 * ---------- (cipher pages) |
1188 * -------------------------------------------
1189 * | krb5 header | cipher text | cipher text |
1190 * -------------------------------------------
1192 data_desc[0].data = conf;
1193 data_desc[0].len = ke->ke_conf_size;
1195 cipher.data = (__u8 *)(khdr + 1);
1196 cipher.len = blocksize + sizeof(*khdr);
1198 if (kctx->kc_enctype == ENCTYPE_ARCFOUR_HMAC) {
1202 rc = krb5_encrypt_bulk(kctx->kc_keye.kb_tfm, khdr,
1203 conf, desc, &cipher, adj_nob);
1207 rawobj_free(&cksum);
1208 return GSS_S_FAILURE;
1211 /* fill in checksum */
1212 LASSERT(token->len >= sizeof(*khdr) + cipher.len + ke->ke_hash_size);
1213 memcpy((char *)(khdr + 1) + cipher.len,
1214 cksum.data + cksum.len - ke->ke_hash_size,
1216 rawobj_free(&cksum);
1218 /* final token length */
1219 token->len = sizeof(*khdr) + cipher.len + ke->ke_hash_size;
1220 return GSS_S_COMPLETE;
1224 __u32 gss_unwrap_kerberos(struct gss_ctx *gctx,
1229 struct krb5_ctx *kctx = gctx->internal_ctx_id;
1230 struct krb5_enctype *ke = &enctypes[kctx->kc_enctype];
1231 struct krb5_header *khdr;
1232 unsigned char *tmpbuf;
1233 int blocksize, bodysize;
1234 rawobj_t cksum = RAWOBJ_EMPTY;
1235 rawobj_t cipher_in, plain_out;
1236 rawobj_t hash_objs[3];
1239 __u8 local_iv[16] = {0};
1243 if (token->len < sizeof(*khdr)) {
1244 CERROR("short signature: %u\n", token->len);
1245 return GSS_S_DEFECTIVE_TOKEN;
1248 khdr = (struct krb5_header *)token->data;
1250 major = verify_krb5_header(kctx, khdr, 1);
1251 if (major != GSS_S_COMPLETE) {
1252 CERROR("bad krb5 header\n");
1257 if (kctx->kc_enctype == ENCTYPE_ARCFOUR_HMAC) {
1258 LASSERT(kctx->kc_keye.kb_tfm == NULL);
1261 LASSERT(kctx->kc_keye.kb_tfm);
1262 blocksize = crypto_blkcipher_blocksize(kctx->kc_keye.kb_tfm);
1265 /* expected token layout:
1266 * ----------------------------------------
1267 * | krb5 header | cipher text | checksum |
1268 * ----------------------------------------
1270 bodysize = token->len - sizeof(*khdr) - ke->ke_hash_size;
1272 if (bodysize % blocksize) {
1273 CERROR("odd bodysize %d\n", bodysize);
1274 return GSS_S_DEFECTIVE_TOKEN;
1277 if (bodysize <= ke->ke_conf_size + sizeof(*khdr)) {
1278 CERROR("incomplete token: bodysize %d\n", bodysize);
1279 return GSS_S_DEFECTIVE_TOKEN;
1282 if (msg->len < bodysize - ke->ke_conf_size - sizeof(*khdr)) {
1283 CERROR("buffer too small: %u, require %d\n",
1284 msg->len, bodysize - ke->ke_conf_size);
1285 return GSS_S_FAILURE;
1289 OBD_ALLOC_LARGE(tmpbuf, bodysize);
1291 return GSS_S_FAILURE;
1293 major = GSS_S_FAILURE;
1295 cipher_in.data = (__u8 *)(khdr + 1);
1296 cipher_in.len = bodysize;
1297 plain_out.data = tmpbuf;
1298 plain_out.len = bodysize;
1300 if (kctx->kc_enctype == ENCTYPE_ARCFOUR_HMAC) {
1302 struct crypto_blkcipher *arc4_tfm;
1304 cksum.data = token->data + token->len - ke->ke_hash_size;
1305 cksum.len = ke->ke_hash_size;
1307 if (krb5_make_checksum(ENCTYPE_ARCFOUR_HMAC, &kctx->kc_keyi,
1308 NULL, 1, &cksum, 0, NULL, &arc4_keye)) {
1309 CERROR("failed to obtain arc4 enc key\n");
1310 GOTO(arc4_out, rc = -EACCES);
1313 arc4_tfm = crypto_alloc_blkcipher("ecb(arc4)", 0, 0);
1314 if (IS_ERR(arc4_tfm)) {
1315 CERROR("failed to alloc tfm arc4 in ECB mode\n");
1316 GOTO(arc4_out_key, rc = -EACCES);
1319 if (crypto_blkcipher_setkey(arc4_tfm,
1320 arc4_keye.data, arc4_keye.len)) {
1321 CERROR("failed to set arc4 key, len %d\n",
1323 GOTO(arc4_out_tfm, rc = -EACCES);
1326 rc = gss_crypt_rawobjs(arc4_tfm, NULL, 1, &cipher_in,
1329 crypto_free_blkcipher(arc4_tfm);
1331 rawobj_free(&arc4_keye);
1333 cksum = RAWOBJ_EMPTY;
1335 rc = gss_crypt_rawobjs(kctx->kc_keye.kb_tfm, local_iv, 1,
1336 &cipher_in, &plain_out, 0);
1340 CERROR("error decrypt\n");
1343 LASSERT(plain_out.len == bodysize);
1345 /* expected clear text layout:
1346 * -----------------------------------------
1347 * | confounder | clear msgs | krb5 header |
1348 * -----------------------------------------
1351 /* verify krb5 header in token is not modified */
1352 if (memcmp(khdr, plain_out.data + plain_out.len - sizeof(*khdr),
1354 CERROR("decrypted krb5 header mismatch\n");
1358 /* verify checksum, compose clear text as layout:
1359 * ------------------------------------------------------
1360 * | confounder | gss header | clear msgs | krb5 header |
1361 * ------------------------------------------------------
1363 hash_objs[0].len = ke->ke_conf_size;
1364 hash_objs[0].data = plain_out.data;
1365 hash_objs[1].len = gsshdr->len;
1366 hash_objs[1].data = gsshdr->data;
1367 hash_objs[2].len = plain_out.len - ke->ke_conf_size - sizeof(*khdr);
1368 hash_objs[2].data = plain_out.data + ke->ke_conf_size;
1369 if (krb5_make_checksum(kctx->kc_enctype, &kctx->kc_keyi,
1370 khdr, 3, hash_objs, 0, NULL, &cksum))
1373 LASSERT(cksum.len >= ke->ke_hash_size);
1374 if (memcmp((char *)(khdr + 1) + bodysize,
1375 cksum.data + cksum.len - ke->ke_hash_size,
1376 ke->ke_hash_size)) {
1377 CERROR("checksum mismatch\n");
1381 msg->len = bodysize - ke->ke_conf_size - sizeof(*khdr);
1382 memcpy(msg->data, tmpbuf + ke->ke_conf_size, msg->len);
1384 major = GSS_S_COMPLETE;
1386 OBD_FREE_LARGE(tmpbuf, bodysize);
1387 rawobj_free(&cksum);
1392 __u32 gss_unwrap_bulk_kerberos(struct gss_ctx *gctx,
1393 struct ptlrpc_bulk_desc *desc,
1394 rawobj_t *token, int adj_nob)
1396 struct krb5_ctx *kctx = gctx->internal_ctx_id;
1397 struct krb5_enctype *ke = &enctypes[kctx->kc_enctype];
1398 struct krb5_header *khdr;
1400 rawobj_t cksum = RAWOBJ_EMPTY;
1401 rawobj_t cipher, plain;
1402 rawobj_t data_desc[1];
1406 LASSERT(ptlrpc_is_bulk_desc_kiov(desc->bd_type));
1409 if (token->len < sizeof(*khdr)) {
1410 CERROR("short signature: %u\n", token->len);
1411 return GSS_S_DEFECTIVE_TOKEN;
1414 khdr = (struct krb5_header *)token->data;
1416 major = verify_krb5_header(kctx, khdr, 1);
1417 if (major != GSS_S_COMPLETE) {
1418 CERROR("bad krb5 header\n");
1423 if (kctx->kc_enctype == ENCTYPE_ARCFOUR_HMAC) {
1424 LASSERT(kctx->kc_keye.kb_tfm == NULL);
1428 LASSERT(kctx->kc_keye.kb_tfm);
1429 blocksize = crypto_blkcipher_blocksize(kctx->kc_keye.kb_tfm);
1431 LASSERT(sizeof(*khdr) >= blocksize && sizeof(*khdr) % blocksize == 0);
1434 * token format is expected as:
1435 * -----------------------------------------------
1436 * | krb5 header | head/tail cipher text | cksum |
1437 * -----------------------------------------------
1439 if (token->len < sizeof(*khdr) + blocksize + sizeof(*khdr) +
1441 CERROR("short token size: %u\n", token->len);
1442 return GSS_S_DEFECTIVE_TOKEN;
1445 cipher.data = (__u8 *) (khdr + 1);
1446 cipher.len = blocksize + sizeof(*khdr);
1447 plain.data = cipher.data;
1448 plain.len = cipher.len;
1450 rc = krb5_decrypt_bulk(kctx->kc_keye.kb_tfm, khdr,
1451 desc, &cipher, &plain, adj_nob);
1453 return GSS_S_DEFECTIVE_TOKEN;
1456 * verify checksum, compose clear text as layout:
1457 * ------------------------------------------
1458 * | confounder | clear pages | krb5 header |
1459 * ------------------------------------------
1461 data_desc[0].data = plain.data;
1462 data_desc[0].len = blocksize;
1464 if (krb5_make_checksum(kctx->kc_enctype, &kctx->kc_keyi,
1469 return GSS_S_FAILURE;
1470 LASSERT(cksum.len >= ke->ke_hash_size);
1472 if (memcmp(plain.data + blocksize + sizeof(*khdr),
1473 cksum.data + cksum.len - ke->ke_hash_size,
1474 ke->ke_hash_size)) {
1475 CERROR("checksum mismatch\n");
1476 rawobj_free(&cksum);
1477 return GSS_S_BAD_SIG;
1480 rawobj_free(&cksum);
1481 return GSS_S_COMPLETE;
1484 int gss_display_kerberos(struct gss_ctx *ctx,
1488 struct krb5_ctx *kctx = ctx->internal_ctx_id;
1491 written = snprintf(buf, bufsize, "krb5 (%s)",
1492 enctype2str(kctx->kc_enctype));
1496 static struct gss_api_ops gss_kerberos_ops = {
1497 .gss_import_sec_context = gss_import_sec_context_kerberos,
1498 .gss_copy_reverse_context = gss_copy_reverse_context_kerberos,
1499 .gss_inquire_context = gss_inquire_context_kerberos,
1500 .gss_get_mic = gss_get_mic_kerberos,
1501 .gss_verify_mic = gss_verify_mic_kerberos,
1502 .gss_wrap = gss_wrap_kerberos,
1503 .gss_unwrap = gss_unwrap_kerberos,
1504 .gss_prep_bulk = gss_prep_bulk_kerberos,
1505 .gss_wrap_bulk = gss_wrap_bulk_kerberos,
1506 .gss_unwrap_bulk = gss_unwrap_bulk_kerberos,
1507 .gss_delete_sec_context = gss_delete_sec_context_kerberos,
1508 .gss_display = gss_display_kerberos,
1511 static struct subflavor_desc gss_kerberos_sfs[] = {
1513 .sf_subflavor = SPTLRPC_SUBFLVR_KRB5N,
1515 .sf_service = SPTLRPC_SVC_NULL,
1519 .sf_subflavor = SPTLRPC_SUBFLVR_KRB5A,
1521 .sf_service = SPTLRPC_SVC_AUTH,
1525 .sf_subflavor = SPTLRPC_SUBFLVR_KRB5I,
1527 .sf_service = SPTLRPC_SVC_INTG,
1531 .sf_subflavor = SPTLRPC_SUBFLVR_KRB5P,
1533 .sf_service = SPTLRPC_SVC_PRIV,
1538 static struct gss_api_mech gss_kerberos_mech = {
1539 /* .gm_owner uses default NULL value for THIS_MODULE */
1541 .gm_oid = (rawobj_t)
1542 {9, "\052\206\110\206\367\022\001\002\002"},
1543 .gm_ops = &gss_kerberos_ops,
1545 .gm_sfs = gss_kerberos_sfs,
1548 int __init init_kerberos_module(void)
1552 spin_lock_init(&krb5_seq_lock);
1554 status = lgss_mech_register(&gss_kerberos_mech);
1556 CERROR("Failed to register kerberos gss mechanism!\n");
1560 void cleanup_kerberos_module(void)
1562 lgss_mech_unregister(&gss_kerberos_mech);