Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame^] | 2 | /** |
| 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 Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #ifndef NDNSEC_UNLOCK_TPM_HPP |
| 16 | #define NDNSEC_UNLOCK_TPM_HPP |
| 17 | |
| 18 | #include "ndnsec-util.hpp" |
| 19 | |
| 20 | int |
| 21 | ndnsec_unlock_tpm(int argc, char** argv) |
| 22 | { |
| 23 | using namespace ndn; |
| 24 | namespace po = boost::program_options; |
| 25 | |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 26 | std::string keyName; |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 27 | |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 28 | po::options_description description("General Usage\n ndnsec unlock-tpm [-h] \nGeneral options"); |
| 29 | description.add_options() |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 30 | ("help,h", "produce help message") |
| 31 | ; |
| 32 | |
| 33 | po::variables_map vm; |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 34 | |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 35 | try |
| 36 | { |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 37 | po::store(po::parse_command_line(argc, argv, description), vm); |
| 38 | po::notify(vm); |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 39 | } |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 40 | catch (const std::exception& e) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 41 | { |
| 42 | std::cerr << "ERROR: " << e.what() << std::endl; |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 43 | std::cerr << description << std::endl; |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 44 | return 1; |
| 45 | } |
| 46 | |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 47 | 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 Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 63 | { |
| 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 |