blob: 86d76359adf8d8e442fc22ccdb018e7fd60a5073 [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 Afanasyev4c9a3d52017-01-03 17:45:19 -08003 * Copyright (c) 2013-2017 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.
Yingdi Yu8d7468f2014-02-21 14:49:45 -080020 */
21
Alexander Afanasyev82c359c2017-01-04 14:48:07 -080022#include "ndnsec.hpp"
Alexander Afanasyevd7db8bf2015-01-04 15:31:02 -080023#include "util.hpp"
Yingdi Yu8d7468f2014-02-21 14:49:45 -080024
Alexander Afanasyev82c359c2017-01-04 14:48:07 -080025namespace ndn {
26namespace ndnsec {
27
Yingdi Yu8d7468f2014-02-21 14:49:45 -080028int
29ndnsec_unlock_tpm(int argc, char** argv)
30{
Alexander Afanasyevcf3a6672015-02-01 20:33:22 -080031#ifdef NDN_CXX_HAVE_GETPASS
Yingdi Yu8d7468f2014-02-21 14:49:45 -080032 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");
Alexander Afanasyev82c359c2017-01-04 14:48:07 -080038 description.add_options()("help,h", "produce help message");
Yingdi Yu8d7468f2014-02-21 14:49:45 -080039
40 po::variables_map vm;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080041
Alexander Afanasyev82c359c2017-01-04 14:48:07 -080042 try {
43 po::store(po::parse_command_line(argc, argv, description), vm);
44 po::notify(vm);
45 }
46 catch (const std::exception& e) {
47 std::cerr << "ERROR: " << e.what() << std::endl;
48 std::cerr << description << std::endl;
49 return 1;
50 }
Yingdi Yu8d7468f2014-02-21 14:49:45 -080051
Alexander Afanasyev82c359c2017-01-04 14:48:07 -080052 if (vm.count("help") != 0) {
53 std::cerr << description << std::endl;
54 return 0;
55 }
Yingdi Yub61f5402014-02-26 17:46:11 -080056
57 bool isUnlocked = false;
58
Alexander Afanasyev82c359c2017-01-04 14:48:07 -080059 security::v1::KeyChain keyChain;
Yingdi Yub61f5402014-02-26 17:46:11 -080060
61 char* password;
62 password = getpass("Password to unlock the TPM: ");
63 isUnlocked = keyChain.unlockTpm(password, strlen(password), true);
64 memset(password, 0, strlen(password));
65
Alexander Afanasyev82c359c2017-01-04 14:48:07 -080066 if (isUnlocked) {
67 std::cerr << "OK: TPM is unlocked" << std::endl;
68 return 0;
69 }
70 else {
71 std::cerr << "ERROR: TPM is still locked" << std::endl;
72 return 1;
73 }
Alexander Afanasyeva2ada222015-01-22 18:34:16 -080074#else
75 std::cerr << "ERROR: Command not supported on this platform" << std::endl;
76 return 1;
77#endif // NDN_CXX_HAVE_GETPASS
Yingdi Yu8d7468f2014-02-21 14:49:45 -080078}
79
Alexander Afanasyev82c359c2017-01-04 14:48:07 -080080} // namespace ndnsec
81} // namespace ndn