stephb9959
2022-11-30 11:43:22 -08:00
parent c0171156fa
commit a57cf08c00
2 changed files with 1 additions and 26 deletions

View File

@@ -658,7 +658,7 @@ namespace OpenWifi {
Params.set(uCentralProtocol::URI, URI); Params.set(uCentralProtocol::URI, URI);
Params.set(uCentralProtocol::KEEP_REDIRECTOR, KeepRedirector ? 1 : 0); Params.set(uCentralProtocol::KEEP_REDIRECTOR, KeepRedirector ? 1 : 0);
if(!R.sysupgrade_not_allowed() && FWSignature.empty()) { if(R.sysupgrade_not_allowed() && FWSignature.empty()) {
Poco::URI uri(URI); Poco::URI uri(URI);
FWSignature = SignatureManager()->Sign(R,uri); FWSignature = SignatureManager()->Sign(R,uri);
} }

View File

@@ -114,67 +114,42 @@ namespace OpenWifi {
inline std::string Sign(const AP_Restrictions &Restrictions, const Poco::URI &uri) { inline std::string Sign(const AP_Restrictions &Restrictions, const Poco::URI &uri) {
std::shared_lock L(KeyMutex_); std::shared_lock L(KeyMutex_);
std::cout << __LINE__ << std::endl;
try { try {
std::cout << __LINE__ << std::endl;
if (Restrictions.algo() == "static") { if (Restrictions.algo() == "static") {
std::cout << __LINE__ << std::endl;
return "aaaaaaaaaa"; return "aaaaaaaaaa";
} }
std::cout << __LINE__ << std::endl;
auto Vendor = Keys_.find(Restrictions.vendor()); auto Vendor = Keys_.find(Restrictions.vendor());
std::cout << __LINE__ << std::endl;
if (Vendor == Keys_.end()) { if (Vendor == Keys_.end()) {
std::cout << __LINE__ << std::endl;
poco_error( Logger(), fmt::format("{}: vendor unknown.", Restrictions.vendor())); poco_error( Logger(), fmt::format("{}: vendor unknown.", Restrictions.vendor()));
std::cout << __LINE__ << std::endl;
return ""; return "";
} }
std::cout << __LINE__ << std::endl;
if (Restrictions.algo() == "dgst-sha256") { if (Restrictions.algo() == "dgst-sha256") {
std::cout << __LINE__ << std::endl;
auto FileHash = auto FileHash =
Utils::ComputeHash(Restrictions.vendor(), Restrictions.algo(), uri.getPathAndQuery()); Utils::ComputeHash(Restrictions.vendor(), Restrictions.algo(), uri.getPathAndQuery());
std::cout << __LINE__ << std::endl;
auto CacheEntry = SignatureCache_.find(FileHash); auto CacheEntry = SignatureCache_.find(FileHash);
std::cout << __LINE__ << std::endl;
if (CacheEntry != end(SignatureCache_)) { if (CacheEntry != end(SignatureCache_)) {
std::cout << __LINE__ << std::endl;
return CacheEntry->second; return CacheEntry->second;
} }
std::cout << __LINE__ << std::endl;
Poco::TemporaryFile TempDownloadedFile; Poco::TemporaryFile TempDownloadedFile;
std::cout << __LINE__ << std::endl;
if (Utils::wgetfile(uri, TempDownloadedFile.path())) { if (Utils::wgetfile(uri, TempDownloadedFile.path())) {
std::cout << __LINE__ << std::endl;
Poco::Crypto::RSADigestEngine R(*Vendor->second, "SHA256"); Poco::Crypto::RSADigestEngine R(*Vendor->second, "SHA256");
std::cout << __LINE__ << std::endl;
Poco::DigestOutputStream ofs(R); Poco::DigestOutputStream ofs(R);
std::cout << __LINE__ << std::endl;
std::fstream ifs(TempDownloadedFile.path(), std::fstream ifs(TempDownloadedFile.path(),
std::ios_base::in | std::ios_base::binary); std::ios_base::in | std::ios_base::binary);
std::cout << __LINE__ << std::endl;
Poco::StreamCopier::copyStream(ifs, ofs); Poco::StreamCopier::copyStream(ifs, ofs);
std::cout << __LINE__ << std::endl;
ofs.flush(); ofs.flush();
std::cout << __LINE__ << std::endl;
auto Signature = Utils::base64encode((const unsigned char *)R.signature().data(),R.signature().size()); auto Signature = Utils::base64encode((const unsigned char *)R.signature().data(),R.signature().size());
std::cout << __LINE__ << std::endl;
SignatureCache_[FileHash] = Signature; SignatureCache_[FileHash] = Signature;
std::cout << __LINE__ << std::endl;
SaveCache(); SaveCache();
std::cout << __LINE__ << std::endl;
return Signature; return Signature;
} }
} }
} catch (const Poco::Exception &E) { } catch (const Poco::Exception &E) {
std::cout << __LINE__ << std::endl;
Logger().log(E); Logger().log(E);
} }
std::cout << __LINE__ << std::endl;
return ""; return "";
} }