blob: c724ca7cca4cd1876dd4e9d22fecc62fedaea405 [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 Yu87581582014-01-14 14:28:39 -08008#ifndef NDN_SEC_TPM_OSX_HPP
9#define NDN_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
Jeff Thompson2747dc02013-10-04 19:11:34 -070014namespace ndn
15{
16
Yingdi Yu87581582014-01-14 14:28:39 -080017class SecTpmOsx : public SecTpm {
Jeff Thompson2747dc02013-10-04 19:11:34 -070018public:
Yingdi Yu87581582014-01-14 14:28:39 -080019 struct Error : public SecTpm::Error { Error(const std::string &what) : SecTpm::Error(what) {} };
20
Jeff Thompson2747dc02013-10-04 19:11:34 -070021 /**
Yingdi Yu87581582014-01-14 14:28:39 -080022 * constructor of OSXKeyChainTpm
Jeff Thompson2747dc02013-10-04 19:11:34 -070023 * @param keychainName the name of keychain
24 */
Yingdi Yu87581582014-01-14 14:28:39 -080025 SecTpmOsx(const std::string & keychainName = "");
Jeff Thompson2747dc02013-10-04 19:11:34 -070026
27 /**
Yingdi Yu87581582014-01-14 14:28:39 -080028 * destructor of OSXKeyChainTpm
Jeff Thompson2747dc02013-10-04 19:11:34 -070029 */
30 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 Yu87581582014-01-14 14:28:39 -080034 // From TrustedPlatformModule
Jeff Thompson2747dc02013-10-04 19:11:34 -070035 virtual void
Yingdi Yu3c5887c2014-01-21 18:19:49 -080036 generateKeyPairInTpm(const Name& keyName, KeyType keyType, int keySize);
Jeff Thompson2747dc02013-10-04 19:11:34 -070037
Jeff Thompson2747dc02013-10-04 19:11:34 -070038 virtual ptr_lib::shared_ptr<PublicKey>
Yingdi Yu87581582014-01-14 14:28:39 -080039 getPublicKeyFromTpm(const Name& keyName);
Jeff Thompson2747dc02013-10-04 19:11:34 -070040
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080041 virtual Block
Yingdi Yub4bb85a2014-01-16 10:11:04 -080042 signInTpm(const uint8_t *data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm);
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080043
Jeff Thompson2747dc02013-10-04 19:11:34 -070044 /**
45 * Decrypt data.
46 * @param keyName The name of the decrypting key.
47 * @param data The byte to be decrypted.
48 * @param dataLength the length of data.
49 * @param isSymmetric If true symmetric encryption is used, otherwise asymmetric decryption is used.
50 * @return The decrypted data.
51 */
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080052 virtual ConstBufferPtr
Yingdi Yub4bb85a2014-01-16 10:11:04 -080053 decryptInTpm(const Name& keyName, const uint8_t* data, size_t dataLength, bool isSymmetric);
Jeff Thompson2747dc02013-10-04 19:11:34 -070054
55 /**
56 * Encrypt data.
57 * @param keyName The name of the encrypting key.
58 * @param data The byte to be encrypted.
59 * @param dataLength the length of data.
60 * @param isSymmetric If true symmetric encryption is used, otherwise asymmetric decryption is used.
61 * @return The encrypted data.
62 */
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080063 virtual ConstBufferPtr
Yingdi Yub4bb85a2014-01-16 10:11:04 -080064 encryptInTpm(const Name& keyName, const uint8_t* data, size_t dataLength, bool isSymmetric);
Jeff Thompson2747dc02013-10-04 19:11:34 -070065
66 /**
67 * Generate a symmetric key.
68 * @param keyName The name of the key.
69 * @param keyType The type of the key, e.g. KEY_TYPE_AES.
70 * @param keySize The size of the key.
71 */
72 virtual void
Yingdi Yub4bb85a2014-01-16 10:11:04 -080073 generateSymmetricKeyInTpm(const Name& keyName, KeyType keyType, int keySize);
Jeff Thompson2747dc02013-10-04 19:11:34 -070074
75 /**
76 * Check if a particular key exists.
77 * @param keyName The name of the key.
78 * @param keyClass The class of the key, e.g. KEY_CLASS_PUBLIC, KEY_CLASS_PRIVATE, or KEY_CLASS_SYMMETRIC.
79 * @return True if the key exists, otherwise false.
80 */
81 virtual bool
Yingdi Yub4bb85a2014-01-16 10:11:04 -080082 doesKeyExistInTpm(const Name& keyName, KeyClass keyClass);
Jeff Thompson2747dc02013-10-04 19:11:34 -070083
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080084
85 ////////////////////////////////////////////////////////////////////////////////////
86 // OSX-specifics
87 ////////////////////////////////////////////////////////////////////////////////////
88
Jeff Thompson2747dc02013-10-04 19:11:34 -070089 /**
90 * configure ACL of a particular key
91 * @param keyName the name of key
92 * @param keyClass the class of key, e.g. Private Key
93 * @param acl the new acl of the key
94 * @param appPath the absolute path to the application
95 * @returns true if setting succeeds
96 */
97 bool
98 setACL(const Name & keyName, KeyClass keyClass, int acl, const std::string & appPath);
99
Alexander Afanasyev04b22a92014-01-05 22:40:17 -0800100 // /**
101 // * verify data (test only)
102 // * @param keyName the name of key
103 // * @param pData the data to be verified
104 // * @param pSig the signature associated with the data
105 // * @param digestAlgo digest algorithm
106 // * @return true if signature can be verified, otherwise false
107 // */
108 // bool
109 // verifyData(const Name & keyName, const Blob & pData, const Blob & pSig, DigestAlgorithm digestAlgo = DIGEST_ALGORITHM_SHA256);
Jeff Thompson2747dc02013-10-04 19:11:34 -0700110
111 private:
Alexander Afanasyev04b22a92014-01-05 22:40:17 -0800112 class Impl;
113 std::auto_ptr<Impl> impl_;
Jeff Thompson2747dc02013-10-04 19:11:34 -0700114};
115
Alexander Afanasyev19508852014-01-29 01:01:51 -0800116} // namespace ndn
Jeff Thompson2747dc02013-10-04 19:11:34 -0700117
Alexander Afanasyev19508852014-01-29 01:01:51 -0800118#endif // NDN_SEC_TPM_OSX_HPP