blob: d6637ef6900f9d9f8b26acbf55d2326a153ecfdc [file] [log] [blame]
Jeff Thompson2747dc02013-10-04 19:11:34 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Yingdi Yu <yingdi@cs.ucla.edu>
5 * See COPYING for copyright and distribution information.
6 */
7
Yingdi Yufc40d872014-02-18 12:56:04 -08008#ifndef NDN_SECURITY_SEC_TPM_OSX_HPP
9#define NDN_SECURITY_SEC_TPM_OSX_HPP
Jeff Thompson2747dc02013-10-04 19:11:34 -070010
Yingdi Yu4f324632014-01-15 18:10:03 -080011#include "../common.hpp"
Yingdi Yu87581582014-01-14 14:28:39 -080012#include "sec-tpm.hpp"
Jeff Thompson2747dc02013-10-04 19:11:34 -070013
Yingdi Yufc40d872014-02-18 12:56:04 -080014namespace ndn {
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070015
Yingdi Yu87581582014-01-14 14:28:39 -080016class SecTpmOsx : public SecTpm {
Jeff Thompson2747dc02013-10-04 19:11:34 -070017public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070018 class Error : public SecTpm::Error
19 {
20 public:
21 explicit
22 Error(const std::string& what)
23 : SecTpm::Error(what)
24 {
25 }
26 };
Yingdi Yu87581582014-01-14 14:28:39 -080027
Yingdi Yu2b2b4792014-02-04 16:27:07 -080028 SecTpmOsx();
Jeff Thompson2747dc02013-10-04 19:11:34 -070029
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070030 virtual
Yingdi Yu87581582014-01-14 14:28:39 -080031 ~SecTpmOsx();
Jeff Thompson2747dc02013-10-04 19:11:34 -070032
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080033
Yingdi Yube4150e2014-02-18 13:02:46 -080034 /******************************
35 * From TrustedPlatformModule *
36 ******************************/
Jeff Thompson2747dc02013-10-04 19:11:34 -070037
Yingdi Yu28fd32f2014-01-28 19:03:03 -080038 virtual void
Yingdi Yube4150e2014-02-18 13:02:46 -080039 setTpmPassword(const uint8_t* password, size_t passwordLength);
40
41 virtual void
42 resetTpmPassword();
43
44 virtual void
45 setInTerminal(bool inTerminal);
46
47 virtual bool
48 getInTerminal();
49
50 virtual bool
51 locked();
52
Yingdi Yu2e57a582014-02-20 23:34:43 -080053 virtual bool
Yingdi Yube4150e2014-02-18 13:02:46 -080054 unlockTpm(const char* password, size_t passwordLength, bool usePassword);
55
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070056 virtual void
Yingdi Yube4150e2014-02-18 13:02:46 -080057 generateKeyPairInTpm(const Name& keyName, KeyType keyType, int keySize)
58 {
59 generateKeyPairInTpmInternal(keyName, keyType, keySize, false);
60 }
61
62 virtual void
63 deleteKeyPairInTpm(const Name& keyName)
64 {
65 deleteKeyPairInTpmInternal(keyName, false);
66 }
Yingdi Yu28fd32f2014-01-28 19:03:03 -080067
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070068 virtual shared_ptr<PublicKey>
Yingdi Yu87581582014-01-14 14:28:39 -080069 getPublicKeyFromTpm(const Name& keyName);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070070
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080071 virtual Block
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070072 signInTpm(const uint8_t* data, size_t dataLength,
73 const Name& keyName, DigestAlgorithm digestAlgorithm)
Yingdi Yube4150e2014-02-18 13:02:46 -080074 {
75 return signInTpmInternal(data, dataLength, keyName, digestAlgorithm, false);
76 }
Yingdi Yufc40d872014-02-18 12:56:04 -080077
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070078 virtual ConstBufferPtr
Yingdi Yufc40d872014-02-18 12:56:04 -080079 decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
Jeff Thompson2747dc02013-10-04 19:11:34 -070080
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080081 virtual ConstBufferPtr
Yingdi Yufc40d872014-02-18 12:56:04 -080082 encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
Jeff Thompson2747dc02013-10-04 19:11:34 -070083
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070084 virtual void
Yingdi Yub4bb85a2014-01-16 10:11:04 -080085 generateSymmetricKeyInTpm(const Name& keyName, KeyType keyType, int keySize);
Jeff Thompson2747dc02013-10-04 19:11:34 -070086
Jeff Thompson2747dc02013-10-04 19:11:34 -070087 virtual bool
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070088 doesKeyExistInTpm(const Name& keyName, KeyClass keyClass);
Yingdi Yu4b752752014-02-18 12:24:03 -080089
90 virtual bool
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070091 generateRandomBlock(uint8_t* res, size_t size);
Jeff Thompson2747dc02013-10-04 19:11:34 -070092
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070093 virtual void
Yingdi Yu2e57a582014-02-20 23:34:43 -080094 addAppToACL(const Name& keyName, KeyClass keyClass, const std::string& appPath, AclType acl);
Jeff Thompson2747dc02013-10-04 19:11:34 -070095
Yingdi Yu8dceb1d2014-02-18 12:45:10 -080096protected:
97 /******************************
98 * From TrustedPlatformModule *
99 ******************************/
100 virtual ConstBufferPtr
Yingdi Yube4150e2014-02-18 13:02:46 -0800101 exportPrivateKeyPkcs1FromTpm(const Name& keyName)
102 {
103 return exportPrivateKeyPkcs1FromTpmInternal(keyName, false);
104 }
Jeff Thompson2747dc02013-10-04 19:11:34 -0700105
Yingdi Yu8dceb1d2014-02-18 12:45:10 -0800106 virtual bool
Yingdi Yube4150e2014-02-18 13:02:46 -0800107 importPrivateKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size)
108 {
109 return importPrivateKeyPkcs1IntoTpmInternal(keyName, buf, size, false);
110 }
Yingdi Yu8dceb1d2014-02-18 12:45:10 -0800111
112 virtual bool
113 importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
Yingdi Yube4150e2014-02-18 13:02:46 -0800114
115 /******************************
116 * OSX-specifics *
117 ******************************/
118 void
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700119 generateKeyPairInTpmInternal(const Name& keyName, KeyType keyType, int keySize, bool needRetry);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700120
Yingdi Yube4150e2014-02-18 13:02:46 -0800121 void
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700122 deleteKeyPairInTpmInternal(const Name& keyName, bool needRetry);
Yingdi Yube4150e2014-02-18 13:02:46 -0800123
124 ConstBufferPtr
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700125 exportPrivateKeyPkcs1FromTpmInternal(const Name& keyName, bool needRetry);
Yingdi Yube4150e2014-02-18 13:02:46 -0800126
127 bool
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700128 importPrivateKeyPkcs1IntoTpmInternal(const Name& keyName,
129 const uint8_t* buf, size_t size,
130 bool needRetry);
Yingdi Yube4150e2014-02-18 13:02:46 -0800131
132 Block
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700133 signInTpmInternal(const uint8_t* data, size_t dataLength,
134 const Name& keyName, DigestAlgorithm digestAlgorithm,
135 bool needRetry);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700136
Yingdi Yu8dceb1d2014-02-18 12:45:10 -0800137private:
Alexander Afanasyev04b22a92014-01-05 22:40:17 -0800138 class Impl;
Yingdi Yu4b752752014-02-18 12:24:03 -0800139 shared_ptr<Impl> m_impl;
Jeff Thompson2747dc02013-10-04 19:11:34 -0700140};
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700141
Alexander Afanasyev19508852014-01-29 01:01:51 -0800142} // namespace ndn
Jeff Thompson2747dc02013-10-04 19:11:34 -0700143
Yingdi Yufc40d872014-02-18 12:56:04 -0800144#endif // NDN_SECURITY_SEC_TPM_OSX_HPP