From 9f88917ac1dc9740b976ad376e19965a66c40354 Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 28 Jun 2013 21:47:25 +0000 Subject: [PATCH] added display of SSL encryption parameters in PeerDetails dialog git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6465 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/pqi/pqipersongrp.cc | 6 +++++ libretroshare/src/pqi/pqipersongrp.h | 4 +++ libretroshare/src/pqi/pqissl.cc | 26 +++++++++++++++++++ libretroshare/src/pqi/pqissl.h | 3 +++ libretroshare/src/pqi/pqisslpersongrp.cc | 13 ++++++++++ libretroshare/src/pqi/pqisslpersongrp.h | 5 ++++ libretroshare/src/retroshare/rsiface.h | 7 +++-- libretroshare/src/retroshare/rspeers.h | 13 ++++++++++ libretroshare/src/rsserver/p3face.h | 2 ++ libretroshare/src/rsserver/rsiface.cc | 2 -- .../src/gui/connect/ConfCertDialog.cpp | 16 ++++++++++-- .../src/gui/connect/ConfCertDialog.ui | 12 ++++++++- 12 files changed, 102 insertions(+), 7 deletions(-) diff --git a/libretroshare/src/pqi/pqipersongrp.cc b/libretroshare/src/pqi/pqipersongrp.cc index 248b694a2..c18eef166 100644 --- a/libretroshare/src/pqi/pqipersongrp.cc +++ b/libretroshare/src/pqi/pqipersongrp.cc @@ -346,6 +346,12 @@ void pqipersongrp::statusChanged() /////////////////////////////////////////////////////////// #endif +bool pqipersongrp::getCryptoParams(const std::string& id,RsPeerCryptoParams& params) +{ + RsStackMutex stack(coreMtx); /******* LOCKED MUTEX **********/ + + return locked_getCryptoParams(id,params) ; +} int pqipersongrp::addPeer(std::string id) { diff --git a/libretroshare/src/pqi/pqipersongrp.h b/libretroshare/src/pqi/pqipersongrp.h index fd8118925..5245106fe 100644 --- a/libretroshare/src/pqi/pqipersongrp.h +++ b/libretroshare/src/pqi/pqipersongrp.h @@ -45,6 +45,7 @@ const unsigned long PQIPERSON_NO_LISTENER = 0x0001; const unsigned long PQIPERSON_ALL_BW_LIMITED = 0x0010; +class RsPeerCryptoParams ; class pqipersongrp: public pqihandler, public pqiMonitor, public p3ServiceServer, public pqiNetListener { @@ -90,8 +91,11 @@ bool notifyConnect(std::string id, uint32_t type, bool success, struct sockad virtual int tick(); virtual int status(); +virtual bool getCryptoParams(const std::string&,RsPeerCryptoParams&) ; protected: +virtual bool locked_getCryptoParams(const std::string&, RsPeerCryptoParams&) { return false ;} + /********* FUNCTIONS to OVERLOAD for specialisation ********/ // THESE NEED TO BE LOCKED UNTIL PQILISTENER IS THREAD-SAFE. virtual pqilistener *locked_createListener(struct sockaddr_in laddr) = 0; diff --git a/libretroshare/src/pqi/pqissl.cc b/libretroshare/src/pqi/pqissl.cc index 2870a4572..57db7b80a 100644 --- a/libretroshare/src/pqi/pqissl.cc +++ b/libretroshare/src/pqi/pqissl.cc @@ -38,6 +38,7 @@ #include "pqi/pqissllistener.h" #include "pqi/p3linkmgr.h" +#include const int pqisslzone = 37714; @@ -309,6 +310,31 @@ bool pqissl::connect_parameter(uint32_t type, uint32_t value) * */ +void pqissl::getCryptoParams(RsPeerCryptoParams& params) +{ + if(active) + { + params.connexion_state = 1 ; + params.cipher_name = std::string( SSL_get_cipher(ssl_connection)); + + int alg ; + int al2 = SSL_get_cipher_bits(ssl_connection,&alg); + + params.cipher_bits_1 = alg ; + params.cipher_bits_2 = al2 ; + + params.cipher_version = SSL_get_cipher_version(ssl_connection) ; + } + else + { + params.connexion_state = 0 ; + params.cipher_name.clear() ; + params.cipher_bits_1 = 0 ; + params.cipher_bits_2 = 0 ; + params.cipher_version.clear() ; + } +} + /* returns ... * -1 if inactive. * 0 if connecting. diff --git a/libretroshare/src/pqi/pqissl.h b/libretroshare/src/pqi/pqissl.h index 988ae1e0d..057ce6dff 100644 --- a/libretroshare/src/pqi/pqissl.h +++ b/libretroshare/src/pqi/pqissl.h @@ -83,6 +83,7 @@ class cert; class pqissllistener; class p3LinkMgr; +class RsPeerCryptoParams ; class pqissl: public NetBinInterface { @@ -152,6 +153,8 @@ public: int accept(SSL *ssl, int fd, struct sockaddr_in foreign_addr); +void getCryptoParams(RsPeerCryptoParams& params) ; + protected: //protected internal fns that are overloaded for udp case. diff --git a/libretroshare/src/pqi/pqisslpersongrp.cc b/libretroshare/src/pqi/pqisslpersongrp.cc index 552c7dbb2..8f135a32b 100644 --- a/libretroshare/src/pqi/pqisslpersongrp.cc +++ b/libretroshare/src/pqi/pqisslpersongrp.cc @@ -55,6 +55,17 @@ pqilistener * pqisslpersongrp::locked_createListener(struct sockaddr_in laddr) return listener; } +bool pqisslpersongrp::locked_getCryptoParams(const std::string& id,RsPeerCryptoParams& params) +{ + std::map::const_iterator it = ssl_tunnels.find(id) ; + + if(it == ssl_tunnels.end()) + return false ; + + it->second->getCryptoParams(params) ; + return true ; +} + pqiperson * pqisslpersongrp::locked_createPerson(std::string id, pqilistener *listener) { pqioutput(PQL_DEBUG_BASIC, pqipersongrpzone, "pqipersongrp::createPerson() PeerId: " + id); @@ -69,6 +80,8 @@ pqiperson * pqisslpersongrp::locked_createPerson(std::string id, pqilistener *li * * ServiceGeneric */ + ssl_tunnels[id] = pqis ; // keeps for getting crypt info per peer. + RsSerialiser *rss = new RsSerialiser(); rss->addSerialType(new RsFileItemSerialiser()); rss->addSerialType(new RsCacheItemSerialiser()); diff --git a/libretroshare/src/pqi/pqisslpersongrp.h b/libretroshare/src/pqi/pqisslpersongrp.h index 956cfdf55..02c197eef 100644 --- a/libretroshare/src/pqi/pqisslpersongrp.h +++ b/libretroshare/src/pqi/pqisslpersongrp.h @@ -31,6 +31,8 @@ #include "pqi/pqipersongrp.h" class p3PeerMgr; +class RsPeerCryptoParams; +class pqissl ; class pqisslpersongrp: public pqipersongrp { @@ -38,6 +40,8 @@ class pqisslpersongrp: public pqipersongrp pqisslpersongrp(SecurityPolicy *pol, unsigned long flags, p3PeerMgr *pm) :pqipersongrp(pol, flags), mPeerMgr(pm) { return; } + bool locked_getCryptoParams(const std::string&, RsPeerCryptoParams&) ; + protected: /********* FUNCTIONS to OVERLOAD for specialisation ********/ @@ -48,6 +52,7 @@ virtual pqiperson *locked_createPerson(std::string id, pqilistener *listener); private: p3PeerMgr *mPeerMgr; + std::map ssl_tunnels ; }; diff --git a/libretroshare/src/retroshare/rsiface.h b/libretroshare/src/retroshare/rsiface.h index d5e54878b..35f06abde 100644 --- a/libretroshare/src/retroshare/rsiface.h +++ b/libretroshare/src/retroshare/rsiface.h @@ -35,6 +35,7 @@ class NotifyBase; class RsIface; class RsControl; class RsInit; +class RsPeerCryptoParams; struct TurtleFileInfo ; /* declare single RsIface for everyone to use! */ @@ -163,8 +164,10 @@ class RsControl /* The Main Interface Class - for controlling the server */ /****************************************/ - NotifyBase &getNotify() { return cb; } - RsIface &getIface() { return rsIface; } + NotifyBase & getNotify() { return cb; } + RsIface & getIface() { return rsIface; } + + virtual bool getPeerCryptoDetails(const std::string& ssl_id,RsPeerCryptoParams& params) = 0; private: NotifyBase &cb; diff --git a/libretroshare/src/retroshare/rspeers.h b/libretroshare/src/retroshare/rspeers.h index 40ef42aa0..4df01a285 100644 --- a/libretroshare/src/retroshare/rspeers.h +++ b/libretroshare/src/retroshare/rspeers.h @@ -228,6 +228,19 @@ class RsPeerDetails uint32_t linkType; }; +// This class is used to get info about crytographic algorithms used with a +// particular peer. +// +class RsPeerCryptoParams +{ + public: + int connexion_state ; + std::string cipher_name ; + int cipher_bits_1 ; + int cipher_bits_2 ; + std::string cipher_version ; +}; + class RsGroupInfo { public: diff --git a/libretroshare/src/rsserver/p3face.h b/libretroshare/src/rsserver/p3face.h index 443f35db4..0a61391fe 100644 --- a/libretroshare/src/rsserver/p3face.h +++ b/libretroshare/src/rsserver/p3face.h @@ -158,6 +158,8 @@ class RsServer: public RsControl, public RsThread /****************************************/ + public: + virtual bool getPeerCryptoDetails(const std::string& ssl_id,RsPeerCryptoParams& params) { return pqih->getCryptoParams(ssl_id,params); } private: diff --git a/libretroshare/src/rsserver/rsiface.cc b/libretroshare/src/rsserver/rsiface.cc index ba0cb04a4..0110eeed1 100644 --- a/libretroshare/src/rsserver/rsiface.cc +++ b/libretroshare/src/rsserver/rsiface.cc @@ -85,13 +85,11 @@ public: virtual void lockData() { -// std::cerr << "RsIfaceReal::lockData()" << std::endl; return rsIfaceMutex.lock(); } virtual void unlockData() { -// std::cerr << "RsIfaceReal::unlockData()" << std::endl; return rsIfaceMutex.unlock(); } diff --git a/retroshare-gui/src/gui/connect/ConfCertDialog.cpp b/retroshare-gui/src/gui/connect/ConfCertDialog.cpp index 69f4ff698..593a609d6 100644 --- a/retroshare-gui/src/gui/connect/ConfCertDialog.cpp +++ b/retroshare-gui/src/gui/connect/ConfCertDialog.cpp @@ -199,9 +199,19 @@ void ConfCertDialog::load() std::map versions; bool retv = rsDisc->getDiscVersions(versions); if (retv && versions.end() != (vit = versions.find(detail.id))) - { ui.version->setText(QString::fromStdString(vit->second)); - } + + RsPeerCryptoParams cdet ; + if(rsicontrol->getPeerCryptoDetails(detail.id,cdet) && cdet.connexion_state!=0) + { + QString ct ; + ct += QString::fromStdString(cdet.cipher_name) ; + ct += QString::number(cdet.cipher_bits_1) ; + ct += "-"+QString::fromStdString(cdet.cipher_version) ; + ui.crypto_info->setText(ct) ; + } + else + ui.crypto_info->setText(tr("Not connected")) ; /* set local address */ ui.localAddress->setText(QString::fromStdString(detail.localAddr)); @@ -245,6 +255,8 @@ void ConfCertDialog::load() ui.version->hide(); ui.label_version->hide(); ui.groupBox_4->hide(); + ui.crypto_info->hide(); + ui.crypto_label->hide(); ui.groupBox->hide(); } diff --git a/retroshare-gui/src/gui/connect/ConfCertDialog.ui b/retroshare-gui/src/gui/connect/ConfCertDialog.ui index 21095d3d7..6fe58495d 100644 --- a/retroshare-gui/src/gui/connect/ConfCertDialog.ui +++ b/retroshare-gui/src/gui/connect/ConfCertDialog.ui @@ -60,7 +60,7 @@ - 3 + 0 @@ -140,6 +140,16 @@ + + + + Encryption + + + + + +