blob: fc1e410ada2865b7a0d3698007ae870b71ce411b [file] [log] [blame]
Yingdi Yu2d9c50f2014-01-21 18:25:00 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Xingyu Ma <maxy12@cs.ucla.edu>
5 * Yingdi Yu <yingdi@cs.ucla.edu>
6 * See COPYING for copyright and distribution information.
7 */
8
Yingdi Yufc40d872014-02-18 12:56:04 -08009#ifndef NDN_SECURITY_SEC_TPM_FILE_HPP
10#define NDN_SECURITY_SEC_TPM_FILE_HPP
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080011
12#include "../common.hpp"
13
14#include "sec-tpm.hpp"
15
Yingdi Yufc40d872014-02-18 12:56:04 -080016namespace ndn {
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080017
18class SecTpmFile : public SecTpm
19{
20public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070021 class Error : public SecTpm::Error
22 {
23 public:
24 explicit
25 Error(const std::string& what)
26 : SecTpm::Error(what)
27 {
28 }
29 };
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080030
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070031 SecTpmFile(const std::string& dir = "");
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080032
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080033 virtual
34 ~SecTpmFile() {};
35
Yingdi Yube4150e2014-02-18 13:02:46 -080036 virtual void
37 setTpmPassword(const uint8_t* password, size_t passwordLength)
38 {}
39
40 virtual void
41 resetTpmPassword()
42 {}
43
44 virtual void
45 setInTerminal(bool inTerminal)
46 {
47 m_inTerminal = inTerminal;
48 }
49
50 virtual bool
51 getInTerminal()
52 {
53 return m_inTerminal;
54 }
55
56 virtual bool
57 locked()
58 {
59 return false;
60 }
61
Yingdi Yu2e57a582014-02-20 23:34:43 -080062 virtual bool
Yingdi Yube4150e2014-02-18 13:02:46 -080063 unlockTpm(const char* password, size_t passwordLength, bool usePassword)
Yingdi Yu2e57a582014-02-20 23:34:43 -080064 {
65 return !locked();
66 }
Yingdi Yube4150e2014-02-18 13:02:46 -080067
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080068 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070069 generateKeyPairInTpm(const Name& keyName, KeyType keyType, int keySize);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080070
Yingdi Yu28fd32f2014-01-28 19:03:03 -080071 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070072 deleteKeyPairInTpm(const Name& keyName);
Yingdi Yu28fd32f2014-01-28 19:03:03 -080073
Yingdi Yufc40d872014-02-18 12:56:04 -080074 virtual shared_ptr<PublicKey>
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070075 getPublicKeyFromTpm(const Name& keyName);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080076
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080077 virtual Block
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070078 signInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080079
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070080 virtual ConstBufferPtr
Yingdi Yufc40d872014-02-18 12:56:04 -080081 decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080082
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080083 virtual ConstBufferPtr
Yingdi Yufc40d872014-02-18 12:56:04 -080084 encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080085
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070086 virtual void
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080087 generateSymmetricKeyInTpm(const Name& keyName, KeyType keyType, int keySize);
88
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080089 virtual bool
90 doesKeyExistInTpm(const Name& keyName, KeyClass keyClass);
91
Yingdi Yu4b752752014-02-18 12:24:03 -080092 virtual bool
93 generateRandomBlock(uint8_t* res, size_t size);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080094
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070095 virtual void
Yingdi Yu2e57a582014-02-20 23:34:43 -080096 addAppToACL(const Name& keyName, KeyClass keyClass, const std::string& appPath, AclType acl)
97 {}
98
Yingdi Yu8dceb1d2014-02-18 12:45:10 -080099protected:
100 /******************************
101 * From TrustedPlatformModule *
102 ******************************/
103 virtual ConstBufferPtr
104 exportPrivateKeyPkcs1FromTpm(const Name& keyName);
105
106 virtual bool
107 importPrivateKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700108
Yingdi Yu8dceb1d2014-02-18 12:45:10 -0800109 virtual bool
110 importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
111
Yingdi Yu2d9c50f2014-01-21 18:25:00 -0800112private:
113 class Impl;
Yingdi Yu4b752752014-02-18 12:24:03 -0800114 shared_ptr<Impl> m_impl;
Yingdi Yube4150e2014-02-18 13:02:46 -0800115 bool m_inTerminal;
Yingdi Yu2d9c50f2014-01-21 18:25:00 -0800116};
Yingdi Yu4b752752014-02-18 12:24:03 -0800117
Yingdi Yufc40d872014-02-18 12:56:04 -0800118} // namespace ndn
Yingdi Yu2d9c50f2014-01-21 18:25:00 -0800119
Yingdi Yufc40d872014-02-18 12:56:04 -0800120#endif //NDN_SECURITY_SEC_TPM_FILE_HPP