blob: 3ee4d7c6feffec12a46ee37d6e5e22272a26b185 [file] [log] [blame]
Yingdi Yu8d7468f2014-02-21 14:49:45 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013, Regents of the University of California
4 * BSD license, See the LICENSE file for more information
5 * Author: Yingdi Yu <yingdi@cs.ucla.edu>
6 */
7
8#ifndef NDNSEC_UNLOCK_TPM_HPP
9#define NDNSEC_UNLOCK_TPM_HPP
10
11#include "ndnsec-util.hpp"
12
13int
14ndnsec_unlock_tpm(int argc, char** argv)
15{
16 using namespace ndn;
17 namespace po = boost::program_options;
18
19 std::string keyName;
20 std::string appPath;
21
22 po::options_description desc("General Usage\n ndnsec unlock-tpm [-h] \nGeneral options");
23 desc.add_options()
24 ("help,h", "produce help message")
25 ;
26
27 po::variables_map vm;
28 po::store(po::parse_command_line(argc, argv, desc), vm);
29 po::notify(vm);
30
31 if (vm.count("help"))
32 {
33 std::cerr << desc << std::endl;
34 return 0;
35 }
36
37 bool res = false;
38
39 try
40 {
41 KeyChain keyChain;
42
43 char* password;
44 password = getpass("Password to unlock the TPM: ");
45 res = keyChain.unlockTpm(password, strlen(password), true);
46 memset(password, 0, strlen(password));
47
48 }
49 catch(const SecPublicInfo::Error& e)
50 {
51 std::cerr << "ERROR: " << e.what() << std::endl;
52 return 1;
53 }
54 catch(const SecTpm::Error& e)
55 {
56 std::cerr << "ERROR: " << e.what() << std::endl;
57 return 1;
58 }
59
60 if(res)
61 {
62 std::cerr << "OK: TPM is unlocked" << std::endl;
63 return 0;
64 }
65 else
66 {
67 std::cerr << "ERROR: TPM is still locked" << std::endl;
68 return 1;
69 }
70}
71
72#endif //NDNSEC_UNLOCK_TPM_HPP