blob: 9834822e55b44e578efd80e25f2861346d1d3390 [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
Jeff Thompsonf21e2242013-10-09 19:01:49 -070011// Only compile if ndn-cpp-config.h defines NDN_CPP_HAVE_OSX_SECURITY 1.
Alexander Afanasyev09c613f2014-01-29 00:23:58 -080012#include "ndn-cpp-config.h"
Jeff Thompsonf21e2242013-10-09 19:01:49 -070013#if NDN_CPP_HAVE_OSX_SECURITY
Jeff Thompson2747dc02013-10-04 19:11:34 -070014
Yingdi Yu4f324632014-01-15 18:10:03 -080015#include "../common.hpp"
Yingdi Yu87581582014-01-14 14:28:39 -080016#include "sec-tpm.hpp"
Jeff Thompson2747dc02013-10-04 19:11:34 -070017
Jeff Thompson2747dc02013-10-04 19:11:34 -070018namespace ndn
19{
20
Yingdi Yu87581582014-01-14 14:28:39 -080021class SecTpmOsx : public SecTpm {
Jeff Thompson2747dc02013-10-04 19:11:34 -070022public:
Yingdi Yu87581582014-01-14 14:28:39 -080023 struct Error : public SecTpm::Error { Error(const std::string &what) : SecTpm::Error(what) {} };
24
Jeff Thompson2747dc02013-10-04 19:11:34 -070025 /**
Yingdi Yu87581582014-01-14 14:28:39 -080026 * constructor of OSXKeyChainTpm
Jeff Thompson2747dc02013-10-04 19:11:34 -070027 * @param keychainName the name of keychain
28 */
Yingdi Yu87581582014-01-14 14:28:39 -080029 SecTpmOsx(const std::string & keychainName = "");
Jeff Thompson2747dc02013-10-04 19:11:34 -070030
31 /**
Yingdi Yu87581582014-01-14 14:28:39 -080032 * destructor of OSXKeyChainTpm
Jeff Thompson2747dc02013-10-04 19:11:34 -070033 */
34 virtual
Yingdi Yu87581582014-01-14 14:28:39 -080035 ~SecTpmOsx();
Jeff Thompson2747dc02013-10-04 19:11:34 -070036
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080037
Yingdi Yu87581582014-01-14 14:28:39 -080038 // From TrustedPlatformModule
Jeff Thompson2747dc02013-10-04 19:11:34 -070039 virtual void
Yingdi Yu3c5887c2014-01-21 18:19:49 -080040 generateKeyPairInTpm(const Name& keyName, KeyType keyType, int keySize);
Jeff Thompson2747dc02013-10-04 19:11:34 -070041
Jeff Thompson2747dc02013-10-04 19:11:34 -070042 virtual ptr_lib::shared_ptr<PublicKey>
Yingdi Yu87581582014-01-14 14:28:39 -080043 getPublicKeyFromTpm(const Name& keyName);
Jeff Thompson2747dc02013-10-04 19:11:34 -070044
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080045 virtual Block
Yingdi Yub4bb85a2014-01-16 10:11:04 -080046 signInTpm(const uint8_t *data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm);
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080047
Jeff Thompson2747dc02013-10-04 19:11:34 -070048 /**
49 * Decrypt data.
50 * @param keyName The name of the decrypting key.
51 * @param data The byte to be decrypted.
52 * @param dataLength the length of data.
53 * @param isSymmetric If true symmetric encryption is used, otherwise asymmetric decryption is used.
54 * @return The decrypted data.
55 */
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080056 virtual ConstBufferPtr
Yingdi Yub4bb85a2014-01-16 10:11:04 -080057 decryptInTpm(const Name& keyName, const uint8_t* data, size_t dataLength, bool isSymmetric);
Jeff Thompson2747dc02013-10-04 19:11:34 -070058
59 /**
60 * Encrypt data.
61 * @param keyName The name of the encrypting key.
62 * @param data The byte to be encrypted.
63 * @param dataLength the length of data.
64 * @param isSymmetric If true symmetric encryption is used, otherwise asymmetric decryption is used.
65 * @return The encrypted data.
66 */
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080067 virtual ConstBufferPtr
Yingdi Yub4bb85a2014-01-16 10:11:04 -080068 encryptInTpm(const Name& keyName, const uint8_t* data, size_t dataLength, bool isSymmetric);
Jeff Thompson2747dc02013-10-04 19:11:34 -070069
70 /**
71 * Generate a symmetric key.
72 * @param keyName The name of the key.
73 * @param keyType The type of the key, e.g. KEY_TYPE_AES.
74 * @param keySize The size of the key.
75 */
76 virtual void
Yingdi Yub4bb85a2014-01-16 10:11:04 -080077 generateSymmetricKeyInTpm(const Name& keyName, KeyType keyType, int keySize);
Jeff Thompson2747dc02013-10-04 19:11:34 -070078
79 /**
80 * Check if a particular key exists.
81 * @param keyName The name of the key.
82 * @param keyClass The class of the key, e.g. KEY_CLASS_PUBLIC, KEY_CLASS_PRIVATE, or KEY_CLASS_SYMMETRIC.
83 * @return True if the key exists, otherwise false.
84 */
85 virtual bool
Yingdi Yub4bb85a2014-01-16 10:11:04 -080086 doesKeyExistInTpm(const Name& keyName, KeyClass keyClass);
Jeff Thompson2747dc02013-10-04 19:11:34 -070087
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080088
89 ////////////////////////////////////////////////////////////////////////////////////
90 // OSX-specifics
91 ////////////////////////////////////////////////////////////////////////////////////
92
Jeff Thompson2747dc02013-10-04 19:11:34 -070093 /**
94 * configure ACL of a particular key
95 * @param keyName the name of key
96 * @param keyClass the class of key, e.g. Private Key
97 * @param acl the new acl of the key
98 * @param appPath the absolute path to the application
99 * @returns true if setting succeeds
100 */
101 bool
102 setACL(const Name & keyName, KeyClass keyClass, int acl, const std::string & appPath);
103
Alexander Afanasyev04b22a92014-01-05 22:40:17 -0800104 // /**
105 // * verify data (test only)
106 // * @param keyName the name of key
107 // * @param pData the data to be verified
108 // * @param pSig the signature associated with the data
109 // * @param digestAlgo digest algorithm
110 // * @return true if signature can be verified, otherwise false
111 // */
112 // bool
113 // verifyData(const Name & keyName, const Blob & pData, const Blob & pSig, DigestAlgorithm digestAlgo = DIGEST_ALGORITHM_SHA256);
Jeff Thompson2747dc02013-10-04 19:11:34 -0700114
115 private:
Alexander Afanasyev04b22a92014-01-05 22:40:17 -0800116 class Impl;
117 std::auto_ptr<Impl> impl_;
Jeff Thompson2747dc02013-10-04 19:11:34 -0700118};
119
120}
121
Jeff Thompsonc5647812013-10-11 18:06:38 -0700122#endif // NDN_CPP_HAVE_OSX_SECURITY
Jeff Thompson2747dc02013-10-04 19:11:34 -0700123
124#endif