Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
3b189d8f
Commit
3b189d8f
authored
Sep 12, 2011
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
crypto/tls: handle non-TLS more robustly
Fixes #2253. R=agl CC=golang-dev
https://golang.org/cl/4960066
parent
9fc68739
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
0 deletions
+59
-0
conn.go
src/pkg/crypto/tls/conn.go
+13
-0
handshake_server_test.go
src/pkg/crypto/tls/handshake_server_test.go
+46
-0
No files found.
src/pkg/crypto/tls/conn.go
View file @
3b189d8f
...
...
@@ -470,6 +470,19 @@ Again:
if
n
>
maxCiphertext
{
return
c
.
sendAlert
(
alertRecordOverflow
)
}
if
!
c
.
haveVers
{
// First message, be extra suspicious:
// this might not be a TLS client.
// Bail out before reading a full 'body', if possible.
// The current max version is 3.1.
// If the version is >= 16.0, it's probably not real.
// Similarly, a clientHello message encodes in
// well under a kilobyte. If the length is >= 12 kB,
// it's probably not real.
if
(
typ
!=
recordTypeAlert
&&
typ
!=
want
)
||
vers
>=
0x1000
||
n
>=
0x3000
{
return
c
.
sendAlert
(
alertUnexpectedMessage
)
}
}
if
err
:=
b
.
readFromUntil
(
c
.
conn
,
recordHeaderLen
+
n
);
err
!=
nil
{
if
err
==
os
.
EOF
{
err
=
io
.
ErrUnexpectedEOF
...
...
src/pkg/crypto/tls/handshake_server_test.go
View file @
3b189d8f
...
...
@@ -142,6 +142,52 @@ func TestHandshakeServerAES(t *testing.T) {
testServerScript
(
t
,
"AES"
,
aesServerScript
,
aesConfig
)
}
func
TestUnexpectedTLS
(
t
*
testing
.
T
)
{
l
,
err
:=
Listen
(
"tcp"
,
"127.0.0.1:0"
,
testConfig
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
ch
:=
make
(
chan
os
.
Error
,
1
)
done
:=
make
(
chan
bool
)
go
func
()
{
// Simulate HTTP client trying to do unencrypted HTTP on TLS port.
c
,
err
:=
net
.
Dial
(
"tcp"
,
l
.
Addr
()
.
String
())
if
err
!=
nil
{
ch
<-
err
<-
done
return
}
defer
func
()
{
<-
done
c
.
Close
()
}()
_
,
err
=
c
.
Write
([]
byte
(
"GET / HTTP/1.0
\r\n
Host: www.google.com
\r\n\r\n
"
))
if
err
!=
nil
{
ch
<-
err
return
}
ch
<-
nil
}()
c
,
err
:=
l
.
Accept
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
buf
:=
make
([]
byte
,
100
)
n
,
err
:=
c
.
Read
(
buf
)
if
n
>
0
||
err
==
nil
{
t
.
Errorf
(
"TLS Read = %d, %v, want error"
,
n
,
err
)
}
t
.
Logf
(
"%d, %v"
,
n
,
err
)
err
=
<-
ch
done
<-
true
if
err
!=
nil
{
t
.
Errorf
(
"TLS Write: %v"
,
err
)
}
}
var
serve
=
flag
.
Bool
(
"serve"
,
false
,
"run a TLS server on :10443"
)
func
TestRunServer
(
t
*
testing
.
T
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment