blob: 1a5bd1f60c038cb65df8368a8b0e575b2d2cf5d0 [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
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070016class SecTpmOsx : public SecTpm
17{
Jeff Thompson2747dc02013-10-04 19:11:34 -070018public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070019 class Error : public SecTpm::Error
20 {
21 public:
22 explicit
23 Error(const std::string& what)
24 : SecTpm::Error(what)
25 {
26 }
27 };
Yingdi Yu87581582014-01-14 14:28:39 -080028
Yingdi Yu2b2b4792014-02-04 16:27:07 -080029 SecTpmOsx();
Jeff Thompson2747dc02013-10-04 19:11:34 -070030
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070031 virtual
Yingdi Yu87581582014-01-14 14:28:39 -080032 ~SecTpmOsx();
Jeff Thompson2747dc02013-10-04 19:11:34 -070033
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080034
Yingdi Yube4150e2014-02-18 13:02:46 -080035 /******************************
36 * From TrustedPlatformModule *
37 ******************************/
Jeff Thompson2747dc02013-10-04 19:11:34 -070038
Yingdi Yu28fd32f2014-01-28 19:03:03 -080039 virtual void
Yingdi Yube4150e2014-02-18 13:02:46 -080040 setTpmPassword(const uint8_t* password, size_t passwordLength);
41
42 virtual void
43 resetTpmPassword();
44
45 virtual void
46 setInTerminal(bool inTerminal);
47
48 virtual bool
49 getInTerminal();
50
51 virtual bool
52 locked();
53
Yingdi Yu2e57a582014-02-20 23:34:43 -080054 virtual bool
Yingdi Yube4150e2014-02-18 13:02:46 -080055 unlockTpm(const char* password, size_t passwordLength, bool usePassword);
56
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070057 virtual void
Yingdi Yube4150e2014-02-18 13:02:46 -080058 generateKeyPairInTpm(const Name& keyName, KeyType keyType, int keySize)
59 {
60 generateKeyPairInTpmInternal(keyName, keyType, keySize, false);
61 }
62
63 virtual void
64 deleteKeyPairInTpm(const Name& keyName)
65 {
66 deleteKeyPairInTpmInternal(keyName, false);
67 }
Yingdi Yu28fd32f2014-01-28 19:03:03 -080068
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070069 virtual shared_ptr<PublicKey>
Yingdi Yu87581582014-01-14 14:28:39 -080070 getPublicKeyFromTpm(const Name& keyName);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070071
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080072 virtual Block
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070073 signInTpm(const uint8_t* data, size_t dataLength,
74 const Name& keyName, DigestAlgorithm digestAlgorithm)
Yingdi Yube4150e2014-02-18 13:02:46 -080075 {
76 return signInTpmInternal(data, dataLength, keyName, digestAlgorithm, false);
77 }
Yingdi Yufc40d872014-02-18 12:56:04 -080078
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070079 virtual ConstBufferPtr
Yingdi Yufc40d872014-02-18 12:56:04 -080080 decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
Jeff Thompson2747dc02013-10-04 19:11:34 -070081
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080082 virtual ConstBufferPtr
Yingdi Yufc40d872014-02-18 12:56:04 -080083 encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
Jeff Thompson2747dc02013-10-04 19:11:34 -070084
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070085 virtual void
Yingdi Yub4bb85a2014-01-16 10:11:04 -080086 generateSymmetricKeyInTpm(const Name& keyName, KeyType keyType, int keySize);
Jeff Thompson2747dc02013-10-04 19:11:34 -070087
Jeff Thompson2747dc02013-10-04 19:11:34 -070088 virtual bool
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070089 doesKeyExistInTpm(const Name& keyName, KeyClass keyClass);
Yingdi Yu4b752752014-02-18 12:24:03 -080090
91 virtual bool
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070092 generateRandomBlock(uint8_t* res, size_t size);
Jeff Thompson2747dc02013-10-04 19:11:34 -070093
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070094 virtual void
Yingdi Yu2e57a582014-02-20 23:34:43 -080095 addAppToACL(const Name& keyName, KeyClass keyClass, const std::string& appPath, AclType acl);
Jeff Thompson2747dc02013-10-04 19:11:34 -070096
Yingdi Yu8dceb1d2014-02-18 12:45:10 -080097protected:
98 /******************************
99 * From TrustedPlatformModule *
100 ******************************/
101 virtual ConstBufferPtr
Yingdi Yube4150e2014-02-18 13:02:46 -0800102 exportPrivateKeyPkcs1FromTpm(const Name& keyName)
103 {
104 return exportPrivateKeyPkcs1FromTpmInternal(keyName, false);
105 }
Jeff Thompson2747dc02013-10-04 19:11:34 -0700106
Yingdi Yu8dceb1d2014-02-18 12:45:10 -0800107 virtual bool
Yingdi Yube4150e2014-02-18 13:02:46 -0800108 importPrivateKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size)
109 {
110 return importPrivateKeyPkcs1IntoTpmInternal(keyName, buf, size, false);
111 }
Yingdi Yu8dceb1d2014-02-18 12:45:10 -0800112
113 virtual bool
114 importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
Yingdi Yube4150e2014-02-18 13:02:46 -0800115
116 /******************************
117 * OSX-specifics *
118 ******************************/
119 void
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700120 generateKeyPairInTpmInternal(const Name& keyName, KeyType keyType, int keySize, bool needRetry);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700121
Yingdi Yube4150e2014-02-18 13:02:46 -0800122 void
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700123 deleteKeyPairInTpmInternal(const Name& keyName, bool needRetry);
Yingdi Yube4150e2014-02-18 13:02:46 -0800124
125 ConstBufferPtr
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700126 exportPrivateKeyPkcs1FromTpmInternal(const Name& keyName, bool needRetry);
Yingdi Yube4150e2014-02-18 13:02:46 -0800127
128 bool
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700129 importPrivateKeyPkcs1IntoTpmInternal(const Name& keyName,
130 const uint8_t* buf, size_t size,
131 bool needRetry);
Yingdi Yube4150e2014-02-18 13:02:46 -0800132
133 Block
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700134 signInTpmInternal(const uint8_t* data, size_t dataLength,
135 const Name& keyName, DigestAlgorithm digestAlgorithm,
136 bool needRetry);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700137
Yingdi Yu8dceb1d2014-02-18 12:45:10 -0800138private:
Alexander Afanasyev04b22a92014-01-05 22:40:17 -0800139 class Impl;
Yingdi Yu4b752752014-02-18 12:24:03 -0800140 shared_ptr<Impl> m_impl;
Jeff Thompson2747dc02013-10-04 19:11:34 -0700141};
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700142
Alexander Afanasyev19508852014-01-29 01:01:51 -0800143} // namespace ndn
Jeff Thompson2747dc02013-10-04 19:11:34 -0700144
Yingdi Yufc40d872014-02-18 12:56:04 -0800145#endif // NDN_SECURITY_SEC_TPM_OSX_HPP