|
|
|
@ -26,13 +26,13 @@ namespace pEp {
|
|
|
|
|
|
|
|
|
|
UpdateDevice::UpdateDevice(const product p)
|
|
|
|
|
: _https({HTTPSDevice()}, ios::binary), _p(p),
|
|
|
|
|
_key(32), _src(nullptr)
|
|
|
|
|
_key(32), _src(nullptr), _str(nullptr)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UpdateDevice::UpdateDevice(const UpdateDevice& second)
|
|
|
|
|
: _https({HTTPSDevice()}, ios::binary), _p(second._p),
|
|
|
|
|
_key(32), _src(nullptr)
|
|
|
|
|
_key(32), _src(nullptr), _str(nullptr)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -40,6 +40,7 @@ namespace pEp {
|
|
|
|
|
{
|
|
|
|
|
close();
|
|
|
|
|
delete _src;
|
|
|
|
|
delete _str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UpdateDevice::open(CryptoPP::RSA::PublicKey update_key)
|
|
|
|
@ -79,15 +80,29 @@ namespace pEp {
|
|
|
|
|
byte iv[12];
|
|
|
|
|
_https->read((char *) iv, sizeof(iv));
|
|
|
|
|
|
|
|
|
|
string snk;
|
|
|
|
|
_delivery_decryptor.SetKeyWithIV(_key, _key.size(), iv, sizeof(iv));
|
|
|
|
|
_src = new CryptoPP::FileSource(_https, true,
|
|
|
|
|
new CryptoPP::AuthenticatedDecryptionFilter(
|
|
|
|
|
_delivery_decryptor,
|
|
|
|
|
new CryptoPP::StringSink(snk)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
_str = stringstream(snk);
|
|
|
|
|
if (filename() == "") {
|
|
|
|
|
string snk;
|
|
|
|
|
_delivery_decryptor.SetKeyWithIV(_key, _key.size(), iv, sizeof(iv));
|
|
|
|
|
_src = new CryptoPP::FileSource(_https, true,
|
|
|
|
|
new CryptoPP::AuthenticatedDecryptionFilter(
|
|
|
|
|
_delivery_decryptor,
|
|
|
|
|
new CryptoPP::StringSink(snk)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
delete _str;
|
|
|
|
|
_str = new stringstream(snk);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
_delivery_decryptor.SetKeyWithIV(_key, _key.size(), iv, sizeof(iv));
|
|
|
|
|
_src = new CryptoPP::FileSource(_https, true,
|
|
|
|
|
new CryptoPP::AuthenticatedDecryptionFilter(
|
|
|
|
|
_delivery_decryptor,
|
|
|
|
|
new CryptoPP::FileSink(filename().c_str(), true)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
delete _str;
|
|
|
|
|
_str = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UpdateDevice::close()
|
|
|
|
@ -95,15 +110,17 @@ namespace pEp {
|
|
|
|
|
_https->close();
|
|
|
|
|
delete _src;
|
|
|
|
|
_src = nullptr;
|
|
|
|
|
delete _str;
|
|
|
|
|
_str = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
streamsize UpdateDevice::read(char* s, streamsize n)
|
|
|
|
|
{
|
|
|
|
|
if (_str.eof())
|
|
|
|
|
if (!_str || _str->eof())
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
_str.read(s, n);
|
|
|
|
|
return _str.gcount();
|
|
|
|
|
_str->read(s, n);
|
|
|
|
|
return _str->gcount();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|