blob: aaaa4ce3dc1b7a140c62084c3355fecb971a3be7 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Yingdi Yu2d9c50f2014-01-21 18:25:00 -08002/**
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -08003 * Copyright (c) 2013-2017 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -070020 *
21 * @author Xingyu Ma <http://www.linkedin.com/pub/xingyu-ma/1a/384/5a8>
22 * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
23 * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080024 */
25
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -080026#ifndef NDN_SECURITY_V1_SEC_TPM_FILE_HPP
27#define NDN_SECURITY_V1_SEC_TPM_FILE_HPP
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080028
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -080029#include "../../common.hpp"
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080030
31#include "sec-tpm.hpp"
32
Yingdi Yufc40d872014-02-18 12:56:04 -080033namespace ndn {
Alexander Afanasyev2fa59392016-07-29 17:24:23 -070034namespace security {
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -080035namespace v1 {
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080036
37class SecTpmFile : public SecTpm
38{
39public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070040 class Error : public SecTpm::Error
41 {
42 public:
43 explicit
44 Error(const std::string& what)
45 : SecTpm::Error(what)
46 {
47 }
48 };
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080049
Alexander Afanasyeva4297a62014-06-19 13:29:34 -070050 explicit
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070051 SecTpmFile(const std::string& dir = "");
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080052
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080053 virtual
Yingdi Yu41546342014-11-30 23:37:53 -080054 ~SecTpmFile();
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080055
Yingdi Yube4150e2014-02-18 13:02:46 -080056 virtual void
57 setTpmPassword(const uint8_t* password, size_t passwordLength)
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070058 {
59 }
Yingdi Yube4150e2014-02-18 13:02:46 -080060
61 virtual void
62 resetTpmPassword()
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070063 {
64 }
Yingdi Yube4150e2014-02-18 13:02:46 -080065
66 virtual void
67 setInTerminal(bool inTerminal)
68 {
69 m_inTerminal = inTerminal;
70 }
71
72 virtual bool
Alexander Afanasyev770827c2014-05-13 17:42:55 -070073 getInTerminal() const
Yingdi Yube4150e2014-02-18 13:02:46 -080074 {
75 return m_inTerminal;
76 }
77
78 virtual bool
Yingdi Yuf56c68f2014-04-24 21:50:13 -070079 isLocked()
Yingdi Yube4150e2014-02-18 13:02:46 -080080 {
81 return false;
82 }
83
Yingdi Yu2e57a582014-02-20 23:34:43 -080084 virtual bool
Yingdi Yube4150e2014-02-18 13:02:46 -080085 unlockTpm(const char* password, size_t passwordLength, bool usePassword)
Yingdi Yu2e57a582014-02-20 23:34:43 -080086 {
Yingdi Yuf56c68f2014-04-24 21:50:13 -070087 return !isLocked();
Yingdi Yu2e57a582014-02-20 23:34:43 -080088 }
Yingdi Yube4150e2014-02-18 13:02:46 -080089
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080090 virtual void
Yingdi Yu7036ce22014-06-19 18:53:37 -070091 generateKeyPairInTpm(const Name& keyName, const KeyParams& params);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080092
Yingdi Yu28fd32f2014-01-28 19:03:03 -080093 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070094 deleteKeyPairInTpm(const Name& keyName);
Yingdi Yu28fd32f2014-01-28 19:03:03 -080095
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -080096 virtual shared_ptr<PublicKey>
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070097 getPublicKeyFromTpm(const Name& keyName);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080098
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080099 virtual Block
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700100 signInTpm(const uint8_t* data, size_t dataLength,
101 const Name& keyName, DigestAlgorithm digestAlgorithm);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -0800102
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700103 virtual ConstBufferPtr
Yingdi Yufc40d872014-02-18 12:56:04 -0800104 decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -0800105
Yingdi Yu2d9c50f2014-01-21 18:25:00 -0800106 virtual ConstBufferPtr
Yingdi Yufc40d872014-02-18 12:56:04 -0800107 encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -0800108
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700109 virtual void
Yingdi Yu7036ce22014-06-19 18:53:37 -0700110 generateSymmetricKeyInTpm(const Name& keyName, const KeyParams& params);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -0800111
Yingdi Yu2d9c50f2014-01-21 18:25:00 -0800112 virtual bool
113 doesKeyExistInTpm(const Name& keyName, KeyClass keyClass);
114
Yingdi Yu4b752752014-02-18 12:24:03 -0800115 virtual bool
116 generateRandomBlock(uint8_t* res, size_t size);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -0800117
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700118 virtual void
Yingdi Yuf56c68f2014-04-24 21:50:13 -0700119 addAppToAcl(const Name& keyName, KeyClass keyClass, const std::string& appPath, AclType acl)
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700120 {
121 }
Yingdi Yu2e57a582014-02-20 23:34:43 -0800122
Yingdi Yu8dceb1d2014-02-18 12:45:10 -0800123protected:
Yingdi Yu7036ce22014-06-19 18:53:37 -0700124 ////////////////////////////////
125 // From TrustedPlatformModule //
126 ////////////////////////////////
Yingdi Yu41546342014-11-30 23:37:53 -0800127 virtual std::string
128 getScheme();
Yingdi Yu7036ce22014-06-19 18:53:37 -0700129
Yingdi Yu8dceb1d2014-02-18 12:45:10 -0800130 virtual ConstBufferPtr
Yingdi Yu5e96e002014-04-23 18:32:15 -0700131 exportPrivateKeyPkcs8FromTpm(const Name& keyName);
Yingdi Yu8dceb1d2014-02-18 12:45:10 -0800132
133 virtual bool
Yingdi Yu5e96e002014-04-23 18:32:15 -0700134 importPrivateKeyPkcs8IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700135
Yingdi Yu8dceb1d2014-02-18 12:45:10 -0800136 virtual bool
137 importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
138
Yingdi Yu41546342014-11-30 23:37:53 -0800139public:
140 static const std::string SCHEME;
141
Yingdi Yu2d9c50f2014-01-21 18:25:00 -0800142private:
143 class Impl;
Yingdi Yu41546342014-11-30 23:37:53 -0800144 unique_ptr<Impl> m_impl;
Yingdi Yube4150e2014-02-18 13:02:46 -0800145 bool m_inTerminal;
Yingdi Yu2d9c50f2014-01-21 18:25:00 -0800146};
Yingdi Yu4b752752014-02-18 12:24:03 -0800147
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -0800148} // namespace v1
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700149} // namespace security
Yingdi Yufc40d872014-02-18 12:56:04 -0800150} // namespace ndn
Yingdi Yu2d9c50f2014-01-21 18:25:00 -0800151
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -0800152#endif // NDN_SECURITY_V1_SEC_TPM_FILE_HPP