mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
websocket: correct challenge response
Tested against latest Chrome. R=ukai, rsc CC=golang-dev https://golang.org/cl/1743053
This commit is contained in:
parent
d0b913fe37
commit
1badb46313
4 changed files with 48 additions and 49 deletions
|
|
@ -5,11 +5,9 @@
|
|||
package websocket
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"bufio"
|
||||
"bytes"
|
||||
"container/vector"
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"http"
|
||||
"io"
|
||||
|
|
@ -157,32 +155,6 @@ func generateKey3() (key []byte) {
|
|||
return
|
||||
}
|
||||
|
||||
/*
|
||||
Gets expected from challenge as described in 4.1 Opening handshake
|
||||
step 42 to 43.
|
||||
cf. http://www.whatwg.org/specs/web-socket-protocol/
|
||||
*/
|
||||
func getExpectedForChallenge(number1, number2 uint32, key3 []byte) (expected []byte, err os.Error) {
|
||||
// 41. Let /challenge/ be the concatenation of /number_1/, expressed
|
||||
// a big-endian 32 bit integer, /number_2/, expressed in a big-
|
||||
// endian 32 bit integer, and the eight bytes of /key_3/ in the
|
||||
// order they were sent to the wire.
|
||||
challenge := make([]byte, 16)
|
||||
challengeBuf := bytes.NewBuffer(challenge)
|
||||
binary.Write(challengeBuf, binary.BigEndian, number1)
|
||||
binary.Write(challengeBuf, binary.BigEndian, number2)
|
||||
copy(challenge[8:], key3)
|
||||
|
||||
// 42. Let /expected/ be the MD5 fingerprint of /challenge/ as a big-
|
||||
// endian 128 bit string.
|
||||
h := md5.New()
|
||||
if _, err = h.Write(challenge); err != nil {
|
||||
return
|
||||
}
|
||||
expected = h.Sum()
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
Web Socket protocol handshake based on
|
||||
http://www.whatwg.org/specs/web-socket-protocol/
|
||||
|
|
@ -258,7 +230,7 @@ func handshake(resourceName, host, origin, location, protocol string, br *bufio.
|
|||
}
|
||||
|
||||
// Step 42-43. get expected data from challange data.
|
||||
expected, err := getExpectedForChallenge(number1, number2, key3)
|
||||
expected, err := getChallengeResponse(number1, number2, key3)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue