Skip to content

Commit f938c60

Browse files
authored
Merge pull request #17 from Kotodian/master
pub init problem
2 parents 1d88191 + 43a6b31 commit f938c60

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

std/crypto/tls/conn.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -688,12 +688,14 @@ func (c *Conn) ResetOrFreeBuffer() {
688688

689689
// readRecordOrCCS reads one or more TLS records from the connection and
690690
// updates the record layer state. Some invariants:
691-
// * c.in must be locked
692-
// * c.input must be empty
691+
// - c.in must be locked
692+
// - c.input must be empty
693+
//
693694
// During the handshake one and only one of the following will happen:
694695
// - c.hand grows
695696
// - c.in.changeCipherSpec is called
696697
// - an error is returned
698+
//
697699
// After the handshake one and only one of the following will happen:
698700
// - c.hand grows
699701
// - c.input is set
@@ -1561,7 +1563,6 @@ func (c *Conn) AppendAndRead(bufAppend []byte, bufRead []byte) (int, int, error)
15611563
}
15621564
c.rawInput = c.allocator.Append(c.rawInput, bufAppend...)
15631565
}
1564-
15651566
if err := c.Handshake(); err != nil {
15661567
if c.isNonBlock && err == errDataNotEnough {
15671568
return len(bufAppend), 0, nil
@@ -1702,7 +1703,6 @@ func (c *Conn) Handshake() error {
17021703

17031704
// c.in.Lock()
17041705
// defer c.in.Unlock()
1705-
17061706
c.handshakeErr = c.handshakeFn()
17071707
if c.isNonBlock && c.handshakeErr == errDataNotEnough {
17081708
c.handshakeErr = nil

std/crypto/tls/handshake_server.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ func (c *Conn) serverHandshake() error {
104104
}
105105
return hs.handshake()
106106
}
107-
108107
hs := c.hs
109108
if hs == nil {
110109
hs = &serverHandshakeState{
@@ -124,7 +123,6 @@ func (hs *serverHandshakeState) handshake() error {
124123
if hs.err != nil && hs.err != errDataNotEnough {
125124
return hs.err
126125
}
127-
128126
if err := hs.processClientHello(); err != nil {
129127
hs.err = err
130128
return err
@@ -203,7 +201,6 @@ func (hs *serverHandshakeState) handshake() error {
203201
atomic.StoreUint32(&c.handshakeStatus, 1)
204202

205203
c.handshakeStatusAsync = stateServerHandshakeHandshakeDone
206-
207204
return nil
208205
}
209206

@@ -651,8 +648,8 @@ func (hs *serverHandshakeState) doFullHandshake() error {
651648
return err
652649
}
653650
}
654-
655651
if c.config.ClientAuth >= RequestClientCert {
652+
// Request a client certificate
656653
initCertReq()
657654
hs.finishedHash.Write(certReq.marshal())
658655
if _, err := c.writeRecord(recordTypeHandshake, certReq.marshal()); err != nil {
@@ -669,6 +666,7 @@ func (hs *serverHandshakeState) doFullHandshake() error {
669666
if _, err := c.flush(); err != nil {
670667
return err
671668
}
669+
672670
}
673671

674672
if c.handshakeStatusAsync < stateServerHandshakeDoFullHandshake2ReadHandshake1 {
@@ -684,7 +682,6 @@ func (hs *serverHandshakeState) doFullHandshake() error {
684682

685683
// If we requested a client certificate, then the client must send a
686684
// certificate message, even if it's empty.
687-
688685
if c.config.ClientAuth >= RequestClientCert {
689686
if c.handshakeStatusAsync < stateServerHandshakeDoFullHandshake2HandleCertificateMsg {
690687
c.handshakeStatusAsync = stateServerHandshakeDoFullHandshake2HandleCertificateMsg
@@ -717,7 +714,6 @@ func (hs *serverHandshakeState) doFullHandshake() error {
717714

718715
}
719716
}
720-
721717
if c.handshakeStatusAsync < stateServerHandshakeDoFullHandshake2HandleVerifyConnection {
722718
c.handshakeStatusAsync = stateServerHandshakeDoFullHandshake2HandleVerifyConnection
723719
if c.config.VerifyConnection != nil {
@@ -747,7 +743,6 @@ func (hs *serverHandshakeState) doFullHandshake() error {
747743
}
748744

749745
}
750-
751746
if c.handshakeStatusAsync >= stateServerHandshakeDoFullHandshake2ReadHandshake3 {
752747
return nil
753748
}
@@ -771,7 +766,6 @@ func (hs *serverHandshakeState) doFullHandshake() error {
771766
c.handshakeStatusAsync = stateServerHandshakeDoFullHandshake2ReadHandshake3
772767
return unexpectedMessageError(certVerify, msg)
773768
}
774-
775769
var sigType uint8
776770
var sigHash crypto.Hash
777771
if c.vers >= VersionTLS12 {
@@ -796,6 +790,11 @@ func (hs *serverHandshakeState) doFullHandshake() error {
796790
}
797791

798792
signed := hs.finishedHash.hashForClientCertificate(sigType, sigHash, hs.masterSecret)
793+
if pub == nil {
794+
if len(c.peerCertificates) > 0 {
795+
pub = c.peerCertificates[0].PublicKey
796+
}
797+
}
799798
if err := verifyHandshakeSignature(sigType, pub, sigHash, signed, certVerify.signature); err != nil {
800799
c.sendAlert(alertDecryptError)
801800
c.handshakeStatusAsync = stateServerHandshakeDoFullHandshake2ReadHandshake3

0 commit comments

Comments
 (0)