blob: 7d2043b63b9350fd254deef5c496eaa8de5473a8 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07002/**
Alexander Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -070020 *
21 * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
Yingdi Yu8d7468f2014-02-21 14:49:45 -080022 */
23
Alexander Afanasyevd7db8bf2015-01-04 15:31:02 -080024#ifndef NDN_TOOLS_NDNSEC_UNLOCK_TPM_HPP
25#define NDN_TOOLS_NDNSEC_UNLOCK_TPM_HPP
Yingdi Yu8d7468f2014-02-21 14:49:45 -080026
Alexander Afanasyevd7db8bf2015-01-04 15:31:02 -080027#include "util.hpp"
Yingdi Yu8d7468f2014-02-21 14:49:45 -080028
29int
30ndnsec_unlock_tpm(int argc, char** argv)
31{
32 using namespace ndn;
33 namespace po = boost::program_options;
34
Yingdi Yub61f5402014-02-26 17:46:11 -080035 std::string keyName;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080036
Yingdi Yub61f5402014-02-26 17:46:11 -080037 po::options_description description("General Usage\n ndnsec unlock-tpm [-h] \nGeneral options");
38 description.add_options()
Yingdi Yu8d7468f2014-02-21 14:49:45 -080039 ("help,h", "produce help message")
40 ;
41
42 po::variables_map vm;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080043
Yingdi Yu8d7468f2014-02-21 14:49:45 -080044 try
45 {
Yingdi Yub61f5402014-02-26 17:46:11 -080046 po::store(po::parse_command_line(argc, argv, description), vm);
47 po::notify(vm);
Yingdi Yu8d7468f2014-02-21 14:49:45 -080048 }
Yingdi Yub61f5402014-02-26 17:46:11 -080049 catch (const std::exception& e)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080050 {
51 std::cerr << "ERROR: " << e.what() << std::endl;
Yingdi Yub61f5402014-02-26 17:46:11 -080052 std::cerr << description << std::endl;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080053 return 1;
54 }
55
Yingdi Yub61f5402014-02-26 17:46:11 -080056 if (vm.count("help") != 0)
57 {
58 std::cerr << description << std::endl;
59 return 0;
60 }
61
62 bool isUnlocked = false;
63
64 KeyChain keyChain;
65
66 char* password;
67 password = getpass("Password to unlock the TPM: ");
68 isUnlocked = keyChain.unlockTpm(password, strlen(password), true);
69 memset(password, 0, strlen(password));
70
71 if (isUnlocked)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080072 {
73 std::cerr << "OK: TPM is unlocked" << std::endl;
74 return 0;
75 }
76 else
77 {
78 std::cerr << "ERROR: TPM is still locked" << std::endl;
79 return 1;
80 }
81}
82
Alexander Afanasyevd7db8bf2015-01-04 15:31:02 -080083#endif // NDN_TOOLS_NDNSEC_UNLOCK_TPM_HPP