add overload to set certificate by buffer, not just by path to a file
This commit is contained in:
parent
35141733fb
commit
aef1335e76
|
@ -881,6 +881,9 @@ namespace libtorrent
|
|||
, std::string const& private_key
|
||||
, std::string const& dh_params
|
||||
, std::string const& passphrase);
|
||||
void set_ssl_cert_buffer(std::string const& certificate
|
||||
, std::string const& private_key
|
||||
, std::string const& dh_params);
|
||||
boost::asio::ssl::context* ssl_ctx() const { return m_ssl_ctx.get(); }
|
||||
#endif
|
||||
|
||||
|
|
|
@ -766,6 +766,9 @@ namespace libtorrent
|
|||
// this client's certificate. The certificate must be signed by the
|
||||
// certificate in the .torrent file to be valid.
|
||||
//
|
||||
// The set_ssl_certificate_buffer() overload takes the actual certificate,
|
||||
// private key and DH params as strings, rather than paths to files.
|
||||
//
|
||||
// ``cert`` is a path to the (signed) certificate in .pem format
|
||||
// corresponding to this torrent.
|
||||
//
|
||||
|
@ -792,6 +795,9 @@ namespace libtorrent
|
|||
, std::string const& private_key
|
||||
, std::string const& dh_params
|
||||
, std::string const& passphrase = "");
|
||||
void set_ssl_certificate_buffer(std::string const& certificate
|
||||
, std::string const& private_key
|
||||
, std::string const& dh_params);
|
||||
|
||||
// Returns the storage implementation for this torrent. This depends on the
|
||||
// storage contructor function that was passed to add_torrent.
|
||||
|
|
|
@ -4394,6 +4394,41 @@ namespace libtorrent
|
|||
alerts().post_alert(torrent_error_alert(get_handle(), ec));
|
||||
}
|
||||
}
|
||||
|
||||
void torrent::set_ssl_cert_buffer(std::string const& certificate
|
||||
, std::string const& private_key
|
||||
, std::string const& dh_params)
|
||||
{
|
||||
if (!m_ssl_ctx) return;
|
||||
|
||||
boost::asio::const_buffer certificate_buf(certificate.c_str(), certificate.size());
|
||||
|
||||
using boost::asio::ssl::context;
|
||||
error_code ec;
|
||||
m_ssl_ctx->use_certificate(certificate_buf, context::pem, ec);
|
||||
if (ec)
|
||||
{
|
||||
if (alerts().should_post<torrent_error_alert>())
|
||||
alerts().post_alert(torrent_error_alert(get_handle(), ec));
|
||||
}
|
||||
|
||||
boost::asio::const_buffer private_key_buf(private_key.c_str(), private_key.size());
|
||||
m_ssl_ctx->use_private_key(private_key_buf, context::pem, ec);
|
||||
if (ec)
|
||||
{
|
||||
if (alerts().should_post<torrent_error_alert>())
|
||||
alerts().post_alert(torrent_error_alert(get_handle(), ec));
|
||||
}
|
||||
|
||||
boost::asio::const_buffer dh_params_buf(dh_params.c_str(), dh_params.size());
|
||||
m_ssl_ctx->use_tmp_dh(dh_params_buf, ec);
|
||||
if (ec)
|
||||
{
|
||||
if (alerts().should_post<torrent_error_alert>())
|
||||
alerts().post_alert(torrent_error_alert(get_handle(), ec));
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void torrent::remove_peer(peer_connection* p)
|
||||
|
|
|
@ -403,6 +403,16 @@ namespace libtorrent
|
|||
#endif
|
||||
}
|
||||
|
||||
void torrent_handle::set_ssl_certificate_buffer(
|
||||
std::string const& certificate
|
||||
, std::string const& private_key
|
||||
, std::string const& dh_params)
|
||||
{
|
||||
#ifdef TORRENT_USE_OPENSSL
|
||||
TORRENT_ASYNC_CALL3(set_ssl_cert_buffer, certificate, private_key, dh_params);
|
||||
#endif
|
||||
}
|
||||
|
||||
void torrent_handle::save_resume_data(int f) const
|
||||
{
|
||||
TORRENT_ASYNC_CALL1(save_resume_data, f);
|
||||
|
|
Loading…
Reference in New Issue