Skip to content

Commit

Permalink
reset has_valid_key after RatchetKey.
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwebrtc committed Aug 31, 2023
1 parent 677bec5 commit bb20946
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions api/crypto/frame_crypto_transformer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ void FrameCryptorTransformer::decryptFrame(
return;
}

if(last_dec_error_ == kDecryptionFailed && !key_handler->have_valid_key) {
if(last_dec_error_ == kDecryptionFailed && !key_handler->has_valid_key) {
// if decryption failed and we have an invalid key,
// please try to decrypt with the next new key
return;
Expand Down Expand Up @@ -584,6 +584,7 @@ void FrameCryptorTransformer::decryptFrame(
decryption_success = true;
// success, so we set the new key
key_handler->SetKeyFromMaterial(new_material, key_index);
key_handler->has_valid_key = true;
if (last_dec_error_ != FrameCryptionState::kKeyRatcheted) {
last_dec_error_ = FrameCryptionState::kKeyRatcheted;
if (observer_)
Expand Down Expand Up @@ -612,7 +613,7 @@ void FrameCryptorTransformer::decryptFrame(
if (!decryption_success) {
if (last_dec_error_ != FrameCryptionState::kDecryptionFailed) {
last_dec_error_ = FrameCryptionState::kDecryptionFailed;
key_handler->have_valid_key = false;
key_handler->has_valid_key = false;
if (observer_)
observer_->OnFrameCryptionStateChanged(participant_id_,
last_dec_error_);
Expand Down
7 changes: 4 additions & 3 deletions api/crypto/frame_crypto_transformer.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class ParticipantKeyHandler {
}
SetKeyFromMaterial(new_material,
key_index != -1 ? key_index : current_key_index_);
has_valid_key = true;
return new_material;
}

Expand All @@ -113,7 +114,7 @@ class ParticipantKeyHandler {
virtual void SetKey(std::vector<uint8_t> password, int key_index) {
webrtc::MutexLock lock(&mutex_);
SetKeyFromMaterial(password, key_index);
have_valid_key = true;
has_valid_key = true;
}

std::vector<uint8_t> RatchetKeyMaterial(
Expand Down Expand Up @@ -145,8 +146,8 @@ class ParticipantKeyHandler {
crypto_key_ring_[current_key_index_] =
DeriveKeys(password, key_provider_->options().ratchet_salt, 128);
}
protected:
bool have_valid_key = false;
protected:
bool has_valid_key = false;
private:
mutable webrtc::Mutex mutex_;
int current_key_index_ = 0;
Expand Down

0 comments on commit bb20946

Please sign in to comment.