blob: d10ce7d08ca5e3dbe45462adc030a5acbbbd5e96 [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 Yu87581582014-01-14 14:28:39 -080026 // From TrustedPlatformModule
Jeff Thompson2747dc02013-10-04 19:11:34 -070027 virtual void
Yingdi Yu3c5887c2014-01-21 18:19:49 -080028 generateKeyPairInTpm(const Name& keyName, KeyType keyType, int keySize);
Jeff Thompson2747dc02013-10-04 19:11:34 -070029
Yingdi Yu28fd32f2014-01-28 19:03:03 -080030 virtual void
Yingdi Yu2b2b4792014-02-04 16:27:07 -080031 deleteKeyPairInTpm(const Name& keyName);
Yingdi Yu28fd32f2014-01-28 19:03:03 -080032
Jeff Thompson2747dc02013-10-04 19:11:34 -070033 virtual ptr_lib::shared_ptr<PublicKey>
Yingdi Yu87581582014-01-14 14:28:39 -080034 getPublicKeyFromTpm(const Name& keyName);
Jeff Thompson2747dc02013-10-04 19:11:34 -070035
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080036 virtual Block
Yingdi Yu2b2b4792014-02-04 16:27:07 -080037 signInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm);
Yingdi Yufc40d872014-02-18 12:56:04 -080038
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080039 virtual ConstBufferPtr
Yingdi Yufc40d872014-02-18 12:56:04 -080040 decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
Jeff Thompson2747dc02013-10-04 19:11:34 -070041
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080042 virtual ConstBufferPtr
Yingdi Yufc40d872014-02-18 12:56:04 -080043 encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
Jeff Thompson2747dc02013-10-04 19:11:34 -070044
Jeff Thompson2747dc02013-10-04 19:11:34 -070045 virtual void
Yingdi Yub4bb85a2014-01-16 10:11:04 -080046 generateSymmetricKeyInTpm(const Name& keyName, KeyType keyType, int keySize);
Jeff Thompson2747dc02013-10-04 19:11:34 -070047
Jeff Thompson2747dc02013-10-04 19:11:34 -070048 virtual bool
Yingdi Yu4b752752014-02-18 12:24:03 -080049 doesKeyExistInTpm(const Name& keyName, KeyClass keyClass);
50
51 virtual bool
52 generateRandomBlock(uint8_t* res, size_t size);
Jeff Thompson2747dc02013-10-04 19:11:34 -070053
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080054
55 ////////////////////////////////////////////////////////////////////////////////////
56 // OSX-specifics
57 ////////////////////////////////////////////////////////////////////////////////////
58
Jeff Thompson2747dc02013-10-04 19:11:34 -070059 /**
Yingdi Yufc40d872014-02-18 12:56:04 -080060 * @brief Configure ACL of a particular key.
61 *
Jeff Thompson2747dc02013-10-04 19:11:34 -070062 * @param keyName the name of key
63 * @param keyClass the class of key, e.g. Private Key
64 * @param acl the new acl of the key
65 * @param appPath the absolute path to the application
66 * @returns true if setting succeeds
67 */
68 bool
Yingdi Yu2b2b4792014-02-04 16:27:07 -080069 setACL(const Name& keyName, KeyClass keyClass, int acl, const std::string& appPath);
Jeff Thompson2747dc02013-10-04 19:11:34 -070070
Yingdi Yu8dceb1d2014-02-18 12:45:10 -080071protected:
72 /******************************
73 * From TrustedPlatformModule *
74 ******************************/
75 virtual ConstBufferPtr
76 exportPrivateKeyPkcs1FromTpm(const Name& keyName);
Jeff Thompson2747dc02013-10-04 19:11:34 -070077
Yingdi Yu8dceb1d2014-02-18 12:45:10 -080078 virtual bool
79 importPrivateKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
80
81 virtual bool
82 importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
83
84private:
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080085 class Impl;
Yingdi Yu4b752752014-02-18 12:24:03 -080086 shared_ptr<Impl> m_impl;
Jeff Thompson2747dc02013-10-04 19:11:34 -070087};
88
Alexander Afanasyev19508852014-01-29 01:01:51 -080089} // namespace ndn
Jeff Thompson2747dc02013-10-04 19:11:34 -070090
Yingdi Yufc40d872014-02-18 12:56:04 -080091#endif // NDN_SECURITY_SEC_TPM_OSX_HPP