blob: 8a108c598f19d6ad80512b3548d80c5aea1a882d [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
Yingdi Yu2e57a582014-02-20 23:34:43 -080054 virtual bool
Yingdi Yube4150e2014-02-18 13:02:46 -080055 unlockTpm(const char* password, size_t passwordLength, bool usePassword)
Yingdi Yu2e57a582014-02-20 23:34:43 -080056 {
57 return !locked();
58 }
Yingdi Yube4150e2014-02-18 13:02:46 -080059
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080060 virtual void
61 generateKeyPairInTpm(const Name & keyName, KeyType keyType, int keySize);
62
Yingdi Yu28fd32f2014-01-28 19:03:03 -080063 virtual void
64 deleteKeyPairInTpm(const Name &keyName);
65
Yingdi Yufc40d872014-02-18 12:56:04 -080066 virtual shared_ptr<PublicKey>
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080067 getPublicKeyFromTpm(const Name & keyName);
68
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080069 virtual Block
70 signInTpm(const uint8_t *data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm);
71
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080072 virtual ConstBufferPtr
Yingdi Yufc40d872014-02-18 12:56:04 -080073 decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080074
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080075 virtual ConstBufferPtr
Yingdi Yufc40d872014-02-18 12:56:04 -080076 encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080077
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080078 virtual void
79 generateSymmetricKeyInTpm(const Name& keyName, KeyType keyType, int keySize);
80
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080081 virtual bool
82 doesKeyExistInTpm(const Name& keyName, KeyClass keyClass);
83
Yingdi Yu4b752752014-02-18 12:24:03 -080084 virtual bool
85 generateRandomBlock(uint8_t* res, size_t size);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080086
Yingdi Yu2e57a582014-02-20 23:34:43 -080087 virtual void
88 addAppToACL(const Name& keyName, KeyClass keyClass, const std::string& appPath, AclType acl)
89 {}
90
Yingdi Yu8dceb1d2014-02-18 12:45:10 -080091protected:
92 /******************************
93 * From TrustedPlatformModule *
94 ******************************/
95 virtual ConstBufferPtr
96 exportPrivateKeyPkcs1FromTpm(const Name& keyName);
97
98 virtual bool
99 importPrivateKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -0800100
Yingdi Yu8dceb1d2014-02-18 12:45:10 -0800101 virtual bool
102 importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
103
Yingdi Yu2d9c50f2014-01-21 18:25:00 -0800104private:
105 class Impl;
Yingdi Yu4b752752014-02-18 12:24:03 -0800106 shared_ptr<Impl> m_impl;
Yingdi Yube4150e2014-02-18 13:02:46 -0800107 bool m_inTerminal;
Yingdi Yu2d9c50f2014-01-21 18:25:00 -0800108};
Yingdi Yu4b752752014-02-18 12:24:03 -0800109
Yingdi Yufc40d872014-02-18 12:56:04 -0800110} // namespace ndn
Yingdi Yu2d9c50f2014-01-21 18:25:00 -0800111
Yingdi Yufc40d872014-02-18 12:56:04 -0800112#endif //NDN_SECURITY_SEC_TPM_FILE_HPP