Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix decrypt re-encrypt segment #383

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `cmd/mp4ff-encrypt` did not parse command line
- `SeigSampleGroupEntry` calculated skipBytes incorrectly
- `cmd/mp4ff-pslister` did not parse annex B HEVC correctly
- error when decrypting and re-encrypting a segement (issue #378)

### Removed

Expand Down
3 changes: 3 additions & 0 deletions mp4/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,9 @@ func DecryptFragment(frag *Fragment, di DecryptInfo, key []byte) error {
trun.DataOffset -= int32(nrBytesRemoved)
}
}
if frag.Mdat.StartPos > frag.Moof.StartPos {
frag.Mdat.StartPos -= nrBytesRemoved
}

return nil
}
Expand Down
20 changes: 20 additions & 0 deletions mp4/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,22 @@ func TestEncryptDecrypt(t *testing.T) {
if !bytes.Equal(rawSeg, decSegBuf.Bytes()) {
t.Errorf("segment not equal after encryption+decryption")
}

// Make a new encryption to check that the decrypted segment is OK
// for re-encryption (Issue #378).

pd2, err := InitProtect(encInit.Init, key, iv, c.scheme, kidUUID, nil)
if err != nil {
t.Error(err)
}
for _, s := range decode.Segments {
for _, f := range s.Fragments {
err := EncryptFragment(f, key, iv, pd2)
if err != nil {
t.Errorf("Error re-encrypting fragment: %v\n", err)
}
}
}
})
}
}
Expand All @@ -238,3 +254,7 @@ func TestDecryptInit(t *testing.T) {
}
}
}

func TestDecryptEncrypt(t *testing.T) {

}
Loading