root/middleware-offline/trunk/_src/eidmw/eidgui/dlgverifysignature.cpp @ 256

Revision 256, 3.7 KB (checked in by vsilva, 7 years ago)

Fix some bugs in PDF native signature. Support more OS

Line 
1/* ****************************************************************************
2
3 * PTeID Middleware Project.
4 * Copyright (C) 2011-2012 Caixa Mágica Software.
5 *
6 * This is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License version
8 * 3.0 as published by the Free Software Foundation.
9 *
10 * This software is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this software; if not, see
17 * http://www.gnu.org/licenses/.
18 *
19 * Author: Luis Medinas <luis.medinas@caixamagica.pt>
20 **************************************************************************** */
21
22#include "dlgverifysignature.h"
23
24#include "eidlib.h"
25#include "mainwnd.h"
26
27using namespace eIDMW;
28
29dlgVerifySignature::dlgVerifySignature( QWidget* parent)
30    : QDialog(parent)
31{
32        ui.setupUi(this);
33
34        //Set icon
35        const QIcon Ico = QIcon( ":/images/Images/Icons/ICO_CARD_EID_PLAIN_16x16.png" );
36        this->setWindowIcon( Ico );
37
38        QDesktopWidget* desktop = QApplication::desktop();
39        int screenNr = desktop->screenNumber();
40        QRect rect = desktop->availableGeometry(screenNr);
41        int height = rect.height();
42
43        int thiswidth = this->width();
44        int thisheight = this->height();
45
46        if (thisheight > height)
47        {
48                this->resize(thiswidth,height-20); //make sure the window fits
49        }
50
51}
52
53dlgVerifySignature::~dlgVerifySignature()
54{
55
56}
57
58void dlgVerifySignature::on_pbCancel_clicked()
59{
60        done(0);
61}
62
63
64QString dlgVerifySignature::translateVerifyReturnCode(int return_code)
65{
66
67        QString msg(tr("Signature Validation error: "));
68switch (return_code)
69{
70        case 1:
71                msg += tr("Couldn't extract signature from zip container");
72                break;
73        case 2:
74                msg += tr("RSA Signature of referenced content is invalid");
75                break;
76        case 3:
77                msg += tr("At least one of the signed file(s) was modified or is missing");
78                break;
79        case 4:
80                msg += tr("RSA Signature of referenced content is invalid");
81                break;
82        case 5:
83                msg += tr("The certificate used to sign this data is not trusted");
84                break;
85        case 6:
86                msg += tr("The timestamp appended to the signature is invalid");
87                break;
88
89}
90
91return msg;
92}
93
94void dlgVerifySignature::on_pbOpenSign_clicked()
95{
96    QString getSignFile;
97    QString nativedafaultpath;
98    char *sig_path_native;
99    int return_code = 0;
100       
101
102    getSignFile = QFileDialog::getOpenFileName(this, tr("Open Signature files"), QDir::homePath(), tr("Zip files 'XAdES' (*.zip)"), NULL);
103    QCoreApplication::processEvents();
104
105    if (!getSignFile.isEmpty())
106    {
107        nativedafaultpath = QDir::toNativeSeparators(getSignFile);
108       
109                sig_path_native = new char[nativedafaultpath.size()*2];
110                strcpy(sig_path_native, nativedafaultpath.toStdString().c_str());
111
112                PTEID_SigVerifier vsign(sig_path_native);
113                return_code = vsign.Verify();
114
115                PTEID_LOG(PTEID_LOG_LEVEL_DEBUG, "eidgui", 
116                                "Return code from VerifySignature(): %d", return_code);
117
118                if (return_code == 0)
119                {
120                        QString msg = tr("Signature was successfully verified.");
121                        char *ts = vsign.GetTimestampString();
122                        if (ts != NULL)
123                        {
124                                QString timestamp = QString("\n") + tr("Timestamp: ");
125                                msg += timestamp;
126                                msg += ts;
127            }
128
129            //Get signer name to show
130            QString signer = QString("\n")+tr("Signed by: ");
131            msg += signer;
132            msg += QString::fromUtf8(vsign.GetSigner());
133
134                        QMessageBox::information(this, tr("Signature Validation"), msg);
135                        this->close();
136                }
137                else
138                {
139                        QString error = translateVerifyReturnCode(return_code);
140                        QMessageBox::critical(this, tr("Signature Validation"), error);
141                        this->close();
142                }
143        }
144}
Note: See TracBrowser for help on using the browser.