draft of autoupdate function and mkdist util
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 5 Jan 2009 17:50:53 +0000 (17:50 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 5 Jan 2009 17:50:53 +0000 (17:50 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@244 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

27 files changed:
mkdist/distkey.cpp [new file with mode: 0644]
mkdist/distkey.h [new file with mode: 0644]
mkdist/mkdist.cpp [new file with mode: 0644]
mkdist/mkdist.pro [new file with mode: 0644]
src/autoupdate.cpp [new file with mode: 0644]
src/autoupdate.h [new file with mode: 0644]
src/main.cpp
src/odtrender.cpp
src/smoke.pro
src/ticketrender.cpp
zip/COPYING [moved from src/zip/COPYING with 100% similarity]
zip/README [moved from src/zip/README with 100% similarity]
zip/crypt.h [moved from src/zip/crypt.h with 100% similarity]
zip/ioapi.c [moved from src/zip/ioapi.c with 100% similarity]
zip/ioapi.h [moved from src/zip/ioapi.h with 100% similarity]
zip/qtioapi.cpp [moved from src/zip/qtioapi.cpp with 100% similarity]
zip/qtioapi.h [moved from src/zip/qtioapi.h with 100% similarity]
zip/qunzip.cpp [moved from src/zip/qunzip.cpp with 100% similarity]
zip/qunzip.h [moved from src/zip/qunzip.h with 100% similarity]
zip/qzip.cpp [moved from src/zip/qzip.cpp with 100% similarity]
zip/qzip.h [moved from src/zip/qzip.h with 100% similarity]
zip/unzip.c [moved from src/zip/unzip.c with 100% similarity]
zip/unzip.h [moved from src/zip/unzip.h with 100% similarity]
zip/zip.c [moved from src/zip/zip.c with 100% similarity]
zip/zip.h [moved from src/zip/zip.h with 100% similarity]
zip/zip.pri [new file with mode: 0644]
zip/zip.pro [moved from src/zip/zip.pri with 85% similarity]

diff --git a/mkdist/distkey.cpp b/mkdist/distkey.cpp
new file mode 100644 (file)
index 0000000..ebf2c8b
--- /dev/null
@@ -0,0 +1,111 @@
+//
+// C++ Implementation: distkey
+//
+// Description: 
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2009
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#include "distkey.h"
+
+#ifdef HAVE_KEYGEN
+
+#include <gmp.h>
+
+#include <QFile>
+#include <QByteArray>
+
+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 (file)
index 0000000..8a11894
--- /dev/null
@@ -0,0 +1,24 @@
+//
+// C++ Interface: distkey
+//
+// Description: 
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2009
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#include <QtGlobal>
+
+#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 (file)
index 0000000..bd7ff36
--- /dev/null
@@ -0,0 +1,24 @@
+//
+// C++ Implementation: mkdist
+//
+// Description: 
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2009
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#include <QCoreApplication>
+#include <QStringList>
+
+#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 (file)
index 0000000..98eb888
--- /dev/null
@@ -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 (file)
index 0000000..7ab768d
--- /dev/null
@@ -0,0 +1,19 @@
+//
+// C++ Implementation: autoupdate
+//
+// Description: 
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (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 (file)
index 0000000..6816529
--- /dev/null
@@ -0,0 +1,18 @@
+//
+// C++ Interface: autoupdate
+//
+// Description: 
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2009
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#ifndef MAGICSMOKE_AUTOUPDATE_H
+#define MAGICSMOKE_AUTOUPDATE_H
+
+void initAutoUpdate();
+
+#endif
index aa8c317..e61d9d2 100644 (file)
@@ -21,6 +21,7 @@
 #include <QSettings>
 #include <QTranslator>
 
+#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();
index a27cd0c..2dc679d 100644 (file)
@@ -20,8 +20,8 @@
 #include <QSettings>
 #include <QTemporaryFile>
 
-#include "zip/qunzip.h"
-#include "zip/qzip.h"
+#include "../zip/qunzip.h"
+#include "../zip/qzip.h"
 
 
 class MOdtRendererPrivate
index 1e554c8..0e79167 100644 (file)
@@ -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
index 5eba63c..f4503c3 100644 (file)
@@ -24,8 +24,8 @@
 #include <QPainter>
 #include <QStringList>
 
-#include "zip/qunzip.h"
-#include "zip/qzip.h"
+#include "../zip/qunzip.h"
+#include "../zip/qzip.h"
 #include "code39.h"
 #include "order.h"
 
similarity index 100%
rename from src/zip/COPYING
rename to zip/COPYING
similarity index 100%
rename from src/zip/README
rename to zip/README
similarity index 100%
rename from src/zip/crypt.h
rename to zip/crypt.h
similarity index 100%
rename from src/zip/ioapi.c
rename to zip/ioapi.c
similarity index 100%
rename from src/zip/ioapi.h
rename to zip/ioapi.h
similarity index 100%
rename from src/zip/qtioapi.cpp
rename to zip/qtioapi.cpp
similarity index 100%
rename from src/zip/qtioapi.h
rename to zip/qtioapi.h
similarity index 100%
rename from src/zip/qunzip.cpp
rename to zip/qunzip.cpp
similarity index 100%
rename from src/zip/qunzip.h
rename to zip/qunzip.h
similarity index 100%
rename from src/zip/qzip.cpp
rename to zip/qzip.cpp
similarity index 100%
rename from src/zip/qzip.h
rename to zip/qzip.h
similarity index 100%
rename from src/zip/unzip.c
rename to zip/unzip.c
similarity index 100%
rename from src/zip/unzip.h
rename to zip/unzip.h
similarity index 100%
rename from src/zip/zip.c
rename to zip/zip.c
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 (file)
index 0000000..844e698
--- /dev/null
@@ -0,0 +1,5 @@
+# Include for ZIP-Library from LinTouch Project
+#
+# Modified for Magic Smoke by (c) Konrad Rosenbaum, 2007
+
+LIBS += -L ../zip -lzip
similarity index 85%
rename from src/zip/zip.pri
rename to zip/zip.pro
index 8f5412f..a3ee791 100644 (file)
 # 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 \