1 /***************************************************************************
2 * Copyright (C) 2005-2020 by the Quassel Project *
3 * devel@quassel-irc.org *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
9 * *
10 * This program 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 *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
20
21 #include "coreidentity.h"
22
23 #include "signalproxy.h"
24
CoreIdentity(IdentityId id,QObject * parent)25 CoreIdentity::CoreIdentity(IdentityId id, QObject* parent)
26 : Identity(id, parent)
27 , _certManager(this)
28 {
29 connect(this, &Identity::idSet, &_certManager, &CoreCertManager::setId);
30 connect(&_certManager, &SyncableObject::updated, this, &SyncableObject::updated);
31 }
32
CoreIdentity(const Identity & other,QObject * parent)33 CoreIdentity::CoreIdentity(const Identity& other, QObject* parent)
34 : Identity(other, parent)
35 , _certManager(this)
36 {
37 connect(this, &Identity::idSet, &_certManager, &CoreCertManager::setId);
38 connect(&_certManager, &SyncableObject::updated, this, &SyncableObject::updated);
39 }
40
CoreIdentity(const CoreIdentity & other,QObject * parent)41 CoreIdentity::CoreIdentity(const CoreIdentity& other, QObject* parent)
42 : Identity(other, parent)
43 , _sslKey(other._sslKey)
44 , _sslCert(other._sslCert)
45 , _certManager(this)
46 {
47 connect(this, &Identity::idSet, &_certManager, &CoreCertManager::setId);
48 connect(&_certManager, &SyncableObject::updated, this, &SyncableObject::updated);
49 }
50
synchronize(SignalProxy * proxy)51 void CoreIdentity::synchronize(SignalProxy* proxy)
52 {
53 proxy->synchronize(this);
54 proxy->synchronize(&_certManager);
55 }
56
setSslKey(const QByteArray & encoded)57 void CoreIdentity::setSslKey(const QByteArray& encoded)
58 {
59 QSslKey key(encoded, QSsl::Rsa);
60 if (key.isNull())
61 key = QSslKey(encoded, QSsl::Ec);
62 if (key.isNull())
63 key = QSslKey(encoded, QSsl::Dsa);
64 setSslKey(key);
65 }
66
setSslCert(const QByteArray & encoded)67 void CoreIdentity::setSslCert(const QByteArray& encoded)
68 {
69 setSslCert(QSslCertificate(encoded));
70 }
71
72 // ========================================
73 // CoreCertManager
74 // ========================================
75
CoreCertManager(CoreIdentity * identity)76 CoreCertManager::CoreCertManager(CoreIdentity* identity)
77 : CertManager(identity->id())
78 , _identity(identity)
79 {
80 setAllowClientUpdates(true);
81 }
82
setId(IdentityId id)83 void CoreCertManager::setId(IdentityId id)
84 {
85 setObjectName(QString::number(id.toInt()));
86 }
87
setSslKey(const QByteArray & encoded)88 void CoreCertManager::setSslKey(const QByteArray& encoded)
89 {
90 _identity->setSslKey(encoded);
91 CertManager::setSslKey(encoded);
92 }
93
setSslCert(const QByteArray & encoded)94 void CoreCertManager::setSslCert(const QByteArray& encoded)
95 {
96 _identity->setSslCert(encoded);
97 CertManager::setSslCert(encoded);
98 }
99