blob: 0a7ba27518f123806c97b61c15e0ee158a4056ad [file] [log] [blame]
Yingdi Yu0b60e7a2015-07-16 21:05:11 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventoff3bf2c2017-10-05 00:14:27 -04002/*
Junxiao Shi68b53852018-07-25 13:56:38 -06003 * Copyright (c) 2013-2018 Regents of the University of California.
Yingdi Yu0b60e7a2015-07-16 21:05:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * 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.
20 */
21
22#ifndef NDN_SECURITY_TPM_BACK_END_OSX_HPP
23#define NDN_SECURITY_TPM_BACK_END_OSX_HPP
24
25#include "back-end.hpp"
Yingdi Yu0b60e7a2015-07-16 21:05:11 -070026
Alexander Afanasyev0cf887d2017-03-26 16:58:59 -050027#ifndef NDN_CXX_HAVE_OSX_FRAMEWORKS
Yingdi Yu0b60e7a2015-07-16 21:05:11 -070028#error "This file should not be compiled ..."
29#endif
30
Davide Pesavento5ee8ec02018-09-01 19:06:12 -040031#include "key-ref-osx.hpp"
32
Yingdi Yu0b60e7a2015-07-16 21:05:11 -070033namespace ndn {
34namespace security {
35namespace tpm {
36
37/**
Yingdi Yufe4733a2015-10-22 14:24:12 -070038 * @brief The back-end implementation of TPM based on macOS Keychain Services.
Yingdi Yu0b60e7a2015-07-16 21:05:11 -070039 */
Davide Pesavento5ee8ec02018-09-01 19:06:12 -040040class BackEndOsx final : public BackEnd
Yingdi Yu0b60e7a2015-07-16 21:05:11 -070041{
42public:
Yingdi Yufe4733a2015-10-22 14:24:12 -070043 /**
Davide Pesavento5ee8ec02018-09-01 19:06:12 -040044 * @brief Create TPM backed based on macOS Keychain Services.
45 *
46 * @param location Not used (required by the TPM registration interface).
Yingdi Yufe4733a2015-10-22 14:24:12 -070047 */
48 explicit
49 BackEndOsx(const std::string& location = "");
Yingdi Yu0b60e7a2015-07-16 21:05:11 -070050
Davide Pesavento5ee8ec02018-09-01 19:06:12 -040051 ~BackEndOsx() final;
Yingdi Yu0b60e7a2015-07-16 21:05:11 -070052
Yingdi Yufe4733a2015-10-22 14:24:12 -070053 static const std::string&
54 getScheme();
55
Yingdi Yu0b60e7a2015-07-16 21:05:11 -070056public: // management
Yingdi Yufe4733a2015-10-22 14:24:12 -070057 bool
58 isTerminalMode() const final;
59
Yingdi Yu0b60e7a2015-07-16 21:05:11 -070060 void
Yingdi Yufe4733a2015-10-22 14:24:12 -070061 setTerminalMode(bool isTerminal) const final;
Yingdi Yu0b60e7a2015-07-16 21:05:11 -070062
Yingdi Yu0b60e7a2015-07-16 21:05:11 -070063 bool
Yingdi Yufe4733a2015-10-22 14:24:12 -070064 isTpmLocked() const final;
Yingdi Yu0b60e7a2015-07-16 21:05:11 -070065
Yingdi Yu0b60e7a2015-07-16 21:05:11 -070066 bool
Yingdi Yufe4733a2015-10-22 14:24:12 -070067 unlockTpm(const char* pw, size_t pwLen) const final;
Yingdi Yu0b60e7a2015-07-16 21:05:11 -070068
69public: // crypto transformation
70 /**
71 * @brief Sign @p buf with @p key using @p digestAlgorithm.
72 */
Davide Pesaventoff3bf2c2017-10-05 00:14:27 -040073 static ConstBufferPtr
74 sign(const KeyRefOsx& key, DigestAlgorithm digestAlgorithm, const uint8_t* buf, size_t size);
Yingdi Yu0b60e7a2015-07-16 21:05:11 -070075
Davide Pesaventoff3bf2c2017-10-05 00:14:27 -040076 static ConstBufferPtr
77 decrypt(const KeyRefOsx& key, const uint8_t* cipherText, size_t cipherSize);
Yingdi Yu0b60e7a2015-07-16 21:05:11 -070078
Davide Pesaventoff3bf2c2017-10-05 00:14:27 -040079 static ConstBufferPtr
80 derivePublicKey(const KeyRefOsx& key);
Yingdi Yu0b60e7a2015-07-16 21:05:11 -070081
82private: // inherited from tpm::BackEnd
Yingdi Yu0b60e7a2015-07-16 21:05:11 -070083 bool
84 doHasKey(const Name& keyName) const final;
85
Yingdi Yu0b60e7a2015-07-16 21:05:11 -070086 unique_ptr<KeyHandle>
87 doGetKeyHandle(const Name& keyName) const final;
88
Yingdi Yu0b60e7a2015-07-16 21:05:11 -070089 unique_ptr<KeyHandle>
90 doCreateKey(const Name& identityName, const KeyParams& params) final;
91
Yingdi Yu0b60e7a2015-07-16 21:05:11 -070092 void
93 doDeleteKey(const Name& keyName) final;
94
Yingdi Yu0b60e7a2015-07-16 21:05:11 -070095 ConstBufferPtr
96 doExportKey(const Name& keyName, const char* pw, size_t pwLen) final;
97
Yingdi Yu0b60e7a2015-07-16 21:05:11 -070098 void
99 doImportKey(const Name& keyName, const uint8_t* buf, size_t size, const char* pw, size_t pwLen) final;
100
101private:
102 class Impl;
Davide Pesavento794f6872017-05-15 23:33:38 -0400103 const unique_ptr<Impl> m_impl;
Yingdi Yu0b60e7a2015-07-16 21:05:11 -0700104};
105
106} // namespace tpm
107} // namespace security
108} // namespace ndn
109
110#endif // NDN_SECURITY_TPM_BACK_END_OSX_HPP