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 RolloverCount calculation error #146

Merged
merged 1 commit into from
Jul 22, 2021
Merged

Conversation

cszdlt
Copy link
Contributor

@cszdlt cszdlt commented Jun 15, 2021

Description

Fix unorder interval exceeds maxROCDisorder causing RolloverCount error.

When there is a serious disorder in the network (the disorder segment is greater than maxROCDisorder), the nextRolloverCount will be calculated incorrectly.Will cause srtp decryption to fail.
This PR fixed this problem.

Imitate libsrtp/crypto/replay/rdbx.c: srtp_index_guess

@Sean-Der
Copy link
Member

Sean-Der commented Jul 5, 2021

Thank you so much @cszdlt

@at-wat mind giving this a look over as well? It looks ok to me, but it is a sensitive area would love your input.

@Sean-Der
Copy link
Member

Sean-Der commented Jul 5, 2021

@cszdlt This is a really great contribution, would you be interested in joining the Pion organization? Would love to know what we could improve, and would love your help.

@Sean-Der Sean-Der requested review from at-wat and Sean-Der July 5, 2021 14:33
@cszdlt
Copy link
Contributor Author

cszdlt commented Jul 5, 2021

I am a beginner with limited ability😅, but I am very happy to be able to help.

@at-wat
Copy link
Member

at-wat commented Jul 5, 2021

I'll take a look tomorrow.

@codecov
Copy link

codecov bot commented Jul 6, 2021

Codecov Report

Merging #146 (057a9d8) into master (d6718e5) will increase coverage by 0.50%.
The diff coverage is 100.00%.

❗ Current head 057a9d8 differs from pull request most recent head 8ec90ad. Consider uploading reports for the commit 8ec90ad to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #146      +/-   ##
==========================================
+ Coverage   75.56%   76.06%   +0.50%     
==========================================
  Files          16       16              
  Lines         757      773      +16     
==========================================
+ Hits          572      588      +16     
  Misses        103      103              
  Partials       82       82              
Flag Coverage Δ
go 76.06% <100.00%> (+0.50%) ⬆️
wasm 75.54% <100.00%> (+0.51%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
context.go 88.76% <100.00%> (+2.46%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d6718e5...8ec90ad. Read the comment docs.

@at-wat
Copy link
Member

at-wat commented Jul 6, 2021

at-wat
at-wat previously approved these changes Jul 6, 2021
context.go Outdated
roc++
seq := int32(sequenceNumber)
localRoc := uint32(s.index >> 16)
localSeq := int32(s.index & 0xffff)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
localSeq := int32(s.index & 0xffff)
localSeq := int32(s.index & (seqNumMax - 1))

just to make it consistent with https://github.com/pion/srtp/pull/146/files#diff-552f47512a00afe5fc6850cc9ddc830a6daeca162750e50aab4ed549685e0253R192
(seqNumMax - 1 is evaluated during compilation)

context.go Show resolved Hide resolved
guessRoc := localRoc
var difference int32 = 0

if s.rolloverHasProcessed {
Copy link
Member

@at-wat at-wat Jul 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/cisco/libsrtp/blob/bd0f27ec0e299ad101a396dde3f7c90d48efc8fc/crypto/replay/rdbx.c#L309-L325
I think above condition (s.index > seqNumMedian) should be checked here to avoid wrong guess after initialization and ROC overflow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this judgment needs to be added.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@at-wat Sorry, I forgot to run the check script. This is my first PR... T_T

context.go Outdated Show resolved Hide resolved
@at-wat at-wat dismissed their stale review July 6, 2021 02:28

s.index > seqNumMedian seems have to be checked

@at-wat
Copy link
Member

at-wat commented Jul 6, 2021

@Sean-Der generate-authors workflow doesn't work for forked PRs since secrets can't be expanded on the forked PRs for security.

Also, passing personal access token of the bot to the third-party action is not good at security unless action version is specified by commit hash.
(actions/checkout persists given token to the disk and stefanzweifel/git-auto-commit-action is using it to push to the repository.)
It is what I wrote in pion/.goassets#63 (comment).

at-wat
at-wat previously approved these changes Jul 22, 2021
Copy link
Member

@at-wat at-wat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, sorry for taking too long.

Mind adding you to AUTHORS.txt by manually running .github/generate-authors.sh script?

@cszdlt
Copy link
Contributor Author

cszdlt commented Jul 22, 2021

LGTM, sorry for taking too long.

Mind adding you to AUTHORS.txt by manually running .github/generate-authors.sh script?

it's okay no problem.
What should I do? @at-wat

@at-wat
Copy link
Member

at-wat commented Jul 22, 2021

Running

GITHUB_WORKSPACE=$(pwd) .github/generate-authors.sh 

will update AUTHORS.txt based on the commit history.
Please commit AUTHORS.txt and push.

@cszdlt
Copy link
Contributor Author

cszdlt commented Jul 22, 2021

Running

GITHUB_WORKSPACE=$(pwd) .github/generate-authors.sh 

will update AUTHORS.txt based on the commit history.
Please commit AUTHORS.txt and push.

The email I set on github is different from my local one, and two entries will be added after running the script... like this:

 backkem <mail@backkem.me>
 chenkaiC4 <chenkaic4@gmail.com>
 Chris Hiszpanski <chris@hiszpanski.name>
+cszdlt <1106543196@qq.com>
+cszdlt <cszdlt@qq.com>
 Hugo Arregui <hugo.arregui@gmail.com>
 Jerko Steiner <jerko.steiner@gmail.com>
 Juliusz Chroboczek <jch@irif.fr>

what should I do?

@at-wat
Copy link
Member

at-wat commented Jul 22, 2021

git rebase -i master

will open an editor to select action for each commit. Change pick to edit of the commits which you want to fix the commit author.
Then,

git commit --amend --reset-author
git rebase --continue

until processing all selected commits. It will update the commit author info to your current git config.

@at-wat
Copy link
Member

at-wat commented Jul 22, 2021

Or it may be easier to squash all commits in this PR.

Fix Unorder interval exceeds maxROCDisorder causing
RolloverCount error.
@cszdlt
Copy link
Contributor Author

cszdlt commented Jul 22, 2021

Or it may be easier to squash all commits in this PR.

Is it like this? :)

@at-wat
Copy link
Member

at-wat commented Jul 22, 2021

Perfect! Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants