blob: 16001c89d7316f7f78b8f3e56e349d118f9f9a2e [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 Yu2e57a582014-02-20 23:34:43 -080017 * @brief SecPublicInfoMemory extends SecPublicInfo and implements its methods to store identity, public key and certificate objects in memory.
Jeff Thompson6c314bc2013-09-23 18:09:38 -070018 */
Yingdi Yu87581582014-01-14 14:28:39 -080019class SecPublicInfoMemory : public SecPublicInfo {
Jeff Thompson6c314bc2013-09-23 18:09:38 -070020public:
Yingdi Yu87581582014-01-14 14:28:39 -080021 struct Error : public SecPublicInfo::Error { Error(const std::string &what) : SecPublicInfo::Error(what) {} };
Alexander Afanasyeve64788e2014-01-05 22:38:21 -080022
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080023 virtual
Yingdi Yu87581582014-01-14 14:28:39 -080024 ~SecPublicInfoMemory();
Jeff Thompson6c314bc2013-09-23 18:09:38 -070025
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080026 virtual bool
Jeff Thompson6c314bc2013-09-23 18:09:38 -070027 doesIdentityExist(const Name& identityName);
28
Jeff Thompson6c314bc2013-09-23 18:09:38 -070029 virtual void
30 addIdentity(const Name& identityName);
31
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080032 virtual bool
Jeff Thompson6c314bc2013-09-23 18:09:38 -070033 revokeIdentity();
34
Jeff Thompson6c314bc2013-09-23 18:09:38 -070035 virtual bool
Yingdi Yu87581582014-01-14 14:28:39 -080036 doesPublicKeyExist(const Name& keyName);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070037
Jeff Thompson6c314bc2013-09-23 18:09:38 -070038 virtual void
Yingdi Yu87581582014-01-14 14:28:39 -080039 addPublicKey(const Name& keyName, KeyType keyType, const PublicKey& publicKeyDer);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070040
Alexander Afanasyeve64788e2014-01-05 22:38:21 -080041 virtual ptr_lib::shared_ptr<PublicKey>
Yingdi Yu87581582014-01-14 14:28:39 -080042 getPublicKey(const Name& keyName);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070043
Jeff Thompson6c314bc2013-09-23 18:09:38 -070044 virtual bool
45 doesCertificateExist(const Name& certificateName);
46
Jeff Thompson6c314bc2013-09-23 18:09:38 -070047 virtual void
Jeff Thompsonc69163b2013-10-12 13:49:50 -070048 addCertificate(const IdentityCertificate& certificate);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070049
Alexander Afanasyeve64788e2014-01-05 22:38:21 -080050 virtual ptr_lib::shared_ptr<IdentityCertificate>
Yingdi Yu88663af2014-01-15 15:21:38 -080051 getCertificate(const Name &certificateName);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070052
53
Jeff Thompson6c314bc2013-09-23 18:09:38 -070054 virtual Name
55 getDefaultIdentity();
56
Jeff Thompson6c314bc2013-09-23 18:09:38 -070057 virtual Name
58 getDefaultKeyNameForIdentity(const Name& identityName);
59
Jeff Thompson6c314bc2013-09-23 18:09:38 -070060 virtual Name
61 getDefaultCertificateNameForKey(const Name& keyName);
62
Yingdi Yu28fd32f2014-01-28 19:03:03 -080063 virtual void
64 getAllIdentities(std::vector<Name> &nameList, bool isDefault);
Alexander Afanasyev0c632112013-12-30 15:59:31 -080065
Yingdi Yu28fd32f2014-01-28 19:03:03 -080066 virtual void
67 getAllKeyNames(std::vector<Name> &nameList, bool isDefault);
Alexander Afanasyev0c632112013-12-30 15:59:31 -080068
Yingdi Yu28fd32f2014-01-28 19:03:03 -080069 virtual void
70 getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name> &nameList, bool isDefault);
Alexander Afanasyev0c632112013-12-30 15:59:31 -080071
Yingdi Yu28fd32f2014-01-28 19:03:03 -080072 virtual void
73 getAllCertificateNames(std::vector<Name> &nameList, bool isDefault);
Alexander Afanasyev0c632112013-12-30 15:59:31 -080074
Yingdi Yu28fd32f2014-01-28 19:03:03 -080075 virtual void
76 getAllCertificateNamesOfKey(const Name& keyName, std::vector<Name> &nameList, bool isDefault);
Yingdi Yu87581582014-01-14 14:28:39 -080077
78protected:
Yingdi Yu87581582014-01-14 14:28:39 -080079 virtual void
80 setDefaultIdentityInternal(const Name& identityName);
81
Yingdi Yu87581582014-01-14 14:28:39 -080082 virtual void
83 setDefaultKeyNameForIdentityInternal(const Name& keyName);
84
Yingdi Yu87581582014-01-14 14:28:39 -080085 virtual void
86 setDefaultCertificateNameForKeyInternal(const Name& certificateName);
87
Yingdi Yu28fd32f2014-01-28 19:03:03 -080088 virtual void
89 deleteCertificateInfo(const Name &certificateName);
90
Yingdi Yu28fd32f2014-01-28 19:03:03 -080091 virtual void
92 deletePublicKeyInfo(const Name &keyName);
93
Yingdi Yu28fd32f2014-01-28 19:03:03 -080094 virtual void
95 deleteIdentityInfo(const Name &identity);
96
Jeff Thompson81842272013-09-25 16:12:33 -070097
98private:
Jeff Thompson61805e92013-10-23 15:19:39 -070099 class KeyRecord {
100 public:
Alexander Afanasyeve64788e2014-01-05 22:38:21 -0800101 KeyRecord(KeyType keyType, const PublicKey &key)
102 : keyType_(keyType), key_(key)
Jeff Thompson61805e92013-10-23 15:19:39 -0700103 {
104 }
105
106 const KeyType getKeyType() const { return keyType_; }
107
Alexander Afanasyeve64788e2014-01-05 22:38:21 -0800108 const PublicKey& getKey() { return key_; }
Jeff Thompson61805e92013-10-23 15:19:39 -0700109
110 private:
Alexander Afanasyeve64788e2014-01-05 22:38:21 -0800111 KeyType keyType_;
112 PublicKey key_;
Jeff Thompson61805e92013-10-23 15:19:39 -0700113 };
114
Jeff Thompson81842272013-09-25 16:12:33 -0700115 std::vector<std::string> identityStore_; /**< A list of name URI. */
116 std::string defaultIdentity_; /**< The default identity in identityStore_, or "" if not defined. */
Alexander Afanasyeve64788e2014-01-05 22:38:21 -0800117 Name defaultKeyName_;
118 Name defaultCert_;
119
120 typedef std::map< std::string, ptr_lib::shared_ptr<KeyRecord> > KeyStore; /**< The map key is the keyName.toUri() */
121 typedef std::map< std::string, ptr_lib::shared_ptr<IdentityCertificate> > CertificateStore; /**< The map key is the certificateName.toUri() */
122
123 KeyStore keyStore_;
124 CertificateStore certificateStore_;
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700125};
126
Yingdi Yufc40d872014-02-18 12:56:04 -0800127} // namespace ndn
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700128
Yingdi Yufc40d872014-02-18 12:56:04 -0800129#endif //NDN_SECURITY_SEC_PUBLIC_INFO_MEMORY_HPP