Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 1 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 2 | #include <linux/ceph/ceph_debug.h> |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 3 | |
| 4 | #include <linux/err.h> |
| 5 | #include <linux/module.h> |
| 6 | #include <linux/random.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 7 | #include <linux/slab.h> |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 8 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 9 | #include <linux/ceph/decode.h> |
| 10 | #include <linux/ceph/auth.h> |
Ilya Dryomov | a51983e | 2015-10-28 23:52:06 +0100 | [diff] [blame] | 11 | #include <linux/ceph/libceph.h> |
Yan, Zheng | 33d0733 | 2014-11-04 16:33:37 +0800 | [diff] [blame] | 12 | #include <linux/ceph/messenger.h> |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 13 | |
| 14 | #include "crypto.h" |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 15 | #include "auth_x.h" |
| 16 | #include "auth_x_protocol.h" |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 17 | |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 18 | static void ceph_x_validate_tickets(struct ceph_auth_client *ac, int *pneed); |
| 19 | |
| 20 | static int ceph_x_is_authenticated(struct ceph_auth_client *ac) |
| 21 | { |
| 22 | struct ceph_x_info *xi = ac->private; |
| 23 | int need; |
| 24 | |
| 25 | ceph_x_validate_tickets(ac, &need); |
| 26 | dout("ceph_x_is_authenticated want=%d need=%d have=%d\n", |
| 27 | ac->want_keys, need, xi->have_keys); |
| 28 | return (ac->want_keys & xi->have_keys) == ac->want_keys; |
| 29 | } |
| 30 | |
Sage Weil | a41359f | 2010-05-25 15:39:06 -0700 | [diff] [blame] | 31 | static int ceph_x_should_authenticate(struct ceph_auth_client *ac) |
| 32 | { |
| 33 | struct ceph_x_info *xi = ac->private; |
| 34 | int need; |
| 35 | |
| 36 | ceph_x_validate_tickets(ac, &need); |
| 37 | dout("ceph_x_should_authenticate want=%d need=%d have=%d\n", |
| 38 | ac->want_keys, need, xi->have_keys); |
| 39 | return need != 0; |
| 40 | } |
| 41 | |
Sage Weil | 807c86e | 2010-03-15 15:52:17 -0700 | [diff] [blame] | 42 | static int ceph_x_encrypt_buflen(int ilen) |
| 43 | { |
| 44 | return sizeof(struct ceph_x_encrypt_header) + ilen + 16 + |
| 45 | sizeof(u32); |
| 46 | } |
| 47 | |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 48 | static int ceph_x_encrypt(struct ceph_crypto_key *secret, |
| 49 | void *ibuf, int ilen, void *obuf, size_t olen) |
| 50 | { |
| 51 | struct ceph_x_encrypt_header head = { |
| 52 | .struct_v = 1, |
| 53 | .magic = cpu_to_le64(CEPHX_ENC_MAGIC) |
| 54 | }; |
| 55 | size_t len = olen - sizeof(u32); |
| 56 | int ret; |
| 57 | |
| 58 | ret = ceph_encrypt2(secret, obuf + sizeof(u32), &len, |
| 59 | &head, sizeof(head), ibuf, ilen); |
| 60 | if (ret) |
| 61 | return ret; |
| 62 | ceph_encode_32(&obuf, len); |
| 63 | return len + sizeof(u32); |
| 64 | } |
| 65 | |
| 66 | static int ceph_x_decrypt(struct ceph_crypto_key *secret, |
Ilya Dryomov | c27a3e4 | 2014-09-09 19:39:15 +0400 | [diff] [blame] | 67 | void **p, void *end, void **obuf, size_t olen) |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 68 | { |
| 69 | struct ceph_x_encrypt_header head; |
| 70 | size_t head_len = sizeof(head); |
| 71 | int len, ret; |
| 72 | |
| 73 | len = ceph_decode_32(p); |
| 74 | if (*p + len > end) |
| 75 | return -EINVAL; |
| 76 | |
| 77 | dout("ceph_x_decrypt len %d\n", len); |
Ilya Dryomov | c27a3e4 | 2014-09-09 19:39:15 +0400 | [diff] [blame] | 78 | if (*obuf == NULL) { |
| 79 | *obuf = kmalloc(len, GFP_NOFS); |
| 80 | if (!*obuf) |
| 81 | return -ENOMEM; |
| 82 | olen = len; |
| 83 | } |
| 84 | |
| 85 | ret = ceph_decrypt2(secret, &head, &head_len, *obuf, &olen, *p, len); |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 86 | if (ret) |
| 87 | return ret; |
| 88 | if (head.struct_v != 1 || le64_to_cpu(head.magic) != CEPHX_ENC_MAGIC) |
| 89 | return -EPERM; |
| 90 | *p += len; |
| 91 | return olen; |
| 92 | } |
| 93 | |
| 94 | /* |
| 95 | * get existing (or insert new) ticket handler |
| 96 | */ |
Yehuda Sadeh | cd84db6 | 2010-06-11 16:58:48 -0700 | [diff] [blame] | 97 | static struct ceph_x_ticket_handler * |
| 98 | get_ticket_handler(struct ceph_auth_client *ac, int service) |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 99 | { |
| 100 | struct ceph_x_ticket_handler *th; |
| 101 | struct ceph_x_info *xi = ac->private; |
| 102 | struct rb_node *parent = NULL, **p = &xi->ticket_handlers.rb_node; |
| 103 | |
| 104 | while (*p) { |
| 105 | parent = *p; |
| 106 | th = rb_entry(parent, struct ceph_x_ticket_handler, node); |
| 107 | if (service < th->service) |
| 108 | p = &(*p)->rb_left; |
| 109 | else if (service > th->service) |
| 110 | p = &(*p)->rb_right; |
| 111 | else |
| 112 | return th; |
| 113 | } |
| 114 | |
| 115 | /* add it */ |
| 116 | th = kzalloc(sizeof(*th), GFP_NOFS); |
| 117 | if (!th) |
| 118 | return ERR_PTR(-ENOMEM); |
| 119 | th->service = service; |
| 120 | rb_link_node(&th->node, parent, p); |
| 121 | rb_insert_color(&th->node, &xi->ticket_handlers); |
| 122 | return th; |
| 123 | } |
| 124 | |
| 125 | static void remove_ticket_handler(struct ceph_auth_client *ac, |
| 126 | struct ceph_x_ticket_handler *th) |
| 127 | { |
| 128 | struct ceph_x_info *xi = ac->private; |
| 129 | |
| 130 | dout("remove_ticket_handler %p %d\n", th, th->service); |
| 131 | rb_erase(&th->node, &xi->ticket_handlers); |
| 132 | ceph_crypto_key_destroy(&th->session_key); |
| 133 | if (th->ticket_blob) |
| 134 | ceph_buffer_put(th->ticket_blob); |
| 135 | kfree(th); |
| 136 | } |
| 137 | |
Ilya Dryomov | 597cda3 | 2014-09-08 17:25:34 +0400 | [diff] [blame] | 138 | static int process_one_ticket(struct ceph_auth_client *ac, |
| 139 | struct ceph_crypto_key *secret, |
Ilya Dryomov | c27a3e4 | 2014-09-09 19:39:15 +0400 | [diff] [blame] | 140 | void **p, void *end) |
Ilya Dryomov | 597cda3 | 2014-09-08 17:25:34 +0400 | [diff] [blame] | 141 | { |
| 142 | struct ceph_x_info *xi = ac->private; |
| 143 | int type; |
| 144 | u8 tkt_struct_v, blob_struct_v; |
| 145 | struct ceph_x_ticket_handler *th; |
Ilya Dryomov | c27a3e4 | 2014-09-09 19:39:15 +0400 | [diff] [blame] | 146 | void *dbuf = NULL; |
Ilya Dryomov | 597cda3 | 2014-09-08 17:25:34 +0400 | [diff] [blame] | 147 | void *dp, *dend; |
| 148 | int dlen; |
| 149 | char is_enc; |
| 150 | struct timespec validity; |
| 151 | struct ceph_crypto_key old_key; |
Ilya Dryomov | c27a3e4 | 2014-09-09 19:39:15 +0400 | [diff] [blame] | 152 | void *ticket_buf = NULL; |
Ilya Dryomov | 597cda3 | 2014-09-08 17:25:34 +0400 | [diff] [blame] | 153 | void *tp, *tpend; |
Ilya Dryomov | e9226d7 | 2014-10-22 18:15:37 +0400 | [diff] [blame] | 154 | void **ptp; |
Ilya Dryomov | 597cda3 | 2014-09-08 17:25:34 +0400 | [diff] [blame] | 155 | struct ceph_timespec new_validity; |
| 156 | struct ceph_crypto_key new_session_key; |
| 157 | struct ceph_buffer *new_ticket_blob; |
| 158 | unsigned long new_expires, new_renew_after; |
| 159 | u64 new_secret_id; |
| 160 | int ret; |
| 161 | |
| 162 | ceph_decode_need(p, end, sizeof(u32) + 1, bad); |
| 163 | |
| 164 | type = ceph_decode_32(p); |
| 165 | dout(" ticket type %d %s\n", type, ceph_entity_type_name(type)); |
| 166 | |
| 167 | tkt_struct_v = ceph_decode_8(p); |
| 168 | if (tkt_struct_v != 1) |
| 169 | goto bad; |
| 170 | |
| 171 | th = get_ticket_handler(ac, type); |
| 172 | if (IS_ERR(th)) { |
| 173 | ret = PTR_ERR(th); |
| 174 | goto out; |
| 175 | } |
| 176 | |
| 177 | /* blob for me */ |
Ilya Dryomov | c27a3e4 | 2014-09-09 19:39:15 +0400 | [diff] [blame] | 178 | dlen = ceph_x_decrypt(secret, p, end, &dbuf, 0); |
Ilya Dryomov | 597cda3 | 2014-09-08 17:25:34 +0400 | [diff] [blame] | 179 | if (dlen <= 0) { |
| 180 | ret = dlen; |
| 181 | goto out; |
| 182 | } |
| 183 | dout(" decrypted %d bytes\n", dlen); |
| 184 | dp = dbuf; |
| 185 | dend = dp + dlen; |
| 186 | |
| 187 | tkt_struct_v = ceph_decode_8(&dp); |
| 188 | if (tkt_struct_v != 1) |
| 189 | goto bad; |
| 190 | |
| 191 | memcpy(&old_key, &th->session_key, sizeof(old_key)); |
| 192 | ret = ceph_crypto_key_decode(&new_session_key, &dp, dend); |
| 193 | if (ret) |
| 194 | goto out; |
| 195 | |
| 196 | ceph_decode_copy(&dp, &new_validity, sizeof(new_validity)); |
| 197 | ceph_decode_timespec(&validity, &new_validity); |
| 198 | new_expires = get_seconds() + validity.tv_sec; |
| 199 | new_renew_after = new_expires - (validity.tv_sec / 4); |
| 200 | dout(" expires=%lu renew_after=%lu\n", new_expires, |
| 201 | new_renew_after); |
| 202 | |
| 203 | /* ticket blob for service */ |
| 204 | ceph_decode_8_safe(p, end, is_enc, bad); |
Ilya Dryomov | 597cda3 | 2014-09-08 17:25:34 +0400 | [diff] [blame] | 205 | if (is_enc) { |
| 206 | /* encrypted */ |
| 207 | dout(" encrypted ticket\n"); |
Ilya Dryomov | c27a3e4 | 2014-09-09 19:39:15 +0400 | [diff] [blame] | 208 | dlen = ceph_x_decrypt(&old_key, p, end, &ticket_buf, 0); |
Ilya Dryomov | 597cda3 | 2014-09-08 17:25:34 +0400 | [diff] [blame] | 209 | if (dlen < 0) { |
| 210 | ret = dlen; |
| 211 | goto out; |
| 212 | } |
Ilya Dryomov | c27a3e4 | 2014-09-09 19:39:15 +0400 | [diff] [blame] | 213 | tp = ticket_buf; |
Ilya Dryomov | e9226d7 | 2014-10-22 18:15:37 +0400 | [diff] [blame] | 214 | ptp = &tp; |
| 215 | tpend = *ptp + dlen; |
Ilya Dryomov | 597cda3 | 2014-09-08 17:25:34 +0400 | [diff] [blame] | 216 | } else { |
| 217 | /* unencrypted */ |
Ilya Dryomov | e9226d7 | 2014-10-22 18:15:37 +0400 | [diff] [blame] | 218 | ptp = p; |
| 219 | tpend = end; |
Ilya Dryomov | 597cda3 | 2014-09-08 17:25:34 +0400 | [diff] [blame] | 220 | } |
Ilya Dryomov | e9226d7 | 2014-10-22 18:15:37 +0400 | [diff] [blame] | 221 | ceph_decode_32_safe(ptp, tpend, dlen, bad); |
Ilya Dryomov | 597cda3 | 2014-09-08 17:25:34 +0400 | [diff] [blame] | 222 | dout(" ticket blob is %d bytes\n", dlen); |
Ilya Dryomov | e9226d7 | 2014-10-22 18:15:37 +0400 | [diff] [blame] | 223 | ceph_decode_need(ptp, tpend, 1 + sizeof(u64), bad); |
| 224 | blob_struct_v = ceph_decode_8(ptp); |
| 225 | new_secret_id = ceph_decode_64(ptp); |
| 226 | ret = ceph_decode_buffer(&new_ticket_blob, ptp, tpend); |
Ilya Dryomov | 597cda3 | 2014-09-08 17:25:34 +0400 | [diff] [blame] | 227 | if (ret) |
| 228 | goto out; |
| 229 | |
| 230 | /* all is well, update our ticket */ |
| 231 | ceph_crypto_key_destroy(&th->session_key); |
| 232 | if (th->ticket_blob) |
| 233 | ceph_buffer_put(th->ticket_blob); |
| 234 | th->session_key = new_session_key; |
| 235 | th->ticket_blob = new_ticket_blob; |
| 236 | th->validity = new_validity; |
| 237 | th->secret_id = new_secret_id; |
| 238 | th->expires = new_expires; |
| 239 | th->renew_after = new_renew_after; |
| 240 | dout(" got ticket service %d (%s) secret_id %lld len %d\n", |
| 241 | type, ceph_entity_type_name(type), th->secret_id, |
| 242 | (int)th->ticket_blob->vec.iov_len); |
| 243 | xi->have_keys |= th->service; |
| 244 | |
| 245 | out: |
Ilya Dryomov | c27a3e4 | 2014-09-09 19:39:15 +0400 | [diff] [blame] | 246 | kfree(ticket_buf); |
| 247 | kfree(dbuf); |
Ilya Dryomov | 597cda3 | 2014-09-08 17:25:34 +0400 | [diff] [blame] | 248 | return ret; |
| 249 | |
| 250 | bad: |
| 251 | ret = -EINVAL; |
| 252 | goto out; |
| 253 | } |
| 254 | |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 255 | static int ceph_x_proc_ticket_reply(struct ceph_auth_client *ac, |
| 256 | struct ceph_crypto_key *secret, |
| 257 | void *buf, void *end) |
| 258 | { |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 259 | void *p = buf; |
Sage Weil | b736b3d | 2010-04-30 12:45:02 -0700 | [diff] [blame] | 260 | u8 reply_struct_v; |
Ilya Dryomov | 597cda3 | 2014-09-08 17:25:34 +0400 | [diff] [blame] | 261 | u32 num; |
| 262 | int ret; |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 263 | |
Ilya Dryomov | 597cda3 | 2014-09-08 17:25:34 +0400 | [diff] [blame] | 264 | ceph_decode_8_safe(&p, end, reply_struct_v, bad); |
Sage Weil | b736b3d | 2010-04-30 12:45:02 -0700 | [diff] [blame] | 265 | if (reply_struct_v != 1) |
Ilya Dryomov | 597cda3 | 2014-09-08 17:25:34 +0400 | [diff] [blame] | 266 | return -EINVAL; |
| 267 | |
| 268 | ceph_decode_32_safe(&p, end, num, bad); |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 269 | dout("%d tickets\n", num); |
Ilya Dryomov | 597cda3 | 2014-09-08 17:25:34 +0400 | [diff] [blame] | 270 | |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 271 | while (num--) { |
Ilya Dryomov | c27a3e4 | 2014-09-09 19:39:15 +0400 | [diff] [blame] | 272 | ret = process_one_ticket(ac, secret, &p, end); |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 273 | if (ret) |
Ilya Dryomov | c27a3e4 | 2014-09-09 19:39:15 +0400 | [diff] [blame] | 274 | return ret; |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 275 | } |
| 276 | |
Ilya Dryomov | c27a3e4 | 2014-09-09 19:39:15 +0400 | [diff] [blame] | 277 | return 0; |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 278 | |
| 279 | bad: |
Ilya Dryomov | c27a3e4 | 2014-09-09 19:39:15 +0400 | [diff] [blame] | 280 | return -EINVAL; |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 281 | } |
| 282 | |
Ilya Dryomov | cbf99a1 | 2015-10-26 11:03:46 +0100 | [diff] [blame] | 283 | static void ceph_x_authorizer_cleanup(struct ceph_x_authorizer *au) |
| 284 | { |
| 285 | ceph_crypto_key_destroy(&au->session_key); |
| 286 | if (au->buf) { |
| 287 | ceph_buffer_put(au->buf); |
| 288 | au->buf = NULL; |
| 289 | } |
| 290 | } |
| 291 | |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 292 | static int ceph_x_build_authorizer(struct ceph_auth_client *ac, |
| 293 | struct ceph_x_ticket_handler *th, |
| 294 | struct ceph_x_authorizer *au) |
| 295 | { |
Sage Weil | 807c86e | 2010-03-15 15:52:17 -0700 | [diff] [blame] | 296 | int maxlen; |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 297 | struct ceph_x_authorize_a *msg_a; |
| 298 | struct ceph_x_authorize_b msg_b; |
| 299 | void *p, *end; |
| 300 | int ret; |
| 301 | int ticket_blob_len = |
| 302 | (th->ticket_blob ? th->ticket_blob->vec.iov_len : 0); |
| 303 | |
| 304 | dout("build_authorizer for %s %p\n", |
| 305 | ceph_entity_type_name(th->service), au); |
| 306 | |
Yan, Zheng | ae385ea | 2014-11-04 16:32:35 +0800 | [diff] [blame] | 307 | ceph_crypto_key_destroy(&au->session_key); |
| 308 | ret = ceph_crypto_key_clone(&au->session_key, &th->session_key); |
| 309 | if (ret) |
Ilya Dryomov | cbf99a1 | 2015-10-26 11:03:46 +0100 | [diff] [blame] | 310 | goto out_au; |
Yan, Zheng | ae385ea | 2014-11-04 16:32:35 +0800 | [diff] [blame] | 311 | |
Sage Weil | 807c86e | 2010-03-15 15:52:17 -0700 | [diff] [blame] | 312 | maxlen = sizeof(*msg_a) + sizeof(msg_b) + |
| 313 | ceph_x_encrypt_buflen(ticket_blob_len); |
| 314 | dout(" need len %d\n", maxlen); |
| 315 | if (au->buf && au->buf->alloc_len < maxlen) { |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 316 | ceph_buffer_put(au->buf); |
| 317 | au->buf = NULL; |
| 318 | } |
| 319 | if (!au->buf) { |
Sage Weil | 807c86e | 2010-03-15 15:52:17 -0700 | [diff] [blame] | 320 | au->buf = ceph_buffer_new(maxlen, GFP_NOFS); |
Yan, Zheng | ae385ea | 2014-11-04 16:32:35 +0800 | [diff] [blame] | 321 | if (!au->buf) { |
Ilya Dryomov | cbf99a1 | 2015-10-26 11:03:46 +0100 | [diff] [blame] | 322 | ret = -ENOMEM; |
| 323 | goto out_au; |
Yan, Zheng | ae385ea | 2014-11-04 16:32:35 +0800 | [diff] [blame] | 324 | } |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 325 | } |
| 326 | au->service = th->service; |
Sage Weil | 0bed9b5 | 2013-03-25 10:26:01 -0700 | [diff] [blame] | 327 | au->secret_id = th->secret_id; |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 328 | |
| 329 | msg_a = au->buf->vec.iov_base; |
| 330 | msg_a->struct_v = 1; |
| 331 | msg_a->global_id = cpu_to_le64(ac->global_id); |
| 332 | msg_a->service_id = cpu_to_le32(th->service); |
| 333 | msg_a->ticket_blob.struct_v = 1; |
| 334 | msg_a->ticket_blob.secret_id = cpu_to_le64(th->secret_id); |
| 335 | msg_a->ticket_blob.blob_len = cpu_to_le32(ticket_blob_len); |
| 336 | if (ticket_blob_len) { |
| 337 | memcpy(msg_a->ticket_blob.blob, th->ticket_blob->vec.iov_base, |
| 338 | th->ticket_blob->vec.iov_len); |
| 339 | } |
| 340 | dout(" th %p secret_id %lld %lld\n", th, th->secret_id, |
| 341 | le64_to_cpu(msg_a->ticket_blob.secret_id)); |
| 342 | |
| 343 | p = msg_a + 1; |
| 344 | p += ticket_blob_len; |
| 345 | end = au->buf->vec.iov_base + au->buf->vec.iov_len; |
| 346 | |
| 347 | get_random_bytes(&au->nonce, sizeof(au->nonce)); |
| 348 | msg_b.struct_v = 1; |
| 349 | msg_b.nonce = cpu_to_le64(au->nonce); |
Yan, Zheng | ae385ea | 2014-11-04 16:32:35 +0800 | [diff] [blame] | 350 | ret = ceph_x_encrypt(&au->session_key, &msg_b, sizeof(msg_b), |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 351 | p, end - p); |
| 352 | if (ret < 0) |
Ilya Dryomov | cbf99a1 | 2015-10-26 11:03:46 +0100 | [diff] [blame] | 353 | goto out_au; |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 354 | p += ret; |
| 355 | au->buf->vec.iov_len = p - au->buf->vec.iov_base; |
| 356 | dout(" built authorizer nonce %llx len %d\n", au->nonce, |
| 357 | (int)au->buf->vec.iov_len); |
Sage Weil | 807c86e | 2010-03-15 15:52:17 -0700 | [diff] [blame] | 358 | BUG_ON(au->buf->vec.iov_len > maxlen); |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 359 | return 0; |
| 360 | |
Ilya Dryomov | cbf99a1 | 2015-10-26 11:03:46 +0100 | [diff] [blame] | 361 | out_au: |
| 362 | ceph_x_authorizer_cleanup(au); |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 363 | return ret; |
| 364 | } |
| 365 | |
| 366 | static int ceph_x_encode_ticket(struct ceph_x_ticket_handler *th, |
| 367 | void **p, void *end) |
| 368 | { |
| 369 | ceph_decode_need(p, end, 1 + sizeof(u64), bad); |
| 370 | ceph_encode_8(p, 1); |
| 371 | ceph_encode_64(p, th->secret_id); |
| 372 | if (th->ticket_blob) { |
| 373 | const char *buf = th->ticket_blob->vec.iov_base; |
| 374 | u32 len = th->ticket_blob->vec.iov_len; |
| 375 | |
| 376 | ceph_encode_32_safe(p, end, len, bad); |
| 377 | ceph_encode_copy_safe(p, end, buf, len, bad); |
| 378 | } else { |
| 379 | ceph_encode_32_safe(p, end, 0, bad); |
| 380 | } |
| 381 | |
| 382 | return 0; |
| 383 | bad: |
| 384 | return -ERANGE; |
| 385 | } |
| 386 | |
| 387 | static void ceph_x_validate_tickets(struct ceph_auth_client *ac, int *pneed) |
| 388 | { |
| 389 | int want = ac->want_keys; |
| 390 | struct ceph_x_info *xi = ac->private; |
| 391 | int service; |
| 392 | |
| 393 | *pneed = ac->want_keys & ~(xi->have_keys); |
| 394 | |
| 395 | for (service = 1; service <= want; service <<= 1) { |
| 396 | struct ceph_x_ticket_handler *th; |
| 397 | |
| 398 | if (!(ac->want_keys & service)) |
| 399 | continue; |
| 400 | |
| 401 | if (*pneed & service) |
| 402 | continue; |
| 403 | |
| 404 | th = get_ticket_handler(ac, service); |
| 405 | |
Dan Carpenter | b545787 | 2010-08-26 11:12:38 +0200 | [diff] [blame] | 406 | if (IS_ERR(th)) { |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 407 | *pneed |= service; |
| 408 | continue; |
| 409 | } |
| 410 | |
| 411 | if (get_seconds() >= th->renew_after) |
| 412 | *pneed |= service; |
| 413 | if (get_seconds() >= th->expires) |
| 414 | xi->have_keys &= ~service; |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | |
| 419 | static int ceph_x_build_request(struct ceph_auth_client *ac, |
| 420 | void *buf, void *end) |
| 421 | { |
| 422 | struct ceph_x_info *xi = ac->private; |
| 423 | int need; |
| 424 | struct ceph_x_request_header *head = buf; |
| 425 | int ret; |
| 426 | struct ceph_x_ticket_handler *th = |
| 427 | get_ticket_handler(ac, CEPH_ENTITY_TYPE_AUTH); |
| 428 | |
Dan Carpenter | b545787 | 2010-08-26 11:12:38 +0200 | [diff] [blame] | 429 | if (IS_ERR(th)) |
| 430 | return PTR_ERR(th); |
| 431 | |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 432 | ceph_x_validate_tickets(ac, &need); |
| 433 | |
| 434 | dout("build_request want %x have %x need %x\n", |
| 435 | ac->want_keys, xi->have_keys, need); |
| 436 | |
| 437 | if (need & CEPH_ENTITY_TYPE_AUTH) { |
| 438 | struct ceph_x_authenticate *auth = (void *)(head + 1); |
| 439 | void *p = auth + 1; |
| 440 | struct ceph_x_challenge_blob tmp; |
| 441 | char tmp_enc[40]; |
| 442 | u64 *u; |
| 443 | |
| 444 | if (p > end) |
| 445 | return -ERANGE; |
| 446 | |
| 447 | dout(" get_auth_session_key\n"); |
| 448 | head->op = cpu_to_le16(CEPHX_GET_AUTH_SESSION_KEY); |
| 449 | |
| 450 | /* encrypt and hash */ |
| 451 | get_random_bytes(&auth->client_challenge, sizeof(u64)); |
| 452 | tmp.client_challenge = auth->client_challenge; |
| 453 | tmp.server_challenge = cpu_to_le64(xi->server_challenge); |
| 454 | ret = ceph_x_encrypt(&xi->secret, &tmp, sizeof(tmp), |
| 455 | tmp_enc, sizeof(tmp_enc)); |
| 456 | if (ret < 0) |
| 457 | return ret; |
| 458 | |
| 459 | auth->struct_v = 1; |
| 460 | auth->key = 0; |
| 461 | for (u = (u64 *)tmp_enc; u + 1 <= (u64 *)(tmp_enc + ret); u++) |
Yehuda Sadeh | cd84db6 | 2010-06-11 16:58:48 -0700 | [diff] [blame] | 462 | auth->key ^= *(__le64 *)u; |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 463 | dout(" server_challenge %llx client_challenge %llx key %llx\n", |
| 464 | xi->server_challenge, le64_to_cpu(auth->client_challenge), |
| 465 | le64_to_cpu(auth->key)); |
| 466 | |
| 467 | /* now encode the old ticket if exists */ |
| 468 | ret = ceph_x_encode_ticket(th, &p, end); |
| 469 | if (ret < 0) |
| 470 | return ret; |
| 471 | |
| 472 | return p - buf; |
| 473 | } |
| 474 | |
| 475 | if (need) { |
| 476 | void *p = head + 1; |
| 477 | struct ceph_x_service_ticket_request *req; |
| 478 | |
| 479 | if (p > end) |
| 480 | return -ERANGE; |
| 481 | head->op = cpu_to_le16(CEPHX_GET_PRINCIPAL_SESSION_KEY); |
| 482 | |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 483 | ret = ceph_x_build_authorizer(ac, th, &xi->auth_authorizer); |
| 484 | if (ret) |
| 485 | return ret; |
| 486 | ceph_encode_copy(&p, xi->auth_authorizer.buf->vec.iov_base, |
| 487 | xi->auth_authorizer.buf->vec.iov_len); |
| 488 | |
| 489 | req = p; |
| 490 | req->keys = cpu_to_le32(need); |
| 491 | p += sizeof(*req); |
| 492 | return p - buf; |
| 493 | } |
| 494 | |
| 495 | return 0; |
| 496 | } |
| 497 | |
| 498 | static int ceph_x_handle_reply(struct ceph_auth_client *ac, int result, |
| 499 | void *buf, void *end) |
| 500 | { |
| 501 | struct ceph_x_info *xi = ac->private; |
| 502 | struct ceph_x_reply_header *head = buf; |
| 503 | struct ceph_x_ticket_handler *th; |
| 504 | int len = end - buf; |
| 505 | int op; |
| 506 | int ret; |
| 507 | |
| 508 | if (result) |
| 509 | return result; /* XXX hmm? */ |
| 510 | |
| 511 | if (xi->starting) { |
| 512 | /* it's a hello */ |
| 513 | struct ceph_x_server_challenge *sc = buf; |
| 514 | |
| 515 | if (len != sizeof(*sc)) |
| 516 | return -EINVAL; |
| 517 | xi->server_challenge = le64_to_cpu(sc->server_challenge); |
| 518 | dout("handle_reply got server challenge %llx\n", |
| 519 | xi->server_challenge); |
| 520 | xi->starting = false; |
| 521 | xi->have_keys &= ~CEPH_ENTITY_TYPE_AUTH; |
| 522 | return -EAGAIN; |
| 523 | } |
| 524 | |
Yehuda Sadeh | 0cf5537 | 2010-06-11 15:57:06 -0700 | [diff] [blame] | 525 | op = le16_to_cpu(head->op); |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 526 | result = le32_to_cpu(head->result); |
| 527 | dout("handle_reply op %d result %d\n", op, result); |
| 528 | switch (op) { |
| 529 | case CEPHX_GET_AUTH_SESSION_KEY: |
| 530 | /* verify auth key */ |
| 531 | ret = ceph_x_proc_ticket_reply(ac, &xi->secret, |
| 532 | buf + sizeof(*head), end); |
| 533 | break; |
| 534 | |
| 535 | case CEPHX_GET_PRINCIPAL_SESSION_KEY: |
| 536 | th = get_ticket_handler(ac, CEPH_ENTITY_TYPE_AUTH); |
Dan Carpenter | b545787 | 2010-08-26 11:12:38 +0200 | [diff] [blame] | 537 | if (IS_ERR(th)) |
| 538 | return PTR_ERR(th); |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 539 | ret = ceph_x_proc_ticket_reply(ac, &th->session_key, |
| 540 | buf + sizeof(*head), end); |
| 541 | break; |
| 542 | |
| 543 | default: |
| 544 | return -EINVAL; |
| 545 | } |
| 546 | if (ret) |
| 547 | return ret; |
| 548 | if (ac->want_keys == xi->have_keys) |
| 549 | return 0; |
| 550 | return -EAGAIN; |
| 551 | } |
| 552 | |
| 553 | static int ceph_x_create_authorizer( |
| 554 | struct ceph_auth_client *ac, int peer_type, |
Alex Elder | 74f1869 | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 555 | struct ceph_auth_handshake *auth) |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 556 | { |
| 557 | struct ceph_x_authorizer *au; |
| 558 | struct ceph_x_ticket_handler *th; |
| 559 | int ret; |
| 560 | |
| 561 | th = get_ticket_handler(ac, peer_type); |
| 562 | if (IS_ERR(th)) |
| 563 | return PTR_ERR(th); |
| 564 | |
| 565 | au = kzalloc(sizeof(*au), GFP_NOFS); |
| 566 | if (!au) |
| 567 | return -ENOMEM; |
| 568 | |
| 569 | ret = ceph_x_build_authorizer(ac, th, au); |
| 570 | if (ret) { |
| 571 | kfree(au); |
| 572 | return ret; |
| 573 | } |
| 574 | |
Alex Elder | 74f1869 | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 575 | auth->authorizer = (struct ceph_authorizer *) au; |
| 576 | auth->authorizer_buf = au->buf->vec.iov_base; |
| 577 | auth->authorizer_buf_len = au->buf->vec.iov_len; |
| 578 | auth->authorizer_reply_buf = au->reply_buf; |
| 579 | auth->authorizer_reply_buf_len = sizeof (au->reply_buf); |
Yan, Zheng | 33d0733 | 2014-11-04 16:33:37 +0800 | [diff] [blame] | 580 | auth->sign_message = ac->ops->sign_message; |
| 581 | auth->check_message_signature = ac->ops->check_message_signature; |
Alex Elder | 74f1869 | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 582 | |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 583 | return 0; |
| 584 | } |
| 585 | |
Sage Weil | 0bed9b5 | 2013-03-25 10:26:01 -0700 | [diff] [blame] | 586 | static int ceph_x_update_authorizer( |
| 587 | struct ceph_auth_client *ac, int peer_type, |
| 588 | struct ceph_auth_handshake *auth) |
| 589 | { |
| 590 | struct ceph_x_authorizer *au; |
| 591 | struct ceph_x_ticket_handler *th; |
Sage Weil | 0bed9b5 | 2013-03-25 10:26:01 -0700 | [diff] [blame] | 592 | |
| 593 | th = get_ticket_handler(ac, peer_type); |
| 594 | if (IS_ERR(th)) |
| 595 | return PTR_ERR(th); |
| 596 | |
| 597 | au = (struct ceph_x_authorizer *)auth->authorizer; |
| 598 | if (au->secret_id < th->secret_id) { |
| 599 | dout("ceph_x_update_authorizer service %u secret %llu < %llu\n", |
| 600 | au->service, au->secret_id, th->secret_id); |
| 601 | return ceph_x_build_authorizer(ac, th, au); |
| 602 | } |
| 603 | return 0; |
| 604 | } |
| 605 | |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 606 | static int ceph_x_verify_authorizer_reply(struct ceph_auth_client *ac, |
| 607 | struct ceph_authorizer *a, size_t len) |
| 608 | { |
| 609 | struct ceph_x_authorizer *au = (void *)a; |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 610 | int ret = 0; |
| 611 | struct ceph_x_authorize_reply reply; |
Ilya Dryomov | c27a3e4 | 2014-09-09 19:39:15 +0400 | [diff] [blame] | 612 | void *preply = &reply; |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 613 | void *p = au->reply_buf; |
| 614 | void *end = p + sizeof(au->reply_buf); |
| 615 | |
Yan, Zheng | ae385ea | 2014-11-04 16:32:35 +0800 | [diff] [blame] | 616 | ret = ceph_x_decrypt(&au->session_key, &p, end, &preply, sizeof(reply)); |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 617 | if (ret < 0) |
| 618 | return ret; |
| 619 | if (ret != sizeof(reply)) |
| 620 | return -EPERM; |
| 621 | |
| 622 | if (au->nonce + 1 != le64_to_cpu(reply.nonce_plus_one)) |
| 623 | ret = -EPERM; |
| 624 | else |
| 625 | ret = 0; |
| 626 | dout("verify_authorizer_reply nonce %llx got %llx ret %d\n", |
| 627 | au->nonce, le64_to_cpu(reply.nonce_plus_one), ret); |
| 628 | return ret; |
| 629 | } |
| 630 | |
| 631 | static void ceph_x_destroy_authorizer(struct ceph_auth_client *ac, |
| 632 | struct ceph_authorizer *a) |
| 633 | { |
| 634 | struct ceph_x_authorizer *au = (void *)a; |
| 635 | |
Ilya Dryomov | cbf99a1 | 2015-10-26 11:03:46 +0100 | [diff] [blame] | 636 | ceph_x_authorizer_cleanup(au); |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 637 | kfree(au); |
| 638 | } |
| 639 | |
| 640 | |
| 641 | static void ceph_x_reset(struct ceph_auth_client *ac) |
| 642 | { |
| 643 | struct ceph_x_info *xi = ac->private; |
| 644 | |
| 645 | dout("reset\n"); |
| 646 | xi->starting = true; |
| 647 | xi->server_challenge = 0; |
| 648 | } |
| 649 | |
| 650 | static void ceph_x_destroy(struct ceph_auth_client *ac) |
| 651 | { |
| 652 | struct ceph_x_info *xi = ac->private; |
| 653 | struct rb_node *p; |
| 654 | |
| 655 | dout("ceph_x_destroy %p\n", ac); |
| 656 | ceph_crypto_key_destroy(&xi->secret); |
| 657 | |
| 658 | while ((p = rb_first(&xi->ticket_handlers)) != NULL) { |
| 659 | struct ceph_x_ticket_handler *th = |
| 660 | rb_entry(p, struct ceph_x_ticket_handler, node); |
| 661 | remove_ticket_handler(ac, th); |
| 662 | } |
| 663 | |
Ilya Dryomov | cbf99a1 | 2015-10-26 11:03:46 +0100 | [diff] [blame] | 664 | ceph_x_authorizer_cleanup(&xi->auth_authorizer); |
Sage Weil | 22b1de0 | 2010-07-05 15:36:49 -0700 | [diff] [blame] | 665 | |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 666 | kfree(ac->private); |
| 667 | ac->private = NULL; |
| 668 | } |
| 669 | |
| 670 | static void ceph_x_invalidate_authorizer(struct ceph_auth_client *ac, |
| 671 | int peer_type) |
| 672 | { |
| 673 | struct ceph_x_ticket_handler *th; |
| 674 | |
| 675 | th = get_ticket_handler(ac, peer_type); |
Dan Carpenter | b545787 | 2010-08-26 11:12:38 +0200 | [diff] [blame] | 676 | if (!IS_ERR(th)) |
Sage Weil | 4b8e8b5 | 2013-03-25 10:25:49 -0700 | [diff] [blame] | 677 | memset(&th->validity, 0, sizeof(th->validity)); |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 678 | } |
| 679 | |
Yan, Zheng | 33d0733 | 2014-11-04 16:33:37 +0800 | [diff] [blame] | 680 | static int calcu_signature(struct ceph_x_authorizer *au, |
| 681 | struct ceph_msg *msg, __le64 *sig) |
| 682 | { |
| 683 | int ret; |
| 684 | char tmp_enc[40]; |
| 685 | __le32 tmp[5] = { |
Ilya Dryomov | d7d5a00 | 2014-12-19 14:00:41 +0300 | [diff] [blame] | 686 | cpu_to_le32(16), msg->hdr.crc, msg->footer.front_crc, |
Yan, Zheng | 33d0733 | 2014-11-04 16:33:37 +0800 | [diff] [blame] | 687 | msg->footer.middle_crc, msg->footer.data_crc, |
| 688 | }; |
| 689 | ret = ceph_x_encrypt(&au->session_key, &tmp, sizeof(tmp), |
| 690 | tmp_enc, sizeof(tmp_enc)); |
| 691 | if (ret < 0) |
| 692 | return ret; |
| 693 | *sig = *(__le64*)(tmp_enc + 4); |
| 694 | return 0; |
| 695 | } |
| 696 | |
| 697 | static int ceph_x_sign_message(struct ceph_auth_handshake *auth, |
| 698 | struct ceph_msg *msg) |
| 699 | { |
| 700 | int ret; |
Ilya Dryomov | 4199b8e | 2015-10-27 16:42:49 +0100 | [diff] [blame] | 701 | |
Ilya Dryomov | a51983e | 2015-10-28 23:52:06 +0100 | [diff] [blame] | 702 | if (ceph_test_opt(from_msgr(msg->con->msgr), NOMSGSIGN)) |
| 703 | return 0; |
| 704 | |
Yan, Zheng | 33d0733 | 2014-11-04 16:33:37 +0800 | [diff] [blame] | 705 | ret = calcu_signature((struct ceph_x_authorizer *)auth->authorizer, |
| 706 | msg, &msg->footer.sig); |
| 707 | if (ret < 0) |
| 708 | return ret; |
| 709 | msg->footer.flags |= CEPH_MSG_FOOTER_SIGNED; |
| 710 | return 0; |
| 711 | } |
| 712 | |
| 713 | static int ceph_x_check_message_signature(struct ceph_auth_handshake *auth, |
| 714 | struct ceph_msg *msg) |
| 715 | { |
| 716 | __le64 sig_check; |
| 717 | int ret; |
| 718 | |
Ilya Dryomov | a51983e | 2015-10-28 23:52:06 +0100 | [diff] [blame] | 719 | if (ceph_test_opt(from_msgr(msg->con->msgr), NOMSGSIGN)) |
| 720 | return 0; |
| 721 | |
Yan, Zheng | 33d0733 | 2014-11-04 16:33:37 +0800 | [diff] [blame] | 722 | ret = calcu_signature((struct ceph_x_authorizer *)auth->authorizer, |
| 723 | msg, &sig_check); |
| 724 | if (ret < 0) |
| 725 | return ret; |
| 726 | if (sig_check == msg->footer.sig) |
| 727 | return 0; |
| 728 | if (msg->footer.flags & CEPH_MSG_FOOTER_SIGNED) |
| 729 | dout("ceph_x_check_message_signature %p has signature %llx " |
| 730 | "expect %llx\n", msg, msg->footer.sig, sig_check); |
| 731 | else |
| 732 | dout("ceph_x_check_message_signature %p sender did not set " |
| 733 | "CEPH_MSG_FOOTER_SIGNED\n", msg); |
| 734 | return -EBADMSG; |
| 735 | } |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 736 | |
| 737 | static const struct ceph_auth_client_ops ceph_x_ops = { |
Sage Weil | 559c1e0 | 2010-05-14 09:55:18 -0700 | [diff] [blame] | 738 | .name = "x", |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 739 | .is_authenticated = ceph_x_is_authenticated, |
Sage Weil | a41359f | 2010-05-25 15:39:06 -0700 | [diff] [blame] | 740 | .should_authenticate = ceph_x_should_authenticate, |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 741 | .build_request = ceph_x_build_request, |
| 742 | .handle_reply = ceph_x_handle_reply, |
| 743 | .create_authorizer = ceph_x_create_authorizer, |
Sage Weil | 0bed9b5 | 2013-03-25 10:26:01 -0700 | [diff] [blame] | 744 | .update_authorizer = ceph_x_update_authorizer, |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 745 | .verify_authorizer_reply = ceph_x_verify_authorizer_reply, |
| 746 | .destroy_authorizer = ceph_x_destroy_authorizer, |
| 747 | .invalidate_authorizer = ceph_x_invalidate_authorizer, |
| 748 | .reset = ceph_x_reset, |
| 749 | .destroy = ceph_x_destroy, |
Yan, Zheng | 33d0733 | 2014-11-04 16:33:37 +0800 | [diff] [blame] | 750 | .sign_message = ceph_x_sign_message, |
| 751 | .check_message_signature = ceph_x_check_message_signature, |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 752 | }; |
| 753 | |
| 754 | |
| 755 | int ceph_x_init(struct ceph_auth_client *ac) |
| 756 | { |
| 757 | struct ceph_x_info *xi; |
| 758 | int ret; |
| 759 | |
| 760 | dout("ceph_x_init %p\n", ac); |
Sage Weil | b0930f8 | 2010-04-29 13:26:53 -0700 | [diff] [blame] | 761 | ret = -ENOMEM; |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 762 | xi = kzalloc(sizeof(*xi), GFP_NOFS); |
| 763 | if (!xi) |
Sage Weil | b0930f8 | 2010-04-29 13:26:53 -0700 | [diff] [blame] | 764 | goto out; |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 765 | |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 766 | ret = -EINVAL; |
Tommi Virtanen | 8323c3a | 2011-03-25 16:32:57 -0700 | [diff] [blame] | 767 | if (!ac->key) { |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 768 | pr_err("no secret set (for auth_x protocol)\n"); |
Sage Weil | b0930f8 | 2010-04-29 13:26:53 -0700 | [diff] [blame] | 769 | goto out_nomem; |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 770 | } |
| 771 | |
Tommi Virtanen | 8323c3a | 2011-03-25 16:32:57 -0700 | [diff] [blame] | 772 | ret = ceph_crypto_key_clone(&xi->secret, ac->key); |
| 773 | if (ret < 0) { |
| 774 | pr_err("cannot clone key: %d\n", ret); |
Sage Weil | b0930f8 | 2010-04-29 13:26:53 -0700 | [diff] [blame] | 775 | goto out_nomem; |
Tommi Virtanen | 8323c3a | 2011-03-25 16:32:57 -0700 | [diff] [blame] | 776 | } |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 777 | |
| 778 | xi->starting = true; |
| 779 | xi->ticket_handlers = RB_ROOT; |
| 780 | |
| 781 | ac->protocol = CEPH_AUTH_CEPHX; |
| 782 | ac->private = xi; |
| 783 | ac->ops = &ceph_x_ops; |
| 784 | return 0; |
| 785 | |
Sage Weil | b0930f8 | 2010-04-29 13:26:53 -0700 | [diff] [blame] | 786 | out_nomem: |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 787 | kfree(xi); |
Sage Weil | b0930f8 | 2010-04-29 13:26:53 -0700 | [diff] [blame] | 788 | out: |
Sage Weil | ec0994e | 2010-02-02 16:25:35 -0800 | [diff] [blame] | 789 | return ret; |
| 790 | } |
| 791 | |
| 792 | |