blob: 8ef5586e8ea3226e18484b8137d30d332237efe6 [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
9#ifndef NDN_SEC_TPM_FILE_HPP
10#define NDN_SEC_TPM_FILE_HPP
11
12#include "../common.hpp"
13
14#include "sec-tpm.hpp"
15
16namespace ndn
17{
18
19class SecTpmFile : public SecTpm
20{
21public:
22 struct Error : public SecTpm::Error { Error(const std::string &what) : SecTpm::Error(what) {} };
23
24 SecTpmFile(const std::string & dir = "");
25
26 /**
27 * @brief destructor
28 */
29 virtual
30 ~SecTpmFile() {};
31
32 /**
33 * Generate a pair of asymmetric keys.
34 * @param keyName The name of the key pair.
35 * @param keyType The type of the key pair, e.g. KEY_TYPE_RSA.
36 * @param keySize The size of the key pair.
37 */
38 virtual void
39 generateKeyPairInTpm(const Name & keyName, KeyType keyType, int keySize);
40
41 /**
42 * Get the public key
43 * @param keyName The name of public key.
44 * @return The public key.
45 */
46 virtual ptr_lib::shared_ptr<PublicKey>
47 getPublicKeyFromTpm(const Name & keyName);
48
49 /**
50 * Fetch the private key for keyName and sign the data, returning a signature block.
51 * Throw Error if signing fails.
52 * @param data Pointer to the input byte array.
53 * @param dataLength The length of data.
54 * @param keyName The name of the signing key.
55 * @param digestAlgorithm the digest algorithm.
56 * @return The signature block.
57 */
58 virtual Block
59 signInTpm(const uint8_t *data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm);
60
61 /**
62 * Decrypt data.
63 * @param keyName The name of the decrypting key.
64 * @param data The byte to be decrypted.
65 * @param dataLength the length of data.
66 * @param isSymmetric If true symmetric encryption is used, otherwise asymmetric encryption is used.
67 * @return The decrypted data.
68 */
69 virtual ConstBufferPtr
70 decryptInTpm(const Name& keyName, const uint8_t* data, size_t dataLength, bool isSymmetric);
71
72 /**
73 * Encrypt data.
74 * @param keyName The name of the encrypting key.
75 * @param data The byte to be encrypted.
76 * @param dataLength the length of data.
77 * @param isSymmetric If true symmetric encryption is used, otherwise asymmetric decryption is used.
78 * @return The encrypted data.
79 */
80 virtual ConstBufferPtr
81 encryptInTpm(const Name& keyName, const uint8_t* data, size_t dataLength, bool isSymmetric);
82
83
84 /**
85 * Generate a symmetric key.
86 * @param keyName The name of the key.
87 * @param keyType The type of the key, e.g. KEY_TYPE_AES.
88 * @param keySize The size of the key.
89 */
90 virtual void
91 generateSymmetricKeyInTpm(const Name& keyName, KeyType keyType, int keySize);
92
93 /**
94 * Check if a particular key exists.
95 * @param keyName The name of the key.
96 * @param keyClass The class of the key, e.g. KEY_CLASS_PUBLIC, KEY_CLASS_PRIVATE, or KEY_CLASS_SYMMETRIC.
97 * @return True if the key exists, otherwise false.
98 */
99 virtual bool
100 doesKeyExistInTpm(const Name& keyName, KeyClass keyClass);
101
102 std::string
103 nameTransform(const std::string &keyName, const std::string &extension);
104
105private:
106 void
107 maintainMapping(std::string str1, std::string str2);
108
109private:
110 class Impl;
111 std::auto_ptr<Impl> impl_;
112};
113}//ndn
114
115#endif