Classified ads
contentencryptionmodel.h
Go to the documentation of this file.
1 /* -*-C++-*- -*-coding: utf-8-unix;-*-
2  Classified Ads is Copyright (c) Antti Jarvinen 2013.
3 
4  This file is part of Classified Ads.
5 
6  Classified Ads is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Classified Ads is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Classified Ads. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef CLASSIFIED_CONTENTENCRYPTIONMODEL_H
21 #define CLASSIFIED_CONTENTENCRYPTIONMODEL_H
22 #include <QSqlDatabase>
23 #include "../mcontroller.h" // because enum from there is needed
24 #include "../net/connection.h"
25 #include <openssl/pem.h> // for EVP_PKEY
26 
27 
28 class Hash ;
30 
36 class ContentEncryptionModel : public QObject {
37  Q_OBJECT
38 
39 public:
40  ContentEncryptionModel(MController *aMController,
41  const MModelProtocolInterface &aModel ) ;
53  bool deleteKeyPair(const Hash& aHash) ;
54 
66  int changeKeyPassword(const Hash& aFingerPrint,
67  const QString& aNewPassword ) ;
84  int sign(const Hash& aSigningKey,
85  const QByteArray& aData,
86  QByteArray& aResultingSignature,
87  const QByteArray* aOptionalMetadata = NULL ) ;
92  bool verify(const Hash& aPresumedSigningKey,
93  const QByteArray& aDataToVerify,
94  const QByteArray& aSignatureToVerify,
95  const QByteArray* aOptionalMetadata = NULL,
96  bool emitErrorMessage = true ) ;
101  bool verify(const QByteArray& aPemBytesOfSigningKey,
102  const QByteArray& aDataToVerify,
103  const QByteArray& aSignatureToVerify,
104  const QByteArray* aOptionalMetadata = NULL,
105  bool emitErrorMessage = true ) ;
119  bool encrypt(const QList<Hash> aRecipients,
120  const QByteArray& aPlainText,
121  QByteArray& aResultingCipherText) ;
132  bool decrypt(const QByteArray& aCipherText,
133  QByteArray& aResultingPlainText) ;
145  QList<Hash> listKeys(bool aPrivateKeys,
146  char *aKeyUidToSearch) ;
156  bool insertOrUpdatePublicKey (const QByteArray& aPublicKey,
157  const Hash& aFingerPrintOfKey,
158  const QString* aDisplayName = NULL ) ;
164  bool insertOrUpdatePrivateKey (const QByteArray& aPrivateKey,
165  const Hash& aFingerPrintOfKey) ;
179  bool PublicKey (const Hash& aFingerPrintOfKeyToFind,
180  QByteArray& aPossibleKeyFound,
181  quint32 *aTimeStampOfKeyFound = NULL) ;
190  bool PrivateKey (const Hash& aFingerPrintOfKeyToFind,
191  QByteArray& aPossibleKeyFound) ;
192 
203  EVP_PKEY *PrivateKeyFromPem(const QByteArray& aPemBytes,
204  bool aEmitErrorMessage = true ) ;
205 
213  EVP_PKEY *PublicKeyFromPem(const QByteArray& aPemBytes) ;
214 
218  Hash hashOfPublicKey(const QByteArray& aPemBytes) ;
219 
220 signals:
225  const QString& aExplanation) ;
226 
227 private: // methods
232  bool doVerify(const QByteArray& aPemBytesOfSigningKey,
233  const QByteArray& aDataToVerify,
234  const QByteArray& aSignatureToVerify,
235  const QByteArray* aOptionalMetadata = NULL,
236  bool emitErrorMessage = true ) ;
237 private: // member variables:
240 } ;
241 #endif
bool PrivateKey(const Hash &aFingerPrintOfKeyToFind, QByteArray &aPossibleKeyFound)
const MModelProtocolInterface & iModel
Definition: contentencryptionmodel.h:239
int changeKeyPassword(const Hash &aFingerPrint, const QString &aNewPassword)
bool encrypt(const QList< Hash > aRecipients, const QByteArray &aPlainText, QByteArray &aResultingCipherText)
EVP_PKEY * PublicKeyFromPem(const QByteArray &aPemBytes)
Hash is class that carries 160-bit digest.
Definition: hash.h:37
CAErrorSituation
Definition: mcontroller.h:48
bool doVerify(const QByteArray &aPemBytesOfSigningKey, const QByteArray &aDataToVerify, const QByteArray &aSignatureToVerify, const QByteArray *aOptionalMetadata=NULL, bool emitErrorMessage=true)
int sign(const Hash &aSigningKey, const QByteArray &aData, QByteArray &aResultingSignature, const QByteArray *aOptionalMetadata=NULL)
bool decrypt(const QByteArray &aCipherText, QByteArray &aResultingPlainText)
EVP_PKEY * PrivateKeyFromPem(const QByteArray &aPemBytes, bool aEmitErrorMessage=true)
MController * iController
Definition: contentencryptionmodel.h:238
bool insertOrUpdatePrivateKey(const QByteArray &aPrivateKey, const Hash &aFingerPrintOfKey)
Pure-virtual interface of datamodel for message parser to use.
Definition: mmodelprotocolinterface.h:44
Pure-virtual interface class for controller. This is spammed across parties needing access to applica...
Definition: mcontroller.h:39
Hash hashOfPublicKey(const QByteArray &aPemBytes)
ContentEncryptionModel(MController *aMController, const MModelProtocolInterface &aModel)
void error(MController::CAErrorSituation aError, const QString &aExplanation)
bool insertOrUpdatePublicKey(const QByteArray &aPublicKey, const Hash &aFingerPrintOfKey, const QString *aDisplayName=NULL)
bool PublicKey(const Hash &aFingerPrintOfKeyToFind, QByteArray &aPossibleKeyFound, quint32 *aTimeStampOfKeyFound=NULL)
QList< Hash > listKeys(bool aPrivateKeys, char *aKeyUidToSearch)
bool deleteKeyPair(const Hash &aHash)
bool verify(const Hash &aPresumedSigningKey, const QByteArray &aDataToVerify, const QByteArray &aSignatureToVerify, const QByteArray *aOptionalMetadata=NULL, bool emitErrorMessage=true)
This is content-crypto-operations-specific part of the datamodel.
Definition: contentencryptionmodel.h:36