From 0caac25d28a3c08b91020ed8fa893887229c017a Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Tue, 19 May 2015 20:13:19 -0700 Subject: . --- attic/updater.cpp | 177 +++++++++++++++++++++++++++++++ buildinstaller.sh | 131 ----------------------- ext/installfiles/linux/buildinstaller.sh | 131 +++++++++++++++++++++++ updater.cpp | 177 ------------------------------- 4 files changed, 308 insertions(+), 308 deletions(-) create mode 100644 attic/updater.cpp delete mode 100755 buildinstaller.sh create mode 100755 ext/installfiles/linux/buildinstaller.sh delete mode 100644 updater.cpp diff --git a/attic/updater.cpp b/attic/updater.cpp new file mode 100644 index 00000000..bc36394b --- /dev/null +++ b/attic/updater.cpp @@ -0,0 +1,177 @@ +/* + * ZeroTier One - Network Virtualization Everywhere + * Copyright (C) 2011-2015 ZeroTier, Inc. + * + * 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 +#include +#include +#include +#include + +#include "version.h" +#include "include/ZeroTierOne.h" +#include "node/Constants.hpp" + +#ifdef __WINDOWS__ +#include +#include +#include +#include +#include +#include +#include +#else +#include +#include +#include +#include +#include +#include +#endif + +#include "node/Utils.hpp" +#include "node/Address.hpp" +#include "node/Dictionary.hpp" +#include "node/Identity.hpp" +#include "osdep/OSUtils.hpp" +#include "osdep/Http.hpp" + +using namespace ZeroTier; + +namespace { + +static std::map< Address,Identity > updateAuthorities() +{ + std::map< Address,Identity > ua; + { // 0001 + Identity id("e9bc3707b5:0:c4cef17bde99eadf9748c4fd11b9b06dc5cd8eb429227811d2c336e6b96a8d329e8abd0a4f45e47fe1bcebf878c004c822d952ff77fc2833af4c74e65985c435"); + ua[id.address()] = id; + } + { // 0002 + Identity id("56520eaf93:0:7d858b47988b34399a9a31136de07b46104d7edb4a98fa1d6da3e583d3a33e48be531532b886f0b12cd16794a66ab9220749ec5112cbe96296b18fe0cc79ca05"); + ua[id.address()] = id; + } + { // 0003 + Identity id("7c195de2e0:0:9f659071c960f9b0f0b96f9f9ecdaa27c7295feed9c79b7db6eedcc11feb705e6dd85c70fa21655204d24c897865b99eb946b753a2bbcf2be5f5e006ae618c54"); + ua[id.address()] = id; + } + { // 0004 + Identity id("415f4cfde7:0:54118e87777b0ea5d922c10b337c4f4bd1db7141845bd54004b3255551a6e356ba6b9e1e85357dbfafc45630b8faa2ebf992f31479e9005f0472685f2d8cbd6e"); + ua[id.address()] = id; + } + return ua; +} + +static bool validateUpdate( + const void *data, + unsigned int len, + const Address &signedBy, + const std::string &signature) +{ + std::map< Address,Identity > ua(updateAuthorities()); + std::map< Address,Identity >::const_iterator updateAuthority = ua.find(signedBy); + if (updateAuthority == ua.end()) + return false; + return updateAuthority->second.verify(data,len,signature.data(),(unsigned int)signature.length()); +} + +/* +static inline const char *updateUrl() +{ +#if defined(__LINUX__) && ( defined(__i386__) || defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(__i386) ) + if (sizeof(void *) == 8) + return "http://download.zerotier.com/ZeroTierOneInstaller-linux-x64-LATEST.nfo"; + else return "http://download.zerotier.com/ZeroTierOneInstaller-linux-x86-LATEST.nfo"; +#define GOT_UPDATE_URL +#endif + +#ifdef __APPLE__ + return "http://download.zerotier.com/ZeroTierOneInstaller-mac-combined-LATEST.nfo"; +#define GOT_UPDATE_URL +#endif + +#ifdef __WINDOWS__ + return "http://download.zerotier.com/ZeroTierOneInstaller-windows-intel-LATEST.nfo"; +#define GOT_UPDATE_URL +#endif + +#ifndef GOT_UPDATE_URL + return ""; +#endif +} +*/ + +static const char *parseUpdateNfo( + const char *nfoText, + unsigned int &vMajor, + unsigned int &vMinor, + unsigned int &vRevision, + Address &signedBy, + std::string &signature, + std::string &url) +{ + try { + Dictionary nfo(nfoText); + + vMajor = Utils::strToUInt(nfo.get("vMajor").c_str()); + vMinor = Utils::strToUInt(nfo.get("vMinor").c_str()); + vRevision = Utils::strToUInt(nfo.get("vRevision").c_str()); + signedBy = nfo.get("signedBy"); + signature = Utils::unhex(nfo.get("ed25519")); + url = nfo.get("url"); + + if (signature.length() != ZT_C25519_SIGNATURE_LEN) + return "bad ed25519 signature, invalid length"; + if ((url.length() <= 7)||(url.substr(0,7) != "http://")) + return "invalid URL, must begin with http://"; + + return (const char *)0; + } catch ( ... ) { + return "invalid NFO file format or one or more required fields missing"; + } +} + +} // anonymous namespace + +#ifdef __WINDOWS__ +int _tmain(int argc, _TCHAR* argv[]) +#else +int main(int argc,char **argv) +#endif +{ +#ifdef __WINDOWS__ + WSADATA wsaData; + WSAStartup(MAKEWORD(2,2),&wsaData); +#endif + + return 0; +} diff --git a/buildinstaller.sh b/buildinstaller.sh deleted file mode 100755 index 8f252dff..00000000 --- a/buildinstaller.sh +++ /dev/null @@ -1,131 +0,0 @@ -#!/bin/bash - -# This script builds the installer for *nix systems. Windows must do everything -# completely differently, as usual. - -export PATH=/bin:/usr/bin:/sbin:/usr/sbin - -if [ ! -f zerotier-one ]; then - echo "Could not find 'zerotier-one' binary, please build before running this script." - exit 2 -fi - -machine=`uname -m` -system=`uname -s` - -vmajor=`cat version.h | grep -F ZEROTIER_ONE_VERSION_MAJOR | cut -d ' ' -f 3` -vminor=`cat version.h | grep -F ZEROTIER_ONE_VERSION_MINOR | cut -d ' ' -f 3` -revision=`cat version.h | grep -F ZEROTIER_ONE_VERSION_REVISION | cut -d ' ' -f 3` - -if [ -z "$vmajor" -o -z "$vminor" -o -z "$revision" ]; then - echo "Unable to extract version info from version.h, aborting installer build." - exit 2 -fi - -rm -rf build-installer -mkdir build-installer - -case "$system" in - - Linux) - # Canonicalize $machine for some architectures... we use x86 - # and x64 for Intel stuff. ARM and others should be fine if - # we ever ship officially for those. - debian_arch=$machine - case "$machine" in - i386|i486|i586|i686) - machine="x86" - debian_arch="i386" - ;; - x86_64|amd64|x64) - machine="x64" - debian_arch="amd64" - ;; - armv6l|arm|armhf) - machine="armv6l" - debian_arch="armhf" - ;; - esac - - echo "Assembling Linux installer for $machine and version $vmajor.$vminor.$revision" - - mkdir -p 'build-installer/var/lib/zerotier-one' - cp -fp 'ext/installfiles/linux/uninstall.sh' 'build-installer/var/lib/zerotier-one' - cp -fp 'zerotier-one' 'build-installer/var/lib/zerotier-one' - mkdir -p 'build-installer/tmp' - cp -fp 'ext/installfiles/linux/init.d/zerotier-one' 'build-installer/tmp/init.d_zerotier-one' - cp -fp 'ext/installfiles/linux/systemd/zerotier-one.service' 'build-installer/tmp/systemd_zerotier-one.service' - - targ="ZeroTierOneInstaller-linux-${machine}-${vmajor}_${vminor}_${revision}" - # Use gzip in Linux since some minimal Linux systems do not have bunzip2 - rm -f build-installer-tmp.tar.gz - cd build-installer - tar -cf - * | gzip -9 >../build-installer-tmp.tar.gz - cd .. - rm -f $targ - cat ext/installfiles/linux/install.tmpl.sh build-installer-tmp.tar.gz >$targ - chmod 0755 $targ - rm -f build-installer-tmp.tar.gz - ls -l $targ - - if [ -f /usr/bin/dpkg-deb -a "$UID" -eq 0 ]; then - echo - echo Found dpkg-deb and you are root, trying to build Debian package. - - rm -rf build-installer-deb - - debbase="build-installer-deb/zerotier-one_${vmajor}.${vminor}.${revision}.autoupdating_$debian_arch" - debfolder="${debbase}/DEBIAN" - mkdir -p $debfolder - - cat 'ext/installfiles/linux/DEBIAN/control.in' | sed "s/__VERSION__/${vmajor}.${vminor}.${revision}.autoupdating/" | sed "s/__ARCH__/${debian_arch}/" >$debfolder/control - cat $debfolder/control - cp -f 'ext/installfiles/linux/DEBIAN/conffiles' "${debfolder}/conffiles" - - mkdir -p "${debbase}/var/lib/zerotier-one/updates.d" - cp -f $targ "${debbase}/var/lib/zerotier-one/updates.d" - - rm -f "${debfolder}/postinst" "${debfolder}/prerm" - - echo '#!/bin/bash' >${debfolder}/postinst - echo "/var/lib/zerotier-one/updates.d/${targ}" >>${debfolder}/postinst - echo "/bin/rm -f /var/lib/zerotier-one/updates.d/*" >>${debfolder}/postinst - chmod a+x ${debfolder}/postinst - - echo '#!/bin/bash' >${debfolder}/prerm - echo 'export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin' >>${debfolder}/prerm - echo 'if [ "$1" != "upgrade" ]; then' >>${debfolder}/prerm - echo ' /var/lib/zerotier-one/uninstall.sh' >>${debfolder}/prerm - echo 'fi' >>${debfolder}/prerm - chmod a+x ${debfolder}/prerm - - dpkg-deb --build $debbase - - mv -f build-installer-deb/*.deb . - rm -rf build-installer-deb - fi - - if [ -f /usr/bin/rpmbuild ]; then - echo - echo Found rpmbuild, trying to build RedHat/CentOS package. - - rm -f /tmp/zerotier-one.spec - curr_dir=`pwd` - cat ext/installfiles/linux/RPM/zerotier-one.spec.in | sed "s/__VERSION__/${vmajor}.${vminor}.${revision}/g" | sed "s/__INSTALLER__/${targ}/g" >/tmp/zerotier-one.spec - - rpmbuild -ba /tmp/zerotier-one.spec - - rm -f /tmp/zerotier-one.spec - fi - - ;; - - *) - echo "Unsupported platform: $system" - exit 2 - -esac - -rm -rf build-installer - -exit 0 diff --git a/ext/installfiles/linux/buildinstaller.sh b/ext/installfiles/linux/buildinstaller.sh new file mode 100755 index 00000000..8f252dff --- /dev/null +++ b/ext/installfiles/linux/buildinstaller.sh @@ -0,0 +1,131 @@ +#!/bin/bash + +# This script builds the installer for *nix systems. Windows must do everything +# completely differently, as usual. + +export PATH=/bin:/usr/bin:/sbin:/usr/sbin + +if [ ! -f zerotier-one ]; then + echo "Could not find 'zerotier-one' binary, please build before running this script." + exit 2 +fi + +machine=`uname -m` +system=`uname -s` + +vmajor=`cat version.h | grep -F ZEROTIER_ONE_VERSION_MAJOR | cut -d ' ' -f 3` +vminor=`cat version.h | grep -F ZEROTIER_ONE_VERSION_MINOR | cut -d ' ' -f 3` +revision=`cat version.h | grep -F ZEROTIER_ONE_VERSION_REVISION | cut -d ' ' -f 3` + +if [ -z "$vmajor" -o -z "$vminor" -o -z "$revision" ]; then + echo "Unable to extract version info from version.h, aborting installer build." + exit 2 +fi + +rm -rf build-installer +mkdir build-installer + +case "$system" in + + Linux) + # Canonicalize $machine for some architectures... we use x86 + # and x64 for Intel stuff. ARM and others should be fine if + # we ever ship officially for those. + debian_arch=$machine + case "$machine" in + i386|i486|i586|i686) + machine="x86" + debian_arch="i386" + ;; + x86_64|amd64|x64) + machine="x64" + debian_arch="amd64" + ;; + armv6l|arm|armhf) + machine="armv6l" + debian_arch="armhf" + ;; + esac + + echo "Assembling Linux installer for $machine and version $vmajor.$vminor.$revision" + + mkdir -p 'build-installer/var/lib/zerotier-one' + cp -fp 'ext/installfiles/linux/uninstall.sh' 'build-installer/var/lib/zerotier-one' + cp -fp 'zerotier-one' 'build-installer/var/lib/zerotier-one' + mkdir -p 'build-installer/tmp' + cp -fp 'ext/installfiles/linux/init.d/zerotier-one' 'build-installer/tmp/init.d_zerotier-one' + cp -fp 'ext/installfiles/linux/systemd/zerotier-one.service' 'build-installer/tmp/systemd_zerotier-one.service' + + targ="ZeroTierOneInstaller-linux-${machine}-${vmajor}_${vminor}_${revision}" + # Use gzip in Linux since some minimal Linux systems do not have bunzip2 + rm -f build-installer-tmp.tar.gz + cd build-installer + tar -cf - * | gzip -9 >../build-installer-tmp.tar.gz + cd .. + rm -f $targ + cat ext/installfiles/linux/install.tmpl.sh build-installer-tmp.tar.gz >$targ + chmod 0755 $targ + rm -f build-installer-tmp.tar.gz + ls -l $targ + + if [ -f /usr/bin/dpkg-deb -a "$UID" -eq 0 ]; then + echo + echo Found dpkg-deb and you are root, trying to build Debian package. + + rm -rf build-installer-deb + + debbase="build-installer-deb/zerotier-one_${vmajor}.${vminor}.${revision}.autoupdating_$debian_arch" + debfolder="${debbase}/DEBIAN" + mkdir -p $debfolder + + cat 'ext/installfiles/linux/DEBIAN/control.in' | sed "s/__VERSION__/${vmajor}.${vminor}.${revision}.autoupdating/" | sed "s/__ARCH__/${debian_arch}/" >$debfolder/control + cat $debfolder/control + cp -f 'ext/installfiles/linux/DEBIAN/conffiles' "${debfolder}/conffiles" + + mkdir -p "${debbase}/var/lib/zerotier-one/updates.d" + cp -f $targ "${debbase}/var/lib/zerotier-one/updates.d" + + rm -f "${debfolder}/postinst" "${debfolder}/prerm" + + echo '#!/bin/bash' >${debfolder}/postinst + echo "/var/lib/zerotier-one/updates.d/${targ}" >>${debfolder}/postinst + echo "/bin/rm -f /var/lib/zerotier-one/updates.d/*" >>${debfolder}/postinst + chmod a+x ${debfolder}/postinst + + echo '#!/bin/bash' >${debfolder}/prerm + echo 'export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin' >>${debfolder}/prerm + echo 'if [ "$1" != "upgrade" ]; then' >>${debfolder}/prerm + echo ' /var/lib/zerotier-one/uninstall.sh' >>${debfolder}/prerm + echo 'fi' >>${debfolder}/prerm + chmod a+x ${debfolder}/prerm + + dpkg-deb --build $debbase + + mv -f build-installer-deb/*.deb . + rm -rf build-installer-deb + fi + + if [ -f /usr/bin/rpmbuild ]; then + echo + echo Found rpmbuild, trying to build RedHat/CentOS package. + + rm -f /tmp/zerotier-one.spec + curr_dir=`pwd` + cat ext/installfiles/linux/RPM/zerotier-one.spec.in | sed "s/__VERSION__/${vmajor}.${vminor}.${revision}/g" | sed "s/__INSTALLER__/${targ}/g" >/tmp/zerotier-one.spec + + rpmbuild -ba /tmp/zerotier-one.spec + + rm -f /tmp/zerotier-one.spec + fi + + ;; + + *) + echo "Unsupported platform: $system" + exit 2 + +esac + +rm -rf build-installer + +exit 0 diff --git a/updater.cpp b/updater.cpp deleted file mode 100644 index bc36394b..00000000 --- a/updater.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* - * ZeroTier One - Network Virtualization Everywhere - * Copyright (C) 2011-2015 ZeroTier, Inc. - * - * 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 -#include -#include -#include -#include - -#include "version.h" -#include "include/ZeroTierOne.h" -#include "node/Constants.hpp" - -#ifdef __WINDOWS__ -#include -#include -#include -#include -#include -#include -#include -#else -#include -#include -#include -#include -#include -#include -#endif - -#include "node/Utils.hpp" -#include "node/Address.hpp" -#include "node/Dictionary.hpp" -#include "node/Identity.hpp" -#include "osdep/OSUtils.hpp" -#include "osdep/Http.hpp" - -using namespace ZeroTier; - -namespace { - -static std::map< Address,Identity > updateAuthorities() -{ - std::map< Address,Identity > ua; - { // 0001 - Identity id("e9bc3707b5:0:c4cef17bde99eadf9748c4fd11b9b06dc5cd8eb429227811d2c336e6b96a8d329e8abd0a4f45e47fe1bcebf878c004c822d952ff77fc2833af4c74e65985c435"); - ua[id.address()] = id; - } - { // 0002 - Identity id("56520eaf93:0:7d858b47988b34399a9a31136de07b46104d7edb4a98fa1d6da3e583d3a33e48be531532b886f0b12cd16794a66ab9220749ec5112cbe96296b18fe0cc79ca05"); - ua[id.address()] = id; - } - { // 0003 - Identity id("7c195de2e0:0:9f659071c960f9b0f0b96f9f9ecdaa27c7295feed9c79b7db6eedcc11feb705e6dd85c70fa21655204d24c897865b99eb946b753a2bbcf2be5f5e006ae618c54"); - ua[id.address()] = id; - } - { // 0004 - Identity id("415f4cfde7:0:54118e87777b0ea5d922c10b337c4f4bd1db7141845bd54004b3255551a6e356ba6b9e1e85357dbfafc45630b8faa2ebf992f31479e9005f0472685f2d8cbd6e"); - ua[id.address()] = id; - } - return ua; -} - -static bool validateUpdate( - const void *data, - unsigned int len, - const Address &signedBy, - const std::string &signature) -{ - std::map< Address,Identity > ua(updateAuthorities()); - std::map< Address,Identity >::const_iterator updateAuthority = ua.find(signedBy); - if (updateAuthority == ua.end()) - return false; - return updateAuthority->second.verify(data,len,signature.data(),(unsigned int)signature.length()); -} - -/* -static inline const char *updateUrl() -{ -#if defined(__LINUX__) && ( defined(__i386__) || defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(__i386) ) - if (sizeof(void *) == 8) - return "http://download.zerotier.com/ZeroTierOneInstaller-linux-x64-LATEST.nfo"; - else return "http://download.zerotier.com/ZeroTierOneInstaller-linux-x86-LATEST.nfo"; -#define GOT_UPDATE_URL -#endif - -#ifdef __APPLE__ - return "http://download.zerotier.com/ZeroTierOneInstaller-mac-combined-LATEST.nfo"; -#define GOT_UPDATE_URL -#endif - -#ifdef __WINDOWS__ - return "http://download.zerotier.com/ZeroTierOneInstaller-windows-intel-LATEST.nfo"; -#define GOT_UPDATE_URL -#endif - -#ifndef GOT_UPDATE_URL - return ""; -#endif -} -*/ - -static const char *parseUpdateNfo( - const char *nfoText, - unsigned int &vMajor, - unsigned int &vMinor, - unsigned int &vRevision, - Address &signedBy, - std::string &signature, - std::string &url) -{ - try { - Dictionary nfo(nfoText); - - vMajor = Utils::strToUInt(nfo.get("vMajor").c_str()); - vMinor = Utils::strToUInt(nfo.get("vMinor").c_str()); - vRevision = Utils::strToUInt(nfo.get("vRevision").c_str()); - signedBy = nfo.get("signedBy"); - signature = Utils::unhex(nfo.get("ed25519")); - url = nfo.get("url"); - - if (signature.length() != ZT_C25519_SIGNATURE_LEN) - return "bad ed25519 signature, invalid length"; - if ((url.length() <= 7)||(url.substr(0,7) != "http://")) - return "invalid URL, must begin with http://"; - - return (const char *)0; - } catch ( ... ) { - return "invalid NFO file format or one or more required fields missing"; - } -} - -} // anonymous namespace - -#ifdef __WINDOWS__ -int _tmain(int argc, _TCHAR* argv[]) -#else -int main(int argc,char **argv) -#endif -{ -#ifdef __WINDOWS__ - WSADATA wsaData; - WSAStartup(MAKEWORD(2,2),&wsaData); -#endif - - return 0; -} -- cgit v1.2.3