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