4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (C) 2015, Trustees of Indiana University
25 * Author: Jeremy Filizetti <jfilizet@iu.edu>
31 #include <gssapi/gssapi.h>
33 #include <lustre/lustre_idl.h>
34 #include <openssl/dh.h>
35 #include <openssl/evp.h>
36 #include <sys/types.h>
40 /* Some limits and defaults */
41 #define SK_CONF_VERSION 1
42 #define SK_GENERATOR 2
43 #define SK_SESSION_MAX_KEYLEN_BYTES 1024
44 #define SK_MAX_KEYLEN_BYTES 128
46 #define MAX_MGSNIDS 16
48 /* String consisting of "lustre:fsname:nodemap_hash" */
49 #define SK_DESCRIPTION_SIZE (9 + MTI_NAME_MAXLEN + LUSTRE_NODEMAP_NAME_LENGTH)
52 SK_TYPE_INVALID = 0x0,
58 /* This is the packed structure format of key files that are distributed.
59 * The on disk format should be store in big-endian. */
60 struct sk_keyfile_config {
61 /* File format version */
63 /* HMAC algorithm used for message integrity */
64 uint16_t skc_hmac_alg;
65 /* Crypt algorithm used for privacy mode */
66 uint16_t skc_crypt_alg;
67 /* Number of seconds that a context is valid after it is created from
70 /* Length of shared key in skc_shared_key */
71 uint32_t skc_shared_keylen;
72 /* Minimum length of the session keys using this keyfile */
73 uint32_t skc_session_keylen;
74 /* Array of MGS NIDs to load key's for. This is for the client since
75 * the upcall only knows the target name which is MGC<IP>@<NET>
76 * Only needed when mounting with mgssec */
77 lnet_nid_t skc_mgsnids[MAX_MGSNIDS];
78 /* File system name for this key. It can be unused for MGS only keys */
79 char skc_fsname[MTI_NAME_MAXLEN + 1];
80 /* Nodemap name for this key. Used by the server side to verify the
81 * client is in the correct nodemap */
82 char skc_nodemap[LUSTRE_NODEMAP_NAME_LENGTH + 1];
84 unsigned char skc_shared_key[SK_MAX_KEYLEN_BYTES];
85 } __attribute__((packed));
87 /* Format passed to the kernel from userspace */
88 struct sk_kernel_ctx {
90 uint16_t skc_hmac_alg;
91 uint16_t skc_crypt_alg;
93 gss_buffer_desc skc_shared_key;
94 gss_buffer_desc skc_iv;
95 gss_buffer_desc skc_session_key;
98 /* Structure used in context initiation to hold all necessary data */
100 uint32_t sc_session_keylen;
102 gss_buffer_desc sc_p;
103 gss_buffer_desc sc_pub_key;
104 gss_buffer_desc sc_tgt;
105 gss_buffer_desc sc_nodemap_hash;
106 gss_buffer_desc sc_hmac;
107 gss_buffer_desc sc_dh_shared_key;
108 struct sk_kernel_ctx sc_kctx;
112 void sk_init_logging(char *program, int verbose, int fg);
113 struct sk_keyfile_config *sk_read_file(char *filename);
114 int sk_load_keyfile(char *path, int type);
115 void sk_config_disk_to_cpu(struct sk_keyfile_config *config);
116 void sk_config_cpu_to_disk(struct sk_keyfile_config *config);
117 int sk_validate_config(const struct sk_keyfile_config *config);
118 uint32_t sk_verify_hash(const char *string, const EVP_MD *hash_alg,
119 const gss_buffer_desc *current_hash);
120 struct sk_cred *sk_create_cred(const char *fsname, const char *cluster,
121 const uint32_t flags);
122 uint32_t sk_gen_params(struct sk_cred *skc, bool initiator);
123 int sk_sign_bufs(gss_buffer_desc *key, gss_buffer_desc *bufs, const int numbufs,
124 const EVP_MD *hash_alg, gss_buffer_desc *hmac);
125 uint32_t sk_verify_hmac(struct sk_cred *skc, gss_buffer_desc *bufs,
126 const int numbufs, const EVP_MD *hash_alg,
127 gss_buffer_desc *hmac);
128 void sk_free_cred(struct sk_cred *skc);
129 int sk_kdf(struct sk_cred *skc, lnet_nid_t client_nid,
130 gss_buffer_desc *key_binding_input);
131 uint32_t sk_compute_key(struct sk_cred *skc, const gss_buffer_desc *pub_key);
132 int sk_serialize_kctx(struct sk_cred *skc, gss_buffer_desc *ctx_token);
133 int sk_decode_netstring(gss_buffer_desc *bufs, int numbufs,
134 gss_buffer_desc *ns);
135 int sk_encode_netstring(gss_buffer_desc *bufs, int numbufs,
136 gss_buffer_desc *ns);
138 #endif /* SK_UTILS_H */