blob: f9cfc5712b9a796c9cde40257cc3efea11e68b6e [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 {
Jeff Thompson2747dc02013-10-04 19:11:34 -070015
Yingdi Yu87581582014-01-14 14:28:39 -080016class SecTpmOsx : public SecTpm {
Jeff Thompson2747dc02013-10-04 19:11:34 -070017public:
Yingdi Yu2b2b4792014-02-04 16:27:07 -080018 struct Error : public SecTpm::Error { Error(const std::string& what) : SecTpm::Error(what) {} };
Yingdi Yu87581582014-01-14 14:28:39 -080019
Yingdi Yu2b2b4792014-02-04 16:27:07 -080020 SecTpmOsx();
Jeff Thompson2747dc02013-10-04 19:11:34 -070021
Jeff Thompson2747dc02013-10-04 19:11:34 -070022 virtual
Yingdi Yu87581582014-01-14 14:28:39 -080023 ~SecTpmOsx();
Jeff Thompson2747dc02013-10-04 19:11:34 -070024
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080025
Yingdi Yube4150e2014-02-18 13:02:46 -080026 /******************************
27 * From TrustedPlatformModule *
28 ******************************/
Jeff Thompson2747dc02013-10-04 19:11:34 -070029
Yingdi Yu28fd32f2014-01-28 19:03:03 -080030 virtual void
Yingdi Yube4150e2014-02-18 13:02:46 -080031 setTpmPassword(const uint8_t* password, size_t passwordLength);
32
33 virtual void
34 resetTpmPassword();
35
36 virtual void
37 setInTerminal(bool inTerminal);
38
39 virtual bool
40 getInTerminal();
41
42 virtual bool
43 locked();
44
Yingdi Yu2e57a582014-02-20 23:34:43 -080045 virtual bool
Yingdi Yube4150e2014-02-18 13:02:46 -080046 unlockTpm(const char* password, size_t passwordLength, bool usePassword);
47
48 virtual void
49 generateKeyPairInTpm(const Name& keyName, KeyType keyType, int keySize)
50 {
51 generateKeyPairInTpmInternal(keyName, keyType, keySize, false);
52 }
53
54 virtual void
55 deleteKeyPairInTpm(const Name& keyName)
56 {
57 deleteKeyPairInTpmInternal(keyName, false);
58 }
Yingdi Yu28fd32f2014-01-28 19:03:03 -080059
Yingdi Yu2e57a582014-02-20 23:34:43 -080060 virtual shared_ptr<PublicKey>
Yingdi Yu87581582014-01-14 14:28:39 -080061 getPublicKeyFromTpm(const Name& keyName);
Jeff Thompson2747dc02013-10-04 19:11:34 -070062
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080063 virtual Block
Yingdi Yube4150e2014-02-18 13:02:46 -080064 signInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm)
65 {
66 return signInTpmInternal(data, dataLength, keyName, digestAlgorithm, false);
67 }
Yingdi Yufc40d872014-02-18 12:56:04 -080068
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080069 virtual ConstBufferPtr
Yingdi Yufc40d872014-02-18 12:56:04 -080070 decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
Jeff Thompson2747dc02013-10-04 19:11:34 -070071
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080072 virtual ConstBufferPtr
Yingdi Yufc40d872014-02-18 12:56:04 -080073 encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
Jeff Thompson2747dc02013-10-04 19:11:34 -070074
Jeff Thompson2747dc02013-10-04 19:11:34 -070075 virtual void
Yingdi Yub4bb85a2014-01-16 10:11:04 -080076 generateSymmetricKeyInTpm(const Name& keyName, KeyType keyType, int keySize);
Jeff Thompson2747dc02013-10-04 19:11:34 -070077
Jeff Thompson2747dc02013-10-04 19:11:34 -070078 virtual bool
Yingdi Yu4b752752014-02-18 12:24:03 -080079 doesKeyExistInTpm(const Name& keyName, KeyClass keyClass);
80
81 virtual bool
82 generateRandomBlock(uint8_t* res, size_t size);
Jeff Thompson2747dc02013-10-04 19:11:34 -070083
Yingdi Yu2e57a582014-02-20 23:34:43 -080084 virtual void
85 addAppToACL(const Name& keyName, KeyClass keyClass, const std::string& appPath, AclType acl);
Jeff Thompson2747dc02013-10-04 19:11:34 -070086
Yingdi Yu8dceb1d2014-02-18 12:45:10 -080087protected:
88 /******************************
89 * From TrustedPlatformModule *
90 ******************************/
91 virtual ConstBufferPtr
Yingdi Yube4150e2014-02-18 13:02:46 -080092 exportPrivateKeyPkcs1FromTpm(const Name& keyName)
93 {
94 return exportPrivateKeyPkcs1FromTpmInternal(keyName, false);
95 }
Jeff Thompson2747dc02013-10-04 19:11:34 -070096
Yingdi Yu8dceb1d2014-02-18 12:45:10 -080097 virtual bool
Yingdi Yube4150e2014-02-18 13:02:46 -080098 importPrivateKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size)
99 {
100 return importPrivateKeyPkcs1IntoTpmInternal(keyName, buf, size, false);
101 }
Yingdi Yu8dceb1d2014-02-18 12:45:10 -0800102
103 virtual bool
104 importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
Yingdi Yube4150e2014-02-18 13:02:46 -0800105
106 /******************************
107 * OSX-specifics *
108 ******************************/
109 void
110 generateKeyPairInTpmInternal(const Name & keyName, KeyType keyType, int keySize, bool retry);
111
112 void
113 deleteKeyPairInTpmInternal(const Name &keyName, bool retry);
114
115 ConstBufferPtr
116 exportPrivateKeyPkcs1FromTpmInternal(const Name& keyName, bool retry);
117
118 bool
119 importPrivateKeyPkcs1IntoTpmInternal(const Name& keyName, const uint8_t* buf, size_t size, bool retry);
120
121 Block
122 signInTpmInternal(const uint8_t *data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm, bool retry);
Yingdi Yu8dceb1d2014-02-18 12:45:10 -0800123
124private:
Alexander Afanasyev04b22a92014-01-05 22:40:17 -0800125 class Impl;
Yingdi Yu4b752752014-02-18 12:24:03 -0800126 shared_ptr<Impl> m_impl;
Jeff Thompson2747dc02013-10-04 19:11:34 -0700127};
128
Alexander Afanasyev19508852014-01-29 01:01:51 -0800129} // namespace ndn
Jeff Thompson2747dc02013-10-04 19:11:34 -0700130
Yingdi Yufc40d872014-02-18 12:56:04 -0800131#endif // NDN_SECURITY_SEC_TPM_OSX_HPP