blob: 8cc20df8ca4f9df4b551644161a9ac20e5c01f39 [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
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070034 ~SecTpmFile()
35 {
36 }
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080037
Yingdi Yube4150e2014-02-18 13:02:46 -080038 virtual void
39 setTpmPassword(const uint8_t* password, size_t passwordLength)
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070040 {
41 }
Yingdi Yube4150e2014-02-18 13:02:46 -080042
43 virtual void
44 resetTpmPassword()
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070045 {
46 }
Yingdi Yube4150e2014-02-18 13:02:46 -080047
48 virtual void
49 setInTerminal(bool inTerminal)
50 {
51 m_inTerminal = inTerminal;
52 }
53
54 virtual bool
55 getInTerminal()
56 {
57 return m_inTerminal;
58 }
59
60 virtual bool
61 locked()
62 {
63 return false;
64 }
65
Yingdi Yu2e57a582014-02-20 23:34:43 -080066 virtual bool
Yingdi Yube4150e2014-02-18 13:02:46 -080067 unlockTpm(const char* password, size_t passwordLength, bool usePassword)
Yingdi Yu2e57a582014-02-20 23:34:43 -080068 {
69 return !locked();
70 }
Yingdi Yube4150e2014-02-18 13:02:46 -080071
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080072 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070073 generateKeyPairInTpm(const Name& keyName, KeyType keyType, int keySize);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080074
Yingdi Yu28fd32f2014-01-28 19:03:03 -080075 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070076 deleteKeyPairInTpm(const Name& keyName);
Yingdi Yu28fd32f2014-01-28 19:03:03 -080077
Yingdi Yufc40d872014-02-18 12:56:04 -080078 virtual shared_ptr<PublicKey>
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070079 getPublicKeyFromTpm(const Name& keyName);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080080
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080081 virtual Block
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070082 signInTpm(const uint8_t* data, size_t dataLength,
83 const Name& keyName, DigestAlgorithm digestAlgorithm);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080084
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070085 virtual ConstBufferPtr
Yingdi Yufc40d872014-02-18 12:56:04 -080086 decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080087
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080088 virtual ConstBufferPtr
Yingdi Yufc40d872014-02-18 12:56:04 -080089 encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080090
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070091 virtual void
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080092 generateSymmetricKeyInTpm(const Name& keyName, KeyType keyType, int keySize);
93
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080094 virtual bool
95 doesKeyExistInTpm(const Name& keyName, KeyClass keyClass);
96
Yingdi Yu4b752752014-02-18 12:24:03 -080097 virtual bool
98 generateRandomBlock(uint8_t* res, size_t size);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080099
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700100 virtual void
Yingdi Yu2e57a582014-02-20 23:34:43 -0800101 addAppToACL(const Name& keyName, KeyClass keyClass, const std::string& appPath, AclType acl)
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700102 {
103 }
Yingdi Yu2e57a582014-02-20 23:34:43 -0800104
Yingdi Yu8dceb1d2014-02-18 12:45:10 -0800105protected:
106 /******************************
107 * From TrustedPlatformModule *
108 ******************************/
109 virtual ConstBufferPtr
110 exportPrivateKeyPkcs1FromTpm(const Name& keyName);
111
112 virtual bool
113 importPrivateKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700114
Yingdi Yu8dceb1d2014-02-18 12:45:10 -0800115 virtual bool
116 importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
117
Yingdi Yu2d9c50f2014-01-21 18:25:00 -0800118private:
119 class Impl;
Yingdi Yu4b752752014-02-18 12:24:03 -0800120 shared_ptr<Impl> m_impl;
Yingdi Yube4150e2014-02-18 13:02:46 -0800121 bool m_inTerminal;
Yingdi Yu2d9c50f2014-01-21 18:25:00 -0800122};
Yingdi Yu4b752752014-02-18 12:24:03 -0800123
Yingdi Yufc40d872014-02-18 12:56:04 -0800124} // namespace ndn
Yingdi Yu2d9c50f2014-01-21 18:25:00 -0800125
Yingdi Yufc40d872014-02-18 12:56:04 -0800126#endif //NDN_SECURITY_SEC_TPM_FILE_HPP