blob: e49387a838891e0b6b74b965b7a1673db261083a [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 Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 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.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -070020 *
21 * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
Yingdi Yu8d7468f2014-02-21 14:49:45 -080022 */
23
Alexander Afanasyevd7db8bf2015-01-04 15:31:02 -080024#ifndef NDN_TOOLS_NDNSEC_SIG_VERIFY_HPP
25#define NDN_TOOLS_NDNSEC_SIG_VERIFY_HPP
Yingdi Yu8d7468f2014-02-21 14:49:45 -080026
Alexander Afanasyevd7db8bf2015-01-04 15:31:02 -080027#include "util.hpp"
Yingdi Yu8d7468f2014-02-21 14:49:45 -080028
29// using namespace ndn;
30// namespace po = boost::program_options;
31
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -070032// shared_ptr<IdentityCertificate>
Yingdi Yu8d7468f2014-02-21 14:49:45 -080033// 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 Afanasyevdfa52c42014-04-24 21:10:11 -070038
Yingdi Yu8d7468f2014-02-21 14:49:45 -080039// Data data;
40// data.wireDecode(Block(make_shared<Buffer>(decoded.begin(), decoded.end())));
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -070041
Alexander Afanasyevf73f0632014-05-12 18:02:37 -070042// shared_ptr<IdentityCertificate> identityCertificate = make_shared<IdentityCertificate>(data);
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -070043
Yingdi Yu8d7468f2014-02-21 14:49:45 -080044// 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 Afanasyevdfa52c42014-04-24 21:10:11 -070056
Yingdi Yu8d7468f2014-02-21 14:49:45 -080057// // Data data;
Alexander Afanasyevf73f0632014-05-12 18:02:37 -070058// // data.wireDecode(make_shared<Buffer>(decoded.c_str(), decoded.size()));
Yingdi Yu8d7468f2014-02-21 14:49:45 -080059// // 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 Afanasyevf73f0632014-05-12 18:02:37 -070065// // shared_ptr<Blob> input = shared_ptr<Blob>(new Blob ((istreambuf_iterator<char>(cin)), istreambuf_iterator<char>()));
Yingdi Yu8d7468f2014-02-21 14:49:45 -080066// // size_t size = input->at(0);
67// // size = ((size << 8) + input->at(1));
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -070068
Yingdi Yu8d7468f2014-02-21 14:49:45 -080069// // 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 Afanasyevdfa52c42014-04-24 21:10:11 -070076int
77ndnsec_sig_verify(int argc, char** argv)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080078{
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 Afanasyevdfa52c42014-04-24 21:10:11 -070093
Yingdi Yu8d7468f2014-02-21 14:49:45 -080094 // 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 Afanasyevdfa52c42014-04-24 21:10:11 -0700106
107 // if (vm.count("help") || vm.count("certificate")==0)
Yingdi Yu8d7468f2014-02-21 14:49:45 -0800108 // {
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
Alexander Afanasyevd7db8bf2015-01-04 15:31:02 -0800128#endif // NDN_TOOLS_NDNSEC_SIG_VERIFY_HPP