v1/sec-tpm-file.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #ifndef NDN_SECURITY_V1_SEC_TPM_FILE_HPP
27 #define NDN_SECURITY_V1_SEC_TPM_FILE_HPP
28 
29 #include "../../common.hpp"
30 
31 #include "sec-tpm.hpp"
32 
33 namespace ndn {
34 namespace security {
35 namespace v1 {
36 
37 class SecTpmFile : public SecTpm
38 {
39 public:
40  class Error : public SecTpm::Error
41  {
42  public:
43  explicit
44  Error(const std::string& what)
45  : SecTpm::Error(what)
46  {
47  }
48  };
49 
50  explicit
51  SecTpmFile(const std::string& dir = "");
52 
53  virtual
54  ~SecTpmFile();
55 
56  virtual void
57  setTpmPassword(const uint8_t* password, size_t passwordLength)
58  {
59  }
60 
61  virtual void
63  {
64  }
65 
66  virtual void
67  setInTerminal(bool inTerminal)
68  {
69  m_inTerminal = inTerminal;
70  }
71 
72  virtual bool
73  getInTerminal() const
74  {
75  return m_inTerminal;
76  }
77 
78  virtual bool
80  {
81  return false;
82  }
83 
84  virtual bool
85  unlockTpm(const char* password, size_t passwordLength, bool usePassword)
86  {
87  return !isLocked();
88  }
89 
90  virtual void
91  generateKeyPairInTpm(const Name& keyName, const KeyParams& params);
92 
93  virtual void
94  deleteKeyPairInTpm(const Name& keyName);
95 
96  virtual shared_ptr<PublicKey>
97  getPublicKeyFromTpm(const Name& keyName);
98 
99  virtual Block
100  signInTpm(const uint8_t* data, size_t dataLength,
101  const Name& keyName, DigestAlgorithm digestAlgorithm);
102 
103  virtual ConstBufferPtr
104  decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
105 
106  virtual ConstBufferPtr
107  encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
108 
109  virtual void
110  generateSymmetricKeyInTpm(const Name& keyName, const KeyParams& params);
111 
112  virtual bool
113  doesKeyExistInTpm(const Name& keyName, KeyClass keyClass);
114 
115  virtual bool
116  generateRandomBlock(uint8_t* res, size_t size);
117 
118  virtual void
119  addAppToAcl(const Name& keyName, KeyClass keyClass, const std::string& appPath, AclType acl)
120  {
121  }
122 
123 protected:
125  // From TrustedPlatformModule //
127  virtual std::string
128  getScheme();
129 
130  virtual ConstBufferPtr
131  exportPrivateKeyPkcs8FromTpm(const Name& keyName);
132 
133  virtual bool
134  importPrivateKeyPkcs8IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
135 
136  virtual bool
137  importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
138 
139 public:
140  static const std::string SCHEME;
141 
142 private:
143  class Impl;
144  unique_ptr<Impl> m_impl;
145  bool m_inTerminal;
146 };
147 
148 } // namespace v1
149 } // namespace security
150 } // namespace ndn
151 
152 #endif // NDN_SECURITY_V1_SEC_TPM_FILE_HPP
Copyright (c) 2013-2017 Regents of the University of California.
Definition: common.hpp:75
virtual ConstBufferPtr decryptInTpm(const uint8_t *data, size_t dataLength, const Name &keyName, bool isSymmetric)
Decrypt data.
virtual ConstBufferPtr exportPrivateKeyPkcs8FromTpm(const Name &keyName)
Export a private key in PKCS#8 format.
virtual void generateSymmetricKeyInTpm(const Name &keyName, const KeyParams &params)
Generate a symmetric key.
virtual bool unlockTpm(const char *password, size_t passwordLength, bool usePassword)
Unlock the TPM.
virtual shared_ptr< PublicKey > getPublicKeyFromTpm(const Name &keyName)
Get a public key.
virtual void resetTpmPassword()
reset password of TPM
Represents a TLV element of NDN packet format.
Definition: block.hpp:42
virtual void setInTerminal(bool inTerminal)
Set inTerminal flag to inTerminal.
virtual Block signInTpm(const uint8_t *data, size_t dataLength, const Name &keyName, DigestAlgorithm digestAlgorithm)
Sign data.
virtual bool getInTerminal() const
Get value of inTerminal flag.
virtual bool isLocked()
Check if TPM is locked.
virtual bool importPublicKeyPkcs1IntoTpm(const Name &keyName, const uint8_t *buf, size_t size)
Import a public key in PKCS#1 formatted buffer of size bufferSize.
virtual void setTpmPassword(const uint8_t *password, size_t passwordLength)
set password of TPM
virtual bool importPrivateKeyPkcs8IntoTpm(const Name &keyName, const uint8_t *buf, size_t size)
Import a private key from PKCS#8 formatted buffer of size bufferSize.
virtual void addAppToAcl(const Name &keyName, KeyClass keyClass, const std::string &appPath, AclType acl)
Add the application into the ACL of a particular key.
virtual bool doesKeyExistInTpm(const Name &keyName, KeyClass keyClass)
Check if a particular key exists.
static const std::string SCHEME
Represents an absolute name.
Definition: name.hpp:42
virtual void generateKeyPairInTpm(const Name &keyName, const KeyParams &params)
Generate a pair of asymmetric keys.
virtual bool generateRandomBlock(uint8_t *res, size_t size)
Generate a random block.
virtual ConstBufferPtr encryptInTpm(const uint8_t *data, size_t dataLength, const Name &keyName, bool isSymmetric)
Encrypt data.
SecTpm is the base class of the TPM classes.
Definition: v1/sec-tpm.hpp:43
virtual std::string getScheme()
SecTpmFile(const std::string &dir="")
Base class of key parameters.
Definition: key-params.hpp:36
virtual void deleteKeyPairInTpm(const Name &keyName)
Delete a key pair of asymmetric keys.
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:33