blob: 4b8496e46a9c18c2a15c7642f0e7a9436bd725f9 [file] [log] [blame]
Yingdi Yu2d9c50f2014-01-21 18:25:00 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07003 * Copyright (c) 2013-2014, Regents of the University of California.
4 * All rights reserved.
5 *
6 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
7 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
8 *
9 * This file licensed under New BSD License. See COPYING for detailed information about
10 * ndn-cxx library copyright, permissions, and redistribution restrictions.
11 *
12 * @author Xingyu Ma <http://www.linkedin.com/pub/xingyu-ma/1a/384/5a8>
13 * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
14 * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080015 */
16
Yingdi Yufc40d872014-02-18 12:56:04 -080017#ifndef NDN_SECURITY_SEC_TPM_FILE_HPP
18#define NDN_SECURITY_SEC_TPM_FILE_HPP
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080019
20#include "../common.hpp"
21
22#include "sec-tpm.hpp"
23
Yingdi Yufc40d872014-02-18 12:56:04 -080024namespace ndn {
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080025
26class SecTpmFile : public SecTpm
27{
28public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070029 class Error : public SecTpm::Error
30 {
31 public:
32 explicit
33 Error(const std::string& what)
34 : SecTpm::Error(what)
35 {
36 }
37 };
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080038
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070039 SecTpmFile(const std::string& dir = "");
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080040
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080041 virtual
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070042 ~SecTpmFile()
43 {
44 }
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080045
Yingdi Yube4150e2014-02-18 13:02:46 -080046 virtual void
47 setTpmPassword(const uint8_t* password, size_t passwordLength)
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070048 {
49 }
Yingdi Yube4150e2014-02-18 13:02:46 -080050
51 virtual void
52 resetTpmPassword()
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070053 {
54 }
Yingdi Yube4150e2014-02-18 13:02:46 -080055
56 virtual void
57 setInTerminal(bool inTerminal)
58 {
59 m_inTerminal = inTerminal;
60 }
61
62 virtual bool
63 getInTerminal()
64 {
65 return m_inTerminal;
66 }
67
68 virtual bool
69 locked()
70 {
71 return false;
72 }
73
Yingdi Yu2e57a582014-02-20 23:34:43 -080074 virtual bool
Yingdi Yube4150e2014-02-18 13:02:46 -080075 unlockTpm(const char* password, size_t passwordLength, bool usePassword)
Yingdi Yu2e57a582014-02-20 23:34:43 -080076 {
77 return !locked();
78 }
Yingdi Yube4150e2014-02-18 13:02:46 -080079
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080080 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070081 generateKeyPairInTpm(const Name& keyName, KeyType keyType, int keySize);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080082
Yingdi Yu28fd32f2014-01-28 19:03:03 -080083 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070084 deleteKeyPairInTpm(const Name& keyName);
Yingdi Yu28fd32f2014-01-28 19:03:03 -080085
Yingdi Yufc40d872014-02-18 12:56:04 -080086 virtual shared_ptr<PublicKey>
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070087 getPublicKeyFromTpm(const Name& keyName);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080088
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080089 virtual Block
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070090 signInTpm(const uint8_t* data, size_t dataLength,
91 const Name& keyName, DigestAlgorithm digestAlgorithm);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080092
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070093 virtual ConstBufferPtr
Yingdi Yufc40d872014-02-18 12:56:04 -080094 decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080095
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080096 virtual ConstBufferPtr
Yingdi Yufc40d872014-02-18 12:56:04 -080097 encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080098
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070099 virtual void
Yingdi Yu2d9c50f2014-01-21 18:25:00 -0800100 generateSymmetricKeyInTpm(const Name& keyName, KeyType keyType, int keySize);
101
Yingdi Yu2d9c50f2014-01-21 18:25:00 -0800102 virtual bool
103 doesKeyExistInTpm(const Name& keyName, KeyClass keyClass);
104
Yingdi Yu4b752752014-02-18 12:24:03 -0800105 virtual bool
106 generateRandomBlock(uint8_t* res, size_t size);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -0800107
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700108 virtual void
Yingdi Yu2e57a582014-02-20 23:34:43 -0800109 addAppToACL(const Name& keyName, KeyClass keyClass, const std::string& appPath, AclType acl)
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700110 {
111 }
Yingdi Yu2e57a582014-02-20 23:34:43 -0800112
Yingdi Yu8dceb1d2014-02-18 12:45:10 -0800113protected:
114 /******************************
115 * From TrustedPlatformModule *
116 ******************************/
117 virtual ConstBufferPtr
Yingdi Yu5e96e002014-04-23 18:32:15 -0700118 exportPrivateKeyPkcs8FromTpm(const Name& keyName);
Yingdi Yu8dceb1d2014-02-18 12:45:10 -0800119
120 virtual bool
Yingdi Yu5e96e002014-04-23 18:32:15 -0700121 importPrivateKeyPkcs8IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700122
Yingdi Yu8dceb1d2014-02-18 12:45:10 -0800123 virtual bool
124 importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
125
Yingdi Yu2d9c50f2014-01-21 18:25:00 -0800126private:
127 class Impl;
Yingdi Yu4b752752014-02-18 12:24:03 -0800128 shared_ptr<Impl> m_impl;
Yingdi Yube4150e2014-02-18 13:02:46 -0800129 bool m_inTerminal;
Yingdi Yu2d9c50f2014-01-21 18:25:00 -0800130};
Yingdi Yu4b752752014-02-18 12:24:03 -0800131
Yingdi Yufc40d872014-02-18 12:56:04 -0800132} // namespace ndn
Yingdi Yu2d9c50f2014-01-21 18:25:00 -0800133
Yingdi Yufc40d872014-02-18 12:56:04 -0800134#endif //NDN_SECURITY_SEC_TPM_FILE_HPP