summaryrefslogtreecommitdiff
path: root/src/auth/RotatingKeyRing.cc
blob: 3d2081e7eaae6c224f100ddc5b0b0a50f92f33d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <errno.h>
#include <map>

#include "include/str_list.h"
#include "common/debug.h"

#include "Crypto.h"
#include "KeyRing.h"

#include "RotatingKeyRing.h"

#define dout_subsys ceph_subsys_auth
#undef dout_prefix
#define dout_prefix *_dout << "auth: "


bool RotatingKeyRing::need_new_secrets() const
{
  Mutex::Locker l(lock);
  return secrets.need_new_secrets();
}

bool RotatingKeyRing::need_new_secrets(utime_t now) const
{
  Mutex::Locker l(lock);
  return secrets.need_new_secrets(now);
}

void RotatingKeyRing::set_secrets(RotatingSecrets& s)
{
  Mutex::Locker l(lock);
  secrets = s;
  dump_rotating();
}

void RotatingKeyRing::dump_rotating() const
{
  ldout(cct, 10) << "dump_rotating:" << dendl;
  for (map<uint64_t, ExpiringCryptoKey>::const_iterator iter = secrets.secrets.begin();
       iter != secrets.secrets.end();
       ++iter)
    ldout(cct, 10) << " id " << iter->first << " " << iter->second << dendl;
}

bool RotatingKeyRing::get_secret(const EntityName& name, CryptoKey& secret) const
{
  Mutex::Locker l(lock);
  return keyring->get_secret(name, secret);
}

bool RotatingKeyRing::get_service_secret(uint32_t service_id_, uint64_t secret_id,
					 CryptoKey& secret) const
{
  Mutex::Locker l(lock);

  if (service_id_ != this->service_id) {
    ldout(cct, 0) << "do not have service " << ceph_entity_type_name(service_id_)
	    << ", i am " << ceph_entity_type_name(this->service_id) << dendl;
    return false;
  }

  map<uint64_t, ExpiringCryptoKey>::const_iterator iter =
    secrets.secrets.find(secret_id);
  if (iter == secrets.secrets.end()) {
    ldout(cct, 0) << "could not find secret_id=" << secret_id << dendl;
    dump_rotating();
    return false;
  }

  secret = iter->second.key;
  return true;
}

KeyRing *RotatingKeyRing::
get_keyring()
{
  return keyring;
}