Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 2 | #ifndef _FS_CEPH_AUTH_H |
| 3 | #define _FS_CEPH_AUTH_H |
| 4 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 5 | #include <linux/ceph/types.h> |
| 6 | #include <linux/ceph/buffer.h> |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 7 | |
| 8 | /* |
| 9 | * Abstract interface for communicating with the authenticate module. |
| 10 | * There is some handshake that takes place between us and the monitor |
| 11 | * to acquire the necessary keys. These are used to generate an |
| 12 | * 'authorizer' that we use when connecting to a service (mds, osd). |
| 13 | */ |
| 14 | |
| 15 | struct ceph_auth_client; |
Yan, Zheng | 33d0733 | 2014-11-04 16:33:37 +0800 | [diff] [blame] | 16 | struct ceph_msg; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 17 | |
Ilya Dryomov | 6c1ea26 | 2016-04-11 19:34:49 +0200 | [diff] [blame] | 18 | struct ceph_authorizer { |
| 19 | void (*destroy)(struct ceph_authorizer *); |
| 20 | }; |
| 21 | |
Alex Elder | 6c4a191 | 2012-05-16 15:16:38 -0500 | [diff] [blame] | 22 | struct ceph_auth_handshake { |
| 23 | struct ceph_authorizer *authorizer; |
| 24 | void *authorizer_buf; |
| 25 | size_t authorizer_buf_len; |
| 26 | void *authorizer_reply_buf; |
| 27 | size_t authorizer_reply_buf_len; |
Yan, Zheng | 33d0733 | 2014-11-04 16:33:37 +0800 | [diff] [blame] | 28 | int (*sign_message)(struct ceph_auth_handshake *auth, |
| 29 | struct ceph_msg *msg); |
| 30 | int (*check_message_signature)(struct ceph_auth_handshake *auth, |
| 31 | struct ceph_msg *msg); |
Alex Elder | 6c4a191 | 2012-05-16 15:16:38 -0500 | [diff] [blame] | 32 | }; |
| 33 | |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 34 | struct ceph_auth_client_ops { |
Sage Weil | 559c1e0 | 2010-05-14 09:55:18 -0700 | [diff] [blame] | 35 | const char *name; |
| 36 | |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 37 | /* |
| 38 | * true if we are authenticated and can connect to |
| 39 | * services. |
| 40 | */ |
| 41 | int (*is_authenticated)(struct ceph_auth_client *ac); |
| 42 | |
| 43 | /* |
Sage Weil | a41359f | 2010-05-25 15:39:06 -0700 | [diff] [blame] | 44 | * true if we should (re)authenticate, e.g., when our tickets |
| 45 | * are getting old and crusty. |
| 46 | */ |
| 47 | int (*should_authenticate)(struct ceph_auth_client *ac); |
| 48 | |
| 49 | /* |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 50 | * build requests and process replies during monitor |
| 51 | * handshake. if handle_reply returns -EAGAIN, we build |
| 52 | * another request. |
| 53 | */ |
| 54 | int (*build_request)(struct ceph_auth_client *ac, void *buf, void *end); |
| 55 | int (*handle_reply)(struct ceph_auth_client *ac, int result, |
| 56 | void *buf, void *end); |
| 57 | |
| 58 | /* |
| 59 | * Create authorizer for connecting to a service, and verify |
| 60 | * the response to authenticate the service. |
| 61 | */ |
| 62 | int (*create_authorizer)(struct ceph_auth_client *ac, int peer_type, |
Alex Elder | 74f1869 | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 63 | struct ceph_auth_handshake *auth); |
Sage Weil | 0bed9b5 | 2013-03-25 10:26:01 -0700 | [diff] [blame] | 64 | /* ensure that an existing authorizer is up to date */ |
| 65 | int (*update_authorizer)(struct ceph_auth_client *ac, int peer_type, |
| 66 | struct ceph_auth_handshake *auth); |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 67 | int (*verify_authorizer_reply)(struct ceph_auth_client *ac, |
Ilya Dryomov | 0dde584 | 2016-12-02 16:35:09 +0100 | [diff] [blame] | 68 | struct ceph_authorizer *a); |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 69 | void (*invalidate_authorizer)(struct ceph_auth_client *ac, |
| 70 | int peer_type); |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 71 | |
| 72 | /* reset when we (re)connect to a monitor */ |
| 73 | void (*reset)(struct ceph_auth_client *ac); |
| 74 | |
| 75 | void (*destroy)(struct ceph_auth_client *ac); |
Yan, Zheng | 33d0733 | 2014-11-04 16:33:37 +0800 | [diff] [blame] | 76 | |
| 77 | int (*sign_message)(struct ceph_auth_handshake *auth, |
| 78 | struct ceph_msg *msg); |
| 79 | int (*check_message_signature)(struct ceph_auth_handshake *auth, |
| 80 | struct ceph_msg *msg); |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | struct ceph_auth_client { |
| 84 | u32 protocol; /* CEPH_AUTH_* */ |
| 85 | void *private; /* for use by protocol implementation */ |
| 86 | const struct ceph_auth_client_ops *ops; /* null iff protocol==0 */ |
| 87 | |
| 88 | bool negotiating; /* true if negotiating protocol */ |
| 89 | const char *name; /* entity name */ |
| 90 | u64 global_id; /* our unique id in system */ |
Tommi Virtanen | 8323c3a | 2011-03-25 16:32:57 -0700 | [diff] [blame] | 91 | const struct ceph_crypto_key *key; /* our secret key */ |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 92 | unsigned want_keys; /* which services we want */ |
Sage Weil | e996607 | 2013-03-25 10:26:30 -0700 | [diff] [blame] | 93 | |
| 94 | struct mutex mutex; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | extern struct ceph_auth_client *ceph_auth_init(const char *name, |
Tommi Virtanen | 8323c3a | 2011-03-25 16:32:57 -0700 | [diff] [blame] | 98 | const struct ceph_crypto_key *key); |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 99 | extern void ceph_auth_destroy(struct ceph_auth_client *ac); |
| 100 | |
| 101 | extern void ceph_auth_reset(struct ceph_auth_client *ac); |
| 102 | |
| 103 | extern int ceph_auth_build_hello(struct ceph_auth_client *ac, |
| 104 | void *buf, size_t len); |
| 105 | extern int ceph_handle_auth_reply(struct ceph_auth_client *ac, |
| 106 | void *buf, size_t len, |
| 107 | void *reply_buf, size_t reply_len); |
Ilya Dryomov | f01d5cb | 2016-06-02 16:45:08 +0200 | [diff] [blame] | 108 | int ceph_auth_entity_name_encode(const char *name, void **p, void *end); |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 109 | |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 110 | extern int ceph_build_auth(struct ceph_auth_client *ac, |
| 111 | void *msg_buf, size_t msg_len); |
| 112 | |
| 113 | extern int ceph_auth_is_authenticated(struct ceph_auth_client *ac); |
Sage Weil | 27859f9 | 2013-03-25 10:26:14 -0700 | [diff] [blame] | 114 | extern int ceph_auth_create_authorizer(struct ceph_auth_client *ac, |
| 115 | int peer_type, |
| 116 | struct ceph_auth_handshake *auth); |
Ilya Dryomov | 6c1ea26 | 2016-04-11 19:34:49 +0200 | [diff] [blame] | 117 | void ceph_auth_destroy_authorizer(struct ceph_authorizer *a); |
Sage Weil | 27859f9 | 2013-03-25 10:26:14 -0700 | [diff] [blame] | 118 | extern int ceph_auth_update_authorizer(struct ceph_auth_client *ac, |
| 119 | int peer_type, |
| 120 | struct ceph_auth_handshake *a); |
| 121 | extern int ceph_auth_verify_authorizer_reply(struct ceph_auth_client *ac, |
Ilya Dryomov | 0dde584 | 2016-12-02 16:35:09 +0100 | [diff] [blame] | 122 | struct ceph_authorizer *a); |
Sage Weil | 27859f9 | 2013-03-25 10:26:14 -0700 | [diff] [blame] | 123 | extern void ceph_auth_invalidate_authorizer(struct ceph_auth_client *ac, |
| 124 | int peer_type); |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 125 | |
Yan, Zheng | 33d0733 | 2014-11-04 16:33:37 +0800 | [diff] [blame] | 126 | static inline int ceph_auth_sign_message(struct ceph_auth_handshake *auth, |
| 127 | struct ceph_msg *msg) |
| 128 | { |
| 129 | if (auth->sign_message) |
| 130 | return auth->sign_message(auth, msg); |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | static inline |
| 135 | int ceph_auth_check_message_signature(struct ceph_auth_handshake *auth, |
| 136 | struct ceph_msg *msg) |
| 137 | { |
| 138 | if (auth->check_message_signature) |
| 139 | return auth->check_message_signature(auth, msg); |
| 140 | return 0; |
| 141 | } |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 142 | #endif |