blob: 7afa036217bf324daf931dad4a56258090b6b835 [file] [log] [blame]
Alexander Afanasyev82c359c2017-01-04 14:48:07 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2017 Regents of the University of California.
4 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * 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.
20 */
21
22#include "util.hpp"
23
24namespace ndn {
25namespace ndnsec {
26
27bool
28getPassword(std::string& password, const std::string& prompt)
29{
30#ifdef NDN_CXX_HAVE_GETPASS
31 bool isReady = false;
32
33 char* pw0 = nullptr;
34
35 pw0 = getpass(prompt.c_str());
36 if (!pw0)
37 return false;
38 std::string password1 = pw0;
39 memset(pw0, 0, strlen(pw0));
40
41 pw0 = getpass("Confirm:");
42 if (!pw0) {
43 char* pw1 = const_cast<char*>(password1.c_str());
44 memset(pw1, 0, password1.size());
45 return false;
46 }
47
48 if (!password1.compare(pw0)) {
49 isReady = true;
50 password.swap(password1);
51 }
52
53 char* pw1 = const_cast<char*>(password1.c_str());
54 memset(pw1, 0, password1.size());
55 memset(pw0, 0, strlen(pw0));
56
57 if (password.empty())
58 return false;
59
60 return isReady;
61#else
62 return false;
63#endif // NDN_CXX_HAVE_GETPASS
64}
65
66shared_ptr<security::v1::IdentityCertificate>
67getIdentityCertificate(const std::string& fileName)
68{
69 if (fileName == "-")
70 return io::load<security::v1::IdentityCertificate>(std::cin);
71 else
72 return io::load<security::v1::IdentityCertificate>(fileName);
73}
74
75} // namespace ndnsec
76} // namespace ndn