MCPcopy Create free account
hub / github.com/ClassicOldSong/Apollo / start

Function start

src/nvhttp.cpp:1636–1771  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1634 }
1635
1636 void start() {
1637 auto shutdown_event = mail::man->event<bool>(mail::shutdown);
1638
1639 auto port_http = net::map_port(PORT_HTTP);
1640 auto port_https = net::map_port(PORT_HTTPS);
1641 auto address_family = net::af_from_enum_string(config::sunshine.address_family);
1642
1643 bool clean_slate = config::sunshine.flags[config::flag::FRESH_STATE];
1644
1645 if (!clean_slate) {
1646 load_state();
1647 }
1648
1649 auto pkey = file_handler::read_file(config::nvhttp.pkey.c_str());
1650 auto cert = file_handler::read_file(config::nvhttp.cert.c_str());
1651 setup(pkey, cert);
1652
1653 // resume doesn't always get the parameter "localAudioPlayMode"
1654 // launch will store it in host_audio
1655 bool host_audio {};
1656
1657 https_server_t https_server {config::nvhttp.cert, config::nvhttp.pkey};
1658 http_server_t http_server;
1659
1660 // Verify certificates after establishing connection
1661 https_server.verify = [](req_https_t req, SSL *ssl) {
1662 crypto::x509_t x509 {
1663#if OPENSSL_VERSION_MAJOR >= 3
1664 SSL_get1_peer_certificate(ssl)
1665#else
1666 SSL_get_peer_certificate(ssl)
1667#endif
1668 };
1669 if (!x509) {
1670 BOOST_LOG(info) << "unknown -- denied"sv;
1671 return false;
1672 }
1673
1674 bool verified = false;
1675 p_named_cert_t named_cert_p;
1676
1677 auto fg = util::fail_guard([&]() {
1678 char subject_name[256];
1679
1680 X509_NAME_oneline(X509_get_subject_name(x509.get()), subject_name, sizeof(subject_name));
1681
1682 if (verified) {
1683 BOOST_LOG(debug) << subject_name << " -- "sv << "verified, device name: "sv << named_cert_p->name;
1684 } else {
1685 BOOST_LOG(debug) << subject_name << " -- "sv << "denied"sv;
1686 }
1687
1688 });
1689
1690 auto err_str = cert_chain.verify(x509.get(), named_cert_p);
1691 if (err_str) {
1692 BOOST_LOG(warning) << "SSL Verification error :: "sv << err_str;
1693 return verified;

Callers

nothing calls this directly

Calls 15

map_portFunction · 0.85
af_from_enum_stringFunction · 0.85
load_stateFunction · 0.85
read_fileFunction · 0.85
setupFunction · 0.85
fail_guardFunction · 0.85
launchFunction · 0.85
resumeFunction · 0.85
af_to_any_address_stringFunction · 0.85
verifyMethod · 0.80
writeMethod · 0.80
startMethod · 0.80

Tested by

no test coverage detected