blob: 0b90fd0d151ed94a449a68ab34864c2009439436 [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.
Jeff Thompson6e229042013-10-10 11:09:49 -070012#include <ndn-cpp/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
15#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 Yu87581582014-01-14 14:28:39 -080040 generateKeyPairInTpm(const Name& keyName, KeyType keyType = KEY_TYPE_RSA, int keySize = 2048);
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 Yu87581582014-01-14 14:28:39 -080046 sign(const uint8_t *data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm);
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080047
48 virtual void
Yingdi Yu87581582014-01-14 14:28:39 -080049 sign(Data &data, const Name& keyName, DigestAlgorithm digestAlgorithm);
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080050
Jeff Thompson2747dc02013-10-04 19:11:34 -070051 /**
52 * Decrypt data.
53 * @param keyName The name of the decrypting key.
54 * @param data The byte to be decrypted.
55 * @param dataLength the length of data.
56 * @param isSymmetric If true symmetric encryption is used, otherwise asymmetric decryption is used.
57 * @return The decrypted data.
58 */
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080059 virtual ConstBufferPtr
Yingdi Yu87581582014-01-14 14:28:39 -080060 decrypt(const Name& keyName, const uint8_t* data, size_t dataLength, bool isSymmetric);
Jeff Thompson2747dc02013-10-04 19:11:34 -070061
62 /**
63 * Encrypt data.
64 * @param keyName The name of the encrypting key.
65 * @param data The byte to be encrypted.
66 * @param dataLength the length of data.
67 * @param isSymmetric If true symmetric encryption is used, otherwise asymmetric decryption is used.
68 * @return The encrypted data.
69 */
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080070 virtual ConstBufferPtr
Yingdi Yu87581582014-01-14 14:28:39 -080071 encrypt(const Name& keyName, const uint8_t* data, size_t dataLength, bool isSymmetric);
Jeff Thompson2747dc02013-10-04 19:11:34 -070072
73 /**
74 * Generate a symmetric key.
75 * @param keyName The name of the key.
76 * @param keyType The type of the key, e.g. KEY_TYPE_AES.
77 * @param keySize The size of the key.
78 */
79 virtual void
Yingdi Yu87581582014-01-14 14:28:39 -080080 generateSymmetricKey(const Name& keyName, KeyType keyType, int keySize);
Jeff Thompson2747dc02013-10-04 19:11:34 -070081
82 /**
83 * Check if a particular key exists.
84 * @param keyName The name of the key.
85 * @param keyClass The class of the key, e.g. KEY_CLASS_PUBLIC, KEY_CLASS_PRIVATE, or KEY_CLASS_SYMMETRIC.
86 * @return True if the key exists, otherwise false.
87 */
88 virtual bool
89 doesKeyExist(const Name& keyName, KeyClass keyClass);
90
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080091
92 ////////////////////////////////////////////////////////////////////////////////////
93 // OSX-specifics
94 ////////////////////////////////////////////////////////////////////////////////////
95
Jeff Thompson2747dc02013-10-04 19:11:34 -070096 /**
97 * configure ACL of a particular key
98 * @param keyName the name of key
99 * @param keyClass the class of key, e.g. Private Key
100 * @param acl the new acl of the key
101 * @param appPath the absolute path to the application
102 * @returns true if setting succeeds
103 */
104 bool
105 setACL(const Name & keyName, KeyClass keyClass, int acl, const std::string & appPath);
106
Alexander Afanasyev04b22a92014-01-05 22:40:17 -0800107 // /**
108 // * verify data (test only)
109 // * @param keyName the name of key
110 // * @param pData the data to be verified
111 // * @param pSig the signature associated with the data
112 // * @param digestAlgo digest algorithm
113 // * @return true if signature can be verified, otherwise false
114 // */
115 // bool
116 // verifyData(const Name & keyName, const Blob & pData, const Blob & pSig, DigestAlgorithm digestAlgo = DIGEST_ALGORITHM_SHA256);
Jeff Thompson2747dc02013-10-04 19:11:34 -0700117
118 private:
Alexander Afanasyev04b22a92014-01-05 22:40:17 -0800119 class Impl;
120 std::auto_ptr<Impl> impl_;
Jeff Thompson2747dc02013-10-04 19:11:34 -0700121};
122
123}
124
Jeff Thompsonc5647812013-10-11 18:06:38 -0700125#endif // NDN_CPP_HAVE_OSX_SECURITY
Jeff Thompson2747dc02013-10-04 19:11:34 -0700126
127#endif