blob: 664b978be4859728b36cef1fd6e42aa1d3733d40 [file] [log] [blame]
Jeff Thompson2747dc02013-10-04 19:11:34 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07003 * Copyright (c) 2013-2014, Regents of the University of California.
4 * All rights reserved.
5 *
6 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
7 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
8 *
9 * This file licensed under New BSD License. See COPYING for detailed information about
10 * ndn-cxx library copyright, permissions, and redistribution restrictions.
11 *
12 * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
Jeff Thompson2747dc02013-10-04 19:11:34 -070013 */
14
Yingdi Yufc40d872014-02-18 12:56:04 -080015#ifndef NDN_SECURITY_SEC_TPM_OSX_HPP
16#define NDN_SECURITY_SEC_TPM_OSX_HPP
Jeff Thompson2747dc02013-10-04 19:11:34 -070017
Yingdi Yu4f324632014-01-15 18:10:03 -080018#include "../common.hpp"
Yingdi Yu87581582014-01-14 14:28:39 -080019#include "sec-tpm.hpp"
Jeff Thompson2747dc02013-10-04 19:11:34 -070020
Yingdi Yufc40d872014-02-18 12:56:04 -080021namespace ndn {
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070022
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070023class SecTpmOsx : public SecTpm
24{
Jeff Thompson2747dc02013-10-04 19:11:34 -070025public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070026 class Error : public SecTpm::Error
27 {
28 public:
29 explicit
30 Error(const std::string& what)
31 : SecTpm::Error(what)
32 {
33 }
34 };
Yingdi Yu87581582014-01-14 14:28:39 -080035
Yingdi Yu2b2b4792014-02-04 16:27:07 -080036 SecTpmOsx();
Jeff Thompson2747dc02013-10-04 19:11:34 -070037
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070038 virtual
Yingdi Yu87581582014-01-14 14:28:39 -080039 ~SecTpmOsx();
Jeff Thompson2747dc02013-10-04 19:11:34 -070040
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080041
Yingdi Yube4150e2014-02-18 13:02:46 -080042 /******************************
43 * From TrustedPlatformModule *
44 ******************************/
Jeff Thompson2747dc02013-10-04 19:11:34 -070045
Yingdi Yu28fd32f2014-01-28 19:03:03 -080046 virtual void
Yingdi Yube4150e2014-02-18 13:02:46 -080047 setTpmPassword(const uint8_t* password, size_t passwordLength);
48
49 virtual void
50 resetTpmPassword();
51
52 virtual void
53 setInTerminal(bool inTerminal);
54
55 virtual bool
56 getInTerminal();
57
58 virtual bool
59 locked();
60
Yingdi Yu2e57a582014-02-20 23:34:43 -080061 virtual bool
Yingdi Yube4150e2014-02-18 13:02:46 -080062 unlockTpm(const char* password, size_t passwordLength, bool usePassword);
63
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070064 virtual void
Yingdi Yube4150e2014-02-18 13:02:46 -080065 generateKeyPairInTpm(const Name& keyName, KeyType keyType, int keySize)
66 {
67 generateKeyPairInTpmInternal(keyName, keyType, keySize, false);
68 }
69
70 virtual void
71 deleteKeyPairInTpm(const Name& keyName)
72 {
73 deleteKeyPairInTpmInternal(keyName, false);
74 }
Yingdi Yu28fd32f2014-01-28 19:03:03 -080075
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070076 virtual shared_ptr<PublicKey>
Yingdi Yu87581582014-01-14 14:28:39 -080077 getPublicKeyFromTpm(const Name& keyName);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070078
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080079 virtual Block
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070080 signInTpm(const uint8_t* data, size_t dataLength,
81 const Name& keyName, DigestAlgorithm digestAlgorithm)
Yingdi Yube4150e2014-02-18 13:02:46 -080082 {
83 return signInTpmInternal(data, dataLength, keyName, digestAlgorithm, false);
84 }
Yingdi Yufc40d872014-02-18 12:56:04 -080085
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070086 virtual ConstBufferPtr
Yingdi Yufc40d872014-02-18 12:56:04 -080087 decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
Jeff Thompson2747dc02013-10-04 19:11:34 -070088
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080089 virtual ConstBufferPtr
Yingdi Yufc40d872014-02-18 12:56:04 -080090 encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
Jeff Thompson2747dc02013-10-04 19:11:34 -070091
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070092 virtual void
Yingdi Yub4bb85a2014-01-16 10:11:04 -080093 generateSymmetricKeyInTpm(const Name& keyName, KeyType keyType, int keySize);
Jeff Thompson2747dc02013-10-04 19:11:34 -070094
Jeff Thompson2747dc02013-10-04 19:11:34 -070095 virtual bool
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070096 doesKeyExistInTpm(const Name& keyName, KeyClass keyClass);
Yingdi Yu4b752752014-02-18 12:24:03 -080097
98 virtual bool
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070099 generateRandomBlock(uint8_t* res, size_t size);
Jeff Thompson2747dc02013-10-04 19:11:34 -0700100
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700101 virtual void
Yingdi Yu2e57a582014-02-20 23:34:43 -0800102 addAppToACL(const Name& keyName, KeyClass keyClass, const std::string& appPath, AclType acl);
Jeff Thompson2747dc02013-10-04 19:11:34 -0700103
Yingdi Yu8dceb1d2014-02-18 12:45:10 -0800104protected:
105 /******************************
106 * From TrustedPlatformModule *
107 ******************************/
108 virtual ConstBufferPtr
Yingdi Yu5e96e002014-04-23 18:32:15 -0700109 exportPrivateKeyPkcs8FromTpm(const Name& keyName)
Yingdi Yube4150e2014-02-18 13:02:46 -0800110 {
Yingdi Yu5e96e002014-04-23 18:32:15 -0700111 return exportPrivateKeyPkcs8FromTpmInternal(keyName, false);
Yingdi Yube4150e2014-02-18 13:02:46 -0800112 }
Jeff Thompson2747dc02013-10-04 19:11:34 -0700113
Yingdi Yu8dceb1d2014-02-18 12:45:10 -0800114 virtual bool
Yingdi Yu5e96e002014-04-23 18:32:15 -0700115 importPrivateKeyPkcs8IntoTpm(const Name& keyName, const uint8_t* buf, size_t size)
Yingdi Yube4150e2014-02-18 13:02:46 -0800116 {
Yingdi Yu5e96e002014-04-23 18:32:15 -0700117 return importPrivateKeyPkcs8IntoTpmInternal(keyName, buf, size, false);
Yingdi Yube4150e2014-02-18 13:02:46 -0800118 }
Yingdi Yu8dceb1d2014-02-18 12:45:10 -0800119
120 virtual bool
121 importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
Yingdi Yube4150e2014-02-18 13:02:46 -0800122
123 /******************************
124 * OSX-specifics *
125 ******************************/
126 void
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700127 generateKeyPairInTpmInternal(const Name& keyName, KeyType keyType, int keySize, bool needRetry);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700128
Yingdi Yube4150e2014-02-18 13:02:46 -0800129 void
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700130 deleteKeyPairInTpmInternal(const Name& keyName, bool needRetry);
Yingdi Yube4150e2014-02-18 13:02:46 -0800131
132 ConstBufferPtr
Yingdi Yu5e96e002014-04-23 18:32:15 -0700133 exportPrivateKeyPkcs8FromTpmInternal(const Name& keyName, bool needRetry);
Yingdi Yube4150e2014-02-18 13:02:46 -0800134
135 bool
Yingdi Yu5e96e002014-04-23 18:32:15 -0700136 importPrivateKeyPkcs8IntoTpmInternal(const Name& keyName,
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700137 const uint8_t* buf, size_t size,
138 bool needRetry);
Yingdi Yube4150e2014-02-18 13:02:46 -0800139
140 Block
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700141 signInTpmInternal(const uint8_t* data, size_t dataLength,
142 const Name& keyName, DigestAlgorithm digestAlgorithm,
143 bool needRetry);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700144
Yingdi Yu8dceb1d2014-02-18 12:45:10 -0800145private:
Alexander Afanasyev04b22a92014-01-05 22:40:17 -0800146 class Impl;
Yingdi Yu4b752752014-02-18 12:24:03 -0800147 shared_ptr<Impl> m_impl;
Jeff Thompson2747dc02013-10-04 19:11:34 -0700148};
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700149
Alexander Afanasyev19508852014-01-29 01:01:51 -0800150} // namespace ndn
Jeff Thompson2747dc02013-10-04 19:11:34 -0700151
Yingdi Yufc40d872014-02-18 12:56:04 -0800152#endif // NDN_SECURITY_SEC_TPM_OSX_HPP