From 150850b80012f852521c9935145cf966946334d5 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Thu, 4 Jul 2013 16:56:19 -0400 Subject: New git repository for release - version 0.2.0 tagged --- packtool.cpp | 182 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 packtool.cpp (limited to 'packtool.cpp') diff --git a/packtool.cpp b/packtool.cpp new file mode 100644 index 00000000..6726c8d7 --- /dev/null +++ b/packtool.cpp @@ -0,0 +1,182 @@ +/* + * ZeroTier One - Global Peer to Peer Ethernet + * Copyright (C) 2012-2013 ZeroTier Networks LLC + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * -- + * + * ZeroTier may be used and distributed under the terms of the GPLv3, which + * are available at: http://www.gnu.org/licenses/gpl-3.0.html + * + * If you would like to embed ZeroTier into a commercial application or + * redistribute it in a modified binary form, please contact ZeroTier Networks + * LLC. Start here: http://www.zerotier.com/ + */ + +#include +#include +#include +#include +#include + +#include "node/Identity.hpp" +#include "node/Pack.hpp" +#include "node/Utils.hpp" + +#include + +using namespace ZeroTier; + +static void printHelp(const char *pn) +{ + std::cout << "Usage: " << pn << " []" << std::endl << std::endl; + std::cout << "Commands:" << std::endl; + std::cout << " list []" << std::endl; + std::cout << " create [ ...]" << std::endl; + std::cout << " extract " << std::endl; + std::cout << std::endl << "To check signatures, use 'list' with an identity argument." << std::endl; +} + +static Pack *readPack(const char *path) +{ + std::string tmp; + if (!Utils::readFile(path,tmp)) + return (Pack *)0; + Pack *p = new Pack(); + if (!p->deserialize(tmp)) { + delete p; + return (Pack *)0; + } + return p; +} + +int main(int argc,char **argv) +{ + if (argc < 2) { + printHelp(argv[0]); + return -1; + } + + if (!strcmp(argv[1],"list")) { + if (argc < 3) { + printHelp(argv[0]); + return -1; + } + + Pack *pack = readPack(argv[2]); + if (!pack) { + std::cout << "Could not read " << argv[2] << std::endl; + return -1; + } + + std::vector entries = pack->getAll(); + for(std::vector::iterator e=entries.begin();e!=entries.end();++e) { + std::cout << (*e)->name << '\t' << (*e)->content.length() << '\t' << Utils::hex((*e)->sha256,32) << "\tsigned by: " << (*e)->signedBy.toString() << std::endl; + } + + if (argc >= 4) { + std::string idser; + if (!Utils::readFile(argv[3],idser)) { + std::cout << "Unable to read identity from " << argv[3] << std::endl; + return -1; + } + Identity id; + if (!id.fromString(idser)) { + std::cout << "Invalid identity" << std::endl; + return -1; + } + + entries = pack->verifyAll(id,true); + for(std::vector::iterator e=entries.begin();e!=entries.end();++e) { + std::cout << "!!! Signature verification FAILED for: " << (*e)->name << std::endl; + } + if (!entries.size()) + std::cout << "Signature for all entries verified OK" << std::endl; + } + + delete pack; + } else if (!strcmp(argv[1],"create")) { + if (argc < 5) { + printHelp(argv[0]); + return -1; + } + + std::string idser; + if (!Utils::readFile(argv[3],idser)) { + std::cout << "Unable to read identity from " << argv[3] << std::endl; + return -1; + } + Identity id; + if (!id.fromString(idser)) { + std::cout << "Invalid identity" << std::endl; + return -1; + } + + if (!id.hasPrivate()) { + std::cout << "Identity must include private key to sign" << std::endl; + return -1; + } + + Pack pack; + for(int i=4;i entries = pack->getAll(); + for(std::vector::iterator e=entries.begin();e!=entries.end();++e) { + if (!Utils::writeFile((*e)->name.c_str(),(*e)->content)) + std::cout << "Error writing " << (*e)->name << std::endl; + else std::cout << "Wrote " << (*e)->name << " (" << (*e)->content.length() << ")" << std::endl; + } + } else { + printHelp(argv[0]); + return -1; + } + + return 0; +} -- cgit v1.2.3