blob: 5f402009239850fc036aca8bcc4be2596a733411 [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
28 /**
29 * Generate a pair of asymmetric keys.
30 * @param keyName The name of the key pair.
31 * @param keyType The type of the key pair, e.g. KEY_TYPE_RSA.
32 * @param keySize The size of the key pair.
33 */
34 virtual void
35 generateKeyPairInTpm(const Name & keyName, KeyType keyType, int keySize);
36
Yingdi Yu28fd32f2014-01-28 19:03:03 -080037 virtual void
38 deleteKeyPairInTpm(const Name &keyName);
39
Yingdi Yufc40d872014-02-18 12:56:04 -080040 virtual shared_ptr<PublicKey>
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080041 getPublicKeyFromTpm(const Name & keyName);
42
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080043 virtual Block
44 signInTpm(const uint8_t *data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm);
45
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080046 virtual ConstBufferPtr
Yingdi Yufc40d872014-02-18 12:56:04 -080047 decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080048
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080049 virtual ConstBufferPtr
Yingdi Yufc40d872014-02-18 12:56:04 -080050 encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080051
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080052 virtual void
53 generateSymmetricKeyInTpm(const Name& keyName, KeyType keyType, int keySize);
54
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080055 virtual bool
56 doesKeyExistInTpm(const Name& keyName, KeyClass keyClass);
57
Yingdi Yu4b752752014-02-18 12:24:03 -080058 virtual bool
59 generateRandomBlock(uint8_t* res, size_t size);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080060
Yingdi Yu8dceb1d2014-02-18 12:45:10 -080061protected:
62 /******************************
63 * From TrustedPlatformModule *
64 ******************************/
65 virtual ConstBufferPtr
66 exportPrivateKeyPkcs1FromTpm(const Name& keyName);
67
68 virtual bool
69 importPrivateKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080070
Yingdi Yu8dceb1d2014-02-18 12:45:10 -080071 virtual bool
72 importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
73
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080074private:
75 class Impl;
Yingdi Yu4b752752014-02-18 12:24:03 -080076 shared_ptr<Impl> m_impl;
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080077};
Yingdi Yu4b752752014-02-18 12:24:03 -080078
Yingdi Yufc40d872014-02-18 12:56:04 -080079} // namespace ndn
Yingdi Yu2d9c50f2014-01-21 18:25:00 -080080
Yingdi Yufc40d872014-02-18 12:56:04 -080081#endif //NDN_SECURITY_SEC_TPM_FILE_HPP