Skip to content

Commit da46189

Browse files
committed
#213: Started: get latest released version over HTTPS
1 parent 9d01d69 commit da46189

8 files changed

Lines changed: 61 additions & 16 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ QtGUI-build*
6868
.settings/*
6969

7070
# Visual studio stuff
71+
.vs
7172
Windows/.vs
7273
Windows/packages
7374
Windows/ipch

Windows/AirspaceConverter/AirspaceConverter.vcxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\packages\openssl-native.3.5.5\build\native\openssl-native.props" Condition="Exists('..\packages\openssl-native.3.5.5\build\native\openssl-native.props')" />
34
<ItemGroup Label="ProjectConfigurations">
45
<ProjectConfiguration Include="Debug|x64">
56
<Configuration>Debug</Configuration>
@@ -113,6 +114,7 @@
113114
<Import Project="..\packages\libzip.1.1.2.7\build\native\libzip.targets" Condition="Exists('..\packages\libzip.1.1.2.7\build\native\libzip.targets')" />
114115
<Import Project="..\packages\zlib_native.redist.1.2.11\build\native\zlib_native.redist.targets" Condition="Exists('..\packages\zlib_native.redist.1.2.11\build\native\zlib_native.redist.targets')" />
115116
<Import Project="..\packages\zlib_native.1.2.11\build\native\zlib_native.targets" Condition="Exists('..\packages\zlib_native.1.2.11\build\native\zlib_native.targets')" />
117+
<Import Project="..\packages\openssl-native.3.5.5\build\native\openssl-native.targets" Condition="Exists('..\packages\openssl-native.3.5.5\build\native\openssl-native.targets')" />
116118
</ImportGroup>
117119
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
118120
<PropertyGroup>
@@ -122,5 +124,7 @@
122124
<Error Condition="!Exists('..\packages\libzip.1.1.2.7\build\native\libzip.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\libzip.1.1.2.7\build\native\libzip.targets'))" />
123125
<Error Condition="!Exists('..\packages\zlib_native.redist.1.2.11\build\native\zlib_native.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\zlib_native.redist.1.2.11\build\native\zlib_native.redist.targets'))" />
124126
<Error Condition="!Exists('..\packages\zlib_native.1.2.11\build\native\zlib_native.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\zlib_native.1.2.11\build\native\zlib_native.targets'))" />
127+
<Error Condition="!Exists('..\packages\openssl-native.3.5.5\build\native\openssl-native.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\openssl-native.3.5.5\build\native\openssl-native.props'))" />
128+
<Error Condition="!Exists('..\packages\openssl-native.3.5.5\build\native\openssl-native.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\openssl-native.3.5.5\build\native\openssl-native.targets'))" />
125129
</Target>
126130
</Project>

Windows/AirspaceConverter/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<packages>
33
<package id="libzip" version="1.1.2.7" targetFramework="native" />
44
<package id="libzip.redist" version="1.1.2.7" targetFramework="native" />
5+
<package id="openssl-native" version="3.5.5" targetFramework="native" />
56
<package id="zlib_native" version="1.2.11" targetFramework="native" />
67
<package id="zlib_native.redist" version="1.2.11" targetFramework="native" />
78
</packages>

Windows/AirspaceConverterLib/AirspaceConverterLib.vcxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\packages\openssl-native.3.5.5\build\native\openssl-native.props" Condition="Exists('..\packages\openssl-native.3.5.5\build\native\openssl-native.props')" />
34
<ItemGroup Label="ProjectConfigurations">
45
<ProjectConfiguration Include="Debug|x64">
56
<Configuration>Debug</Configuration>
@@ -137,6 +138,7 @@
137138
<Import Project="..\packages\libzip.1.1.2.7\build\native\libzip.targets" Condition="Exists('..\packages\libzip.1.1.2.7\build\native\libzip.targets')" />
138139
<Import Project="..\packages\zlib_native.redist.1.2.11\build\native\zlib_native.redist.targets" Condition="Exists('..\packages\zlib_native.redist.1.2.11\build\native\zlib_native.redist.targets')" />
139140
<Import Project="..\packages\zlib_native.1.2.11\build\native\zlib_native.targets" Condition="Exists('..\packages\zlib_native.1.2.11\build\native\zlib_native.targets')" />
141+
<Import Project="..\packages\openssl-native.3.5.5\build\native\openssl-native.targets" Condition="Exists('..\packages\openssl-native.3.5.5\build\native\openssl-native.targets')" />
140142
</ImportGroup>
141143
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
142144
<PropertyGroup>
@@ -146,5 +148,7 @@
146148
<Error Condition="!Exists('..\packages\libzip.1.1.2.7\build\native\libzip.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\libzip.1.1.2.7\build\native\libzip.targets'))" />
147149
<Error Condition="!Exists('..\packages\zlib_native.redist.1.2.11\build\native\zlib_native.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\zlib_native.redist.1.2.11\build\native\zlib_native.redist.targets'))" />
148150
<Error Condition="!Exists('..\packages\zlib_native.1.2.11\build\native\zlib_native.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\zlib_native.1.2.11\build\native\zlib_native.targets'))" />
151+
<Error Condition="!Exists('..\packages\openssl-native.3.5.5\build\native\openssl-native.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\openssl-native.3.5.5\build\native\openssl-native.props'))" />
152+
<Error Condition="!Exists('..\packages\openssl-native.3.5.5\build\native\openssl-native.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\openssl-native.3.5.5\build\native\openssl-native.targets'))" />
149153
</Target>
150154
</Project>

Windows/AirspaceConverterLib/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<packages>
33
<package id="libzip" version="1.1.2.7" targetFramework="native" />
44
<package id="libzip.redist" version="1.1.2.7" targetFramework="native" />
5+
<package id="openssl-native" version="3.5.5" targetFramework="native" />
56
<package id="zlib_native" version="1.2.11" targetFramework="native" />
67
<package id="zlib_native.redist" version="1.2.11" targetFramework="native" />
78
</packages>

Windows/AirspaceConverterMFC/AirspaceConverterMFC.vcxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\packages\openssl-native.3.5.5\build\native\openssl-native.props" Condition="Exists('..\packages\openssl-native.3.5.5\build\native\openssl-native.props')" />
34
<ItemGroup Label="ProjectConfigurations">
45
<ProjectConfiguration Include="Debug|x64">
56
<Configuration>Debug</Configuration>
@@ -157,6 +158,7 @@
157158
<Import Project="..\packages\libzip.1.1.2.7\build\native\libzip.targets" Condition="Exists('..\packages\libzip.1.1.2.7\build\native\libzip.targets')" />
158159
<Import Project="..\packages\zlib_native.redist.1.2.11\build\native\zlib_native.redist.targets" Condition="Exists('..\packages\zlib_native.redist.1.2.11\build\native\zlib_native.redist.targets')" />
159160
<Import Project="..\packages\zlib_native.1.2.11\build\native\zlib_native.targets" Condition="Exists('..\packages\zlib_native.1.2.11\build\native\zlib_native.targets')" />
161+
<Import Project="..\packages\openssl-native.3.5.5\build\native\openssl-native.targets" Condition="Exists('..\packages\openssl-native.3.5.5\build\native\openssl-native.targets')" />
160162
</ImportGroup>
161163
<ProjectExtensions>
162164
<VisualStudio>
@@ -171,5 +173,7 @@
171173
<Error Condition="!Exists('..\packages\libzip.1.1.2.7\build\native\libzip.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\libzip.1.1.2.7\build\native\libzip.targets'))" />
172174
<Error Condition="!Exists('..\packages\zlib_native.redist.1.2.11\build\native\zlib_native.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\zlib_native.redist.1.2.11\build\native\zlib_native.redist.targets'))" />
173175
<Error Condition="!Exists('..\packages\zlib_native.1.2.11\build\native\zlib_native.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\zlib_native.1.2.11\build\native\zlib_native.targets'))" />
176+
<Error Condition="!Exists('..\packages\openssl-native.3.5.5\build\native\openssl-native.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\openssl-native.3.5.5\build\native\openssl-native.props'))" />
177+
<Error Condition="!Exists('..\packages\openssl-native.3.5.5\build\native\openssl-native.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\openssl-native.3.5.5\build\native\openssl-native.targets'))" />
174178
</Target>
175179
</Project>

Windows/AirspaceConverterMFC/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<packages>
33
<package id="libzip" version="1.1.2.7" targetFramework="native" />
44
<package id="libzip.redist" version="1.1.2.7" targetFramework="native" />
5+
<package id="openssl-native" version="3.5.5" targetFramework="native" />
56
<package id="zlib_native" version="1.2.11" targetFramework="native" />
67
<package id="zlib_native.redist" version="1.2.11" targetFramework="native" />
78
</packages>

src/AirspaceConverter.cpp

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,18 @@
3131
#include <filesystem>
3232
#include <format>
3333
#include <boost/algorithm/string/predicate.hpp>
34-
#include <boost/beast/core.hpp> // The HTTP client used to check for new version from Boost Beast is available from version 1.70
34+
#include <boost/beast/core.hpp>
3535
#include <boost/beast/http.hpp>
3636
#include <boost/beast/version.hpp>
37+
#include <boost/asio/connect.hpp>
38+
#include <boost/asio/ip/tcp.hpp>
39+
#include <boost/asio/ssl.hpp>
40+
41+
//TEST beast
42+
//#include <cstdlib>
43+
44+
45+
3746

3847
#ifdef __linux__ // If on Linux...
3948
const std::string AirspaceConverter::basePath(std::filesystem::canonical("/proc/self/exe").parent_path().string());
@@ -693,19 +702,43 @@ bool AirspaceConverter::CheckForNewVersion(int& versionDifference) {
693702
// The io_context is required for all I/O
694703
boost::asio::io_context ioc;
695704

705+
// The SSL context is required, and holds certificates
706+
boost::asio::ssl::context ctx(boost::asio::ssl::context::tlsv13_client);
707+
708+
//TODO: Use the default paths for finding CA certificates
709+
//ctx.set_default_verify_paths();
710+
711+
//TODO: Verify the remote server's certificate
712+
//ctx.set_verify_mode(boost::asio::ssl::verify_peer);
713+
714+
// FIXME: For now, we will not verify the server's certificate (not secure, but avoids issues with missing CA certificates)
715+
ctx.set_verify_mode(boost::asio::ssl::verify_none);
716+
696717
// These objects perform our I/O
697718
boost::asio::ip::tcp::resolver resolver(ioc);
698-
boost::beast::tcp_stream stream(ioc);
719+
boost::asio::ssl::stream<boost::beast::tcp_stream> stream(ioc, ctx);
699720

700-
// Look up the domain name
721+
// Domain name
701722
const std::string host = "alus.it";
702-
const auto results = resolver.resolve(host, "80");
723+
724+
// Set SNI Hostname (many hosts need this to handshake successfully)
725+
if (!SSL_set_tlsext_host_name(stream.native_handle(), host.c_str()))
726+
throw boost::beast::system_error(static_cast<int>(::ERR_get_error()), boost::asio::error::get_ssl_category());
727+
728+
// Set the expected hostname in the peer certificate for verification
729+
stream.set_verify_callback(boost::asio::ssl::host_name_verification(host));
730+
731+
// Look up the domain name
732+
const auto results = resolver.resolve(host, "443");
703733

704734
// Make the connection on the IP address we get from a lookup
705-
stream.connect(results);
735+
boost::beast::get_lowest_layer(stream).connect(results);
736+
737+
// Perform the SSL handshake
738+
stream.handshake(boost::asio::ssl::stream_base::client);
706739

707740
// Set up an HTTP GET request message (for HTTPS more libs would be required)
708-
boost::beast::http::request<boost::beast::http::string_body> req{boost::beast::http::verb::get, "/AirspaceConverter/lastVersion.txt", 11};
741+
boost::beast::http::request<boost::beast::http::string_body> req{ boost::beast::http::verb::get, "/AirspaceConverter/lastVersion.txt", 11 };
709742
req.set(boost::beast::http::field::host, host);
710743
req.set(boost::beast::http::field::user_agent, BOOST_BEAST_VERSION_STRING);
711744

@@ -716,24 +749,20 @@ bool AirspaceConverter::CheckForNewVersion(int& versionDifference) {
716749
boost::beast::flat_buffer buffer;
717750

718751
// Declare a container to hold the response
719-
boost::beast::http::response<boost::beast::http::string_body> res;
752+
boost::beast::http::response<boost::beast::http::dynamic_body> res;
720753

721754
// Receive the HTTP response
722755
boost::beast::http::read(stream, buffer, res);
723756

724-
// Gracefully close the socket
757+
// Gracefully close the stream
725758
boost::beast::error_code ec;
726-
stream.socket().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec);
759+
stream.shutdown(ec);
727760

728761
// Not_connected happens sometimes: so don't bother reporting it.
729-
if (ec && ec != boost::beast::errc::not_connected) {
730-
throw boost::beast::system_error{ec};
731-
}
762+
if (ec && ec != boost::beast::errc::not_connected) throw boost::beast::system_error{ec};
732763

733-
// If we get here then the connection is closed gracefully
734-
735-
// The content is the latest version string
736-
const std::string latestVersion = res.body();
764+
// If we get here then the connection is closed gracefully: The content is the latest version string
765+
const std::string latestVersion = boost::beast::buffers_to_string(res.body().data());
737766
const int latestVersionNumber = VersionToNumber(latestVersion);
738767
if (latestVersionNumber > 0) {
739768
versionDifference = latestVersionNumber - runningVersionNumber;

0 commit comments

Comments
 (0)