Skip to content

Commit

Permalink
Add a special error message if we are trying to talk TLS to a HTTP-on…
Browse files Browse the repository at this point in the history
…ly server
  • Loading branch information
rolandshoemaker committed Jan 19, 2017
1 parent cb64fee commit 6aead2e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions va/va.go
@@ -1,6 +1,7 @@
package va

import (
"bytes"
"crypto/sha256"
"crypto/subtle"
"crypto/tls"
Expand Down Expand Up @@ -385,13 +386,21 @@ func (va *ValidationAuthorityImpl) validateTLSSNI01(ctx context.Context, identif
return va.validateTLSWithZName(ctx, identifier, challenge, ZName)
}

// badTLSHeader contains the string 'HTTP /' which is returned when
// we try to talk TLS to a server that only talks HTTP
var badTLSHeader = []byte{0x48, 0x54, 0x54, 0x50, 0x2f}

// parseHTTPConnError returns a ProblemDetails corresponding to an error
// that occurred during domain validation.
func parseHTTPConnError(detail string, err error) *probs.ProblemDetails {
if urlErr, ok := err.(*url.Error); ok {
err = urlErr.Err
}

if tlsErr, ok := err.(tls.RecordHeaderError); ok && bytes.Compare(tlsErr.RecordHeader[:], badTLSHeader) == 0 {
return probs.Malformed(fmt.Sprintf("%s: Server only speaks HTTP, not TLS", detail))
}

// XXX: On all of the resolvers I tested that validate DNSSEC, there is
// no differentiation between a DNSSEC failure and an unknown host. If we
// do not verify DNSSEC ourselves, this function should be modified.
Expand Down
14 changes: 14 additions & 0 deletions va/va_test.go
Expand Up @@ -492,6 +492,20 @@ func TestTLSSNI(t *testing.T) {
t.Fatalf("Server's down; expected refusal. Where did we connect?")
}
test.AssertEquals(t, prob.Type, probs.ConnectionProblem)

httpOnly := httpSrv(t, "")
defer httpOnly.Close()
port, err = getPort(httpOnly)
test.AssertNotError(t, err, "failed to get test server port")
va.tlsPort = port

log.Clear()
_, err = va.validateTLSSNI01(ctx, ident, chall)
test.AssertError(t, err, "TLS SNI validation passed when talking to a HTTP-only server")
test.Assert(t, strings.HasSuffix(
err.Error(),
"Server only speaks HTTP, not TLS",
), "validateTLSSNI01 didn't return useful error")
}

func brokenTLSSrv() *httptest.Server {
Expand Down

0 comments on commit 6aead2e

Please sign in to comment.