blob: faf9c4ccfe19d069c5ea8d36e115f458739d3e0d [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Jeff Thompson6c314bc2013-09-23 18:09:38 -07002/**
Alexander Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -070020 *
21 * @author Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson6c314bc2013-09-23 18:09:38 -070022 */
23
Yingdi Yufc40d872014-02-18 12:56:04 -080024#ifndef NDN_SECURITY_SEC_PUBLIC_INFO_MEMORY_HPP
25#define NDN_SECURITY_SEC_PUBLIC_INFO_MEMORY_HPP
Jeff Thompson6c314bc2013-09-23 18:09:38 -070026
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080027#include "../common.hpp"
Yingdi Yu87581582014-01-14 14:28:39 -080028#include "sec-public-info.hpp"
Jeff Thompson6c314bc2013-09-23 18:09:38 -070029
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -070030#include <map>
31
Jeff Thompson6c314bc2013-09-23 18:09:38 -070032namespace ndn {
33
34/**
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070035 * @brief SecPublicInfoMemory extends SecPublicInfo and implements its methods to store identity,
36 * public key and certificate objects in memory.
Jeff Thompson6c314bc2013-09-23 18:09:38 -070037 */
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070038class SecPublicInfoMemory : public SecPublicInfo
39{
Jeff Thompson6c314bc2013-09-23 18:09:38 -070040public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070041 class Error : public SecPublicInfo::Error
42 {
43 public:
44 explicit
45 Error(const std::string& what)
46 : SecPublicInfo::Error(what)
47 {
48 }
49 };
Alexander Afanasyeve64788e2014-01-05 22:38:21 -080050
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080051 virtual
Yingdi Yu87581582014-01-14 14:28:39 -080052 ~SecPublicInfoMemory();
Jeff Thompson6c314bc2013-09-23 18:09:38 -070053
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080054 virtual bool
Jeff Thompson6c314bc2013-09-23 18:09:38 -070055 doesIdentityExist(const Name& identityName);
56
Jeff Thompson6c314bc2013-09-23 18:09:38 -070057 virtual void
58 addIdentity(const Name& identityName);
59
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080060 virtual bool
Jeff Thompson6c314bc2013-09-23 18:09:38 -070061 revokeIdentity();
62
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070063 virtual bool
Yingdi Yu87581582014-01-14 14:28:39 -080064 doesPublicKeyExist(const Name& keyName);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070065
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070066 virtual void
Yingdi Yu87581582014-01-14 14:28:39 -080067 addPublicKey(const Name& keyName, KeyType keyType, const PublicKey& publicKeyDer);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070068
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070069 virtual shared_ptr<PublicKey>
Yingdi Yu87581582014-01-14 14:28:39 -080070 getPublicKey(const Name& keyName);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070071
Jeff Thompson6c314bc2013-09-23 18:09:38 -070072 virtual bool
73 doesCertificateExist(const Name& certificateName);
74
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070075 virtual void
Jeff Thompsonc69163b2013-10-12 13:49:50 -070076 addCertificate(const IdentityCertificate& certificate);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070077
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070078 virtual shared_ptr<IdentityCertificate>
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070079 getCertificate(const Name& certificateName);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070080
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070081 virtual Name
Jeff Thompson6c314bc2013-09-23 18:09:38 -070082 getDefaultIdentity();
83
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070084 virtual Name
Jeff Thompson6c314bc2013-09-23 18:09:38 -070085 getDefaultKeyNameForIdentity(const Name& identityName);
86
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070087 virtual Name
Jeff Thompson6c314bc2013-09-23 18:09:38 -070088 getDefaultCertificateNameForKey(const Name& keyName);
89
Yingdi Yu28fd32f2014-01-28 19:03:03 -080090 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070091 getAllIdentities(std::vector<Name>& nameList, bool isDefault);
Alexander Afanasyev0c632112013-12-30 15:59:31 -080092
Yingdi Yu28fd32f2014-01-28 19:03:03 -080093 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070094 getAllKeyNames(std::vector<Name>& nameList, bool isDefault);
Alexander Afanasyev0c632112013-12-30 15:59:31 -080095
Yingdi Yu28fd32f2014-01-28 19:03:03 -080096 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070097 getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name>& nameList, bool isDefault);
Alexander Afanasyev0c632112013-12-30 15:59:31 -080098
Yingdi Yu28fd32f2014-01-28 19:03:03 -080099 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700100 getAllCertificateNames(std::vector<Name>& nameList, bool isDefault);
101
102 virtual void
103 getAllCertificateNamesOfKey(const Name& keyName, std::vector<Name>& nameList, bool isDefault);
Yingdi Yu87581582014-01-14 14:28:39 -0800104
105protected:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700106 virtual void
Yingdi Yu87581582014-01-14 14:28:39 -0800107 setDefaultIdentityInternal(const Name& identityName);
108
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700109 virtual void
Yingdi Yu87581582014-01-14 14:28:39 -0800110 setDefaultKeyNameForIdentityInternal(const Name& keyName);
111
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700112 virtual void
113 setDefaultCertificateNameForKeyInternal(const Name& certificateName);
Yingdi Yu87581582014-01-14 14:28:39 -0800114
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800115 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700116 deleteCertificateInfo(const Name& certificateName);
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800117
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800118 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700119 deletePublicKeyInfo(const Name& keyName);
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800120
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800121 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700122 deleteIdentityInfo(const Name& identity);
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800123
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700124
Jeff Thompson81842272013-09-25 16:12:33 -0700125private:
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -0700126 class KeyRecord
127 {
Jeff Thompson61805e92013-10-23 15:19:39 -0700128 public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700129 KeyRecord(KeyType keyType, const PublicKey& key)
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700130 : m_keyType(keyType), m_key(key)
Jeff Thompson61805e92013-10-23 15:19:39 -0700131 {
132 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700133
Alexander Afanasyev24b75c82014-05-31 15:59:31 +0300134 KeyType
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700135 getKeyType() const
136 {
137 return m_keyType;
138 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700139
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700140 const PublicKey&
141 getKey()
142 {
143 return m_key;
144 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700145
Jeff Thompson61805e92013-10-23 15:19:39 -0700146 private:
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700147 KeyType m_keyType;
148 PublicKey m_key;
Jeff Thompson61805e92013-10-23 15:19:39 -0700149 };
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700150
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700151 std::vector<std::string> m_identityStore; // A list of name URI.
152 std::string m_defaultIdentity; // The default identity in m_identityStore, or "" if not defined.
153 Name m_defaultKeyName;
154 Name m_defaultCert;
Alexander Afanasyeve64788e2014-01-05 22:38:21 -0800155
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700156 // The map key is the keyName.toUri()
157 typedef std::map<std::string, shared_ptr<KeyRecord> > KeyStore;
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700158
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700159 // The map key is the certificateName.toUri()
160 typedef std::map<std::string, shared_ptr<IdentityCertificate> > CertificateStore;
161
162 KeyStore m_keyStore;
163 CertificateStore m_certificateStore;
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700164};
165
Yingdi Yufc40d872014-02-18 12:56:04 -0800166} // namespace ndn
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700167
Yingdi Yufc40d872014-02-18 12:56:04 -0800168#endif //NDN_SECURITY_SEC_PUBLIC_INFO_MEMORY_HPP