(t *testing.T, rp string)
| 330 | } |
| 331 | |
| 332 | func testProtectedBuffer(t *testing.T, rp string) { |
| 333 | key := []byte{ |
| 334 | // 16 arbitrary bytes. |
| 335 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0xd2, 0x4c, 0xce, 0x4f, 0x49} |
| 336 | |
| 337 | // Encrypt a message to be passed to NewConn as a client-side protected |
| 338 | // buffer. |
| 339 | newCrypto := protocols[rp] |
| 340 | if newCrypto == nil { |
| 341 | t.Fatalf("Unknown record protocol %q", rp) |
| 342 | } |
| 343 | crypto, err := newCrypto(core.ClientSide, key) |
| 344 | if err != nil { |
| 345 | t.Fatalf("Failed to create a crypter for protocol %q: %v", rp, err) |
| 346 | } |
| 347 | msg := []byte("Client Protected Message") |
| 348 | encryptedMsg, err := crypto.Encrypt(nil, msg) |
| 349 | if err != nil { |
| 350 | t.Fatalf("Failed to encrypt the client protected message: %v", err) |
| 351 | } |
| 352 | protectedMsg := make([]byte, 8) // 8 bytes = 4 length + 4 type |
| 353 | binary.LittleEndian.PutUint32(protectedMsg, uint32(len(encryptedMsg))+4) // 4 bytes for the type |
| 354 | binary.LittleEndian.PutUint32(protectedMsg[4:], altsRecordMsgType) |
| 355 | protectedMsg = append(protectedMsg, encryptedMsg...) |
| 356 | |
| 357 | _, serverConn := newConnPair(rp, nil, protectedMsg) |
| 358 | rcvClientMsg := make([]byte, len(msg)) |
| 359 | if n, err := serverConn.Read(rcvClientMsg); n != len(rcvClientMsg) || err != nil { |
| 360 | t.Fatalf("Server Read() = %v, %v; want %v, <nil>", n, err, len(rcvClientMsg)) |
| 361 | } |
| 362 | if !reflect.DeepEqual(msg, rcvClientMsg) { |
| 363 | t.Fatalf("Client protected/Server Read() = %v, want %v", rcvClientMsg, msg) |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | func (s) TestProtectedBuffer(t *testing.T) { |
| 368 | for _, rp := range recordProtocols { |
no test coverage detected