]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/tls: add server-side OCSP stapling support.
authorAdam Langley <agl@golang.org>
Thu, 14 Apr 2011 18:47:28 +0000 (14:47 -0400)
committerAdam Langley <agl@golang.org>
Thu, 14 Apr 2011 18:47:28 +0000 (14:47 -0400)
We already had support on the client side. I also changed the name of
the flag in the ServerHello structure to match the name of the same
flag in the ClientHello (ocspStapling).

R=bradfitzgo
CC=golang-dev
https://golang.org/cl/4408044

src/pkg/crypto/tls/common.go
src/pkg/crypto/tls/handshake_client.go
src/pkg/crypto/tls/handshake_messages.go
src/pkg/crypto/tls/handshake_server.go

index fb2916ae05b63d9c5298d52354ebb4673956068f..102d986f00e7c0d468318d04c8e6f7e0622af4f7 100644 (file)
@@ -178,6 +178,9 @@ func (c *Config) cipherSuites() []uint16 {
 type Certificate struct {
        Certificate [][]byte
        PrivateKey  *rsa.PrivateKey
+       // OCSPStaple contains an optional OCSP response which will be served
+       // to clients that request it.
+       OCSPStaple []byte
 }
 
 // A TLS record.
index 540b25c8753a7408df7adfa9fc35bee35b9dc088..0e45c5057df42fd32c8bb277f13620bb6f94a786 100644 (file)
@@ -145,7 +145,7 @@ func (c *Conn) clientHandshake() os.Error {
 
        c.peerCertificates = certs
 
-       if serverHello.certStatus {
+       if serverHello.ocspStapling {
                msg, err = c.readHandshake()
                if err != nil {
                        return err
index e5e8562713df54485c857a481718f4acd84795b3..6645adce4f21258213952f60db835e2cbb30a1c4 100644 (file)
@@ -306,7 +306,7 @@ type serverHelloMsg struct {
        compressionMethod uint8
        nextProtoNeg      bool
        nextProtos        []string
-       certStatus        bool
+       ocspStapling      bool
 }
 
 func (m *serverHelloMsg) marshal() []byte {
@@ -327,7 +327,7 @@ func (m *serverHelloMsg) marshal() []byte {
                nextProtoLen += len(m.nextProtos)
                extensionsLength += nextProtoLen
        }
-       if m.certStatus {
+       if m.ocspStapling {
                numExtensions++
        }
        if numExtensions > 0 {
@@ -373,7 +373,7 @@ func (m *serverHelloMsg) marshal() []byte {
                        z = z[1+l:]
                }
        }
-       if m.certStatus {
+       if m.ocspStapling {
                z[0] = byte(extensionStatusRequest >> 8)
                z[1] = byte(extensionStatusRequest)
                z = z[4:]
@@ -406,7 +406,7 @@ func (m *serverHelloMsg) unmarshal(data []byte) bool {
 
        m.nextProtoNeg = false
        m.nextProtos = nil
-       m.certStatus = false
+       m.ocspStapling = false
 
        if len(data) == 0 {
                // ServerHello is optionally followed by extension data
@@ -450,7 +450,7 @@ func (m *serverHelloMsg) unmarshal(data []byte) bool {
                        if length > 0 {
                                return false
                        }
-                       m.certStatus = true
+                       m.ocspStapling = true
                }
                data = data[length:]
        }
index 809c8c15e5df19a2db9e3d4387c11c9bc1b39859..37c8d154ac4dc47955308bf0ad41d91ab2e8b4e2 100644 (file)
@@ -103,6 +103,9 @@ FindCipherSuite:
                hello.nextProtoNeg = true
                hello.nextProtos = config.NextProtos
        }
+       if clientHello.ocspStapling && len(config.Certificates[0].OCSPStaple) > 0 {
+               hello.ocspStapling = true
+       }
 
        finishedHash.Write(hello.marshal())
        c.writeRecord(recordTypeHandshake, hello.marshal())
@@ -116,6 +119,14 @@ FindCipherSuite:
        finishedHash.Write(certMsg.marshal())
        c.writeRecord(recordTypeHandshake, certMsg.marshal())
 
+       if hello.ocspStapling {
+               certStatus := new(certificateStatusMsg)
+               certStatus.statusType = statusTypeOCSP
+               certStatus.response = config.Certificates[0].OCSPStaple
+               finishedHash.Write(certStatus.marshal())
+               c.writeRecord(recordTypeHandshake, certStatus.marshal())
+       }
+
        keyAgreement := suite.ka()
 
        skx, err := keyAgreement.generateServerKeyExchange(config, clientHello, hello)