blob: 58d85295ba0a0cd1d61cbe358984835fd08f5bb5 [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:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070021 class Error : public SecPublicInfo::Error
22 {
23 public:
24 explicit
25 Error(const std::string& what)
26 : SecPublicInfo::Error(what)
27 {
28 }
29 };
Alexander Afanasyeve64788e2014-01-05 22:38:21 -080030
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080031 virtual
Yingdi Yu87581582014-01-14 14:28:39 -080032 ~SecPublicInfoMemory();
Jeff Thompson6c314bc2013-09-23 18:09:38 -070033
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080034 virtual bool
Jeff Thompson6c314bc2013-09-23 18:09:38 -070035 doesIdentityExist(const Name& identityName);
36
Jeff Thompson6c314bc2013-09-23 18:09:38 -070037 virtual void
38 addIdentity(const Name& identityName);
39
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080040 virtual bool
Jeff Thompson6c314bc2013-09-23 18:09:38 -070041 revokeIdentity();
42
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070043 virtual bool
Yingdi Yu87581582014-01-14 14:28:39 -080044 doesPublicKeyExist(const Name& keyName);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070045
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070046 virtual void
Yingdi Yu87581582014-01-14 14:28:39 -080047 addPublicKey(const Name& keyName, KeyType keyType, const PublicKey& publicKeyDer);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070048
Alexander Afanasyeve64788e2014-01-05 22:38:21 -080049 virtual ptr_lib::shared_ptr<PublicKey>
Yingdi Yu87581582014-01-14 14:28:39 -080050 getPublicKey(const Name& keyName);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070051
Jeff Thompson6c314bc2013-09-23 18:09:38 -070052 virtual bool
53 doesCertificateExist(const Name& certificateName);
54
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070055 virtual void
Jeff Thompsonc69163b2013-10-12 13:49:50 -070056 addCertificate(const IdentityCertificate& certificate);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070057
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070058 virtual ptr_lib::shared_ptr<IdentityCertificate>
59 getCertificate(const Name& certificateName);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070060
61
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)
Alexander Afanasyeve64788e2014-01-05 22:38:21 -0800110 : keyType_(keyType), key_(key)
Jeff Thompson61805e92013-10-23 15:19:39 -0700111 {
112 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700113
Jeff Thompson61805e92013-10-23 15:19:39 -0700114 const KeyType getKeyType() const { return keyType_; }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700115
Alexander Afanasyeve64788e2014-01-05 22:38:21 -0800116 const PublicKey& getKey() { return key_; }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700117
Jeff Thompson61805e92013-10-23 15:19:39 -0700118 private:
Alexander Afanasyeve64788e2014-01-05 22:38:21 -0800119 KeyType keyType_;
120 PublicKey key_;
Jeff Thompson61805e92013-10-23 15:19:39 -0700121 };
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700122
Jeff Thompson81842272013-09-25 16:12:33 -0700123 std::vector<std::string> identityStore_; /**< A list of name URI. */
124 std::string defaultIdentity_; /**< The default identity in identityStore_, or "" if not defined. */
Alexander Afanasyeve64788e2014-01-05 22:38:21 -0800125 Name defaultKeyName_;
126 Name defaultCert_;
127
128 typedef std::map< std::string, ptr_lib::shared_ptr<KeyRecord> > KeyStore; /**< The map key is the keyName.toUri() */
129 typedef std::map< std::string, ptr_lib::shared_ptr<IdentityCertificate> > CertificateStore; /**< The map key is the certificateName.toUri() */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700130
131 KeyStore keyStore_;
132 CertificateStore certificateStore_;
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700133};
134
Yingdi Yufc40d872014-02-18 12:56:04 -0800135} // namespace ndn
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700136
Yingdi Yufc40d872014-02-18 12:56:04 -0800137#endif //NDN_SECURITY_SEC_PUBLIC_INFO_MEMORY_HPP