blob: 20ccde6b9e3cbeed9dca35dc64d20fa1586447de [file] [log] [blame]
Jeff Thompson6c314bc2013-09-23 18:09:38 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07003 * Copyright (c) 2013-2014, Regents of the University of California.
4 * All rights reserved.
5 *
6 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
7 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
8 *
9 * This file licensed under New BSD License. See COPYING for detailed information about
10 * ndn-cxx library copyright, permissions, and redistribution restrictions.
11 *
12 * @author Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson6c314bc2013-09-23 18:09:38 -070013 */
14
Yingdi Yufc40d872014-02-18 12:56:04 -080015#ifndef NDN_SECURITY_SEC_PUBLIC_INFO_MEMORY_HPP
16#define NDN_SECURITY_SEC_PUBLIC_INFO_MEMORY_HPP
Jeff Thompson6c314bc2013-09-23 18:09:38 -070017
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080018#include "../common.hpp"
Yingdi Yu87581582014-01-14 14:28:39 -080019#include "sec-public-info.hpp"
Jeff Thompson6c314bc2013-09-23 18:09:38 -070020
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -070021#include <map>
22
Jeff Thompson6c314bc2013-09-23 18:09:38 -070023namespace ndn {
24
25/**
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070026 * @brief SecPublicInfoMemory extends SecPublicInfo and implements its methods to store identity,
27 * public key and certificate objects in memory.
Jeff Thompson6c314bc2013-09-23 18:09:38 -070028 */
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070029class SecPublicInfoMemory : public SecPublicInfo
30{
Jeff Thompson6c314bc2013-09-23 18:09:38 -070031public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070032 class Error : public SecPublicInfo::Error
33 {
34 public:
35 explicit
36 Error(const std::string& what)
37 : SecPublicInfo::Error(what)
38 {
39 }
40 };
Alexander Afanasyeve64788e2014-01-05 22:38:21 -080041
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080042 virtual
Yingdi Yu87581582014-01-14 14:28:39 -080043 ~SecPublicInfoMemory();
Jeff Thompson6c314bc2013-09-23 18:09:38 -070044
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080045 virtual bool
Jeff Thompson6c314bc2013-09-23 18:09:38 -070046 doesIdentityExist(const Name& identityName);
47
Jeff Thompson6c314bc2013-09-23 18:09:38 -070048 virtual void
49 addIdentity(const Name& identityName);
50
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080051 virtual bool
Jeff Thompson6c314bc2013-09-23 18:09:38 -070052 revokeIdentity();
53
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070054 virtual bool
Yingdi Yu87581582014-01-14 14:28:39 -080055 doesPublicKeyExist(const Name& keyName);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070056
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070057 virtual void
Yingdi Yu87581582014-01-14 14:28:39 -080058 addPublicKey(const Name& keyName, KeyType keyType, const PublicKey& publicKeyDer);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070059
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070060 virtual shared_ptr<PublicKey>
Yingdi Yu87581582014-01-14 14:28:39 -080061 getPublicKey(const Name& keyName);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070062
Jeff Thompson6c314bc2013-09-23 18:09:38 -070063 virtual bool
64 doesCertificateExist(const Name& certificateName);
65
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070066 virtual void
Jeff Thompsonc69163b2013-10-12 13:49:50 -070067 addCertificate(const IdentityCertificate& certificate);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070068
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070069 virtual shared_ptr<IdentityCertificate>
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070070 getCertificate(const Name& certificateName);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070071
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070072 virtual Name
Jeff Thompson6c314bc2013-09-23 18:09:38 -070073 getDefaultIdentity();
74
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070075 virtual Name
Jeff Thompson6c314bc2013-09-23 18:09:38 -070076 getDefaultKeyNameForIdentity(const Name& identityName);
77
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070078 virtual Name
Jeff Thompson6c314bc2013-09-23 18:09:38 -070079 getDefaultCertificateNameForKey(const Name& keyName);
80
Yingdi Yu28fd32f2014-01-28 19:03:03 -080081 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070082 getAllIdentities(std::vector<Name>& nameList, bool isDefault);
Alexander Afanasyev0c632112013-12-30 15:59:31 -080083
Yingdi Yu28fd32f2014-01-28 19:03:03 -080084 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070085 getAllKeyNames(std::vector<Name>& nameList, bool isDefault);
Alexander Afanasyev0c632112013-12-30 15:59:31 -080086
Yingdi Yu28fd32f2014-01-28 19:03:03 -080087 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070088 getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name>& nameList, bool isDefault);
Alexander Afanasyev0c632112013-12-30 15:59:31 -080089
Yingdi Yu28fd32f2014-01-28 19:03:03 -080090 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070091 getAllCertificateNames(std::vector<Name>& nameList, bool isDefault);
92
93 virtual void
94 getAllCertificateNamesOfKey(const Name& keyName, std::vector<Name>& nameList, bool isDefault);
Yingdi Yu87581582014-01-14 14:28:39 -080095
96protected:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070097 virtual void
Yingdi Yu87581582014-01-14 14:28:39 -080098 setDefaultIdentityInternal(const Name& identityName);
99
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700100 virtual void
Yingdi Yu87581582014-01-14 14:28:39 -0800101 setDefaultKeyNameForIdentityInternal(const Name& keyName);
102
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700103 virtual void
104 setDefaultCertificateNameForKeyInternal(const Name& certificateName);
Yingdi Yu87581582014-01-14 14:28:39 -0800105
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800106 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700107 deleteCertificateInfo(const Name& certificateName);
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800108
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800109 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700110 deletePublicKeyInfo(const Name& keyName);
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800111
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800112 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700113 deleteIdentityInfo(const Name& identity);
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800114
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700115
Jeff Thompson81842272013-09-25 16:12:33 -0700116private:
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -0700117 class KeyRecord
118 {
Jeff Thompson61805e92013-10-23 15:19:39 -0700119 public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700120 KeyRecord(KeyType keyType, const PublicKey& key)
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700121 : m_keyType(keyType), m_key(key)
Jeff Thompson61805e92013-10-23 15:19:39 -0700122 {
123 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700124
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700125 const KeyType
126 getKeyType() const
127 {
128 return m_keyType;
129 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700130
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700131 const PublicKey&
132 getKey()
133 {
134 return m_key;
135 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700136
Jeff Thompson61805e92013-10-23 15:19:39 -0700137 private:
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700138 KeyType m_keyType;
139 PublicKey m_key;
Jeff Thompson61805e92013-10-23 15:19:39 -0700140 };
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700141
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700142 std::vector<std::string> m_identityStore; // A list of name URI.
143 std::string m_defaultIdentity; // The default identity in m_identityStore, or "" if not defined.
144 Name m_defaultKeyName;
145 Name m_defaultCert;
Alexander Afanasyeve64788e2014-01-05 22:38:21 -0800146
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700147 // The map key is the keyName.toUri()
148 typedef std::map<std::string, shared_ptr<KeyRecord> > KeyStore;
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700149
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700150 // The map key is the certificateName.toUri()
151 typedef std::map<std::string, shared_ptr<IdentityCertificate> > CertificateStore;
152
153 KeyStore m_keyStore;
154 CertificateStore m_certificateStore;
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700155};
156
Yingdi Yufc40d872014-02-18 12:56:04 -0800157} // namespace ndn
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700158
Yingdi Yufc40d872014-02-18 12:56:04 -0800159#endif //NDN_SECURITY_SEC_PUBLIC_INFO_MEMORY_HPP