Vanetza
Loading...
Searching...
No Matches
certificate_cache.hpp
1#ifndef VANETZA_CERTIFICATE_CACHE_HPP
2#define VANETZA_CERTIFICATE_CACHE_HPP
3
4#include <vanetza/common/clock.hpp>
5#include <vanetza/common/runtime.hpp>
6#include <vanetza/security/v2/certificate.hpp>
7#include <boost/heap/binomial_heap.hpp>
8#include <list>
9#include <map>
10
11namespace vanetza
12{
13namespace security
14{
15namespace v2
16{
17
18/**
19 * CertificateCache remembers validated certificates for some time.
20 * This is necessary for certificate lookup when only its digest is known.
21 */
23{
24public:
25 CertificateCache(const Runtime& rt);
26
27 /**
28 * Puts a (validated) certificate into the cache.
29 *
30 * \param certificate certificate to add to the cache
31 */
32 void insert(const Certificate& certificate);
33
34 /**
35 * Lookup certificates based on the passed HashedId8.
36 *
37 * \param id hash identifier of the certificate
38 * \param type type of certificate to lookup
39 * \return all stored certificates matching the passed identifier and type
40 */
41 std::list<Certificate> lookup(const HashedId8& id, SubjectType type);
42
43 /**
44 * Number of currently stored certificates
45 * \return cache size
46 */
47 std::size_t size() const { return m_certificates.size(); }
48
49private:
50 struct CachedCertificate;
52
53 struct Expiry : public Clock::time_point
54 {
55 Expiry(Clock::time_point, map_type::iterator);
56 const map_type::iterator certificate;
57 };
58
60
62 {
63 Certificate certificate;
64 heap_type::handle_type handle;
65 };
66
67 const Runtime& m_runtime;
68 heap_type m_expiries;
69 map_type m_certificates;
70
71 void drop_expired();
72 bool is_expired(const Expiry&) const;
73 void refresh(heap_type::handle_type&, Clock::duration);
74};
75
76} // namespace v2
77} // namespace security
78} // namespace vanetza
79
80#endif /* VANETZA_CERTIFICATE_CACHE_HPP */
virtual const PositionFix & position_fix()=0
virtual Clock::time_point now() const =0
static CertificateValidity valid()
Create CertificateValidity signalling a valid certificate This method is equivalent to default constr...
CertificateInvalidReason reason() const
Get reason for certificate invalidity This call is only safe if reason is available,...
void insert(const Certificate &certificate)
std::list< Certificate > lookup(const HashedId8 &id, SubjectType type)
virtual CertificateValidity check_certificate(const Certificate &certificate)=0
IntX specified in TS 103 097 v1.2.1, section 4.2.1.
Definition int_x.hpp:21
virtual void request_unrecognized_certificate(HashedId8 id)=0
bool is_known(const HashedId8 &digest) const
bool announce(const HashedId8 &digest)
virtual CertificateCache & cache()=0
virtual Verdict valid_for_signing(const CertificateView &certificate, ItsAid app)=0
virtual void discard_p2p_request(HashedId3 id)=0
virtual void enqueue_p2p_request(HashedId3 id)=0
virtual void request_unrecognized_certificate(HashedId8 id)=0
described in TS 103 097 v1.2.1 (2015-06), section 6.1
SecuredMessage as specified in TS 103 097 v1.2.1, section 5.1.
const TrailerField * trailer_field(TrailerFieldType type) const