14 #include "certificateprovider.h"
15 #include "featurestarttls.h"
16 #include "streambase.h"
18 #include <gloox/connectiontlsserver.h>
19 #include <gloox/gloox.h>
20 #include <gloox/tag.h>
28 CertificateProvider* cp )
29 : m_state( TLSCanceled ), m_cp( cp ),
30 m_encryption( 0 ), m_required( required )
41 static const std::string filter =
"/starttls[@xmlns='" + gloox::XMLNS_STREAM_TLS +
"']";
49 if( m_state == TLSCanceled
52 bool haveCert =
false;
55 m_key = m_cp->handleKeyRequest( m_parent->
jid().server() );
56 m_cert = m_cp->handleCertificateRequest( m_parent->
jid().server() );
57 haveCert = ( !m_key.empty() && !m_cert.empty() );
62 t =
new gloox::Tag(
"starttls" );
63 t->setXmlns( gloox::XMLNS_STREAM_TLS );
65 new gloox::Tag( t,
"required" );
67 new gloox::Tag( t,
"optional" );
73 gloox::StreamErrorInternalServerError );
74 else if( !m_required )
81 void FeatureSTARTTLS::handleTag( gloox::Tag* _tag )
83 if( !_tag || _tag->xmlns() != gloox::XMLNS_STREAM_TLS )
86 const std::string& name = _tag->name();
88 if( name ==
"starttls" && m_state == TLSOffered )
90 gloox::Tag* p =
new gloox::Tag(
"proceed" );
91 p->setXmlns( gloox::XMLNS_STREAM_TLS );
94 m_encryption =
new gloox::ConnectionTLSServer( m_parent, m_parent->
connection(),
96 m_encryption->registerTLSHandler(
this );
98 m_encryption->setClientCert( m_key, m_cert );
99 m_encryption->connect();
101 m_state = TLSHandshake;
103 else if( name ==
"failure" )
105 m_state = TLSCanceled;
110 void FeatureSTARTTLS::handleHandshakeResult(
const gloox::TLSBase* ,
111 bool success, gloox::CertInfo& certinfo )
113 printf(
"handshake result: %d\n", success );
115 m_encryption->registerTLSHandler( 0 );
120 m_state = TLSEnabled;
121 if( !certinfo.compression.empty() )
124 printf(
"TLS compression enabled, disabling stream compression (XEP-138)\n" );
132 m_state = TLSCanceled;
133 gloox::Tag* f =
new gloox::Tag(
"failure" );
134 f->setXmlns( gloox::XMLNS_STREAM_TLS );