PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/quassel-0.7.3/src/client/clientidentity.cpp

#
C++ | 110 lines | 72 code | 16 blank | 22 comment | 9 complexity | 8142c750fd329264a30d51f12cf42570 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0
  1. /***************************************************************************
  2. * Copyright (C) 2005-09 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. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  19. ***************************************************************************/
  20. #include "clientidentity.h"
  21. #include "client.h"
  22. #include "signalproxy.h"
  23. INIT_SYNCABLE_OBJECT(CertIdentity)
  24. CertIdentity::CertIdentity(IdentityId id, QObject *parent)
  25. : Identity(id, parent)
  26. #ifdef HAVE_SSL
  27. , _certManager(0),
  28. _isDirty(false)
  29. #endif
  30. {
  31. }
  32. CertIdentity::CertIdentity(const Identity &other, QObject *parent)
  33. : Identity(other, parent)
  34. #ifdef HAVE_SSL
  35. , _certManager(0),
  36. _isDirty(false)
  37. #endif
  38. {
  39. }
  40. CertIdentity::CertIdentity(const CertIdentity &other, QObject *parent)
  41. : Identity(other, parent)
  42. #ifdef HAVE_SSL
  43. , _certManager(0),
  44. _isDirty(other._isDirty),
  45. _sslKey(other._sslKey),
  46. _sslCert(other._sslCert)
  47. #endif
  48. {
  49. }
  50. #ifdef HAVE_SSL
  51. void CertIdentity::enableEditSsl(bool enable) {
  52. if(!enable || _certManager)
  53. return;
  54. _certManager = new ClientCertManager(id(), this);
  55. if(isValid()) { // this means we are not a newly created Identity but have a proper Id
  56. Client::signalProxy()->synchronize(_certManager);
  57. connect(_certManager, SIGNAL(updated()), this, SLOT(markClean()));
  58. connect(_certManager, SIGNAL(initDone()), this, SLOT(markClean()));
  59. }
  60. }
  61. void CertIdentity::setSslKey(const QSslKey &key) {
  62. if(key.toPem() == _sslKey.toPem())
  63. return;
  64. _sslKey = key;
  65. _isDirty = true;
  66. }
  67. void CertIdentity::setSslCert(const QSslCertificate &cert) {
  68. if(cert.toPem() == _sslCert.toPem())
  69. return;
  70. _sslCert = cert;
  71. _isDirty = true;
  72. }
  73. void CertIdentity::requestUpdateSslSettings() {
  74. if(!_certManager)
  75. return;
  76. _certManager->requestUpdate(_certManager->toVariantMap());
  77. }
  78. void CertIdentity::markClean() {
  79. _isDirty = false;
  80. emit sslSettingsUpdated();
  81. }
  82. // ========================================
  83. // ClientCertManager
  84. // ========================================
  85. void ClientCertManager::setSslKey(const QByteArray &encoded) {
  86. QSslKey key(encoded, QSsl::Rsa);
  87. if(key.isNull())
  88. key = QSslKey(encoded, QSsl::Dsa);
  89. _certIdentity->setSslKey(key);
  90. }
  91. void ClientCertManager::setSslCert(const QByteArray &encoded) {
  92. _certIdentity->setSslCert(QSslCertificate(encoded));
  93. }
  94. #endif // HAVE_SSL