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