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
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (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 GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with Classified Ads; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 
21 #ifndef CLASSIFIED_CONTENTENCRYPTIONMODEL_H
22 #define CLASSIFIED_CONTENTENCRYPTIONMODEL_H
23 #include <QSqlDatabase>
24 #include "../mcontroller.h" // because enum from there is needed
25 #include "../net/connection.h"
26 #include <openssl/pem.h> // for EVP_PKEY
27 
28 
29 class Hash ;
31 
37 class ContentEncryptionModel : public QObject {
38  Q_OBJECT
39 
40 public:
41  ContentEncryptionModel(MController *aMController,
42  const MModelProtocolInterface &aModel ) ;
54  bool deleteKeyPair(const Hash& aHash) ;
55 
67  int changeKeyPassword(const Hash& aFingerPrint,
68  const QString& aNewPassword ) ;
85  int sign(const Hash& aSigningKey,
86  const QByteArray& aData,
87  QByteArray& aResultingSignature,
88  const QByteArray* aOptionalMetadata = NULL ) ;
93  bool verify(const Hash& aPresumedSigningKey,
94  const QByteArray& aDataToVerify,
95  const QByteArray& aSignatureToVerify,
96  const QByteArray* aOptionalMetadata = NULL,
97  bool emitErrorMessage = true ) ;
102  bool verify(const QByteArray& aPemBytesOfSigningKey,
103  const QByteArray& aDataToVerify,
104  const QByteArray& aSignatureToVerify,
105  const QByteArray* aOptionalMetadata = NULL,
106  bool emitErrorMessage = true ) ;
120  bool encrypt(const QList<Hash> aRecipients,
121  const QByteArray& aPlainText,
122  QByteArray& aResultingCipherText) ;
139  bool decrypt(const QByteArray& aCipherText,
140  QByteArray& aResultingPlainText,
141  bool aEmitErrorOnFailure = true ) ;
153  QList<Hash> listKeys(bool aPrivateKeys,
154  char *aKeyUidToSearch) ;
164  bool insertOrUpdatePublicKey (const QByteArray& aPublicKey,
165  const Hash& aFingerPrintOfKey,
166  const QString* aDisplayName = NULL ) ;
172  bool insertOrUpdatePrivateKey (const QByteArray& aPrivateKey,
173  const Hash& aFingerPrintOfKey) ;
187  bool PublicKey (const Hash& aFingerPrintOfKeyToFind,
188  QByteArray& aPossibleKeyFound,
189  quint32 *aTimeStampOfKeyFound = NULL) ;
198  bool PrivateKey (const Hash& aFingerPrintOfKeyToFind,
199  QByteArray& aPossibleKeyFound) ;
200 
211  EVP_PKEY *PrivateKeyFromPem(const QByteArray& aPemBytes,
212  bool aEmitErrorMessage = true ) ;
213 
221  EVP_PKEY *PublicKeyFromPem(const QByteArray& aPemBytes) ;
222 
226  Hash hashOfPublicKey(const QByteArray& aPemBytes) ;
227 
231  QByteArray randomBytes(int aNumberOfBytes) ;
232 
233 signals:
238  const QString& aExplanation) ;
239 
240 private: // methods
245  bool doVerify(const QByteArray& aPemBytesOfSigningKey,
246  const QByteArray& aDataToVerify,
247  const QByteArray& aSignatureToVerify,
248  const QByteArray* aOptionalMetadata = NULL,
249  bool emitErrorMessage = true ) ;
250 private: // member variables:
253 } ;
254 #endif
QByteArray randomBytes(int aNumberOfBytes)
bool PrivateKey(const Hash &aFingerPrintOfKeyToFind, QByteArray &aPossibleKeyFound)
const MModelProtocolInterface & iModel
Definition: contentencryptionmodel.h:252
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:38
CAErrorSituation
Definition: mcontroller.h:57
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)
EVP_PKEY * PrivateKeyFromPem(const QByteArray &aPemBytes, bool aEmitErrorMessage=true)
MController * iController
Definition: contentencryptionmodel.h:251
bool insertOrUpdatePrivateKey(const QByteArray &aPrivateKey, const Hash &aFingerPrintOfKey)
Pure-virtual interface of datamodel for message parser to use.
Definition: mmodelprotocolinterface.h:46
Pure-virtual interface class for controller. This is spammed across parties needing access to applica...
Definition: mcontroller.h:48
Hash hashOfPublicKey(const QByteArray &aPemBytes)
ContentEncryptionModel(MController *aMController, const MModelProtocolInterface &aModel)
void error(MController::CAErrorSituation aError, const QString &aExplanation)
bool decrypt(const QByteArray &aCipherText, QByteArray &aResultingPlainText, bool aEmitErrorOnFailure=true)
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:37