blob: 3dc68774c0b8fbbf608e2cbec5ff85d3ddc0c842 [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 Yube4150e2014-02-18 13:02:46 -080072 signInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm)
73 {
74 return signInTpmInternal(data, dataLength, keyName, digestAlgorithm, false);
75 }
Yingdi Yufc40d872014-02-18 12:56:04 -080076
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070077 virtual ConstBufferPtr
Yingdi Yufc40d872014-02-18 12:56:04 -080078 decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
Jeff Thompson2747dc02013-10-04 19:11:34 -070079
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080080 virtual ConstBufferPtr
Yingdi Yufc40d872014-02-18 12:56:04 -080081 encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
Jeff Thompson2747dc02013-10-04 19:11:34 -070082
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070083 virtual void
Yingdi Yub4bb85a2014-01-16 10:11:04 -080084 generateSymmetricKeyInTpm(const Name& keyName, KeyType keyType, int keySize);
Jeff Thompson2747dc02013-10-04 19:11:34 -070085
Jeff Thompson2747dc02013-10-04 19:11:34 -070086 virtual bool
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070087 doesKeyExistInTpm(const Name& keyName, KeyClass keyClass);
Yingdi Yu4b752752014-02-18 12:24:03 -080088
89 virtual bool
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070090 generateRandomBlock(uint8_t* res, size_t size);
Jeff Thompson2747dc02013-10-04 19:11:34 -070091
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070092 virtual void
Yingdi Yu2e57a582014-02-20 23:34:43 -080093 addAppToACL(const Name& keyName, KeyClass keyClass, const std::string& appPath, AclType acl);
Jeff Thompson2747dc02013-10-04 19:11:34 -070094
Yingdi Yu8dceb1d2014-02-18 12:45:10 -080095protected:
96 /******************************
97 * From TrustedPlatformModule *
98 ******************************/
99 virtual ConstBufferPtr
Yingdi Yube4150e2014-02-18 13:02:46 -0800100 exportPrivateKeyPkcs1FromTpm(const Name& keyName)
101 {
102 return exportPrivateKeyPkcs1FromTpmInternal(keyName, false);
103 }
Jeff Thompson2747dc02013-10-04 19:11:34 -0700104
Yingdi Yu8dceb1d2014-02-18 12:45:10 -0800105 virtual bool
Yingdi Yube4150e2014-02-18 13:02:46 -0800106 importPrivateKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size)
107 {
108 return importPrivateKeyPkcs1IntoTpmInternal(keyName, buf, size, false);
109 }
Yingdi Yu8dceb1d2014-02-18 12:45:10 -0800110
111 virtual bool
112 importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
Yingdi Yube4150e2014-02-18 13:02:46 -0800113
114 /******************************
115 * OSX-specifics *
116 ******************************/
117 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700118 generateKeyPairInTpmInternal(const Name& keyName, KeyType keyType, int keySize, bool retry);
119
Yingdi Yube4150e2014-02-18 13:02:46 -0800120 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700121 deleteKeyPairInTpmInternal(const Name& keyName, bool retry);
Yingdi Yube4150e2014-02-18 13:02:46 -0800122
123 ConstBufferPtr
124 exportPrivateKeyPkcs1FromTpmInternal(const Name& keyName, bool retry);
125
126 bool
127 importPrivateKeyPkcs1IntoTpmInternal(const Name& keyName, const uint8_t* buf, size_t size, bool retry);
128
129 Block
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700130 signInTpmInternal(const uint8_t* data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm, bool retry);
131
Yingdi Yu8dceb1d2014-02-18 12:45:10 -0800132private:
Alexander Afanasyev04b22a92014-01-05 22:40:17 -0800133 class Impl;
Yingdi Yu4b752752014-02-18 12:24:03 -0800134 shared_ptr<Impl> m_impl;
Jeff Thompson2747dc02013-10-04 19:11:34 -0700135};
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700136
Alexander Afanasyev19508852014-01-29 01:01:51 -0800137} // namespace ndn
Jeff Thompson2747dc02013-10-04 19:11:34 -0700138
Yingdi Yufc40d872014-02-18 12:56:04 -0800139#endif // NDN_SECURITY_SEC_TPM_OSX_HPP