blob: 94e1187cf8a5662214709985ee6ce9994c7bed46 [file] [log] [blame]
Yingdi Yu8d7468f2014-02-21 14:49:45 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07002/**
3 * 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 Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
Yingdi Yu8d7468f2014-02-21 14:49:45 -080013 */
14
15#ifndef NDNSEC_UNLOCK_TPM_HPP
16#define NDNSEC_UNLOCK_TPM_HPP
17
18#include "ndnsec-util.hpp"
19
20int
21ndnsec_unlock_tpm(int argc, char** argv)
22{
23 using namespace ndn;
24 namespace po = boost::program_options;
25
Yingdi Yub61f5402014-02-26 17:46:11 -080026 std::string keyName;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080027
Yingdi Yub61f5402014-02-26 17:46:11 -080028 po::options_description description("General Usage\n ndnsec unlock-tpm [-h] \nGeneral options");
29 description.add_options()
Yingdi Yu8d7468f2014-02-21 14:49:45 -080030 ("help,h", "produce help message")
31 ;
32
33 po::variables_map vm;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080034
Yingdi Yu8d7468f2014-02-21 14:49:45 -080035 try
36 {
Yingdi Yub61f5402014-02-26 17:46:11 -080037 po::store(po::parse_command_line(argc, argv, description), vm);
38 po::notify(vm);
Yingdi Yu8d7468f2014-02-21 14:49:45 -080039 }
Yingdi Yub61f5402014-02-26 17:46:11 -080040 catch (const std::exception& e)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080041 {
42 std::cerr << "ERROR: " << e.what() << std::endl;
Yingdi Yub61f5402014-02-26 17:46:11 -080043 std::cerr << description << std::endl;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080044 return 1;
45 }
46
Yingdi Yub61f5402014-02-26 17:46:11 -080047 if (vm.count("help") != 0)
48 {
49 std::cerr << description << std::endl;
50 return 0;
51 }
52
53 bool isUnlocked = false;
54
55 KeyChain keyChain;
56
57 char* password;
58 password = getpass("Password to unlock the TPM: ");
59 isUnlocked = keyChain.unlockTpm(password, strlen(password), true);
60 memset(password, 0, strlen(password));
61
62 if (isUnlocked)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080063 {
64 std::cerr << "OK: TPM is unlocked" << std::endl;
65 return 0;
66 }
67 else
68 {
69 std::cerr << "ERROR: TPM is still locked" << std::endl;
70 return 1;
71 }
72}
73
74#endif //NDNSEC_UNLOCK_TPM_HPP