From: konrad Date: Mon, 5 Jan 2009 17:50:53 +0000 (+0000) Subject: draft of autoupdate function and mkdist util X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=63a524a8ef239c2315b73aba762217c901e48a04;p=web%2Fkonrad%2Fsmoke.git draft of autoupdate function and mkdist util git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@244 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- diff --git a/mkdist/distkey.cpp b/mkdist/distkey.cpp new file mode 100644 index 0000000..ebf2c8b --- /dev/null +++ b/mkdist/distkey.cpp @@ -0,0 +1,111 @@ +// +// C++ Implementation: distkey +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#include "distkey.h" + +#ifdef HAVE_KEYGEN + +#include + +#include +#include + +int keygen() +{ + //open /dev/random + QFile rf("/dev/random"); + if(!rf.open(QIODevice::ReadOnly)){ + qDebug("Error: cannot open /dev/random, giving up."); + return -1; + } + //generate p,q,n,e,d + mpz_t p,q,n,d,e,t; + mpz_init(p); + mpz_init(q); + mpz_init(n); + mpz_init(d); + mpz_init(e); + mpz_init(t); + do{ + qDebug("generating p..."); + QByteArray ba=rf.read(64); + if(ba.size()<64){ + qDebug("Exception: p<512 bit"); + return -1; + } + ba.prepend((char)1); + mpz_set_str(t,ba.toHex().data(),16); + mpz_nextprime(p,t); + qDebug("generating q..."); + ba=rf.read(64); + if(ba.size()<64){ + qDebug("Exception: q<512 bit"); + return -1; + } + ba.prepend((char)1); + mpz_set_str(t,ba.toHex().data(),16); + mpz_nextprime(q,t); + qDebug("calculating n..."); + mpz_mul(n,p,q); + mpz_sub_ui(d,p,1); + mpz_sub_ui(e,q,1); + mpz_mul(t,d,e); + qDebug("testing e=3..."); + mpz_set_ui(e,3); + mpz_gcd(d,t,e); + if(mpz_cmp_ui(d,1)>0){ + qDebug("testing e=7..."); + mpz_set_ui(e,3); + mpz_gcd(d,t,e); + if(mpz_cmp_ui(d,1)>0){ + qDebug("testing failed, restarting..."); + continue; + } + } + break; + }while(true); + qDebug("calculating d..."); + mpz_invert(d,e,t); + qDebug("testing key..."); + //generate a number p < n + QByteArray ba; + ba.fill('f',260); + mpz_set_str(t,ba.data(),16); + mpz_mod(p,t,n); + //encrypt it + mpz_powm(q,p,e,n); + //decrypt it + mpz_powm(t,q,d,n); + //compare + if(mpz_cmp(p,t)!=0){ + qDebug("test failed!"); + return -1; + } + qDebug("writing key.h..."); + QFile fd("key.h"); + if(!fd.open(QIODevice::WriteOnly|QIODevice::Truncate)){ + qDebug("Error: cannot open key.h"); + return -1; + } + char buf[1024];//more than enough for a 1024 bit number in hex + fd.write("//generated file, don't edit!\n#define RSA_N \"0x"); + fd.write(mpz_get_str(buf,16,n)); + fd.write("\"\n#define RSA_E \"0x"); + fd.write(mpz_get_str(buf,16,e)); + fd.write("\"\n#define RSA_D \"0x"); + fd.write(mpz_get_str(buf,16,d)); + fd.write("\"\n"); + fd.close(); + return 0; +} + +#endif diff --git a/mkdist/distkey.h b/mkdist/distkey.h new file mode 100644 index 0000000..8a11894 --- /dev/null +++ b/mkdist/distkey.h @@ -0,0 +1,24 @@ +// +// C++ Interface: distkey +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#include + +#if !defined(Q_OS_WIN32) && !defined(Q_OS_WIN64) && !defined(Q_OS_WINCE) +#define HAVE_KEYGEN 1 + +#define DISTKEYGEN if(app.arguments().contains("-keygen"))return keygen(); + +int keygen(); + +#else +#define DISTKEYGEN +#endif diff --git a/mkdist/mkdist.cpp b/mkdist/mkdist.cpp new file mode 100644 index 0000000..bd7ff36 --- /dev/null +++ b/mkdist/mkdist.cpp @@ -0,0 +1,24 @@ +// +// C++ Implementation: mkdist +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#include +#include + +#include "distkey.h" + +int main(int argc,char**argv) +{ + QCoreApplication app(argc,argv); + DISTKEYGEN; + + return app.exec(); +} diff --git a/mkdist/mkdist.pro b/mkdist/mkdist.pro new file mode 100644 index 0000000..98eb888 --- /dev/null +++ b/mkdist/mkdist.pro @@ -0,0 +1,8 @@ +TEMPLATE = app +TARGET = mkdist + +include(../zip/zip.pri) +LIBS += -lgmp + +SOURCES += mkdist.cpp distkey.cpp +HEADERS += distkey.h \ No newline at end of file diff --git a/src/autoupdate.cpp b/src/autoupdate.cpp new file mode 100644 index 0000000..7ab768d --- /dev/null +++ b/src/autoupdate.cpp @@ -0,0 +1,19 @@ +// +// C++ Implementation: autoupdate +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#include "autoupdate.h" + +void initAutoUpdate() +{ + //... +} + diff --git a/src/autoupdate.h b/src/autoupdate.h new file mode 100644 index 0000000..6816529 --- /dev/null +++ b/src/autoupdate.h @@ -0,0 +1,18 @@ +// +// C++ Interface: autoupdate +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#ifndef MAGICSMOKE_AUTOUPDATE_H +#define MAGICSMOKE_AUTOUPDATE_H + +void initAutoUpdate(); + +#endif diff --git a/src/main.cpp b/src/main.cpp index aa8c317..e61d9d2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,6 +21,7 @@ #include #include +#include "autoupdate.h" #include "keygen.h" #include "mainwindow.h" #include "hmac.h" @@ -157,6 +158,9 @@ int main(int argc,char**argv) QSettings().setValue("profiles/0/name",ipname); } + //initialize auto update + initAutoUpdate(); + //open main window MMainWindow mmw; mmw.showMaximized(); diff --git a/src/odtrender.cpp b/src/odtrender.cpp index a27cd0c..2dc679d 100644 --- a/src/odtrender.cpp +++ b/src/odtrender.cpp @@ -20,8 +20,8 @@ #include #include -#include "zip/qunzip.h" -#include "zip/qzip.h" +#include "../zip/qunzip.h" +#include "../zip/qzip.h" class MOdtRendererPrivate diff --git a/src/smoke.pro b/src/smoke.pro index 1e554c8..0e79167 100644 --- a/src/smoke.pro +++ b/src/smoke.pro @@ -49,7 +49,8 @@ SOURCES = \ templatedlg.cpp \ office.cpp \ centbox.cpp \ - moneylog.cpp + moneylog.cpp \ + autoupdate.cpp HEADERS = \ keygen.h \ @@ -77,7 +78,8 @@ HEADERS = \ templatedlg.h \ office.h \ centbox.h \ - moneylog.h + moneylog.h \ + autoupdate.h #some PHP files are listed in this file to scan them for translatable items #use genphpscan.sh to regenerate it. @@ -91,4 +93,5 @@ TRANSLATIONS = \ smoke_en.ts -include(zip/zip.pri) +include(../zip/zip.pri) +LIBS += -lgmp diff --git a/src/ticketrender.cpp b/src/ticketrender.cpp index 5eba63c..f4503c3 100644 --- a/src/ticketrender.cpp +++ b/src/ticketrender.cpp @@ -24,8 +24,8 @@ #include #include -#include "zip/qunzip.h" -#include "zip/qzip.h" +#include "../zip/qunzip.h" +#include "../zip/qzip.h" #include "code39.h" #include "order.h" diff --git a/src/zip/COPYING b/zip/COPYING similarity index 100% rename from src/zip/COPYING rename to zip/COPYING diff --git a/src/zip/README b/zip/README similarity index 100% rename from src/zip/README rename to zip/README diff --git a/src/zip/crypt.h b/zip/crypt.h similarity index 100% rename from src/zip/crypt.h rename to zip/crypt.h diff --git a/src/zip/ioapi.c b/zip/ioapi.c similarity index 100% rename from src/zip/ioapi.c rename to zip/ioapi.c diff --git a/src/zip/ioapi.h b/zip/ioapi.h similarity index 100% rename from src/zip/ioapi.h rename to zip/ioapi.h diff --git a/src/zip/qtioapi.cpp b/zip/qtioapi.cpp similarity index 100% rename from src/zip/qtioapi.cpp rename to zip/qtioapi.cpp diff --git a/src/zip/qtioapi.h b/zip/qtioapi.h similarity index 100% rename from src/zip/qtioapi.h rename to zip/qtioapi.h diff --git a/src/zip/qunzip.cpp b/zip/qunzip.cpp similarity index 100% rename from src/zip/qunzip.cpp rename to zip/qunzip.cpp diff --git a/src/zip/qunzip.h b/zip/qunzip.h similarity index 100% rename from src/zip/qunzip.h rename to zip/qunzip.h diff --git a/src/zip/qzip.cpp b/zip/qzip.cpp similarity index 100% rename from src/zip/qzip.cpp rename to zip/qzip.cpp diff --git a/src/zip/qzip.h b/zip/qzip.h similarity index 100% rename from src/zip/qzip.h rename to zip/qzip.h diff --git a/src/zip/unzip.c b/zip/unzip.c similarity index 100% rename from src/zip/unzip.c rename to zip/unzip.c diff --git a/src/zip/unzip.h b/zip/unzip.h similarity index 100% rename from src/zip/unzip.h rename to zip/unzip.h diff --git a/src/zip/zip.c b/zip/zip.c similarity index 100% rename from src/zip/zip.c rename to zip/zip.c diff --git a/src/zip/zip.h b/zip/zip.h similarity index 100% rename from src/zip/zip.h rename to zip/zip.h diff --git a/zip/zip.pri b/zip/zip.pri new file mode 100644 index 0000000..844e698 --- /dev/null +++ b/zip/zip.pri @@ -0,0 +1,5 @@ +# Include for ZIP-Library from LinTouch Project +# +# Modified for Magic Smoke by (c) Konrad Rosenbaum, 2007 + +LIBS += -L ../zip -lzip diff --git a/src/zip/zip.pri b/zip/zip.pro similarity index 85% rename from src/zip/zip.pri rename to zip/zip.pro index 8f5412f..a3ee791 100644 --- a/src/zip/zip.pri +++ b/zip/zip.pro @@ -27,18 +27,22 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. +TEMPLATE = lib +TARGET = zip +DESTDIR = ../zip + SOURCES += \ - zip/ioapi.c \ - zip/unzip.c \ - zip/zip.c \ - zip/qtioapi.cpp \ - zip/qunzip.cpp \ - zip/qzip.cpp \ + ioapi.c \ + unzip.c \ + zip.c \ + qtioapi.cpp \ + qunzip.cpp \ + qzip.cpp \ HEADERS += \ - zip/ioapi.h \ - zip/unzip.h \ - zip/zip.h \ - zip/qtioapi.h \ - zip/qunzip.h \ - zip/qzip.h \ + ioapi.h \ + unzip.h \ + zip.h \ + qtioapi.h \ + qunzip.h \ + qzip.h \