86d86768b3
* refactor: const correctness Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: extract-method AsarFileValidator::EnsureHashExists() Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: replace use of deprecated crypto API https://crbug.com/364687923 Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: use span API in AsarFileValidator::OnRead() Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: replace use of deprecated crypto API https://crbug.com/364687923 Co-authored-by: Charles Kerr <charles@charleskerr.com> * fixup! refactor: use span API in AsarFileValidator::OnRead() fix: electron-ia32-testing FTBFS Co-authored-by: Charles Kerr <charles@charleskerr.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com>
64 lines
2 KiB
C++
64 lines
2 KiB
C++
// Copyright (c) 2021 Slack Technologies, Inc.
|
|
// Use of this source code is governed by the MIT license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_NET_ASAR_ASAR_FILE_VALIDATOR_H_
|
|
#define ELECTRON_SHELL_BROWSER_NET_ASAR_ASAR_FILE_VALIDATOR_H_
|
|
|
|
#include <memory>
|
|
|
|
#include "crypto/secure_hash.h"
|
|
#include "mojo/public/cpp/system/file_data_source.h"
|
|
#include "mojo/public/cpp/system/filtered_data_source.h"
|
|
#include "shell/common/asar/archive.h"
|
|
|
|
namespace asar {
|
|
|
|
class AsarFileValidator : public mojo::FilteredDataSource::Filter {
|
|
public:
|
|
AsarFileValidator(IntegrityPayload integrity, base::File file);
|
|
~AsarFileValidator() override;
|
|
|
|
// disable copy
|
|
AsarFileValidator(const AsarFileValidator&) = delete;
|
|
AsarFileValidator& operator=(const AsarFileValidator&) = delete;
|
|
|
|
// mojo::FilteredDataSource::Filter
|
|
void OnRead(base::span<char> buffer,
|
|
mojo::FileDataSource::ReadResult* result) override;
|
|
|
|
void OnDone() override;
|
|
|
|
void SetRange(uint64_t read_start, uint64_t extra_read, uint64_t read_max);
|
|
void SetCurrentBlock(int current_block);
|
|
|
|
protected:
|
|
bool FinishBlock();
|
|
|
|
private:
|
|
void EnsureBlockHashExists();
|
|
|
|
base::File file_;
|
|
IntegrityPayload integrity_;
|
|
|
|
// The offset in the file_ that the underlying file reader is starting at
|
|
uint64_t read_start_ = 0;
|
|
// The number of bytes this DataSourceFilter will have seen that aren't used
|
|
// by the DataProducer. These extra bytes are exclusively for hash validation
|
|
// but we need to know how many we've used so we know when we're done.
|
|
uint64_t extra_read_ = 0;
|
|
// The maximum offset in the file_ that we should read to, used to determine
|
|
// which bytes we're missing or if we need to read up to a block boundary in
|
|
// OnDone
|
|
uint64_t read_max_ = 0;
|
|
bool done_reading_ = false;
|
|
int current_block_;
|
|
int max_block_;
|
|
uint64_t current_hash_byte_count_ = 0U;
|
|
uint64_t total_hash_byte_count_ = 0;
|
|
std::unique_ptr<crypto::SecureHash> current_hash_;
|
|
};
|
|
|
|
} // namespace asar
|
|
|
|
#endif // ELECTRON_SHELL_BROWSER_NET_ASAR_ASAR_FILE_VALIDATOR_H_
|