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/lustre_idl.h>
62 #include <lustre_net.h>
63 #include <lustre_import.h>
64 #include <lustre_sec.h>
67 #include "gss_internal.h"
71 #include "gss_crypto.h"
73 static spinlock_t krb5_seq_lock;
77 char *ke_enc_name; /* linux tfm name */
78 char *ke_hash_name; /* linux tfm name */
79 int ke_enc_mode; /* linux tfm mode */
80 int ke_hash_size; /* checksum size */
81 int ke_conf_size; /* confounder size */
82 unsigned int ke_hash_hmac:1; /* is hmac? */
86 * NOTE: for aes128-cts and aes256-cts, MIT implementation use CTS encryption.
87 * but currently we simply CBC with padding, because linux doesn't support CTS
88 * yet. this need to be fixed in the future.
90 static struct krb5_enctype enctypes[] = {
91 [ENCTYPE_DES_CBC_RAW] = { /* des-cbc-md5 */
100 [ENCTYPE_DES3_CBC_RAW] = { /* des3-hmac-sha1 */
109 [ENCTYPE_AES128_CTS_HMAC_SHA1_96] = { /* aes128-cts */
110 "aes128-cts-hmac-sha1-96",
118 [ENCTYPE_AES256_CTS_HMAC_SHA1_96] = { /* aes256-cts */
119 "aes256-cts-hmac-sha1-96",
127 [ENCTYPE_ARCFOUR_HMAC] = { /* arcfour-hmac-md5 */
138 #define MAX_ENCTYPES sizeof(enctypes)/sizeof(struct krb5_enctype)
140 static const char * enctype2str(__u32 enctype)
142 if (enctype < MAX_ENCTYPES && enctypes[enctype].ke_dispname)
143 return enctypes[enctype].ke_dispname;
149 int krb5_init_keys(struct krb5_ctx *kctx)
151 struct krb5_enctype *ke;
153 if (kctx->kc_enctype >= MAX_ENCTYPES ||
154 enctypes[kctx->kc_enctype].ke_hash_size == 0) {
155 CERROR("unsupported enctype %x\n", kctx->kc_enctype);
159 ke = &enctypes[kctx->kc_enctype];
161 /* tfm arc4 is stateful, user should alloc-use-free by his own */
162 if (kctx->kc_enctype != ENCTYPE_ARCFOUR_HMAC &&
163 gss_keyblock_init(&kctx->kc_keye, ke->ke_enc_name, ke->ke_enc_mode))
166 /* tfm hmac is stateful, user should alloc-use-free by his own */
167 if (ke->ke_hash_hmac == 0 &&
168 gss_keyblock_init(&kctx->kc_keyi, ke->ke_enc_name, ke->ke_enc_mode))
170 if (ke->ke_hash_hmac == 0 &&
171 gss_keyblock_init(&kctx->kc_keyc, ke->ke_enc_name, ke->ke_enc_mode))
178 void delete_context_kerberos(struct krb5_ctx *kctx)
180 rawobj_free(&kctx->kc_mech_used);
182 gss_keyblock_free(&kctx->kc_keye);
183 gss_keyblock_free(&kctx->kc_keyi);
184 gss_keyblock_free(&kctx->kc_keyc);
188 __u32 import_context_rfc1964(struct krb5_ctx *kctx, char *p, char *end)
190 unsigned int tmp_uint, keysize;
193 if (gss_get_bytes(&p, end, &tmp_uint, sizeof(tmp_uint)))
195 kctx->kc_seed_init = (tmp_uint != 0);
198 if (gss_get_bytes(&p, end, kctx->kc_seed, sizeof(kctx->kc_seed)))
201 /* sign/seal algorithm, not really used now */
202 if (gss_get_bytes(&p, end, &tmp_uint, sizeof(tmp_uint)) ||
203 gss_get_bytes(&p, end, &tmp_uint, sizeof(tmp_uint)))
207 if (gss_get_bytes(&p, end, &kctx->kc_endtime, sizeof(kctx->kc_endtime)))
211 if (gss_get_bytes(&p, end, &tmp_uint, sizeof(tmp_uint)))
213 kctx->kc_seq_send = tmp_uint;
216 if (gss_get_rawobj(&p, end, &kctx->kc_mech_used))
219 /* old style enc/seq keys in format:
223 * we decompose them to fit into the new context
227 if (gss_get_bytes(&p, end, &kctx->kc_enctype, sizeof(kctx->kc_enctype)))
230 if (gss_get_bytes(&p, end, &keysize, sizeof(keysize)))
233 if (gss_get_keyblock(&p, end, &kctx->kc_keye, keysize))
237 if (gss_get_bytes(&p, end, &tmp_uint, sizeof(tmp_uint)) ||
238 tmp_uint != kctx->kc_enctype)
241 if (gss_get_bytes(&p, end, &tmp_uint, sizeof(tmp_uint)) ||
245 if (gss_get_keyblock(&p, end, &kctx->kc_keyc, keysize))
248 /* old style fallback */
249 if (gss_keyblock_dup(&kctx->kc_keyi, &kctx->kc_keyc))
255 CDEBUG(D_SEC, "successfully imported rfc1964 context\n");
258 return GSS_S_FAILURE;
261 /* Flags for version 2 context flags */
262 #define KRB5_CTX_FLAG_INITIATOR 0x00000001
263 #define KRB5_CTX_FLAG_CFX 0x00000002
264 #define KRB5_CTX_FLAG_ACCEPTOR_SUBKEY 0x00000004
267 __u32 import_context_rfc4121(struct krb5_ctx *kctx, char *p, char *end)
269 unsigned int tmp_uint, keysize;
272 if (gss_get_bytes(&p, end, &kctx->kc_endtime, sizeof(kctx->kc_endtime)))
276 if (gss_get_bytes(&p, end, &tmp_uint, sizeof(tmp_uint)))
279 if (tmp_uint & KRB5_CTX_FLAG_INITIATOR)
280 kctx->kc_initiate = 1;
281 if (tmp_uint & KRB5_CTX_FLAG_CFX)
283 if (tmp_uint & KRB5_CTX_FLAG_ACCEPTOR_SUBKEY)
284 kctx->kc_have_acceptor_subkey = 1;
287 if (gss_get_bytes(&p, end, &kctx->kc_seq_send,
288 sizeof(kctx->kc_seq_send)))
292 if (gss_get_bytes(&p, end, &kctx->kc_enctype, sizeof(kctx->kc_enctype)))
295 /* size of each key */
296 if (gss_get_bytes(&p, end, &keysize, sizeof(keysize)))
299 /* number of keys - should always be 3 */
300 if (gss_get_bytes(&p, end, &tmp_uint, sizeof(tmp_uint)))
304 CERROR("Invalid number of keys: %u\n", tmp_uint);
309 if (gss_get_keyblock(&p, end, &kctx->kc_keye, keysize))
312 if (gss_get_keyblock(&p, end, &kctx->kc_keyi, keysize))
315 if (gss_get_keyblock(&p, end, &kctx->kc_keyc, keysize))
318 CDEBUG(D_SEC, "successfully imported v2 context\n");
321 return GSS_S_FAILURE;
325 * The whole purpose here is trying to keep user level gss context parsing
326 * from nfs-utils unchanged as possible as we can, they are not quite mature
327 * yet, and many stuff still not clear, like heimdal etc.
330 __u32 gss_import_sec_context_kerberos(rawobj_t *inbuf,
331 struct gss_ctx *gctx)
333 struct krb5_ctx *kctx;
334 char *p = (char *)inbuf->data;
335 char *end = (char *)(inbuf->data + inbuf->len);
336 unsigned int tmp_uint, rc;
338 if (gss_get_bytes(&p, end, &tmp_uint, sizeof(tmp_uint))) {
339 CERROR("Fail to read version\n");
340 return GSS_S_FAILURE;
343 /* only support 0, 1 for the moment */
345 CERROR("Invalid version %u\n", tmp_uint);
346 return GSS_S_FAILURE;
351 return GSS_S_FAILURE;
353 if (tmp_uint == 0 || tmp_uint == 1) {
354 kctx->kc_initiate = tmp_uint;
355 rc = import_context_rfc1964(kctx, p, end);
357 rc = import_context_rfc4121(kctx, p, end);
361 rc = krb5_init_keys(kctx);
364 delete_context_kerberos(kctx);
367 return GSS_S_FAILURE;
370 gctx->internal_ctx_id = kctx;
371 return GSS_S_COMPLETE;
375 __u32 gss_copy_reverse_context_kerberos(struct gss_ctx *gctx,
376 struct gss_ctx *gctx_new)
378 struct krb5_ctx *kctx = gctx->internal_ctx_id;
379 struct krb5_ctx *knew;
383 return GSS_S_FAILURE;
385 knew->kc_initiate = kctx->kc_initiate ? 0 : 1;
386 knew->kc_cfx = kctx->kc_cfx;
387 knew->kc_seed_init = kctx->kc_seed_init;
388 knew->kc_have_acceptor_subkey = kctx->kc_have_acceptor_subkey;
389 knew->kc_endtime = kctx->kc_endtime;
391 memcpy(knew->kc_seed, kctx->kc_seed, sizeof(kctx->kc_seed));
392 knew->kc_seq_send = kctx->kc_seq_recv;
393 knew->kc_seq_recv = kctx->kc_seq_send;
394 knew->kc_enctype = kctx->kc_enctype;
396 if (rawobj_dup(&knew->kc_mech_used, &kctx->kc_mech_used))
399 if (gss_keyblock_dup(&knew->kc_keye, &kctx->kc_keye))
401 if (gss_keyblock_dup(&knew->kc_keyi, &kctx->kc_keyi))
403 if (gss_keyblock_dup(&knew->kc_keyc, &kctx->kc_keyc))
405 if (krb5_init_keys(knew))
408 gctx_new->internal_ctx_id = knew;
409 CDEBUG(D_SEC, "successfully copied reverse context\n");
410 return GSS_S_COMPLETE;
413 delete_context_kerberos(knew);
415 return GSS_S_FAILURE;
419 __u32 gss_inquire_context_kerberos(struct gss_ctx *gctx,
420 unsigned long *endtime)
422 struct krb5_ctx *kctx = gctx->internal_ctx_id;
424 *endtime = (unsigned long)((__u32) kctx->kc_endtime);
425 return GSS_S_COMPLETE;
429 void gss_delete_sec_context_kerberos(void *internal_ctx)
431 struct krb5_ctx *kctx = internal_ctx;
433 delete_context_kerberos(kctx);
438 * compute (keyed/keyless) checksum against the plain text which appended
439 * with krb5 wire token header.
442 __s32 krb5_make_checksum(__u32 enctype,
443 struct gss_keyblock *kb,
444 struct krb5_header *khdr,
445 int msgcnt, rawobj_t *msgs,
446 int iovcnt, lnet_kiov_t *iovs,
449 struct krb5_enctype *ke = &enctypes[enctype];
450 struct crypto_hash *tfm;
452 __u32 code = GSS_S_FAILURE;
455 if (!(tfm = crypto_alloc_hash(ke->ke_hash_name, 0, 0))) {
456 CERROR("failed to alloc TFM: %s\n", ke->ke_hash_name);
457 return GSS_S_FAILURE;
460 cksum->len = crypto_hash_digestsize(tfm);
461 OBD_ALLOC_LARGE(cksum->data, cksum->len);
467 hdr.data = (__u8 *)khdr;
468 hdr.len = sizeof(*khdr);
470 if (ke->ke_hash_hmac)
471 rc = gss_digest_hmac(tfm, &kb->kb_key,
472 &hdr, msgcnt, msgs, iovcnt, iovs, cksum);
474 rc = gss_digest_norm(tfm, kb,
475 &hdr, msgcnt, msgs, iovcnt, iovs, cksum);
478 code = GSS_S_COMPLETE;
480 crypto_free_hash(tfm);
484 static void fill_krb5_header(struct krb5_ctx *kctx,
485 struct krb5_header *khdr,
488 unsigned char acceptor_flag;
490 acceptor_flag = kctx->kc_initiate ? 0 : FLAG_SENDER_IS_ACCEPTOR;
493 khdr->kh_tok_id = cpu_to_be16(KG_TOK_WRAP_MSG);
494 khdr->kh_flags = acceptor_flag | FLAG_WRAP_CONFIDENTIAL;
495 khdr->kh_ec = cpu_to_be16(0);
496 khdr->kh_rrc = cpu_to_be16(0);
498 khdr->kh_tok_id = cpu_to_be16(KG_TOK_MIC_MSG);
499 khdr->kh_flags = acceptor_flag;
500 khdr->kh_ec = cpu_to_be16(0xffff);
501 khdr->kh_rrc = cpu_to_be16(0xffff);
504 khdr->kh_filler = 0xff;
505 spin_lock(&krb5_seq_lock);
506 khdr->kh_seq = cpu_to_be64(kctx->kc_seq_send++);
507 spin_unlock(&krb5_seq_lock);
510 static __u32 verify_krb5_header(struct krb5_ctx *kctx,
511 struct krb5_header *khdr,
514 unsigned char acceptor_flag;
515 __u16 tok_id, ec_rrc;
517 acceptor_flag = kctx->kc_initiate ? FLAG_SENDER_IS_ACCEPTOR : 0;
520 tok_id = KG_TOK_WRAP_MSG;
523 tok_id = KG_TOK_MIC_MSG;
528 if (be16_to_cpu(khdr->kh_tok_id) != tok_id) {
529 CERROR("bad token id\n");
530 return GSS_S_DEFECTIVE_TOKEN;
532 if ((khdr->kh_flags & FLAG_SENDER_IS_ACCEPTOR) != acceptor_flag) {
533 CERROR("bad direction flag\n");
534 return GSS_S_BAD_SIG;
536 if (privacy && (khdr->kh_flags & FLAG_WRAP_CONFIDENTIAL) == 0) {
537 CERROR("missing confidential flag\n");
538 return GSS_S_BAD_SIG;
540 if (khdr->kh_filler != 0xff) {
541 CERROR("bad filler\n");
542 return GSS_S_DEFECTIVE_TOKEN;
544 if (be16_to_cpu(khdr->kh_ec) != ec_rrc ||
545 be16_to_cpu(khdr->kh_rrc) != ec_rrc) {
546 CERROR("bad EC or RRC\n");
547 return GSS_S_DEFECTIVE_TOKEN;
549 return GSS_S_COMPLETE;
553 __u32 gss_get_mic_kerberos(struct gss_ctx *gctx,
560 struct krb5_ctx *kctx = gctx->internal_ctx_id;
561 struct krb5_enctype *ke = &enctypes[kctx->kc_enctype];
562 struct krb5_header *khdr;
563 rawobj_t cksum = RAWOBJ_EMPTY;
565 /* fill krb5 header */
566 LASSERT(token->len >= sizeof(*khdr));
567 khdr = (struct krb5_header *)token->data;
568 fill_krb5_header(kctx, khdr, 0);
571 if (krb5_make_checksum(kctx->kc_enctype, &kctx->kc_keyc,
572 khdr, msgcnt, msgs, iovcnt, iovs, &cksum))
573 return GSS_S_FAILURE;
575 LASSERT(cksum.len >= ke->ke_hash_size);
576 LASSERT(token->len >= sizeof(*khdr) + ke->ke_hash_size);
577 memcpy(khdr + 1, cksum.data + cksum.len - ke->ke_hash_size,
580 token->len = sizeof(*khdr) + ke->ke_hash_size;
582 return GSS_S_COMPLETE;
586 __u32 gss_verify_mic_kerberos(struct gss_ctx *gctx,
593 struct krb5_ctx *kctx = gctx->internal_ctx_id;
594 struct krb5_enctype *ke = &enctypes[kctx->kc_enctype];
595 struct krb5_header *khdr;
596 rawobj_t cksum = RAWOBJ_EMPTY;
599 if (token->len < sizeof(*khdr)) {
600 CERROR("short signature: %u\n", token->len);
601 return GSS_S_DEFECTIVE_TOKEN;
604 khdr = (struct krb5_header *)token->data;
606 major = verify_krb5_header(kctx, khdr, 0);
607 if (major != GSS_S_COMPLETE) {
608 CERROR("bad krb5 header\n");
612 if (token->len < sizeof(*khdr) + ke->ke_hash_size) {
613 CERROR("short signature: %u, require %d\n",
614 token->len, (int) sizeof(*khdr) + ke->ke_hash_size);
615 return GSS_S_FAILURE;
618 if (krb5_make_checksum(kctx->kc_enctype, &kctx->kc_keyc,
619 khdr, msgcnt, msgs, iovcnt, iovs, &cksum)) {
620 CERROR("failed to make checksum\n");
621 return GSS_S_FAILURE;
624 LASSERT(cksum.len >= ke->ke_hash_size);
625 if (memcmp(khdr + 1, cksum.data + cksum.len - ke->ke_hash_size,
627 CERROR("checksum mismatch\n");
629 return GSS_S_BAD_SIG;
633 return GSS_S_COMPLETE;
637 * if adj_nob != 0, we adjust desc->bd_nob to the actual cipher text size.
640 int krb5_encrypt_bulk(struct crypto_blkcipher *tfm,
641 struct krb5_header *khdr,
643 struct ptlrpc_bulk_desc *desc,
647 struct blkcipher_desc ciph_desc;
648 __u8 local_iv[16] = {0};
649 struct scatterlist src, dst;
650 struct sg_table sg_src, sg_dst;
651 int blocksize, i, rc, nob = 0;
653 LASSERT(ptlrpc_is_bulk_desc_kiov(desc->bd_type));
654 LASSERT(desc->bd_iov_count);
655 LASSERT(GET_ENC_KIOV(desc));
657 blocksize = crypto_blkcipher_blocksize(tfm);
658 LASSERT(blocksize > 1);
659 LASSERT(cipher->len == blocksize + sizeof(*khdr));
662 ciph_desc.info = local_iv;
665 /* encrypt confounder */
666 rc = gss_setup_sgtable(&sg_src, &src, confounder, blocksize);
670 rc = gss_setup_sgtable(&sg_dst, &dst, cipher->data, blocksize);
672 gss_teardown_sgtable(&sg_src);
676 rc = crypto_blkcipher_encrypt_iv(&ciph_desc, sg_dst.sgl,
677 sg_src.sgl, blocksize);
679 gss_teardown_sgtable(&sg_dst);
680 gss_teardown_sgtable(&sg_src);
683 CERROR("error to encrypt confounder: %d\n", rc);
687 /* encrypt clear pages */
688 for (i = 0; i < desc->bd_iov_count; i++) {
689 sg_init_table(&src, 1);
690 sg_set_page(&src, BD_GET_KIOV(desc, i).kiov_page,
691 (BD_GET_KIOV(desc, i).kiov_len +
694 BD_GET_KIOV(desc, i).kiov_offset);
697 sg_init_table(&dst, 1);
698 sg_set_page(&dst, BD_GET_ENC_KIOV(desc, i).kiov_page,
699 src.length, src.offset);
701 BD_GET_ENC_KIOV(desc, i).kiov_offset = dst.offset;
702 BD_GET_ENC_KIOV(desc, i).kiov_len = dst.length;
704 rc = crypto_blkcipher_encrypt_iv(&ciph_desc, &dst, &src,
707 CERROR("error to encrypt page: %d\n", rc);
712 /* encrypt krb5 header */
713 rc = gss_setup_sgtable(&sg_src, &src, khdr, sizeof(*khdr));
717 rc = gss_setup_sgtable(&sg_dst, &dst, cipher->data + blocksize,
720 gss_teardown_sgtable(&sg_src);
724 rc = crypto_blkcipher_encrypt_iv(&ciph_desc, sg_dst.sgl, sg_src.sgl,
727 gss_teardown_sgtable(&sg_dst);
728 gss_teardown_sgtable(&sg_src);
731 CERROR("error to encrypt krb5 header: %d\n", rc);
742 * desc->bd_nob_transferred is the size of cipher text received.
743 * desc->bd_nob is the target size of plain text supposed to be.
745 * if adj_nob != 0, we adjust each page's kiov_len to the actual
747 * - for client read: we don't know data size for each page, so
748 * bd_iov[]->kiov_len is set to PAGE_SIZE, but actual data received might
749 * be smaller, so we need to adjust it according to
750 * bd_u.bd_kiov.bd_enc_vec[]->kiov_len.
751 * this means we DO NOT support the situation that server send an odd size
752 * data in a page which is not the last one.
753 * - for server write: we knows exactly data size for each page being expected,
754 * thus kiov_len is accurate already, so we should not adjust it at all.
755 * and bd_u.bd_kiov.bd_enc_vec[]->kiov_len should be
756 * round_up(bd_iov[]->kiov_len) which
757 * should have been done by prep_bulk().
760 int krb5_decrypt_bulk(struct crypto_blkcipher *tfm,
761 struct krb5_header *khdr,
762 struct ptlrpc_bulk_desc *desc,
767 struct blkcipher_desc ciph_desc;
768 __u8 local_iv[16] = {0};
769 struct scatterlist src, dst;
770 struct sg_table sg_src, sg_dst;
771 int ct_nob = 0, pt_nob = 0;
772 int blocksize, i, rc;
774 LASSERT(ptlrpc_is_bulk_desc_kiov(desc->bd_type));
775 LASSERT(desc->bd_iov_count);
776 LASSERT(GET_ENC_KIOV(desc));
777 LASSERT(desc->bd_nob_transferred);
779 blocksize = crypto_blkcipher_blocksize(tfm);
780 LASSERT(blocksize > 1);
781 LASSERT(cipher->len == blocksize + sizeof(*khdr));
784 ciph_desc.info = local_iv;
787 if (desc->bd_nob_transferred % blocksize) {
788 CERROR("odd transferred nob: %d\n", desc->bd_nob_transferred);
792 /* decrypt head (confounder) */
793 rc = gss_setup_sgtable(&sg_src, &src, cipher->data, blocksize);
797 rc = gss_setup_sgtable(&sg_dst, &dst, plain->data, blocksize);
799 gss_teardown_sgtable(&sg_src);
803 rc = crypto_blkcipher_decrypt_iv(&ciph_desc, sg_dst.sgl,
804 sg_src.sgl, blocksize);
806 gss_teardown_sgtable(&sg_dst);
807 gss_teardown_sgtable(&sg_src);
810 CERROR("error to decrypt confounder: %d\n", rc);
814 for (i = 0; i < desc->bd_iov_count && ct_nob < desc->bd_nob_transferred;
816 if (BD_GET_ENC_KIOV(desc, i).kiov_offset % blocksize
818 BD_GET_ENC_KIOV(desc, i).kiov_len % blocksize
820 CERROR("page %d: odd offset %u len %u, blocksize %d\n",
821 i, BD_GET_ENC_KIOV(desc, i).kiov_offset,
822 BD_GET_ENC_KIOV(desc, i).kiov_len,
828 if (ct_nob + BD_GET_ENC_KIOV(desc, i).kiov_len >
829 desc->bd_nob_transferred)
830 BD_GET_ENC_KIOV(desc, i).kiov_len =
831 desc->bd_nob_transferred - ct_nob;
833 BD_GET_KIOV(desc, i).kiov_len =
834 BD_GET_ENC_KIOV(desc, i).kiov_len;
835 if (pt_nob + BD_GET_ENC_KIOV(desc, i).kiov_len >
837 BD_GET_KIOV(desc, i).kiov_len =
838 desc->bd_nob - pt_nob;
840 /* this should be guaranteed by LNET */
841 LASSERT(ct_nob + BD_GET_ENC_KIOV(desc, i).
843 desc->bd_nob_transferred);
844 LASSERT(BD_GET_KIOV(desc, i).kiov_len <=
845 BD_GET_ENC_KIOV(desc, i).kiov_len);
848 if (BD_GET_ENC_KIOV(desc, i).kiov_len == 0)
851 sg_init_table(&src, 1);
852 sg_set_page(&src, BD_GET_ENC_KIOV(desc, i).kiov_page,
853 BD_GET_ENC_KIOV(desc, i).kiov_len,
854 BD_GET_ENC_KIOV(desc, i).kiov_offset);
856 if (BD_GET_KIOV(desc, i).kiov_len % blocksize == 0)
858 BD_GET_KIOV(desc, i).kiov_page);
860 rc = crypto_blkcipher_decrypt_iv(&ciph_desc, &dst, &src,
863 CERROR("error to decrypt page: %d\n", rc);
867 if (BD_GET_KIOV(desc, i).kiov_len % blocksize != 0) {
868 memcpy(page_address(BD_GET_KIOV(desc, i).kiov_page) +
869 BD_GET_KIOV(desc, i).kiov_offset,
870 page_address(BD_GET_ENC_KIOV(desc, i).
872 BD_GET_KIOV(desc, i).kiov_offset,
873 BD_GET_KIOV(desc, i).kiov_len);
876 ct_nob += BD_GET_ENC_KIOV(desc, i).kiov_len;
877 pt_nob += BD_GET_KIOV(desc, i).kiov_len;
880 if (unlikely(ct_nob != desc->bd_nob_transferred)) {
881 CERROR("%d cipher text transferred but only %d decrypted\n",
882 desc->bd_nob_transferred, ct_nob);
886 if (unlikely(!adj_nob && pt_nob != desc->bd_nob)) {
887 CERROR("%d plain text expected but only %d received\n",
888 desc->bd_nob, pt_nob);
892 /* if needed, clear up the rest unused iovs */
894 while (i < desc->bd_iov_count)
895 BD_GET_KIOV(desc, i++).kiov_len = 0;
897 /* decrypt tail (krb5 header) */
898 rc = gss_setup_sgtable(&sg_src, &src, cipher->data + blocksize,
903 rc = gss_setup_sgtable(&sg_dst, &dst, cipher->data + blocksize,
906 gss_teardown_sgtable(&sg_src);
910 rc = crypto_blkcipher_decrypt_iv(&ciph_desc, sg_dst.sgl, sg_src.sgl,
913 gss_teardown_sgtable(&sg_src);
914 gss_teardown_sgtable(&sg_dst);
917 CERROR("error to decrypt tail: %d\n", rc);
921 if (memcmp(cipher->data + blocksize, khdr, sizeof(*khdr))) {
922 CERROR("krb5 header doesn't match\n");
930 __u32 gss_wrap_kerberos(struct gss_ctx *gctx,
936 struct krb5_ctx *kctx = gctx->internal_ctx_id;
937 struct krb5_enctype *ke = &enctypes[kctx->kc_enctype];
938 struct krb5_header *khdr;
940 rawobj_t cksum = RAWOBJ_EMPTY;
941 rawobj_t data_desc[3], cipher;
942 __u8 conf[GSS_MAX_CIPHER_BLOCK];
946 LASSERT(ke->ke_conf_size <= GSS_MAX_CIPHER_BLOCK);
947 LASSERT(kctx->kc_keye.kb_tfm == NULL ||
949 crypto_blkcipher_blocksize(kctx->kc_keye.kb_tfm));
952 * final token format:
953 * ---------------------------------------------------
954 * | krb5 header | cipher text | checksum (16 bytes) |
955 * ---------------------------------------------------
958 /* fill krb5 header */
959 LASSERT(token->len >= sizeof(*khdr));
960 khdr = (struct krb5_header *)token->data;
961 fill_krb5_header(kctx, khdr, 1);
963 /* generate confounder */
964 cfs_get_random_bytes(conf, ke->ke_conf_size);
966 /* get encryption blocksize. note kc_keye might not associated with
967 * a tfm, currently only for arcfour-hmac */
968 if (kctx->kc_enctype == ENCTYPE_ARCFOUR_HMAC) {
969 LASSERT(kctx->kc_keye.kb_tfm == NULL);
972 LASSERT(kctx->kc_keye.kb_tfm);
973 blocksize = crypto_blkcipher_blocksize(kctx->kc_keye.kb_tfm);
975 LASSERT(blocksize <= ke->ke_conf_size);
977 /* padding the message */
978 if (gss_add_padding(msg, msg_buflen, blocksize))
979 return GSS_S_FAILURE;
982 * clear text layout for checksum:
983 * ------------------------------------------------------
984 * | confounder | gss header | clear msgs | krb5 header |
985 * ------------------------------------------------------
987 data_desc[0].data = conf;
988 data_desc[0].len = ke->ke_conf_size;
989 data_desc[1].data = gsshdr->data;
990 data_desc[1].len = gsshdr->len;
991 data_desc[2].data = msg->data;
992 data_desc[2].len = msg->len;
994 /* compute checksum */
995 if (krb5_make_checksum(kctx->kc_enctype, &kctx->kc_keyi,
996 khdr, 3, data_desc, 0, NULL, &cksum))
997 return GSS_S_FAILURE;
998 LASSERT(cksum.len >= ke->ke_hash_size);
1001 * clear text layout for encryption:
1002 * -----------------------------------------
1003 * | confounder | clear msgs | krb5 header |
1004 * -----------------------------------------
1006 data_desc[0].data = conf;
1007 data_desc[0].len = ke->ke_conf_size;
1008 data_desc[1].data = msg->data;
1009 data_desc[1].len = msg->len;
1010 data_desc[2].data = (__u8 *) khdr;
1011 data_desc[2].len = sizeof(*khdr);
1013 /* cipher text will be directly inplace */
1014 cipher.data = (__u8 *)(khdr + 1);
1015 cipher.len = token->len - sizeof(*khdr);
1016 LASSERT(cipher.len >= ke->ke_conf_size + msg->len + sizeof(*khdr));
1018 if (kctx->kc_enctype == ENCTYPE_ARCFOUR_HMAC) {
1020 struct crypto_blkcipher *arc4_tfm;
1022 if (krb5_make_checksum(ENCTYPE_ARCFOUR_HMAC, &kctx->kc_keyi,
1023 NULL, 1, &cksum, 0, NULL, &arc4_keye)) {
1024 CERROR("failed to obtain arc4 enc key\n");
1025 GOTO(arc4_out, rc = -EACCES);
1028 arc4_tfm = crypto_alloc_blkcipher("ecb(arc4)", 0, 0);
1029 if (IS_ERR(arc4_tfm)) {
1030 CERROR("failed to alloc tfm arc4 in ECB mode\n");
1031 GOTO(arc4_out_key, rc = -EACCES);
1034 if (crypto_blkcipher_setkey(arc4_tfm, arc4_keye.data,
1036 CERROR("failed to set arc4 key, len %d\n",
1038 GOTO(arc4_out_tfm, rc = -EACCES);
1041 rc = gss_crypt_rawobjs(arc4_tfm, 1, 3, data_desc, &cipher, 1);
1043 crypto_free_blkcipher(arc4_tfm);
1045 rawobj_free(&arc4_keye);
1047 do {} while(0); /* just to avoid compile warning */
1049 rc = gss_crypt_rawobjs(kctx->kc_keye.kb_tfm, 0, 3, data_desc,
1054 rawobj_free(&cksum);
1055 return GSS_S_FAILURE;
1058 /* fill in checksum */
1059 LASSERT(token->len >= sizeof(*khdr) + cipher.len + ke->ke_hash_size);
1060 memcpy((char *)(khdr + 1) + cipher.len,
1061 cksum.data + cksum.len - ke->ke_hash_size,
1063 rawobj_free(&cksum);
1065 /* final token length */
1066 token->len = sizeof(*khdr) + cipher.len + ke->ke_hash_size;
1067 return GSS_S_COMPLETE;
1071 __u32 gss_prep_bulk_kerberos(struct gss_ctx *gctx,
1072 struct ptlrpc_bulk_desc *desc)
1074 struct krb5_ctx *kctx = gctx->internal_ctx_id;
1077 LASSERT(ptlrpc_is_bulk_desc_kiov(desc->bd_type));
1078 LASSERT(desc->bd_iov_count);
1079 LASSERT(GET_ENC_KIOV(desc));
1080 LASSERT(kctx->kc_keye.kb_tfm);
1082 blocksize = crypto_blkcipher_blocksize(kctx->kc_keye.kb_tfm);
1084 for (i = 0; i < desc->bd_iov_count; i++) {
1085 LASSERT(BD_GET_ENC_KIOV(desc, i).kiov_page);
1087 * offset should always start at page boundary of either
1088 * client or server side.
1090 if (BD_GET_KIOV(desc, i).kiov_offset & blocksize) {
1091 CERROR("odd offset %d in page %d\n",
1092 BD_GET_KIOV(desc, i).kiov_offset, i);
1093 return GSS_S_FAILURE;
1096 BD_GET_ENC_KIOV(desc, i).kiov_offset =
1097 BD_GET_KIOV(desc, i).kiov_offset;
1098 BD_GET_ENC_KIOV(desc, i).kiov_len =
1099 (BD_GET_KIOV(desc, i).kiov_len +
1100 blocksize - 1) & (~(blocksize - 1));
1103 return GSS_S_COMPLETE;
1107 __u32 gss_wrap_bulk_kerberos(struct gss_ctx *gctx,
1108 struct ptlrpc_bulk_desc *desc,
1109 rawobj_t *token, int adj_nob)
1111 struct krb5_ctx *kctx = gctx->internal_ctx_id;
1112 struct krb5_enctype *ke = &enctypes[kctx->kc_enctype];
1113 struct krb5_header *khdr;
1115 rawobj_t cksum = RAWOBJ_EMPTY;
1116 rawobj_t data_desc[1], cipher;
1117 __u8 conf[GSS_MAX_CIPHER_BLOCK];
1120 LASSERT(ptlrpc_is_bulk_desc_kiov(desc->bd_type));
1122 LASSERT(ke->ke_conf_size <= GSS_MAX_CIPHER_BLOCK);
1125 * final token format:
1126 * --------------------------------------------------
1127 * | krb5 header | head/tail cipher text | checksum |
1128 * --------------------------------------------------
1131 /* fill krb5 header */
1132 LASSERT(token->len >= sizeof(*khdr));
1133 khdr = (struct krb5_header *)token->data;
1134 fill_krb5_header(kctx, khdr, 1);
1136 /* generate confounder */
1137 cfs_get_random_bytes(conf, ke->ke_conf_size);
1139 /* get encryption blocksize. note kc_keye might not associated with
1140 * a tfm, currently only for arcfour-hmac */
1141 if (kctx->kc_enctype == ENCTYPE_ARCFOUR_HMAC) {
1142 LASSERT(kctx->kc_keye.kb_tfm == NULL);
1145 LASSERT(kctx->kc_keye.kb_tfm);
1146 blocksize = crypto_blkcipher_blocksize(kctx->kc_keye.kb_tfm);
1150 * we assume the size of krb5_header (16 bytes) must be n * blocksize.
1151 * the bulk token size would be exactly (sizeof(krb5_header) +
1152 * blocksize + sizeof(krb5_header) + hashsize)
1154 LASSERT(blocksize <= ke->ke_conf_size);
1155 LASSERT(sizeof(*khdr) >= blocksize && sizeof(*khdr) % blocksize == 0);
1156 LASSERT(token->len >= sizeof(*khdr) + blocksize + sizeof(*khdr) + 16);
1159 * clear text layout for checksum:
1160 * ------------------------------------------
1161 * | confounder | clear pages | krb5 header |
1162 * ------------------------------------------
1164 data_desc[0].data = conf;
1165 data_desc[0].len = ke->ke_conf_size;
1167 /* compute checksum */
1168 if (krb5_make_checksum(kctx->kc_enctype, &kctx->kc_keyi,
1170 desc->bd_iov_count, GET_KIOV(desc),
1172 return GSS_S_FAILURE;
1173 LASSERT(cksum.len >= ke->ke_hash_size);
1176 * clear text layout for encryption:
1177 * ------------------------------------------
1178 * | confounder | clear pages | krb5 header |
1179 * ------------------------------------------
1181 * ---------- (cipher pages) |
1183 * -------------------------------------------
1184 * | krb5 header | cipher text | cipher text |
1185 * -------------------------------------------
1187 data_desc[0].data = conf;
1188 data_desc[0].len = ke->ke_conf_size;
1190 cipher.data = (__u8 *)(khdr + 1);
1191 cipher.len = blocksize + sizeof(*khdr);
1193 if (kctx->kc_enctype == ENCTYPE_ARCFOUR_HMAC) {
1197 rc = krb5_encrypt_bulk(kctx->kc_keye.kb_tfm, khdr,
1198 conf, desc, &cipher, adj_nob);
1202 rawobj_free(&cksum);
1203 return GSS_S_FAILURE;
1206 /* fill in checksum */
1207 LASSERT(token->len >= sizeof(*khdr) + cipher.len + ke->ke_hash_size);
1208 memcpy((char *)(khdr + 1) + cipher.len,
1209 cksum.data + cksum.len - ke->ke_hash_size,
1211 rawobj_free(&cksum);
1213 /* final token length */
1214 token->len = sizeof(*khdr) + cipher.len + ke->ke_hash_size;
1215 return GSS_S_COMPLETE;
1219 __u32 gss_unwrap_kerberos(struct gss_ctx *gctx,
1224 struct krb5_ctx *kctx = gctx->internal_ctx_id;
1225 struct krb5_enctype *ke = &enctypes[kctx->kc_enctype];
1226 struct krb5_header *khdr;
1227 unsigned char *tmpbuf;
1228 int blocksize, bodysize;
1229 rawobj_t cksum = RAWOBJ_EMPTY;
1230 rawobj_t cipher_in, plain_out;
1231 rawobj_t hash_objs[3];
1237 if (token->len < sizeof(*khdr)) {
1238 CERROR("short signature: %u\n", token->len);
1239 return GSS_S_DEFECTIVE_TOKEN;
1242 khdr = (struct krb5_header *)token->data;
1244 major = verify_krb5_header(kctx, khdr, 1);
1245 if (major != GSS_S_COMPLETE) {
1246 CERROR("bad krb5 header\n");
1251 if (kctx->kc_enctype == ENCTYPE_ARCFOUR_HMAC) {
1252 LASSERT(kctx->kc_keye.kb_tfm == NULL);
1255 LASSERT(kctx->kc_keye.kb_tfm);
1256 blocksize = crypto_blkcipher_blocksize(kctx->kc_keye.kb_tfm);
1259 /* expected token layout:
1260 * ----------------------------------------
1261 * | krb5 header | cipher text | checksum |
1262 * ----------------------------------------
1264 bodysize = token->len - sizeof(*khdr) - ke->ke_hash_size;
1266 if (bodysize % blocksize) {
1267 CERROR("odd bodysize %d\n", bodysize);
1268 return GSS_S_DEFECTIVE_TOKEN;
1271 if (bodysize <= ke->ke_conf_size + sizeof(*khdr)) {
1272 CERROR("incomplete token: bodysize %d\n", bodysize);
1273 return GSS_S_DEFECTIVE_TOKEN;
1276 if (msg->len < bodysize - ke->ke_conf_size - sizeof(*khdr)) {
1277 CERROR("buffer too small: %u, require %d\n",
1278 msg->len, bodysize - ke->ke_conf_size);
1279 return GSS_S_FAILURE;
1283 OBD_ALLOC_LARGE(tmpbuf, bodysize);
1285 return GSS_S_FAILURE;
1287 major = GSS_S_FAILURE;
1289 cipher_in.data = (__u8 *)(khdr + 1);
1290 cipher_in.len = bodysize;
1291 plain_out.data = tmpbuf;
1292 plain_out.len = bodysize;
1294 if (kctx->kc_enctype == ENCTYPE_ARCFOUR_HMAC) {
1296 struct crypto_blkcipher *arc4_tfm;
1298 cksum.data = token->data + token->len - ke->ke_hash_size;
1299 cksum.len = ke->ke_hash_size;
1301 if (krb5_make_checksum(ENCTYPE_ARCFOUR_HMAC, &kctx->kc_keyi,
1302 NULL, 1, &cksum, 0, NULL, &arc4_keye)) {
1303 CERROR("failed to obtain arc4 enc key\n");
1304 GOTO(arc4_out, rc = -EACCES);
1307 arc4_tfm = crypto_alloc_blkcipher("ecb(arc4)", 0, 0);
1308 if (IS_ERR(arc4_tfm)) {
1309 CERROR("failed to alloc tfm arc4 in ECB mode\n");
1310 GOTO(arc4_out_key, rc = -EACCES);
1313 if (crypto_blkcipher_setkey(arc4_tfm,
1314 arc4_keye.data, arc4_keye.len)) {
1315 CERROR("failed to set arc4 key, len %d\n",
1317 GOTO(arc4_out_tfm, rc = -EACCES);
1320 rc = gss_crypt_rawobjs(arc4_tfm, 1, 1, &cipher_in,
1323 crypto_free_blkcipher(arc4_tfm);
1325 rawobj_free(&arc4_keye);
1327 cksum = RAWOBJ_EMPTY;
1329 rc = gss_crypt_rawobjs(kctx->kc_keye.kb_tfm, 0, 1, &cipher_in,
1334 CERROR("error decrypt\n");
1337 LASSERT(plain_out.len == bodysize);
1339 /* expected clear text layout:
1340 * -----------------------------------------
1341 * | confounder | clear msgs | krb5 header |
1342 * -----------------------------------------
1345 /* verify krb5 header in token is not modified */
1346 if (memcmp(khdr, plain_out.data + plain_out.len - sizeof(*khdr),
1348 CERROR("decrypted krb5 header mismatch\n");
1352 /* verify checksum, compose clear text as layout:
1353 * ------------------------------------------------------
1354 * | confounder | gss header | clear msgs | krb5 header |
1355 * ------------------------------------------------------
1357 hash_objs[0].len = ke->ke_conf_size;
1358 hash_objs[0].data = plain_out.data;
1359 hash_objs[1].len = gsshdr->len;
1360 hash_objs[1].data = gsshdr->data;
1361 hash_objs[2].len = plain_out.len - ke->ke_conf_size - sizeof(*khdr);
1362 hash_objs[2].data = plain_out.data + ke->ke_conf_size;
1363 if (krb5_make_checksum(kctx->kc_enctype, &kctx->kc_keyi,
1364 khdr, 3, hash_objs, 0, NULL, &cksum))
1367 LASSERT(cksum.len >= ke->ke_hash_size);
1368 if (memcmp((char *)(khdr + 1) + bodysize,
1369 cksum.data + cksum.len - ke->ke_hash_size,
1370 ke->ke_hash_size)) {
1371 CERROR("checksum mismatch\n");
1375 msg->len = bodysize - ke->ke_conf_size - sizeof(*khdr);
1376 memcpy(msg->data, tmpbuf + ke->ke_conf_size, msg->len);
1378 major = GSS_S_COMPLETE;
1380 OBD_FREE_LARGE(tmpbuf, bodysize);
1381 rawobj_free(&cksum);
1386 __u32 gss_unwrap_bulk_kerberos(struct gss_ctx *gctx,
1387 struct ptlrpc_bulk_desc *desc,
1388 rawobj_t *token, int adj_nob)
1390 struct krb5_ctx *kctx = gctx->internal_ctx_id;
1391 struct krb5_enctype *ke = &enctypes[kctx->kc_enctype];
1392 struct krb5_header *khdr;
1394 rawobj_t cksum = RAWOBJ_EMPTY;
1395 rawobj_t cipher, plain;
1396 rawobj_t data_desc[1];
1400 LASSERT(ptlrpc_is_bulk_desc_kiov(desc->bd_type));
1403 if (token->len < sizeof(*khdr)) {
1404 CERROR("short signature: %u\n", token->len);
1405 return GSS_S_DEFECTIVE_TOKEN;
1408 khdr = (struct krb5_header *)token->data;
1410 major = verify_krb5_header(kctx, khdr, 1);
1411 if (major != GSS_S_COMPLETE) {
1412 CERROR("bad krb5 header\n");
1417 if (kctx->kc_enctype == ENCTYPE_ARCFOUR_HMAC) {
1418 LASSERT(kctx->kc_keye.kb_tfm == NULL);
1422 LASSERT(kctx->kc_keye.kb_tfm);
1423 blocksize = crypto_blkcipher_blocksize(kctx->kc_keye.kb_tfm);
1425 LASSERT(sizeof(*khdr) >= blocksize && sizeof(*khdr) % blocksize == 0);
1428 * token format is expected as:
1429 * -----------------------------------------------
1430 * | krb5 header | head/tail cipher text | cksum |
1431 * -----------------------------------------------
1433 if (token->len < sizeof(*khdr) + blocksize + sizeof(*khdr) +
1435 CERROR("short token size: %u\n", token->len);
1436 return GSS_S_DEFECTIVE_TOKEN;
1439 cipher.data = (__u8 *) (khdr + 1);
1440 cipher.len = blocksize + sizeof(*khdr);
1441 plain.data = cipher.data;
1442 plain.len = cipher.len;
1444 rc = krb5_decrypt_bulk(kctx->kc_keye.kb_tfm, khdr,
1445 desc, &cipher, &plain, adj_nob);
1447 return GSS_S_DEFECTIVE_TOKEN;
1450 * verify checksum, compose clear text as layout:
1451 * ------------------------------------------
1452 * | confounder | clear pages | krb5 header |
1453 * ------------------------------------------
1455 data_desc[0].data = plain.data;
1456 data_desc[0].len = blocksize;
1458 if (krb5_make_checksum(kctx->kc_enctype, &kctx->kc_keyi,
1463 return GSS_S_FAILURE;
1464 LASSERT(cksum.len >= ke->ke_hash_size);
1466 if (memcmp(plain.data + blocksize + sizeof(*khdr),
1467 cksum.data + cksum.len - ke->ke_hash_size,
1468 ke->ke_hash_size)) {
1469 CERROR("checksum mismatch\n");
1470 rawobj_free(&cksum);
1471 return GSS_S_BAD_SIG;
1474 rawobj_free(&cksum);
1475 return GSS_S_COMPLETE;
1478 int gss_display_kerberos(struct gss_ctx *ctx,
1482 struct krb5_ctx *kctx = ctx->internal_ctx_id;
1485 written = snprintf(buf, bufsize, "krb5 (%s)",
1486 enctype2str(kctx->kc_enctype));
1490 static struct gss_api_ops gss_kerberos_ops = {
1491 .gss_import_sec_context = gss_import_sec_context_kerberos,
1492 .gss_copy_reverse_context = gss_copy_reverse_context_kerberos,
1493 .gss_inquire_context = gss_inquire_context_kerberos,
1494 .gss_get_mic = gss_get_mic_kerberos,
1495 .gss_verify_mic = gss_verify_mic_kerberos,
1496 .gss_wrap = gss_wrap_kerberos,
1497 .gss_unwrap = gss_unwrap_kerberos,
1498 .gss_prep_bulk = gss_prep_bulk_kerberos,
1499 .gss_wrap_bulk = gss_wrap_bulk_kerberos,
1500 .gss_unwrap_bulk = gss_unwrap_bulk_kerberos,
1501 .gss_delete_sec_context = gss_delete_sec_context_kerberos,
1502 .gss_display = gss_display_kerberos,
1505 static struct subflavor_desc gss_kerberos_sfs[] = {
1507 .sf_subflavor = SPTLRPC_SUBFLVR_KRB5N,
1509 .sf_service = SPTLRPC_SVC_NULL,
1513 .sf_subflavor = SPTLRPC_SUBFLVR_KRB5A,
1515 .sf_service = SPTLRPC_SVC_AUTH,
1519 .sf_subflavor = SPTLRPC_SUBFLVR_KRB5I,
1521 .sf_service = SPTLRPC_SVC_INTG,
1525 .sf_subflavor = SPTLRPC_SUBFLVR_KRB5P,
1527 .sf_service = SPTLRPC_SVC_PRIV,
1533 * currently we leave module owner NULL
1535 static struct gss_api_mech gss_kerberos_mech = {
1536 .gm_owner = NULL, /*THIS_MODULE, */
1538 .gm_oid = (rawobj_t)
1539 {9, "\052\206\110\206\367\022\001\002\002"},
1540 .gm_ops = &gss_kerberos_ops,
1542 .gm_sfs = gss_kerberos_sfs,
1545 int __init init_kerberos_module(void)
1549 spin_lock_init(&krb5_seq_lock);
1551 status = lgss_mech_register(&gss_kerberos_mech);
1553 CERROR("Failed to register kerberos gss mechanism!\n");
1557 void cleanup_kerberos_module(void)
1559 lgss_mech_unregister(&gss_kerberos_mech);