Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [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 | /** |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2014 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 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. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 20 | * |
| 21 | * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/> |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 22 | */ |
| 23 | |
| 24 | #ifndef NDNSEC_SIG_VERIFY_HPP |
| 25 | #define NDNSEC_SIG_VERIFY_HPP |
| 26 | |
| 27 | #include "ndnsec-util.hpp" |
| 28 | |
| 29 | // using namespace ndn; |
| 30 | // namespace po = boost::program_options; |
| 31 | |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 32 | // shared_ptr<IdentityCertificate> |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 33 | // getCertificate(const std::string& certString) |
| 34 | // { |
| 35 | // std::string decoded; |
| 36 | // CryptoPP::StringSource ss2(reinterpret_cast<const unsigned char *>(certString.c_str()), certString.size(), true, |
| 37 | // new CryptoPP::Base64Decoder(new CryptoPP::StringSink(decoded))); |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 38 | |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 39 | // Data data; |
| 40 | // data.wireDecode(Block(make_shared<Buffer>(decoded.begin(), decoded.end()))); |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 41 | |
Alexander Afanasyev | f73f063 | 2014-05-12 18:02:37 -0700 | [diff] [blame] | 42 | // shared_ptr<IdentityCertificate> identityCertificate = make_shared<IdentityCertificate>(data); |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 43 | |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 44 | // return identityCertificate; |
| 45 | // } |
| 46 | |
| 47 | // bool |
| 48 | // verifySignature(shared_ptr<IdentityCertificate> certificate, bool isDataPacket) |
| 49 | // { |
| 50 | // throw std::runtime_error("Not supported yet"); |
| 51 | // // if(isDataPacket) |
| 52 | // // { |
| 53 | // // std::string decoded; |
| 54 | // // CryptoPP::FileSource ss2(cin, true, |
| 55 | // // new CryptoPP::Base64Decoder(new CryptoPP::StringSink(decoded))); |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 56 | |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 57 | // // Data data; |
Alexander Afanasyev | f73f063 | 2014-05-12 18:02:37 -0700 | [diff] [blame] | 58 | // // data.wireDecode(make_shared<Buffer>(decoded.c_str(), decoded.size())); |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 59 | // // return PolicyManager::verifySignature(data, certificate->getPublicKeyInfo()); |
| 60 | // // } |
| 61 | // // else |
| 62 | // // { |
| 63 | // // // The first two bytes indicates the boundary of the of the signed data and signature. |
| 64 | // // // for example, if the size of the signed data is 300, then the boundary should be 300, so the first two bytes should be: 0x01 0x2C |
Alexander Afanasyev | f73f063 | 2014-05-12 18:02:37 -0700 | [diff] [blame] | 65 | // // shared_ptr<Blob> input = shared_ptr<Blob>(new Blob ((istreambuf_iterator<char>(cin)), istreambuf_iterator<char>())); |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 66 | // // size_t size = input->at(0); |
| 67 | // // size = ((size << 8) + input->at(1)); |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 68 | |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 69 | // // Blob signedBlob(input->buf()+2, size); |
| 70 | // // Blob signature(input->buf()+2+size, input->size()-2-size); |
| 71 | |
| 72 | // // return PolicyManager::verifySignature(signedBlob, signature, certificate->getPublicKeyInfo()); |
| 73 | // // } |
| 74 | // } |
| 75 | |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 76 | int |
| 77 | ndnsec_sig_verify(int argc, char** argv) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 78 | { |
| 79 | std::cerr << "Not supported yet" << std::endl; |
| 80 | return 1; |
| 81 | // bool isDataPacket = false; |
| 82 | // std::string certString; |
| 83 | |
| 84 | // po::options_description desc("General Usage\n ndn-sig-verify [-h] [-d] certificate\nGeneral options"); |
| 85 | // desc.add_options() |
| 86 | // ("help,h", "produce help message") |
| 87 | // ("data,d", "if specified, input from stdin will be treated as a Data packet, otherwise binary data") |
| 88 | // ("certificate,c", po::value<std::string>(&certString), "the certificate bits") |
| 89 | // ; |
| 90 | |
| 91 | // po::positional_options_description p; |
| 92 | // p.add("certificate", 1); |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 93 | |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 94 | // po::variables_map vm; |
| 95 | // try |
| 96 | // { |
| 97 | // po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm); |
| 98 | // po::notify(vm); |
| 99 | // } |
| 100 | // catch( const std::exception& e) |
| 101 | // { |
| 102 | // std::cerr << e.what() << std::endl; |
| 103 | // std::cerr << desc << std::endl; |
| 104 | // return 1; |
| 105 | // } |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 106 | |
| 107 | // if (vm.count("help") || vm.count("certificate")==0) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 108 | // { |
| 109 | // std::cerr << desc << std::endl; |
| 110 | // return 1; |
| 111 | // } |
| 112 | // if (vm.count("data")) |
| 113 | // isDataPacket = true; |
| 114 | |
| 115 | // try |
| 116 | // { |
| 117 | // shared_ptr<IdentityCertificate> certificate = getCertificate(certString); |
| 118 | // bool res = verifySignature(certificate, isDataPacket); |
| 119 | // return (res ? 0 : 1); |
| 120 | // } |
| 121 | // catch(const std::exception &e) |
| 122 | // { |
| 123 | // std::cerr << "ERROR: " << e.what() << std::endl; |
| 124 | // return 1; |
| 125 | // } |
| 126 | } |
| 127 | |
| 128 | #endif //NDNSEC_SIG_VERIFY_HPP |