blob: 2ecdc43185464dda66d85b0c4f9161397a3f2ddc [file] [log] [blame]
Jeff Thompson6c314bc2013-09-23 18:09:38 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
5 * See COPYING for copyright and distribution information.
6 */
7
Yingdi Yufc40d872014-02-18 12:56:04 -08008#ifndef NDN_SECURITY_SEC_PUBLIC_INFO_MEMORY_HPP
9#define NDN_SECURITY_SEC_PUBLIC_INFO_MEMORY_HPP
Jeff Thompson6c314bc2013-09-23 18:09:38 -070010
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080011#include "../common.hpp"
Yingdi Yu87581582014-01-14 14:28:39 -080012#include "sec-public-info.hpp"
Jeff Thompson6c314bc2013-09-23 18:09:38 -070013
14namespace ndn {
15
16/**
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070017 * @brief SecPublicInfoMemory extends SecPublicInfo and implements its methods to store identity,
18 * public key and certificate objects in memory.
Jeff Thompson6c314bc2013-09-23 18:09:38 -070019 */
Yingdi Yu87581582014-01-14 14:28:39 -080020class SecPublicInfoMemory : public SecPublicInfo {
Jeff Thompson6c314bc2013-09-23 18:09:38 -070021public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070022 class Error : public SecPublicInfo::Error
23 {
24 public:
25 explicit
26 Error(const std::string& what)
27 : SecPublicInfo::Error(what)
28 {
29 }
30 };
Alexander Afanasyeve64788e2014-01-05 22:38:21 -080031
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080032 virtual
Yingdi Yu87581582014-01-14 14:28:39 -080033 ~SecPublicInfoMemory();
Jeff Thompson6c314bc2013-09-23 18:09:38 -070034
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080035 virtual bool
Jeff Thompson6c314bc2013-09-23 18:09:38 -070036 doesIdentityExist(const Name& identityName);
37
Jeff Thompson6c314bc2013-09-23 18:09:38 -070038 virtual void
39 addIdentity(const Name& identityName);
40
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080041 virtual bool
Jeff Thompson6c314bc2013-09-23 18:09:38 -070042 revokeIdentity();
43
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070044 virtual bool
Yingdi Yu87581582014-01-14 14:28:39 -080045 doesPublicKeyExist(const Name& keyName);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070046
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070047 virtual void
Yingdi Yu87581582014-01-14 14:28:39 -080048 addPublicKey(const Name& keyName, KeyType keyType, const PublicKey& publicKeyDer);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070049
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070050 virtual shared_ptr<PublicKey>
Yingdi Yu87581582014-01-14 14:28:39 -080051 getPublicKey(const Name& keyName);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070052
Jeff Thompson6c314bc2013-09-23 18:09:38 -070053 virtual bool
54 doesCertificateExist(const Name& certificateName);
55
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070056 virtual void
Jeff Thompsonc69163b2013-10-12 13:49:50 -070057 addCertificate(const IdentityCertificate& certificate);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070058
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070059 virtual shared_ptr<IdentityCertificate>
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070060 getCertificate(const Name& certificateName);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070061
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070062 virtual Name
Jeff Thompson6c314bc2013-09-23 18:09:38 -070063 getDefaultIdentity();
64
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070065 virtual Name
Jeff Thompson6c314bc2013-09-23 18:09:38 -070066 getDefaultKeyNameForIdentity(const Name& identityName);
67
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070068 virtual Name
Jeff Thompson6c314bc2013-09-23 18:09:38 -070069 getDefaultCertificateNameForKey(const Name& keyName);
70
Yingdi Yu28fd32f2014-01-28 19:03:03 -080071 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070072 getAllIdentities(std::vector<Name>& nameList, bool isDefault);
Alexander Afanasyev0c632112013-12-30 15:59:31 -080073
Yingdi Yu28fd32f2014-01-28 19:03:03 -080074 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070075 getAllKeyNames(std::vector<Name>& nameList, bool isDefault);
Alexander Afanasyev0c632112013-12-30 15:59:31 -080076
Yingdi Yu28fd32f2014-01-28 19:03:03 -080077 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070078 getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name>& nameList, bool isDefault);
Alexander Afanasyev0c632112013-12-30 15:59:31 -080079
Yingdi Yu28fd32f2014-01-28 19:03:03 -080080 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070081 getAllCertificateNames(std::vector<Name>& nameList, bool isDefault);
82
83 virtual void
84 getAllCertificateNamesOfKey(const Name& keyName, std::vector<Name>& nameList, bool isDefault);
Yingdi Yu87581582014-01-14 14:28:39 -080085
86protected:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070087 virtual void
Yingdi Yu87581582014-01-14 14:28:39 -080088 setDefaultIdentityInternal(const Name& identityName);
89
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070090 virtual void
Yingdi Yu87581582014-01-14 14:28:39 -080091 setDefaultKeyNameForIdentityInternal(const Name& keyName);
92
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070093 virtual void
94 setDefaultCertificateNameForKeyInternal(const Name& certificateName);
Yingdi Yu87581582014-01-14 14:28:39 -080095
Yingdi Yu28fd32f2014-01-28 19:03:03 -080096 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070097 deleteCertificateInfo(const Name& certificateName);
Yingdi Yu28fd32f2014-01-28 19:03:03 -080098
Yingdi Yu28fd32f2014-01-28 19:03:03 -080099 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700100 deletePublicKeyInfo(const Name& keyName);
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800101
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800102 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700103 deleteIdentityInfo(const Name& identity);
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800104
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700105
Jeff Thompson81842272013-09-25 16:12:33 -0700106private:
Jeff Thompson61805e92013-10-23 15:19:39 -0700107 class KeyRecord {
108 public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700109 KeyRecord(KeyType keyType, const PublicKey& key)
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700110 : m_keyType(keyType), m_key(key)
Jeff Thompson61805e92013-10-23 15:19:39 -0700111 {
112 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700113
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700114 const KeyType
115 getKeyType() const
116 {
117 return m_keyType;
118 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700119
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700120 const PublicKey&
121 getKey()
122 {
123 return m_key;
124 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700125
Jeff Thompson61805e92013-10-23 15:19:39 -0700126 private:
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700127 KeyType m_keyType;
128 PublicKey m_key;
Jeff Thompson61805e92013-10-23 15:19:39 -0700129 };
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700130
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700131 std::vector<std::string> m_identityStore; // A list of name URI.
132 std::string m_defaultIdentity; // The default identity in m_identityStore, or "" if not defined.
133 Name m_defaultKeyName;
134 Name m_defaultCert;
Alexander Afanasyeve64788e2014-01-05 22:38:21 -0800135
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700136 // The map key is the keyName.toUri()
137 typedef std::map<std::string, shared_ptr<KeyRecord> > KeyStore;
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700138
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700139 // The map key is the certificateName.toUri()
140 typedef std::map<std::string, shared_ptr<IdentityCertificate> > CertificateStore;
141
142 KeyStore m_keyStore;
143 CertificateStore m_certificateStore;
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700144};
145
Yingdi Yufc40d872014-02-18 12:56:04 -0800146} // namespace ndn
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700147
Yingdi Yufc40d872014-02-18 12:56:04 -0800148#endif //NDN_SECURITY_SEC_PUBLIC_INFO_MEMORY_HPP