blob: 0c6b70ff27057211144d5cf885e5b686b5476799 [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
21namespace ndn {
22
23/**
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070024 * @brief SecPublicInfoMemory extends SecPublicInfo and implements its methods to store identity,
25 * public key and certificate objects in memory.
Jeff Thompson6c314bc2013-09-23 18:09:38 -070026 */
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070027class SecPublicInfoMemory : public SecPublicInfo
28{
Jeff Thompson6c314bc2013-09-23 18:09:38 -070029public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070030 class Error : public SecPublicInfo::Error
31 {
32 public:
33 explicit
34 Error(const std::string& what)
35 : SecPublicInfo::Error(what)
36 {
37 }
38 };
Alexander Afanasyeve64788e2014-01-05 22:38:21 -080039
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080040 virtual
Yingdi Yu87581582014-01-14 14:28:39 -080041 ~SecPublicInfoMemory();
Jeff Thompson6c314bc2013-09-23 18:09:38 -070042
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080043 virtual bool
Jeff Thompson6c314bc2013-09-23 18:09:38 -070044 doesIdentityExist(const Name& identityName);
45
Jeff Thompson6c314bc2013-09-23 18:09:38 -070046 virtual void
47 addIdentity(const Name& identityName);
48
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080049 virtual bool
Jeff Thompson6c314bc2013-09-23 18:09:38 -070050 revokeIdentity();
51
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070052 virtual bool
Yingdi Yu87581582014-01-14 14:28:39 -080053 doesPublicKeyExist(const Name& keyName);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070054
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070055 virtual void
Yingdi Yu87581582014-01-14 14:28:39 -080056 addPublicKey(const Name& keyName, KeyType keyType, const PublicKey& publicKeyDer);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070057
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070058 virtual shared_ptr<PublicKey>
Yingdi Yu87581582014-01-14 14:28:39 -080059 getPublicKey(const Name& keyName);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070060
Jeff Thompson6c314bc2013-09-23 18:09:38 -070061 virtual bool
62 doesCertificateExist(const Name& certificateName);
63
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070064 virtual void
Jeff Thompsonc69163b2013-10-12 13:49:50 -070065 addCertificate(const IdentityCertificate& certificate);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070066
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070067 virtual shared_ptr<IdentityCertificate>
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070068 getCertificate(const Name& certificateName);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070069
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070070 virtual Name
Jeff Thompson6c314bc2013-09-23 18:09:38 -070071 getDefaultIdentity();
72
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070073 virtual Name
Jeff Thompson6c314bc2013-09-23 18:09:38 -070074 getDefaultKeyNameForIdentity(const Name& identityName);
75
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070076 virtual Name
Jeff Thompson6c314bc2013-09-23 18:09:38 -070077 getDefaultCertificateNameForKey(const Name& keyName);
78
Yingdi Yu28fd32f2014-01-28 19:03:03 -080079 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070080 getAllIdentities(std::vector<Name>& nameList, bool isDefault);
Alexander Afanasyev0c632112013-12-30 15:59:31 -080081
Yingdi Yu28fd32f2014-01-28 19:03:03 -080082 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070083 getAllKeyNames(std::vector<Name>& nameList, bool isDefault);
Alexander Afanasyev0c632112013-12-30 15:59:31 -080084
Yingdi Yu28fd32f2014-01-28 19:03:03 -080085 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070086 getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name>& nameList, bool isDefault);
Alexander Afanasyev0c632112013-12-30 15:59:31 -080087
Yingdi Yu28fd32f2014-01-28 19:03:03 -080088 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070089 getAllCertificateNames(std::vector<Name>& nameList, bool isDefault);
90
91 virtual void
92 getAllCertificateNamesOfKey(const Name& keyName, std::vector<Name>& nameList, bool isDefault);
Yingdi Yu87581582014-01-14 14:28:39 -080093
94protected:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070095 virtual void
Yingdi Yu87581582014-01-14 14:28:39 -080096 setDefaultIdentityInternal(const Name& identityName);
97
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070098 virtual void
Yingdi Yu87581582014-01-14 14:28:39 -080099 setDefaultKeyNameForIdentityInternal(const Name& keyName);
100
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700101 virtual void
102 setDefaultCertificateNameForKeyInternal(const Name& certificateName);
Yingdi Yu87581582014-01-14 14:28:39 -0800103
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800104 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700105 deleteCertificateInfo(const Name& certificateName);
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800106
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800107 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700108 deletePublicKeyInfo(const Name& keyName);
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800109
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800110 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700111 deleteIdentityInfo(const Name& identity);
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800112
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700113
Jeff Thompson81842272013-09-25 16:12:33 -0700114private:
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -0700115 class KeyRecord
116 {
Jeff Thompson61805e92013-10-23 15:19:39 -0700117 public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700118 KeyRecord(KeyType keyType, const PublicKey& key)
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700119 : m_keyType(keyType), m_key(key)
Jeff Thompson61805e92013-10-23 15:19:39 -0700120 {
121 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700122
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700123 const KeyType
124 getKeyType() const
125 {
126 return m_keyType;
127 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700128
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700129 const PublicKey&
130 getKey()
131 {
132 return m_key;
133 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700134
Jeff Thompson61805e92013-10-23 15:19:39 -0700135 private:
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700136 KeyType m_keyType;
137 PublicKey m_key;
Jeff Thompson61805e92013-10-23 15:19:39 -0700138 };
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700139
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700140 std::vector<std::string> m_identityStore; // A list of name URI.
141 std::string m_defaultIdentity; // The default identity in m_identityStore, or "" if not defined.
142 Name m_defaultKeyName;
143 Name m_defaultCert;
Alexander Afanasyeve64788e2014-01-05 22:38:21 -0800144
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700145 // The map key is the keyName.toUri()
146 typedef std::map<std::string, shared_ptr<KeyRecord> > KeyStore;
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700147
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700148 // The map key is the certificateName.toUri()
149 typedef std::map<std::string, shared_ptr<IdentityCertificate> > CertificateStore;
150
151 KeyStore m_keyStore;
152 CertificateStore m_certificateStore;
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700153};
154
Yingdi Yufc40d872014-02-18 12:56:04 -0800155} // namespace ndn
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700156
Yingdi Yufc40d872014-02-18 12:56:04 -0800157#endif //NDN_SECURITY_SEC_PUBLIC_INFO_MEMORY_HPP