]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
4e7a5dcd SW |
2 | #ifndef _FS_CEPH_AUTH_H |
3 | #define _FS_CEPH_AUTH_H | |
4 | ||
3d14c5d2 YS |
5 | #include <linux/ceph/types.h> |
6 | #include <linux/ceph/buffer.h> | |
4e7a5dcd SW |
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; | |
33d07337 | 16 | struct ceph_msg; |
4e7a5dcd | 17 | |
6c1ea260 ID |
18 | struct ceph_authorizer { |
19 | void (*destroy)(struct ceph_authorizer *); | |
20 | }; | |
21 | ||
6c4a1915 AE |
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; | |
33d07337 YZ |
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); | |
6c4a1915 AE |
32 | }; |
33 | ||
4e7a5dcd SW |
34 | struct ceph_auth_client_ops { |
35 | /* | |
36 | * true if we are authenticated and can connect to | |
37 | * services. | |
38 | */ | |
39 | int (*is_authenticated)(struct ceph_auth_client *ac); | |
40 | ||
a41359fa SW |
41 | /* |
42 | * true if we should (re)authenticate, e.g., when our tickets | |
43 | * are getting old and crusty. | |
44 | */ | |
45 | int (*should_authenticate)(struct ceph_auth_client *ac); | |
46 | ||
4e7a5dcd SW |
47 | /* |
48 | * build requests and process replies during monitor | |
49 | * handshake. if handle_reply returns -EAGAIN, we build | |
50 | * another request. | |
51 | */ | |
52 | int (*build_request)(struct ceph_auth_client *ac, void *buf, void *end); | |
53 | int (*handle_reply)(struct ceph_auth_client *ac, int result, | |
285ea34f ID |
54 | void *buf, void *end, u8 *session_key, |
55 | int *session_key_len, u8 *con_secret, | |
56 | int *con_secret_len); | |
4e7a5dcd SW |
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, | |
74f1869f | 63 | struct ceph_auth_handshake *auth); |
0bed9b5c SW |
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); | |
6daca13d ID |
67 | int (*add_authorizer_challenge)(struct ceph_auth_client *ac, |
68 | struct ceph_authorizer *a, | |
69 | void *challenge_buf, | |
70 | int challenge_buf_len); | |
4e7a5dcd | 71 | int (*verify_authorizer_reply)(struct ceph_auth_client *ac, |
285ea34f ID |
72 | struct ceph_authorizer *a, |
73 | void *reply, int reply_len, | |
74 | u8 *session_key, int *session_key_len, | |
75 | u8 *con_secret, int *con_secret_len); | |
9bd2e6f8 SW |
76 | void (*invalidate_authorizer)(struct ceph_auth_client *ac, |
77 | int peer_type); | |
4e7a5dcd SW |
78 | |
79 | /* reset when we (re)connect to a monitor */ | |
80 | void (*reset)(struct ceph_auth_client *ac); | |
81 | ||
82 | void (*destroy)(struct ceph_auth_client *ac); | |
33d07337 YZ |
83 | |
84 | int (*sign_message)(struct ceph_auth_handshake *auth, | |
85 | struct ceph_msg *msg); | |
86 | int (*check_message_signature)(struct ceph_auth_handshake *auth, | |
87 | struct ceph_msg *msg); | |
4e7a5dcd SW |
88 | }; |
89 | ||
90 | struct ceph_auth_client { | |
91 | u32 protocol; /* CEPH_AUTH_* */ | |
92 | void *private; /* for use by protocol implementation */ | |
93 | const struct ceph_auth_client_ops *ops; /* null iff protocol==0 */ | |
94 | ||
95 | bool negotiating; /* true if negotiating protocol */ | |
96 | const char *name; /* entity name */ | |
97 | u64 global_id; /* our unique id in system */ | |
8323c3aa | 98 | const struct ceph_crypto_key *key; /* our secret key */ |
4e7a5dcd | 99 | unsigned want_keys; /* which services we want */ |
e9966076 | 100 | |
00498b99 ID |
101 | int preferred_mode; /* CEPH_CON_MODE_* */ |
102 | int fallback_mode; /* ditto */ | |
103 | ||
e9966076 | 104 | struct mutex mutex; |
4e7a5dcd SW |
105 | }; |
106 | ||
00498b99 ID |
107 | struct ceph_auth_client *ceph_auth_init(const char *name, |
108 | const struct ceph_crypto_key *key, | |
109 | const int *con_modes); | |
4e7a5dcd SW |
110 | extern void ceph_auth_destroy(struct ceph_auth_client *ac); |
111 | ||
112 | extern void ceph_auth_reset(struct ceph_auth_client *ac); | |
113 | ||
114 | extern int ceph_auth_build_hello(struct ceph_auth_client *ac, | |
115 | void *buf, size_t len); | |
116 | extern int ceph_handle_auth_reply(struct ceph_auth_client *ac, | |
117 | void *buf, size_t len, | |
118 | void *reply_buf, size_t reply_len); | |
f01d5cb2 | 119 | int ceph_auth_entity_name_encode(const char *name, void **p, void *end); |
4e7a5dcd | 120 | |
9bd2e6f8 SW |
121 | extern int ceph_build_auth(struct ceph_auth_client *ac, |
122 | void *msg_buf, size_t msg_len); | |
9bd2e6f8 | 123 | extern int ceph_auth_is_authenticated(struct ceph_auth_client *ac); |
cd1a677c ID |
124 | |
125 | int __ceph_auth_get_authorizer(struct ceph_auth_client *ac, | |
126 | struct ceph_auth_handshake *auth, | |
127 | int peer_type, bool force_new, | |
128 | int *proto, int *pref_mode, int *fallb_mode); | |
6c1ea260 | 129 | void ceph_auth_destroy_authorizer(struct ceph_authorizer *a); |
6daca13d ID |
130 | int ceph_auth_add_authorizer_challenge(struct ceph_auth_client *ac, |
131 | struct ceph_authorizer *a, | |
132 | void *challenge_buf, | |
133 | int challenge_buf_len); | |
285ea34f ID |
134 | int ceph_auth_verify_authorizer_reply(struct ceph_auth_client *ac, |
135 | struct ceph_authorizer *a, | |
136 | void *reply, int reply_len, | |
137 | u8 *session_key, int *session_key_len, | |
138 | u8 *con_secret, int *con_secret_len); | |
27859f97 SW |
139 | extern void ceph_auth_invalidate_authorizer(struct ceph_auth_client *ac, |
140 | int peer_type); | |
9bd2e6f8 | 141 | |
33d07337 YZ |
142 | static inline int ceph_auth_sign_message(struct ceph_auth_handshake *auth, |
143 | struct ceph_msg *msg) | |
144 | { | |
145 | if (auth->sign_message) | |
146 | return auth->sign_message(auth, msg); | |
147 | return 0; | |
148 | } | |
149 | ||
150 | static inline | |
151 | int ceph_auth_check_message_signature(struct ceph_auth_handshake *auth, | |
152 | struct ceph_msg *msg) | |
153 | { | |
154 | if (auth->check_message_signature) | |
155 | return auth->check_message_signature(auth, msg); | |
156 | return 0; | |
157 | } | |
cd1a677c ID |
158 | |
159 | int ceph_auth_get_request(struct ceph_auth_client *ac, void *buf, int buf_len); | |
160 | int ceph_auth_handle_reply_more(struct ceph_auth_client *ac, void *reply, | |
161 | int reply_len, void *buf, int buf_len); | |
162 | int ceph_auth_handle_reply_done(struct ceph_auth_client *ac, | |
163 | u64 global_id, void *reply, int reply_len, | |
164 | u8 *session_key, int *session_key_len, | |
165 | u8 *con_secret, int *con_secret_len); | |
166 | bool ceph_auth_handle_bad_method(struct ceph_auth_client *ac, | |
167 | int used_proto, int result, | |
168 | const int *allowed_protos, int proto_cnt, | |
169 | const int *allowed_modes, int mode_cnt); | |
170 | ||
171 | int ceph_auth_get_authorizer(struct ceph_auth_client *ac, | |
172 | struct ceph_auth_handshake *auth, | |
173 | int peer_type, void *buf, int *buf_len); | |
174 | int ceph_auth_handle_svc_reply_more(struct ceph_auth_client *ac, | |
175 | struct ceph_auth_handshake *auth, | |
176 | void *reply, int reply_len, | |
177 | void *buf, int *buf_len); | |
178 | int ceph_auth_handle_svc_reply_done(struct ceph_auth_client *ac, | |
179 | struct ceph_auth_handshake *auth, | |
180 | void *reply, int reply_len, | |
181 | u8 *session_key, int *session_key_len, | |
182 | u8 *con_secret, int *con_secret_len); | |
183 | bool ceph_auth_handle_bad_authorizer(struct ceph_auth_client *ac, | |
184 | int peer_type, int used_proto, int result, | |
185 | const int *allowed_protos, int proto_cnt, | |
186 | const int *allowed_modes, int mode_cnt); | |
187 | ||
4e7a5dcd | 188 | #endif |