]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #include <map> |
2 | ||
3 | #include "common/debug.h" | |
4 | #include "auth/RotatingKeyRing.h" | |
5 | #include "auth/KeyRing.h" | |
6 | ||
7 | #define dout_subsys ceph_subsys_auth | |
8 | #undef dout_prefix | |
9 | #define dout_prefix *_dout << "auth: " | |
10 | ||
11 | ||
12 | bool RotatingKeyRing::need_new_secrets() const | |
13 | { | |
11fdf7f2 | 14 | std::lock_guard l{lock}; |
7c673cae FG |
15 | return secrets.need_new_secrets(); |
16 | } | |
17 | ||
18 | bool RotatingKeyRing::need_new_secrets(utime_t now) const | |
19 | { | |
11fdf7f2 | 20 | std::lock_guard l{lock}; |
7c673cae FG |
21 | return secrets.need_new_secrets(now); |
22 | } | |
23 | ||
224ce89b | 24 | void RotatingKeyRing::set_secrets(RotatingSecrets&& s) |
7c673cae | 25 | { |
11fdf7f2 | 26 | std::lock_guard l{lock}; |
224ce89b | 27 | secrets = std::move(s); |
7c673cae FG |
28 | dump_rotating(); |
29 | } | |
30 | ||
31 | void RotatingKeyRing::dump_rotating() const | |
32 | { | |
33 | ldout(cct, 10) << "dump_rotating:" << dendl; | |
f67539c2 | 34 | for (auto iter = secrets.secrets.begin(); |
7c673cae FG |
35 | iter != secrets.secrets.end(); |
36 | ++iter) | |
37 | ldout(cct, 10) << " id " << iter->first << " " << iter->second << dendl; | |
38 | } | |
39 | ||
40 | bool RotatingKeyRing::get_secret(const EntityName& name, CryptoKey& secret) const | |
41 | { | |
11fdf7f2 | 42 | std::lock_guard l{lock}; |
7c673cae FG |
43 | return keyring->get_secret(name, secret); |
44 | } | |
45 | ||
46 | bool RotatingKeyRing::get_service_secret(uint32_t service_id_, uint64_t secret_id, | |
47 | CryptoKey& secret) const | |
48 | { | |
11fdf7f2 | 49 | std::lock_guard l{lock}; |
7c673cae FG |
50 | |
51 | if (service_id_ != this->service_id) { | |
52 | ldout(cct, 0) << "do not have service " << ceph_entity_type_name(service_id_) | |
53 | << ", i am " << ceph_entity_type_name(this->service_id) << dendl; | |
54 | return false; | |
55 | } | |
56 | ||
f67539c2 | 57 | auto iter = secrets.secrets.find(secret_id); |
7c673cae FG |
58 | if (iter == secrets.secrets.end()) { |
59 | ldout(cct, 0) << "could not find secret_id=" << secret_id << dendl; | |
60 | dump_rotating(); | |
61 | return false; | |
62 | } | |
63 | ||
64 | secret = iter->second.key; | |
65 | return true; | |
66 | } | |
67 | ||
11fdf7f2 | 68 | KeyRing* RotatingKeyRing::get_keyring() |
7c673cae FG |
69 | { |
70 | return keyring; | |
71 | } |