blob: 4887a15998d58016b05d460da8c0a47aa7d3f6b7 [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:
21 struct Error : public SecTpm::Error { Error(const std::string &what) : SecTpm::Error(what) {} };
22
23 SecTpmFile(const std::string & dir = "");
24
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080025 virtual
26 ~SecTpmFile() {};
27
Yingdi Yube4150e2014-02-18 13:02:46 -080028 virtual void
29 setTpmPassword(const uint8_t* password, size_t passwordLength)
30 {}
31
32 virtual void
33 resetTpmPassword()
34 {}
35
36 virtual void
37 setInTerminal(bool inTerminal)
38 {
39 m_inTerminal = inTerminal;
40 }
41
42 virtual bool
43 getInTerminal()
44 {
45 return m_inTerminal;
46 }
47
48 virtual bool
49 locked()
50 {
51 return false;
52 }
53
54 virtual void
55 unlockTpm(const char* password, size_t passwordLength, bool usePassword)
56 {}
57
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080058 virtual void
59 generateKeyPairInTpm(const Name & keyName, KeyType keyType, int keySize);
60
Yingdi Yu28fd32f2014-01-28 19:03:03 -080061 virtual void
62 deleteKeyPairInTpm(const Name &keyName);
63
Yingdi Yufc40d872014-02-18 12:56:04 -080064 virtual shared_ptr<PublicKey>
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080065 getPublicKeyFromTpm(const Name & keyName);
66
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080067 virtual Block
68 signInTpm(const uint8_t *data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm);
69
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080070 virtual ConstBufferPtr
Yingdi Yufc40d872014-02-18 12:56:04 -080071 decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080072
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080073 virtual ConstBufferPtr
Yingdi Yufc40d872014-02-18 12:56:04 -080074 encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080075
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080076 virtual void
77 generateSymmetricKeyInTpm(const Name& keyName, KeyType keyType, int keySize);
78
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080079 virtual bool
80 doesKeyExistInTpm(const Name& keyName, KeyClass keyClass);
81
Yingdi Yu4b752752014-02-18 12:24:03 -080082 virtual bool
83 generateRandomBlock(uint8_t* res, size_t size);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080084
Yingdi Yu8dceb1d2014-02-18 12:45:10 -080085protected:
86 /******************************
87 * From TrustedPlatformModule *
88 ******************************/
89 virtual ConstBufferPtr
90 exportPrivateKeyPkcs1FromTpm(const Name& keyName);
91
92 virtual bool
93 importPrivateKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080094
Yingdi Yu8dceb1d2014-02-18 12:45:10 -080095 virtual bool
96 importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
97
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080098private:
99 class Impl;
Yingdi Yu4b752752014-02-18 12:24:03 -0800100 shared_ptr<Impl> m_impl;
Yingdi Yube4150e2014-02-18 13:02:46 -0800101 bool m_inTerminal;
Yingdi Yu2d9c50f2014-01-21 18:25:00 -0800102};
Yingdi Yu4b752752014-02-18 12:24:03 -0800103
Yingdi Yufc40d872014-02-18 12:56:04 -0800104} // namespace ndn
Yingdi Yu2d9c50f2014-01-21 18:25:00 -0800105
Yingdi Yufc40d872014-02-18 12:56:04 -0800106#endif //NDN_SECURITY_SEC_TPM_FILE_HPP