Skip to content

Commit

Permalink
rtmp: fix RTMPE handshake error when a public key starts with zero (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 authored Aug 30, 2023
1 parent f69be81 commit fc353ce
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion internal/rtmp/handshake/dh.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package handshake

import (
"bytes"
"crypto/rand"
"fmt"
"math/big"
Expand Down Expand Up @@ -100,6 +101,10 @@ func dhGenerateKeyPair() ([]byte, []byte, error) {
y.Exp(&g, &x, &p)
pub := y.Bytes()

if len(pub) < dhKeyLength {
pub = append(bytes.Repeat([]byte{0}, dhKeyLength-len(pub)), pub...)
}

return priv, pub, nil
}

Expand All @@ -114,5 +119,11 @@ func dhComputeSharedSecret(priv []byte, pub []byte) []byte {
p.SetBytes(p1024)
var z big.Int
z.Exp(&y, &x, &p)
return z.Bytes()
sec := z.Bytes()

if len(sec) < dhKeyLength {
sec = append(bytes.Repeat([]byte{0}, dhKeyLength-len(sec)), sec...)
}

return sec
}

0 comments on commit fc353ce

Please sign in to comment.