rtmp: use bytes.Equal for signature matching

This commit is contained in:
Dan Kortschak 2018-09-06 12:26:35 +09:30
parent 6c6ed78e8f
commit aac0801cdb
1 changed files with 4 additions and 10 deletions

View File

@ -46,6 +46,7 @@ typedef struct sockaddr sockaddr;
import "C" import "C"
import ( import (
"bytes"
"errors" "errors"
"fmt" "fmt"
"log" "log"
@ -1586,7 +1587,6 @@ func C_RTMP_ReadPacket(r *C_RTMP, packet *C_RTMPPacket) (ok bool) {
// int HandShake(RTMP* r, int FP9HandShake); // int HandShake(RTMP* r, int FP9HandShake);
// rtmp.c +3744 // rtmp.c +3744
func C_HandShake(r *C_RTMP, FP9HandShake int32) (ok bool) { func C_HandShake(r *C_RTMP, FP9HandShake int32) (ok bool) {
var bMatch int
var uptime, suptime uint32 var uptime, suptime uint32
var typ byte var typ byte
//clientbuf := make([]byte, RTMP_SIG_SIZE+1) //clientbuf := make([]byte, RTMP_SIG_SIZE+1)
@ -1642,15 +1642,9 @@ func C_HandShake(r *C_RTMP, FP9HandShake int32) (ok bool) {
return false return false
} }
// TODO: find golang memcmp if !bytes.Equal(serversig[:RTMP_SIG_SIZE], clientbuf[1:RTMP_SIG_SIZE+1]) {
bMatch = 0 log.Printf("Client signature does not match: %q != %q",
if memcmp(unsafe.Pointer(&serversig[0]), unsafe.Pointer(clientsig), serversig[:RTMP_SIG_SIZE], clientbuf[1:RTMP_SIG_SIZE+1])
RTMP_SIG_SIZE) == 0 {
bMatch = 1
}
if bMatch == 0 {
log.Println("Client signature does not match!")
} }
return true return true
} }