Add example for returning supported authentication methods, fix the
parse-url example by including the correct header, fix some small bugs in libleet itself
This commit is contained in:
parent
495c01cd2b
commit
95602980cd
|
@ -9,6 +9,7 @@
|
|||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <libleet/libleet.hpp>
|
||||
#include <libleet/Request.hpp>
|
||||
|
||||
int main() {
|
||||
std::string targetURL{};
|
||||
|
|
4
examples/return-supported-methods/.gitignore
vendored
Normal file
4
examples/return-supported-methods/.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
subprojects/*-*
|
||||
subprojects/packagecache
|
||||
build
|
||||
return-supported-methods
|
29
examples/return-supported-methods/meson.build
Normal file
29
examples/return-supported-methods/meson.build
Normal file
|
@ -0,0 +1,29 @@
|
|||
project(
|
||||
'return-supported-methods',
|
||||
'cpp',
|
||||
version : '"0.1"',
|
||||
default_options : ['warning_level=3']
|
||||
)
|
||||
|
||||
cc = meson.get_compiler('cpp')
|
||||
|
||||
project_source_files = [
|
||||
'return-supported-methods.cpp',
|
||||
]
|
||||
|
||||
project_dependencies = [
|
||||
dependency('libleet'),
|
||||
]
|
||||
|
||||
build_args = [
|
||||
'-DVERSION=' + meson.project_version(),
|
||||
]
|
||||
|
||||
project_target = executable(
|
||||
meson.project_name(),
|
||||
project_source_files, install : true,
|
||||
dependencies: project_dependencies,
|
||||
c_args : build_args,
|
||||
)
|
||||
|
||||
test('return-supported-methods', project_target)
|
|
@ -0,0 +1,25 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <libleet/libleet.hpp>
|
||||
|
||||
int main() {
|
||||
std::string username{};
|
||||
std::cout << "\033[2J\033[1;1H";
|
||||
std::cout << "Enter a Matrix username (@<username>:<home server>)\n> ";
|
||||
std::getline(std::cin, username);
|
||||
|
||||
if (username[0] != '@') {
|
||||
std::cout << "You are stupid.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
leet::Homeserver = leet::returnServerDiscovery(leet::returnHomeServerFromString(username));
|
||||
|
||||
std::vector<std::string> supportedTypes = leet::returnSupportedLoginTypes();
|
||||
|
||||
for (const auto& it : supportedTypes) {
|
||||
std::cout << it << "\n";
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@
|
|||
#define LIBLEET_HPP
|
||||
#ifndef LEET_NO_ENCRYPTION
|
||||
#include <random>
|
||||
#include <cstring>
|
||||
|
||||
namespace leetCrypto {
|
||||
/**
|
||||
|
|
|
@ -11,17 +11,6 @@
|
|||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <boost/beast/core.hpp>
|
||||
#include <boost/beast/http.hpp>
|
||||
#include <boost/beast/version.hpp>
|
||||
#include <boost/beast/ssl.hpp>
|
||||
#include <boost/asio/connect.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <boost/asio/ssl/error.hpp>
|
||||
#include <boost/asio/ssl/stream.hpp>
|
||||
#include <boost/asio/ssl/rfc2818_verification.hpp>
|
||||
#include <boost/asio/ssl/host_name_verification.hpp>
|
||||
#include <openssl/ssl.h>
|
||||
|
||||
namespace leetRequest {
|
||||
enum { /* supported protocols */
|
||||
|
@ -116,7 +105,6 @@ namespace leetRequest {
|
|||
std::string userCert{}; // User-specified root certificate string
|
||||
|
||||
const std::string getRootCertificates();
|
||||
void applyRootCertificates(boost::asio::ssl::context& ctx, const std::string& cert);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -152,6 +152,9 @@
|
|||
<None Include="packages.config" />
|
||||
<None Include="README.md" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="include\libleet.hpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="packages\nlohmann.json.3.11.2\build\native\nlohmann.json.targets" Condition="Exists('packages\nlohmann.json.3.11.2\build\native\nlohmann.json.targets')" />
|
||||
|
@ -172,4 +175,4 @@
|
|||
<Error Condition="!Exists('packages\rmt_openssl.1.1.0.3\build\native\rmt_openssl.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\rmt_openssl.1.1.0.3\build\native\rmt_openssl.targets'))" />
|
||||
<Error Condition="!Exists('packages\openssl-vc141-static-x86_64.1.1.0\build\native\openssl-vc141-static-x86_64.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\openssl-vc141-static-x86_64.1.1.0\build\native\openssl-vc141-static-x86_64.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
||||
</Project>
|
|
@ -28,4 +28,9 @@
|
|||
<None Include="docs\Doxyfile" />
|
||||
<None Include="docs\index.css" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="include\libleet.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -16,7 +16,6 @@
|
|||
#include <chrono>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <exception>
|
||||
#include <map>
|
||||
|
|
|
@ -12,6 +12,17 @@
|
|||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <boost/beast/core.hpp>
|
||||
#include <boost/beast/http.hpp>
|
||||
#include <boost/beast/version.hpp>
|
||||
#include <boost/beast/ssl.hpp>
|
||||
#include <boost/asio/connect.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <boost/asio/ssl/error.hpp>
|
||||
#include <boost/asio/ssl/stream.hpp>
|
||||
#include <boost/asio/ssl/rfc2818_verification.hpp>
|
||||
#include <boost/asio/ssl/host_name_verification.hpp>
|
||||
#include <openssl/ssl.h>
|
||||
#include "../../include/net/Request.hpp"
|
||||
#include "Cert.cpp"
|
||||
|
||||
|
@ -80,7 +91,15 @@ leetRequest::Response leetRequest::Request::makeRequest() {
|
|||
try {
|
||||
boost::asio::ssl::context ctx(boost::asio::ssl::context::tlsv12_client);
|
||||
|
||||
leetRequest::applyRootCertificates(ctx, leetRequest::getRootCertificates());
|
||||
const std::string_view cert{leetRequest::getRootCertificates()};
|
||||
|
||||
boost::system::error_code ec;
|
||||
|
||||
ctx.add_certificate_authority(boost::asio::buffer(cert.data(), cert.size()), ec);
|
||||
|
||||
if (ec) {
|
||||
throw boost::system::system_error{ec};
|
||||
}
|
||||
|
||||
boost::asio::io_context ioc;
|
||||
boost::asio::ip::tcp::resolver resolver(ioc);
|
||||
|
@ -91,8 +110,8 @@ leetRequest::Response leetRequest::Request::makeRequest() {
|
|||
boost::beast::ssl_stream<boost::beast::tcp_stream> stream(ioc, ctx);
|
||||
|
||||
if (!SSL_set_tlsext_host_name(stream.native_handle(), Host.c_str())) {
|
||||
boost::beast::error_code ec{static_cast<int>(::ERR_get_error()), boost::asio::error::get_ssl_category()};
|
||||
throw boost::beast::system_error{ec};
|
||||
boost::system::error_code ssl_ec{static_cast<int>(::ERR_get_error()), boost::asio::error::get_ssl_category()};
|
||||
throw boost::beast::system_error{ssl_ec};
|
||||
}
|
||||
|
||||
const auto results { resolver.resolve(Host, std::to_string(Port)) };
|
||||
|
@ -160,8 +179,6 @@ leetRequest::Response leetRequest::Request::makeRequest() {
|
|||
resp.statusCode = res.result_int();
|
||||
resp.Body = boost::beast::buffers_to_string(res.body().data());
|
||||
|
||||
boost::beast::error_code ec;
|
||||
|
||||
stream.next_layer().cancel();
|
||||
stream.shutdown(ec);
|
||||
stream.next_layer().close();
|
||||
|
@ -198,13 +215,3 @@ const bool leetRequest::Request::downloadFile() {
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
void leetRequest::applyRootCertificates(boost::asio::ssl::context& ctx, const std::string& cert) {
|
||||
boost::system::error_code ec;
|
||||
|
||||
ctx.add_certificate_authority(boost::asio::buffer(cert.data(), cert.size()), ec);
|
||||
|
||||
if (ec) {
|
||||
throw boost::system::system_error{ec};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue