blob: 5d2dcff67fa3ed502de29137c606b0264478a03c [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
Yingdi Yub61f5402014-02-26 17:46:11 -080019 std::string keyName;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080020
Yingdi Yub61f5402014-02-26 17:46:11 -080021 po::options_description description("General Usage\n ndnsec unlock-tpm [-h] \nGeneral options");
22 description.add_options()
Yingdi Yu8d7468f2014-02-21 14:49:45 -080023 ("help,h", "produce help message")
24 ;
25
26 po::variables_map vm;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080027
Yingdi Yu8d7468f2014-02-21 14:49:45 -080028 try
29 {
Yingdi Yub61f5402014-02-26 17:46:11 -080030 po::store(po::parse_command_line(argc, argv, description), vm);
31 po::notify(vm);
Yingdi Yu8d7468f2014-02-21 14:49:45 -080032 }
Yingdi Yub61f5402014-02-26 17:46:11 -080033 catch (const std::exception& e)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080034 {
35 std::cerr << "ERROR: " << e.what() << std::endl;
Yingdi Yub61f5402014-02-26 17:46:11 -080036 std::cerr << description << std::endl;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080037 return 1;
38 }
39
Yingdi Yub61f5402014-02-26 17:46:11 -080040 if (vm.count("help") != 0)
41 {
42 std::cerr << description << std::endl;
43 return 0;
44 }
45
46 bool isUnlocked = false;
47
48 KeyChain keyChain;
49
50 char* password;
51 password = getpass("Password to unlock the TPM: ");
52 isUnlocked = keyChain.unlockTpm(password, strlen(password), true);
53 memset(password, 0, strlen(password));
54
55 if (isUnlocked)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080056 {
57 std::cerr << "OK: TPM is unlocked" << std::endl;
58 return 0;
59 }
60 else
61 {
62 std::cerr << "ERROR: TPM is still locked" << std::endl;
63 return 1;
64 }
65}
66
67#endif //NDNSEC_UNLOCK_TPM_HPP