2007-05-23 06:10:28 +00:00
/*
2007-06-08 04:07:34 +00:00
Copyright ( C ) 2007 Justin Karneges < justin @ affinix . com >
Permission is hereby granted , free of charge , to any person obtaining a copy
of this software and associated documentation files ( the " Software " ) , to deal
in the Software without restriction , including without limitation the rights
to use , copy , modify , merge , publish , distribute , sublicense , and / or sell
copies of the Software , and to permit persons to whom the Software is
furnished to do so , subject to the following conditions :
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software .
THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR
IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY ,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE
AUTHORS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER LIABILITY , WHETHER IN
AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE .
*/
2007-05-23 06:10:28 +00:00
2007-05-03 22:14:13 +00:00
# include <QtCore>
# include <QtGui>
# include <QtCrypto>
# include "ui_mainwin.h"
2007-05-29 08:16:00 +00:00
# include "prompter.h"
2007-05-03 22:14:13 +00:00
# include "mylistview.h"
# include "ui_loadstore.h"
2007-05-23 06:10:28 +00:00
# include "pkcs11configdlg/pkcs11configdlg.h"
2007-05-03 22:14:13 +00:00
2007-05-29 08:16:00 +00:00
# define VERSION "0.0.1"
class Icons
{
public :
QPixmap cert , crl , keybundle , pgppub , pgpsec ;
} ;
Icons * g_icons = 0 ;
//----------------------------------------------------------------------------
// CertItem
//----------------------------------------------------------------------------
class CertItem
{
public :
enum StorageType { File , Entry } ;
QString name ;
QCA : : CertificateChain chain ;
bool havePrivate ;
StorageType storageType ; // private storage type
bool usable ; // storage is accessible
QString fileName ;
QCA : : KeyStoreEntry keyStoreEntry ;
CertItem ( ) ;
QString toString ( ) const ;
bool fromString ( const QString & in ) ;
} ;
static QString escape ( const QString & in )
2007-05-03 22:14:13 +00:00
{
QString out ;
for ( int n = 0 ; n < in . length ( ) ; + + n )
{
if ( in [ n ] = = ' \\ ' )
out + = " \\ \\ " ;
else if ( in [ n ] = = ' : ' )
out + = " \\ c " ;
2007-05-29 08:16:00 +00:00
else if ( in [ n ] = = ' \n ' )
out + = " \\ n " ;
2007-05-03 22:14:13 +00:00
else
out + = in [ n ] ;
}
return out ;
}
2007-05-29 08:16:00 +00:00
static QString unescape ( const QString & in )
2007-05-03 22:14:13 +00:00
{
QString out ;
for ( int n = 0 ; n < in . length ( ) ; + + n )
{
if ( in [ n ] = = ' \\ ' )
{
if ( n + 1 < in . length ( ) )
{
+ + n ;
if ( in [ n ] = = ' \\ ' )
out + = ' \\ ' ;
else if ( in [ n ] = = ' c ' )
out + = ' : ' ;
2007-05-29 08:16:00 +00:00
else if ( in [ n ] = = ' n ' )
out + = ' \n ' ;
2007-05-03 22:14:13 +00:00
}
}
else
out + = in [ n ] ;
}
return out ;
}
2007-05-29 08:16:00 +00:00
CertItem : : CertItem ( ) :
havePrivate ( false ) ,
storageType ( File ) ,
usable ( false )
2007-05-03 22:14:13 +00:00
{
2007-05-29 08:16:00 +00:00
}
2007-05-03 22:14:13 +00:00
2007-05-29 08:16:00 +00:00
QString CertItem : : toString ( ) const
{
QStringList parts ;
parts + = name ;
parts + = QString : : number ( chain . count ( ) ) ;
foreach ( const QCA : : Certificate & cert , chain )
parts + = QCA : : Base64 ( ) . arrayToString ( cert . toDER ( ) ) ;
2007-05-03 22:14:13 +00:00
2007-05-29 08:16:00 +00:00
if ( havePrivate )
2007-05-03 22:14:13 +00:00
{
2007-05-29 08:16:00 +00:00
if ( storageType = = File )
2007-05-03 22:14:13 +00:00
{
2007-05-29 08:16:00 +00:00
parts + = " privateFile " ;
2007-05-03 22:14:13 +00:00
parts + = fileName ;
}
else // Entry
{
2007-05-29 08:16:00 +00:00
parts + = " privateEntry " ;
parts + = keyStoreEntry . toString ( ) ;
2007-05-03 22:14:13 +00:00
}
}
2007-05-29 08:16:00 +00:00
for ( int n = 0 ; n < parts . count ( ) ; + + n )
parts [ n ] = escape ( parts [ n ] ) ;
return parts . join ( " : " ) ;
}
2007-05-03 22:14:13 +00:00
2007-05-29 08:16:00 +00:00
bool CertItem : : fromString ( const QString & in )
{
QStringList parts = in . split ( ' : ' ) ;
for ( int n = 0 ; n < parts . count ( ) ; + + n )
parts [ n ] = unescape ( parts [ n ] ) ;
if ( parts . count ( ) < 3 )
return false ;
name = parts [ 0 ] ;
int chainCount = parts [ 1 ] . toInt ( ) ;
if ( chainCount < 1 | | chainCount > parts . count ( ) - 2 )
return false ;
chain . clear ( ) ;
for ( int n = 0 ; n < chainCount ; + + n )
{
2007-06-12 02:30:58 +00:00
QCA : : Certificate cert = QCA : : Certificate : : fromDER ( QCA : : Base64 ( ) . stringToArray ( parts [ n + 2 ] ) . toByteArray ( ) ) ;
2007-05-29 08:16:00 +00:00
if ( cert . isNull ( ) )
2007-05-03 22:14:13 +00:00
return false ;
2007-05-29 08:16:00 +00:00
chain + = cert ;
}
int at = chain . count ( ) + 2 ;
2007-05-03 22:14:13 +00:00
2007-05-29 08:16:00 +00:00
if ( at < parts . count ( ) )
{
havePrivate = true ;
2007-05-03 22:14:13 +00:00
usable = false ;
2007-05-29 08:16:00 +00:00
if ( parts [ at ] = = " privateFile " )
2007-05-03 22:14:13 +00:00
{
2007-05-29 08:16:00 +00:00
storageType = File ;
fileName = parts [ at + 1 ] ;
2007-05-03 22:14:13 +00:00
if ( QFile : : exists ( fileName ) )
usable = true ;
}
2007-05-29 08:16:00 +00:00
else if ( parts [ at ] = = " privateEntry " )
2007-05-03 22:14:13 +00:00
{
2007-05-29 08:16:00 +00:00
storageType = Entry ;
keyStoreEntry = QCA : : KeyStoreEntry ( parts [ at + 1 ] ) ;
if ( ! keyStoreEntry . isNull ( ) )
2007-05-03 22:14:13 +00:00
usable = true ;
}
else
return false ;
}
2007-05-29 08:16:00 +00:00
return true ;
}
//----------------------------------------------------------------------------
// CertListModel
//----------------------------------------------------------------------------
class CertListModel : public QAbstractListModel
2007-05-03 22:14:13 +00:00
{
Q_OBJECT
public :
2007-05-29 08:16:00 +00:00
QList < CertItem > list ;
2007-05-03 22:14:13 +00:00
2007-05-29 08:16:00 +00:00
CertListModel ( QObject * parent = 0 ) :
2007-05-03 22:14:13 +00:00
QAbstractListModel ( parent )
{
}
int rowCount ( const QModelIndex & parent = QModelIndex ( ) ) const
{
Q_UNUSED ( parent ) ;
return list . count ( ) ;
}
QVariant data ( const QModelIndex & index , int role ) const
{
if ( ! index . isValid ( ) )
return QVariant ( ) ;
if ( index . row ( ) > = list . count ( ) )
return QVariant ( ) ;
if ( role = = Qt : : DisplayRole )
return list [ index . row ( ) ] . name ;
2007-05-29 08:16:00 +00:00
else if ( role = = Qt : : EditRole )
return list [ index . row ( ) ] . name ;
else if ( role = = Qt : : DecorationRole & & g_icons )
2007-05-03 22:14:13 +00:00
{
2007-05-29 08:16:00 +00:00
const CertItem & i = list [ index . row ( ) ] ;
if ( i . havePrivate )
return g_icons - > keybundle ;
else
return g_icons - > cert ;
2007-05-03 22:14:13 +00:00
}
else
return QVariant ( ) ;
}
2007-05-29 08:16:00 +00:00
Qt : : ItemFlags flags ( const QModelIndex & index ) const
{
if ( ! index . isValid ( ) )
return Qt : : ItemIsEnabled ;
return QAbstractItemModel : : flags ( index ) | Qt : : ItemIsEditable ;
}
bool setData ( const QModelIndex & index , const QVariant & value , int role )
{
if ( index . isValid ( ) & & role = = Qt : : EditRole )
{
QString str = value . toString ( ) ;
list [ index . row ( ) ] . name = str ;
emit dataChanged ( index , index ) ;
return true ;
}
return false ;
}
void addItems ( const QList < CertItem > & items )
{
if ( items . isEmpty ( ) )
return ;
beginInsertRows ( QModelIndex ( ) , list . size ( ) , list . size ( ) + items . count ( ) - 1 ) ;
list + = items ;
endInsertRows ( ) ;
}
void addItem ( const CertItem & i )
2007-05-03 22:14:13 +00:00
{
beginInsertRows ( QModelIndex ( ) , list . size ( ) , list . size ( ) ) ;
list + = i ;
endInsertRows ( ) ;
}
void removeItem ( int at )
{
beginRemoveRows ( QModelIndex ( ) , at , at ) ;
list . removeAt ( at ) ;
endRemoveRows ( ) ;
}
QString getUniqueName ( const QString & name )
{
int num = 1 ;
while ( 1 )
{
QString tryname ;
if ( num = = 1 )
tryname = name ;
else
tryname = name + QString ( " (%1) " ) . arg ( num ) ;
bool found = false ;
2007-05-29 08:16:00 +00:00
foreach ( const CertItem & i , list )
2007-05-03 22:14:13 +00:00
{
if ( i . name = = tryname )
{
found = true ;
break ;
}
}
if ( ! found )
return tryname ;
+ + num ;
}
}
} ;
2007-05-29 08:16:00 +00:00
//----------------------------------------------------------------------------
// Operation
//----------------------------------------------------------------------------
2007-05-03 22:14:13 +00:00
class Operation : public QObject
{
Q_OBJECT
public :
Operation ( QObject * parent = 0 ) :
QObject ( parent )
{
}
signals :
void error ( const QString & str ) ;
} ;
2007-05-29 08:16:00 +00:00
static QString validityToString ( QCA : : Validity v )
{
QString s ;
switch ( v )
{
case QCA : : ValidityGood :
s = Operation : : tr ( " Validated " ) ;
break ;
case QCA : : ErrorRejected :
s = Operation : : tr ( " Root CA is marked to reject the specified purpose " ) ;
break ;
case QCA : : ErrorUntrusted :
s = Operation : : tr ( " Certificate not trusted for the required purpose " ) ;
break ;
case QCA : : ErrorSignatureFailed :
s = Operation : : tr ( " Invalid signature " ) ;
break ;
case QCA : : ErrorInvalidCA :
s = Operation : : tr ( " Invalid CA certificate " ) ;
break ;
case QCA : : ErrorInvalidPurpose :
s = Operation : : tr ( " Invalid certificate purpose " ) ;
break ;
case QCA : : ErrorSelfSigned :
s = Operation : : tr ( " Certificate is self-signed " ) ;
break ;
case QCA : : ErrorRevoked :
s = Operation : : tr ( " Certificate has been revoked " ) ;
break ;
case QCA : : ErrorPathLengthExceeded :
s = Operation : : tr ( " Maximum certificate chain length exceeded " ) ;
break ;
case QCA : : ErrorExpired :
s = Operation : : tr ( " Certificate has expired " ) ;
break ;
case QCA : : ErrorExpiredCA :
s = Operation : : tr ( " CA has expired " ) ;
break ;
case QCA : : ErrorValidityUnknown :
default :
s = Operation : : tr ( " General certificate validation error " ) ;
break ;
}
return s ;
}
static QString smErrorToString ( QCA : : SecureMessage : : Error e )
{
QMap < QCA : : SecureMessage : : Error , QString > map ;
map [ QCA : : SecureMessage : : ErrorPassphrase ] = Operation : : tr ( " Invalid passphrase " ) ;
map [ QCA : : SecureMessage : : ErrorFormat ] = Operation : : tr ( " Bad input format " ) ;
map [ QCA : : SecureMessage : : ErrorSignerExpired ] = Operation : : tr ( " Signer key is expired " ) ;
map [ QCA : : SecureMessage : : ErrorSignerInvalid ] = Operation : : tr ( " Signer key is invalid " ) ;
map [ QCA : : SecureMessage : : ErrorEncryptExpired ] = Operation : : tr ( " Encrypting key is expired " ) ;
map [ QCA : : SecureMessage : : ErrorEncryptUntrusted ] = Operation : : tr ( " Encrypting key is untrusted " ) ;
map [ QCA : : SecureMessage : : ErrorEncryptInvalid ] = Operation : : tr ( " Encrypting key is invalid " ) ;
map [ QCA : : SecureMessage : : ErrorNeedCard ] = Operation : : tr ( " Card was needed but not found " ) ;
map [ QCA : : SecureMessage : : ErrorCertKeyMismatch ] = Operation : : tr ( " Certificate and private key don't match " ) ;
map [ QCA : : SecureMessage : : ErrorUnknown ] = Operation : : tr ( " General error " ) ;
return map [ e ] ;
}
2007-05-03 22:14:13 +00:00
class SignOperation : public Operation
{
Q_OBJECT
private :
QByteArray in ;
2007-05-29 08:16:00 +00:00
CertItem * item ;
2007-05-03 22:14:13 +00:00
QCA : : CMS * cms ;
QCA : : KeyLoader * loader ;
QCA : : KeyBundle key ;
QCA : : SecureMessage * msg ;
public :
2007-05-29 08:16:00 +00:00
SignOperation ( const QByteArray & _in , CertItem * _item , QCA : : CMS * _cms , QObject * parent = 0 ) :
2007-05-03 22:14:13 +00:00
Operation ( parent ) ,
in ( _in ) ,
item ( _item ) ,
cms ( _cms ) ,
loader ( 0 ) ,
msg ( 0 )
{
2007-05-29 08:16:00 +00:00
if ( item - > storageType = = CertItem : : File )
2007-05-03 22:14:13 +00:00
{
loader = new QCA : : KeyLoader ( this ) ;
connect ( loader , SIGNAL ( finished ( ) ) , SLOT ( loaded ( ) ) ) ;
loader - > loadKeyBundleFromFile ( item - > fileName ) ;
}
else // Entry
{
2007-05-29 08:16:00 +00:00
key = item - > keyStoreEntry . keyBundle ( ) ;
2007-05-03 22:14:13 +00:00
QMetaObject : : invokeMethod ( this , " do_sign " , Qt : : QueuedConnection ) ;
}
}
~ SignOperation ( )
{
}
signals :
void finished ( const QString & sig ) ;
private slots :
void loaded ( )
{
if ( loader - > convertResult ( ) ! = QCA : : ConvertGood )
{
emit error ( tr ( " Error opening key file. " ) ) ;
return ;
}
key = loader - > keyBundle ( ) ;
delete loader ;
loader = 0 ;
do_sign ( ) ;
}
void do_sign ( )
{
2007-05-29 08:16:00 +00:00
//printf("do_sign\n");
2007-05-03 22:14:13 +00:00
QCA : : SecureMessageKey signer ;
signer . setX509CertificateChain ( key . certificateChain ( ) ) ;
signer . setX509PrivateKey ( key . privateKey ( ) ) ;
msg = new QCA : : SecureMessage ( cms ) ;
connect ( msg , SIGNAL ( finished ( ) ) , SLOT ( msg_finished ( ) ) ) ;
msg - > setFormat ( QCA : : SecureMessage : : Ascii ) ;
msg - > setSigner ( signer ) ;
msg - > startSign ( QCA : : SecureMessage : : Detached ) ;
update ( ) ;
}
void update ( )
{
2007-05-29 08:16:00 +00:00
//printf("update\n");
2007-05-03 22:14:13 +00:00
QByteArray buf = in . mid ( 0 , 16384 ) ; // 16k chunks
in = in . mid ( buf . size ( ) ) ;
msg - > update ( buf ) ;
if ( in . isEmpty ( ) )
msg - > end ( ) ;
else
QMetaObject : : invokeMethod ( this , " update " , Qt : : QueuedConnection ) ;
}
void msg_finished ( )
{
2007-05-29 08:16:00 +00:00
//printf("msg_finished\n");
2007-05-03 22:14:13 +00:00
if ( ! msg - > success ( ) )
{
2007-05-29 08:16:00 +00:00
QString str = smErrorToString ( msg - > errorCode ( ) ) ;
2007-05-03 22:14:13 +00:00
delete msg ;
msg = 0 ;
2007-05-29 08:16:00 +00:00
emit error ( tr ( " Error during sign operation. \n Reason: %1 " ) . arg ( str ) ) ;
2007-05-03 22:14:13 +00:00
return ;
}
QByteArray result = msg - > signature ( ) ;
delete msg ;
msg = 0 ;
emit finished ( QString : : fromLatin1 ( result ) ) ;
}
} ;
class VerifyOperation : public Operation
{
Q_OBJECT
private :
QByteArray in , sig ;
QCA : : CMS * cms ;
QCA : : SecureMessage * msg ;
public :
VerifyOperation ( const QByteArray & _in , const QByteArray & _sig , QCA : : CMS * _cms , QObject * parent = 0 ) :
Operation ( parent ) ,
in ( _in ) ,
sig ( _sig ) ,
cms ( _cms ) ,
msg ( 0 )
{
2007-05-29 08:16:00 +00:00
//printf("do_verify\n");
2007-05-03 22:14:13 +00:00
msg = new QCA : : SecureMessage ( cms ) ;
connect ( msg , SIGNAL ( finished ( ) ) , SLOT ( msg_finished ( ) ) ) ;
msg - > setFormat ( QCA : : SecureMessage : : Ascii ) ;
msg - > startVerify ( sig ) ;
QMetaObject : : invokeMethod ( this , " update " , Qt : : QueuedConnection ) ;
}
signals :
void finished ( ) ;
private slots :
void update ( )
{
2007-05-29 08:16:00 +00:00
//printf("update\n");
2007-05-03 22:14:13 +00:00
QByteArray buf = in . mid ( 0 , 16384 ) ; // 16k chunks
in = in . mid ( buf . size ( ) ) ;
msg - > update ( buf ) ;
if ( in . isEmpty ( ) )
msg - > end ( ) ;
else
QMetaObject : : invokeMethod ( this , " update " , Qt : : QueuedConnection ) ;
}
void msg_finished ( )
{
2007-05-29 08:16:00 +00:00
//printf("msg_finished\n");
2007-05-03 22:14:13 +00:00
if ( ! msg - > success ( ) )
{
2007-05-29 08:16:00 +00:00
QString str = smErrorToString ( msg - > errorCode ( ) ) ;
2007-05-03 22:14:13 +00:00
delete msg ;
msg = 0 ;
2007-05-29 08:16:00 +00:00
emit error ( tr ( " Error during verify operation. \n Reason: %1 " ) . arg ( str ) ) ;
2007-05-03 22:14:13 +00:00
return ;
}
QCA : : SecureMessageSignature signer = msg - > signer ( ) ;
QCA : : SecureMessageSignature : : IdentityResult r = signer . identityResult ( ) ;
delete msg ;
msg = 0 ;
if ( r ! = QCA : : SecureMessageSignature : : Valid )
{
2007-05-29 08:16:00 +00:00
QString str ;
if ( r = = QCA : : SecureMessageSignature : : InvalidSignature )
str = tr ( " Invalid signature " ) ;
else if ( r = = QCA : : SecureMessageSignature : : InvalidKey )
str = tr ( " Invalid key: %1 " ) . arg ( validityToString ( signer . keyValidity ( ) ) ) ;
else if ( r = = QCA : : SecureMessageSignature : : NoKey )
str = tr ( " Key not found " ) ;
else // unknown
str = tr ( " Unknown " ) ;
emit error ( tr ( " Verification failed! \n Reason: %1 " ) . arg ( str ) ) ;
2007-05-03 22:14:13 +00:00
return ;
}
emit finished ( ) ;
}
} ;
QAction * actionView , * actionRename , * actionRemove ;
MyListView : : MyListView ( QWidget * parent ) :
QListView ( parent )
{
}
void MyListView : : contextMenuEvent ( QContextMenuEvent * event )
{
QItemSelection selection = selectionModel ( ) - > selection ( ) ;
if ( selection . indexes ( ) . isEmpty ( ) )
return ;
QMenu menu ( this ) ;
menu . addAction ( actionView ) ;
menu . addAction ( actionRename ) ;
menu . addAction ( actionRemove ) ;
menu . exec ( event - > globalPos ( ) ) ;
}
2007-05-29 08:16:00 +00:00
/*static QString entryTypeToString(QCA::KeyStoreEntry::Type type)
2007-05-03 22:14:13 +00:00
{
QString out ;
switch ( type )
{
case QCA : : KeyStoreEntry : : TypeKeyBundle : out = " X " ; break ;
case QCA : : KeyStoreEntry : : TypeCertificate : out = " C " ; break ;
case QCA : : KeyStoreEntry : : TypeCRL : out = " R " ; break ;
case QCA : : KeyStoreEntry : : TypePGPSecretKey : out = " S " ; break ;
case QCA : : KeyStoreEntry : : TypePGPPublicKey : out = " P " ; break ;
default : out = " U " ; break ;
}
return out ;
2007-05-29 08:16:00 +00:00
} */
static QPixmap entryTypeToIcon ( QCA : : KeyStoreEntry : : Type type )
{
QPixmap out ;
switch ( type )
{
case QCA : : KeyStoreEntry : : TypeKeyBundle : out = g_icons - > keybundle ; break ;
case QCA : : KeyStoreEntry : : TypeCertificate : out = g_icons - > cert ; break ;
case QCA : : KeyStoreEntry : : TypeCRL : out = g_icons - > crl ; break ;
case QCA : : KeyStoreEntry : : TypePGPSecretKey : out = g_icons - > pgpsec ; break ;
case QCA : : KeyStoreEntry : : TypePGPPublicKey : out = g_icons - > pgppub ; break ;
default : break ;
}
return out ;
2007-05-03 22:14:13 +00:00
}
class KeyStoreModel : public QStandardItemModel
{
Q_OBJECT
public :
QCA : : KeyStoreManager ksm ;
QList < QCA : : KeyStore * > stores ;
QList < QStandardItem * > storeItems ;
QList < QList < QCA : : KeyStoreEntry > > storeEntries ;
QList < QList < QStandardItem * > > storeEntryItems ;
KeyStoreModel ( QObject * parent = 0 ) :
QStandardItemModel ( parent ) , ksm ( this )
{
// make sure keystores are started
QCA : : KeyStoreManager : : start ( ) ;
connect ( & ksm , SIGNAL ( keyStoreAvailable ( const QString & ) ) , SLOT ( ks_available ( const QString & ) ) ) ;
QStringList list = ksm . keyStores ( ) ;
foreach ( const QString & s , list )
ks_available ( s ) ;
}
private slots :
void ks_available ( const QString & keyStoreId )
{
QCA : : KeyStore * ks = new QCA : : KeyStore ( keyStoreId , & ksm ) ;
2007-05-29 08:16:00 +00:00
// TODO: only list non-pgp identity stores
//if(!ks->holdsIdentities() || ks->type() == QCA::KeyStore::PGPKeyring)
// return;
2007-05-03 22:14:13 +00:00
connect ( ks , SIGNAL ( updated ( ) ) , SLOT ( ks_updated ( ) ) ) ;
connect ( ks , SIGNAL ( unavailable ( ) ) , SLOT ( ks_unavailable ( ) ) ) ;
stores + = ks ;
ks - > startAsynchronousMode ( ) ;
QStandardItem * item = new QStandardItem ( ks - > name ( ) ) ;
storeItems + = item ;
storeEntries + = QList < QCA : : KeyStoreEntry > ( ) ;
storeEntryItems + = QList < QStandardItem * > ( ) ;
appendRow ( item ) ;
}
void ks_updated ( )
{
QCA : : KeyStore * ks = ( QCA : : KeyStore * ) sender ( ) ;
int at = stores . indexOf ( ks ) ;
QList < QCA : : KeyStoreEntry > entries = ks - > entryList ( ) ;
2007-05-29 08:16:00 +00:00
// TODO: only list keybundles
2007-05-03 22:14:13 +00:00
/*for(int n = 0; n < entries.count(); ++n)
{
if ( entries [ n ] . type ( ) ! = QCA : : KeyStoreEntry : : TypeKeyBundle )
{
entries . removeAt ( n ) ;
- - n ; // adjust position
}
} */
storeEntries [ at ] = entries ;
storeEntryItems [ at ] . clear ( ) ;
2007-05-29 08:16:00 +00:00
// fake CRL, just to show off the icon
/*if(ks->type() == QCA::KeyStore::System)
{
QStandardItem * item = new QStandardItem ( entryTypeToIcon ( QCA : : KeyStoreEntry : : TypeCRL ) , " Santa's Naughty List " ) ;
storeEntryItems [ at ] + = item ;
storeItems [ at ] - > appendRow ( item ) ;
} */
2007-05-03 22:14:13 +00:00
foreach ( const QCA : : KeyStoreEntry & entry , entries )
{
2007-05-29 08:16:00 +00:00
QStandardItem * item = new QStandardItem ( entryTypeToIcon ( entry . type ( ) ) , entry . name ( ) ) ;
2007-05-03 22:14:13 +00:00
storeEntryItems [ at ] + = item ;
storeItems [ at ] - > appendRow ( item ) ;
}
}
void ks_unavailable ( )
{
QCA : : KeyStore * ks = ( QCA : : KeyStore * ) sender ( ) ;
Q_UNUSED ( ks ) ;
2007-05-29 08:16:00 +00:00
// TODO: remove from internal list and display
2007-05-03 22:14:13 +00:00
}
} ;
class LoadStore : public QDialog
{
Q_OBJECT
private :
Ui_LoadStore ui ;
KeyStoreModel * model ;
QCA : : KeyStoreEntry cur_entry ;
public :
LoadStore ( QWidget * parent = 0 ) :
QDialog ( parent )
{
ui . setupUi ( this ) ;
ui . lv_stores - > header ( ) - > hide ( ) ;
ui . buttonBox - > button ( QDialogButtonBox : : Ok ) - > setEnabled ( false ) ;
model = new KeyStoreModel ( this ) ;
ui . lv_stores - > setModel ( model ) ;
connect ( ui . lv_stores - > selectionModel ( ) , SIGNAL ( selectionChanged ( const QItemSelection & , const QItemSelection & ) ) , SLOT ( stores_selectionChanged ( const QItemSelection & , const QItemSelection & ) ) ) ;
}
signals :
void entrySelected ( const QCA : : KeyStoreEntry & entry ) ;
protected slots :
virtual void accept ( )
{
QCA : : KeyStoreEntry entry = cur_entry ;
QDialog : : accept ( ) ;
emit entrySelected ( entry ) ;
}
private slots :
void stores_selectionChanged ( const QItemSelection & selected , const QItemSelection & deselected )
{
Q_UNUSED ( deselected ) ;
bool valid = false ;
QCA : : KeyStoreEntry entry ;
{
QModelIndex index ;
if ( ! selected . indexes ( ) . isEmpty ( ) )
index = selected . indexes ( ) . first ( ) ;
if ( index . isValid ( ) )
{
QModelIndex pindex = index . parent ( ) ;
// are we clicking on an entry?
if ( pindex . isValid ( ) )
{
int store_at = pindex . row ( ) ;
int entry_at = index . row ( ) ;
entry = model - > storeEntries [ store_at ] [ entry_at ] ;
if ( entry . type ( ) = = QCA : : KeyStoreEntry : : TypeKeyBundle )
valid = true ;
}
}
}
if ( valid )
cur_entry = entry ;
else
cur_entry = QCA : : KeyStoreEntry ( ) ;
QPushButton * ok = ui . buttonBox - > button ( QDialogButtonBox : : Ok ) ;
if ( valid & & ! ok - > isEnabled ( ) )
ok - > setEnabled ( true ) ;
else if ( ! valid & & ok - > isEnabled ( ) )
ok - > setEnabled ( false ) ;
}
} ;
2007-05-29 08:16:00 +00:00
class MyPrompter : public Prompter
{
Q_OBJECT
private :
QMap < QString , QCA : : SecureArray > known ;
public :
MyPrompter ( QObject * parent = 0 ) :
Prompter ( parent )
{
}
protected :
virtual QCA : : SecureArray knownPassword ( const QCA : : Event & event )
{
if ( event . source ( ) = = QCA : : Event : : Data & & ! event . fileName ( ) . isEmpty ( ) )
return known . value ( event . fileName ( ) ) ;
else
return QCA : : SecureArray ( ) ;
}
virtual void userSubmitted ( const QCA : : SecureArray & password , const QCA : : Event & event )
{
if ( event . source ( ) = = QCA : : Event : : Data & & ! event . fileName ( ) . isEmpty ( ) )
known [ event . fileName ( ) ] = password ;
}
} ;
2007-05-03 22:14:13 +00:00
class MainWin : public QMainWindow
{
Q_OBJECT
private :
Ui_MainWin ui ;
2007-05-29 08:16:00 +00:00
MyPrompter * prompter ;
2007-05-03 22:14:13 +00:00
QCA : : KeyLoader * keyLoader ;
QString keyLoader_fileName ;
2007-05-29 08:16:00 +00:00
CertListModel * users , * roots ;
2007-05-03 22:14:13 +00:00
QCA : : CMS * cms ;
Operation * op ;
public :
MainWin ( QWidget * parent = 0 ) :
QMainWindow ( parent ) ,
keyLoader ( 0 ) ,
op ( 0 )
{
ui . setupUi ( this ) ;
2007-05-29 08:16:00 +00:00
g_icons = new Icons ;
g_icons - > cert = QPixmap ( " :/gfx/icons/cert16.png " ) ;
g_icons - > crl = QPixmap ( " :/gfx/icons/crl16.png " ) ;
g_icons - > keybundle = QPixmap ( " :/gfx/icons/keybundle16.png " ) ;
g_icons - > pgppub = QPixmap ( " :/gfx/icons/publickey16.png " ) ;
g_icons - > pgpsec = QPixmap ( " :/gfx/icons/keypair16.png " ) ;
if ( g_icons - > cert . isNull ( ) | | g_icons - > crl . isNull ( ) | | g_icons - > keybundle . isNull ( ) | | g_icons - > pgppub . isNull ( ) | | g_icons - > pgpsec . isNull ( ) )
printf ( " warning: not all icons loaded \n " ) ;
2007-05-03 22:14:13 +00:00
actionView = new QAction ( tr ( " &View " ) , this ) ;
actionRename = new QAction ( tr ( " Re&name " ) , this ) ;
actionRemove = new QAction ( tr ( " Rem&ove " ) , this ) ;
// TODO
actionView - > setEnabled ( false ) ;
2007-05-29 08:16:00 +00:00
connect ( ui . actionLoadIdentityFile , SIGNAL ( triggered ( ) ) , SLOT ( load_file ( ) ) ) ;
connect ( ui . actionLoadIdentityEntry , SIGNAL ( triggered ( ) ) , SLOT ( load_device ( ) ) ) ;
connect ( ui . actionLoadAuthority , SIGNAL ( triggered ( ) ) , SLOT ( load_root ( ) ) ) ;
connect ( ui . actionConfigurePkcs11 , SIGNAL ( triggered ( ) ) , SLOT ( mod_config ( ) ) ) ;
2007-05-03 22:14:13 +00:00
connect ( ui . actionQuit , SIGNAL ( triggered ( ) ) , SLOT ( close ( ) ) ) ;
2007-05-29 08:16:00 +00:00
connect ( ui . actionAbout , SIGNAL ( triggered ( ) ) , SLOT ( about ( ) ) ) ;
2007-05-03 22:14:13 +00:00
connect ( ui . pb_sign , SIGNAL ( clicked ( ) ) , SLOT ( do_sign ( ) ) ) ;
connect ( ui . pb_verify , SIGNAL ( clicked ( ) ) , SLOT ( do_verify ( ) ) ) ;
2007-05-29 08:16:00 +00:00
//connect(actionView, SIGNAL(triggered()), SLOT(item_view()));
2007-05-03 22:14:13 +00:00
connect ( actionRename , SIGNAL ( triggered ( ) ) , SLOT ( item_rename ( ) ) ) ;
connect ( actionRemove , SIGNAL ( triggered ( ) ) , SLOT ( item_remove ( ) ) ) ;
ui . pb_sign - > setEnabled ( false ) ;
2007-05-29 08:16:00 +00:00
prompter = new MyPrompter ( this ) ;
2007-05-03 22:14:13 +00:00
2007-05-29 08:16:00 +00:00
users = new CertListModel ( this ) ;
ui . lv_users - > setModel ( users ) ;
connect ( ui . lv_users - > selectionModel ( ) , SIGNAL ( selectionChanged ( const QItemSelection & , const QItemSelection & ) ) , SLOT ( users_selectionChanged ( const QItemSelection & , const QItemSelection & ) ) ) ;
2007-05-03 22:14:13 +00:00
2007-05-29 08:16:00 +00:00
roots = new CertListModel ( this ) ;
ui . lv_authorities - > setModel ( roots ) ;
2007-05-03 22:14:13 +00:00
2007-05-29 08:16:00 +00:00
// FIXME: is this redundant?
ui . lv_users - > model = users ;
ui . lv_authorities - > model = roots ;
2007-05-03 22:14:13 +00:00
cms = new QCA : : CMS ( this ) ;
2007-05-29 08:16:00 +00:00
QStringList ulist , rlist ;
2007-05-03 22:14:13 +00:00
{
2007-05-29 08:16:00 +00:00
QSettings settings ( " Affinix " , " CMS Signer " ) ;
ulist = settings . value ( " users " ) . toStringList ( ) ;
rlist = settings . value ( " roots " ) . toStringList ( ) ;
2007-05-03 22:14:13 +00:00
}
2007-05-29 08:16:00 +00:00
QList < CertItem > userslist ;
foreach ( const QString & s , ulist )
{
CertItem i ;
if ( i . fromString ( s ) )
userslist + = i ;
}
2007-05-03 22:14:13 +00:00
2007-05-29 08:16:00 +00:00
QList < CertItem > rootslist ;
foreach ( const QString & s , rlist )
{
CertItem i ;
if ( i . fromString ( s ) )
rootslist + = i ;
}
users - > addItems ( userslist ) ;
roots - > addItems ( rootslist ) ;
}
2007-05-03 22:14:13 +00:00
2007-05-29 08:16:00 +00:00
~ MainWin ( )
{
QStringList ulist ;
foreach ( const CertItem & i , users - > list )
ulist + = i . toString ( ) ;
QStringList rlist ;
foreach ( const CertItem & i , roots - > list )
rlist + = i . toString ( ) ;
QSettings settings ( " Affinix " , " CMS Signer " ) ;
settings . setValue ( " users " , ulist ) ;
settings . setValue ( " roots " , rlist ) ;
delete g_icons ;
g_icons = 0 ;
2007-05-03 22:14:13 +00:00
}
2007-05-29 08:16:00 +00:00
private slots :
2007-05-03 22:14:13 +00:00
void load_file ( )
{
2007-05-04 21:26:08 +00:00
QString fileName = QFileDialog : : getOpenFileName ( this , tr ( " Open File " ) , QString ( ) , tr ( " X.509 Identities (*.p12 *.pfx) " ) ) ;
2007-05-03 22:14:13 +00:00
if ( fileName . isEmpty ( ) )
return ;
setEnabled ( false ) ;
keyLoader = new QCA : : KeyLoader ( this ) ;
connect ( keyLoader , SIGNAL ( finished ( ) ) , SLOT ( load_file_finished ( ) ) ) ;
keyLoader_fileName = fileName ;
keyLoader - > loadKeyBundleFromFile ( fileName ) ;
}
void load_device ( )
{
LoadStore * w = new LoadStore ( this ) ;
w - > setAttribute ( Qt : : WA_DeleteOnClose , true ) ;
w - > setWindowModality ( Qt : : WindowModal ) ;
connect ( w , SIGNAL ( entrySelected ( const QCA : : KeyStoreEntry & ) ) , SLOT ( load_device_finished ( const QCA : : KeyStoreEntry & ) ) ) ;
w - > show ( ) ;
}
2007-05-29 08:16:00 +00:00
void load_root ( )
{
QString fileName = QFileDialog : : getOpenFileName ( this , tr ( " Open File " ) , QString ( ) , tr ( " X.509 Certificates (*.pem *.crt) " ) ) ;
if ( fileName . isEmpty ( ) )
return ;
QCA : : Certificate cert = QCA : : Certificate : : fromPEMFile ( fileName ) ;
if ( cert . isNull ( ) )
{
QMessageBox : : information ( this , tr ( " Error " ) , tr ( " Error opening certificate file. " ) ) ;
return ;
}
QString name = roots - > getUniqueName ( cert . commonName ( ) ) ;
// TODO: check for duplicate entries?
CertItem i ;
i . name = name ;
i . chain + = cert ;
roots - > addItem ( i ) ;
}
2007-05-03 22:14:13 +00:00
void load_file_finished ( )
{
2007-05-29 08:16:00 +00:00
// TODO: show more descriptive reason?
2007-05-03 22:14:13 +00:00
if ( keyLoader - > convertResult ( ) ! = QCA : : ConvertGood )
{
setEnabled ( true ) ;
QMessageBox : : information ( this , tr ( " Error " ) , tr ( " Error opening key file. " ) ) ;
return ;
}
QCA : : KeyBundle kb = keyLoader - > keyBundle ( ) ;
delete keyLoader ;
keyLoader = 0 ;
2007-05-29 08:16:00 +00:00
QCA : : CertificateChain chain = kb . certificateChain ( ) ;
QCA : : Certificate cert = chain . primary ( ) ;
2007-05-03 22:14:13 +00:00
2007-05-29 08:16:00 +00:00
QString name = users - > getUniqueName ( cert . commonName ( ) ) ;
2007-05-03 22:14:13 +00:00
// TODO: check for duplicate identities?
2007-05-29 08:16:00 +00:00
CertItem i ;
2007-05-03 22:14:13 +00:00
i . name = name ;
2007-05-29 08:16:00 +00:00
i . chain = chain ;
i . havePrivate = true ;
i . storageType = CertItem : : File ;
2007-05-03 22:14:13 +00:00
i . fileName = keyLoader_fileName ;
i . usable = true ;
2007-05-29 08:16:00 +00:00
users - > addItem ( i ) ;
2007-05-03 22:14:13 +00:00
2007-05-29 08:16:00 +00:00
ui . lv_users - > selectionModel ( ) - > select ( users - > index ( users - > list . count ( ) - 1 ) , QItemSelectionModel : : Clear | QItemSelectionModel : : Select | QItemSelectionModel : : Current ) ;
2007-05-03 22:14:13 +00:00
setEnabled ( true ) ;
}
void load_device_finished ( const QCA : : KeyStoreEntry & entry )
{
QCA : : KeyBundle kb = entry . keyBundle ( ) ;
2007-05-29 08:16:00 +00:00
QCA : : CertificateChain chain = kb . certificateChain ( ) ;
QCA : : Certificate cert = chain . primary ( ) ;
2007-05-03 22:14:13 +00:00
2007-05-29 08:16:00 +00:00
QString name = users - > getUniqueName ( entry . name ( ) ) ;
2007-05-03 22:14:13 +00:00
2007-05-29 08:16:00 +00:00
// TODO: check for duplicate identities?
CertItem i ;
2007-05-03 22:14:13 +00:00
i . name = name ;
2007-05-29 08:16:00 +00:00
i . chain = chain ;
i . havePrivate = true ;
i . storageType = CertItem : : Entry ;
i . keyStoreEntry = entry ;
2007-05-03 22:14:13 +00:00
i . usable = true ;
2007-05-29 08:16:00 +00:00
users - > addItem ( i ) ;
2007-05-03 22:14:13 +00:00
2007-05-29 08:16:00 +00:00
ui . lv_users - > selectionModel ( ) - > select ( users - > index ( users - > list . count ( ) - 1 ) , QItemSelectionModel : : Clear | QItemSelectionModel : : Select | QItemSelectionModel : : Current ) ;
2007-05-03 22:14:13 +00:00
setEnabled ( true ) ;
}
void mod_config ( )
{
2007-05-23 06:10:28 +00:00
if ( ! Pkcs11ConfigDlg : : isSupported ( ) )
2007-05-03 22:14:13 +00:00
{
QMessageBox : : information ( this , tr ( " Error " ) , tr ( " No provider available supporting standard PKCS#11 configuration. " ) ) ;
return ;
}
2007-05-23 06:10:28 +00:00
Pkcs11ConfigDlg * w = new Pkcs11ConfigDlg ( this ) ;
2007-05-03 22:14:13 +00:00
w - > setAttribute ( Qt : : WA_DeleteOnClose , true ) ;
w - > setWindowModality ( Qt : : WindowModal ) ;
w - > show ( ) ;
}
2007-05-29 08:16:00 +00:00
void users_selectionChanged ( const QItemSelection & selected , const QItemSelection & deselected )
2007-05-03 22:14:13 +00:00
{
Q_UNUSED ( deselected ) ;
if ( ! selected . indexes ( ) . isEmpty ( ) & & ! ui . pb_sign - > isEnabled ( ) )
ui . pb_sign - > setEnabled ( true ) ;
else if ( selected . indexes ( ) . isEmpty ( ) & & ui . pb_sign - > isEnabled ( ) )
ui . pb_sign - > setEnabled ( false ) ;
}
2007-05-29 08:16:00 +00:00
/*void item_view()
2007-05-03 22:14:13 +00:00
{
if ( ui . lv_identities - > hasFocus ( ) )
{
QItemSelection selection = ui . lv_identities - > selectionModel ( ) - > selection ( ) ;
if ( selection . indexes ( ) . isEmpty ( ) )
return ;
QModelIndex index = selection . indexes ( ) . first ( ) ;
identity_view ( index . row ( ) ) ;
}
else // lv_known
{
QItemSelection selection = ui . lv_known - > selectionModel ( ) - > selection ( ) ;
if ( selection . indexes ( ) . isEmpty ( ) )
return ;
QModelIndex index = selection . indexes ( ) . first ( ) ;
known_view ( index . row ( ) ) ;
}
2007-05-29 08:16:00 +00:00
} */
2007-05-03 22:14:13 +00:00
void item_rename ( )
{
2007-05-29 08:16:00 +00:00
if ( ui . lv_users - > hasFocus ( ) )
2007-05-03 22:14:13 +00:00
{
2007-05-29 08:16:00 +00:00
QItemSelection selection = ui . lv_users - > selectionModel ( ) - > selection ( ) ;
2007-05-03 22:14:13 +00:00
if ( selection . indexes ( ) . isEmpty ( ) )
return ;
QModelIndex index = selection . indexes ( ) . first ( ) ;
2007-05-29 08:16:00 +00:00
users_rename ( index . row ( ) ) ;
2007-05-03 22:14:13 +00:00
}
2007-05-29 08:16:00 +00:00
else // lv_authorities
2007-05-03 22:14:13 +00:00
{
2007-05-29 08:16:00 +00:00
QItemSelection selection = ui . lv_authorities - > selectionModel ( ) - > selection ( ) ;
2007-05-03 22:14:13 +00:00
if ( selection . indexes ( ) . isEmpty ( ) )
return ;
QModelIndex index = selection . indexes ( ) . first ( ) ;
2007-05-29 08:16:00 +00:00
roots_rename ( index . row ( ) ) ;
2007-05-03 22:14:13 +00:00
}
}
void item_remove ( )
{
2007-05-29 08:16:00 +00:00
if ( ui . lv_users - > hasFocus ( ) )
2007-05-03 22:14:13 +00:00
{
2007-05-29 08:16:00 +00:00
QItemSelection selection = ui . lv_users - > selectionModel ( ) - > selection ( ) ;
2007-05-03 22:14:13 +00:00
if ( selection . indexes ( ) . isEmpty ( ) )
return ;
QModelIndex index = selection . indexes ( ) . first ( ) ;
2007-05-29 08:16:00 +00:00
users_remove ( index . row ( ) ) ;
2007-05-03 22:14:13 +00:00
}
2007-05-29 08:16:00 +00:00
else // lv_authorities
2007-05-03 22:14:13 +00:00
{
2007-05-29 08:16:00 +00:00
QItemSelection selection = ui . lv_authorities - > selectionModel ( ) - > selection ( ) ;
2007-05-03 22:14:13 +00:00
if ( selection . indexes ( ) . isEmpty ( ) )
return ;
QModelIndex index = selection . indexes ( ) . first ( ) ;
2007-05-29 08:16:00 +00:00
roots_remove ( index . row ( ) ) ;
2007-05-03 22:14:13 +00:00
}
}
2007-05-29 08:16:00 +00:00
/*void identity_view(int at)
2007-05-03 22:14:13 +00:00
{
printf ( " identity_view: %d \n " , at ) ;
2007-05-29 08:16:00 +00:00
} */
2007-05-03 22:14:13 +00:00
2007-05-29 08:16:00 +00:00
void users_rename ( int at )
2007-05-03 22:14:13 +00:00
{
2007-05-29 08:16:00 +00:00
QModelIndex index = users - > index ( at ) ;
ui . lv_users - > setFocus ( ) ;
ui . lv_users - > setCurrentIndex ( index ) ;
ui . lv_users - > selectionModel ( ) - > select ( index , QItemSelectionModel : : Clear | QItemSelectionModel : : Select | QItemSelectionModel : : Current ) ;
ui . lv_users - > edit ( index ) ;
2007-05-03 22:14:13 +00:00
}
2007-05-29 08:16:00 +00:00
void users_remove ( int at )
2007-05-03 22:14:13 +00:00
{
2007-05-29 08:16:00 +00:00
users - > removeItem ( at ) ;
2007-05-03 22:14:13 +00:00
}
2007-05-29 08:16:00 +00:00
/*void known_view(int at)
2007-05-03 22:14:13 +00:00
{
printf ( " known_view: %d \n " , at ) ;
2007-05-29 08:16:00 +00:00
} */
2007-05-03 22:14:13 +00:00
2007-05-29 08:16:00 +00:00
void roots_rename ( int at )
2007-05-03 22:14:13 +00:00
{
2007-05-29 08:16:00 +00:00
QModelIndex index = roots - > index ( at ) ;
ui . lv_authorities - > setFocus ( ) ;
ui . lv_authorities - > setCurrentIndex ( index ) ;
ui . lv_authorities - > selectionModel ( ) - > select ( index , QItemSelectionModel : : Clear | QItemSelectionModel : : Select | QItemSelectionModel : : Current ) ;
ui . lv_authorities - > edit ( index ) ;
2007-05-03 22:14:13 +00:00
}
2007-05-29 08:16:00 +00:00
void roots_remove ( int at )
2007-05-03 22:14:13 +00:00
{
2007-05-29 08:16:00 +00:00
roots - > removeItem ( at ) ;
2007-05-03 22:14:13 +00:00
}
void do_sign ( )
{
2007-05-29 08:16:00 +00:00
QItemSelection selection = ui . lv_users - > selectionModel ( ) - > selection ( ) ;
if ( selection . indexes ( ) . isEmpty ( ) )
return ;
QModelIndex index = selection . indexes ( ) . first ( ) ;
int at = index . row ( ) ;
op = new SignOperation ( ui . te_data - > toPlainText ( ) . toUtf8 ( ) , & users - > list [ at ] , cms , this ) ;
2007-05-03 22:14:13 +00:00
connect ( op , SIGNAL ( finished ( const QString & ) ) , SLOT ( sign_finished ( const QString & ) ) ) ;
connect ( op , SIGNAL ( error ( const QString & ) ) , SLOT ( op_error ( const QString & ) ) ) ;
}
void do_verify ( )
{
2007-05-29 08:16:00 +00:00
// prepare root certs
2007-05-03 22:14:13 +00:00
QCA : : CertificateCollection col ;
2007-05-29 08:16:00 +00:00
// system store
2007-05-03 22:14:13 +00:00
col + = QCA : : systemStore ( ) ;
2007-05-29 08:16:00 +00:00
// additional roots configured in application
foreach ( const CertItem & i , roots - > list )
col . addCertificate ( i . chain . primary ( ) ) ;
// consider self-signed users as roots
// (it is therefore not possible with this application to
// have people in your keyring that you don't trust)
foreach ( const CertItem & i , users - > list )
{
QCA : : Certificate cert = i . chain . primary ( ) ;
if ( cert . isSelfSigned ( ) )
col . addCertificate ( cert ) ;
}
2007-05-03 22:14:13 +00:00
cms - > setTrustedCertificates ( col ) ;
op = new VerifyOperation ( ui . te_data - > toPlainText ( ) . toUtf8 ( ) , ui . te_sig - > toPlainText ( ) . toUtf8 ( ) , cms , this ) ;
connect ( op , SIGNAL ( finished ( ) ) , SLOT ( verify_finished ( ) ) ) ;
connect ( op , SIGNAL ( error ( const QString & ) ) , SLOT ( op_error ( const QString & ) ) ) ;
}
void about ( )
{
2007-05-29 08:16:00 +00:00
int ver = qcaVersion ( ) ;
int maj = ( ver > > 16 ) & 0xff ;
int min = ( ver > > 8 ) & 0xff ;
int bug = ver & 0xff ;
QString verstr ;
verstr . sprintf ( " %d.%d.%d " , maj , min , bug ) ;
QString str ;
str + = tr ( " CMS Signer version %1 by Justin Karneges " ) . arg ( VERSION ) + ' \n ' ;
str + = tr ( " A simple tool for creating and verifying digital signatures. " ) + ' \n ' ;
str + = ' \n ' ;
str + = tr ( " Using QCA version %1 " ) . arg ( verstr ) + ' \n ' ;
str + = ' \n ' ;
str + = tr ( " Icons by Jason Kim " ) + ' \n ' ;
QCA : : ProviderList list = QCA : : providers ( ) ;
foreach ( QCA : : Provider * p , list )
{
QString credit = p - > credit ( ) ;
if ( ! credit . isEmpty ( ) )
{
str + = ' \n ' ;
str + = credit ;
}
}
QMessageBox : : about ( this , tr ( " About CMS Signer " ) , str ) ;
2007-05-03 22:14:13 +00:00
}
void sign_finished ( const QString & sig )
{
ui . te_sig - > setPlainText ( sig ) ;
}
void verify_finished ( )
{
QMessageBox : : information ( this , tr ( " Verify " ) , tr ( " Signature verified successfully. " ) ) ;
}
void op_error ( const QString & msg )
{
QMessageBox : : information ( this , tr ( " Error " ) , msg ) ;
delete op ;
op = 0 ;
}
} ;
int main ( int argc , char * * argv )
{
QCA : : Initializer qcaInit ;
QApplication qapp ( argc , argv ) ;
2007-05-29 08:16:00 +00:00
qapp . setApplicationName ( MainWin : : tr ( " CMS Signer " ) ) ;
2007-05-03 22:14:13 +00:00
if ( ! QCA : : isSupported ( " cms " ) )
{
2007-05-29 08:16:00 +00:00
QMessageBox : : critical ( 0 , qapp . applicationName ( ) + " : " + MainWin : : tr ( " Error " ) , MainWin : : tr ( " No support for CMS is available. Please install an appropriate QCA plugin, such as qca-openssl. " ) ) ;
2007-05-03 22:14:13 +00:00
return 1 ;
}
MainWin mainWin ;
mainWin . show ( ) ;
return qapp . exec ( ) ;
}
# include "main.moc"