1) Change default gofmt default settings for

parsing and printing to new syntax.

                  Use -oldparser to parse the old syntax,
                  use -oldprinter to print the old syntax.

               2) Change default gofmt formatting settings
                  to use tabs for indentation only and to use
                  spaces for alignment. This will make the code
                  alignment insensitive to an editor's tabwidth.

                  Use -spaces=false to use tabs for alignment.

               3) Manually changed src/exp/parser/parser_test.go
                  so that it doesn't try to parse the parser's
                  source files using the old syntax (they have
                  new syntax now).

               4) gofmt -w src misc test/bench

	       1st set of files.

R=rsc
CC=agl, golang-dev, iant, ken2, r
https://golang.org/cl/180047
This commit is contained in:
Robert Griesemer 2009-12-15 15:33:31 -08:00
parent 34356e9a6a
commit 5a1d3323fe
139 changed files with 9422 additions and 9422 deletions

View file

@ -5,33 +5,33 @@
package tls
import (
"crypto/hmac";
"crypto/rc4";
"crypto/rsa";
"crypto/sha1";
"crypto/subtle";
"crypto/x509";
"io";
"crypto/hmac"
"crypto/rc4"
"crypto/rsa"
"crypto/sha1"
"crypto/subtle"
"crypto/x509"
"io"
)
// A serverHandshake performs the server side of the TLS 1.1 handshake protocol.
type clientHandshake struct {
writeChan chan<- interface{};
controlChan chan<- interface{};
msgChan <-chan interface{};
config *Config;
writeChan chan<- interface{}
controlChan chan<- interface{}
msgChan <-chan interface{}
config *Config
}
func (h *clientHandshake) loop(writeChan chan<- interface{}, controlChan chan<- interface{}, msgChan <-chan interface{}, config *Config) {
h.writeChan = writeChan;
h.controlChan = controlChan;
h.msgChan = msgChan;
h.config = config;
h.writeChan = writeChan
h.controlChan = controlChan
h.msgChan = msgChan
h.config = config
defer close(writeChan);
defer close(controlChan);
defer close(writeChan)
defer close(controlChan)
finishedHash := newFinishedHash();
finishedHash := newFinishedHash()
hello := &clientHelloMsg{
major: defaultMajor,
@ -39,175 +39,175 @@ func (h *clientHandshake) loop(writeChan chan<- interface{}, controlChan chan<-
cipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
compressionMethods: []uint8{compressionNone},
random: make([]byte, 32),
};
}
currentTime := uint32(config.Time());
hello.random[0] = byte(currentTime >> 24);
hello.random[1] = byte(currentTime >> 16);
hello.random[2] = byte(currentTime >> 8);
hello.random[3] = byte(currentTime);
_, err := io.ReadFull(config.Rand, hello.random[4:]);
currentTime := uint32(config.Time())
hello.random[0] = byte(currentTime >> 24)
hello.random[1] = byte(currentTime >> 16)
hello.random[2] = byte(currentTime >> 8)
hello.random[3] = byte(currentTime)
_, err := io.ReadFull(config.Rand, hello.random[4:])
if err != nil {
h.error(alertInternalError);
return;
h.error(alertInternalError)
return
}
finishedHash.Write(hello.marshal());
writeChan <- writerSetVersion{defaultMajor, defaultMinor};
writeChan <- hello;
finishedHash.Write(hello.marshal())
writeChan <- writerSetVersion{defaultMajor, defaultMinor}
writeChan <- hello
serverHello, ok := h.readHandshakeMsg().(*serverHelloMsg);
serverHello, ok := h.readHandshakeMsg().(*serverHelloMsg)
if !ok {
h.error(alertUnexpectedMessage);
return;
h.error(alertUnexpectedMessage)
return
}
finishedHash.Write(serverHello.marshal());
major, minor, ok := mutualVersion(serverHello.major, serverHello.minor);
finishedHash.Write(serverHello.marshal())
major, minor, ok := mutualVersion(serverHello.major, serverHello.minor)
if !ok {
h.error(alertProtocolVersion);
return;
h.error(alertProtocolVersion)
return
}
writeChan <- writerSetVersion{major, minor};
writeChan <- writerSetVersion{major, minor}
if serverHello.cipherSuite != TLS_RSA_WITH_RC4_128_SHA ||
serverHello.compressionMethod != compressionNone {
h.error(alertUnexpectedMessage);
return;
h.error(alertUnexpectedMessage)
return
}
certMsg, ok := h.readHandshakeMsg().(*certificateMsg);
certMsg, ok := h.readHandshakeMsg().(*certificateMsg)
if !ok || len(certMsg.certificates) == 0 {
h.error(alertUnexpectedMessage);
return;
h.error(alertUnexpectedMessage)
return
}
finishedHash.Write(certMsg.marshal());
finishedHash.Write(certMsg.marshal())
certs := make([]*x509.Certificate, len(certMsg.certificates));
certs := make([]*x509.Certificate, len(certMsg.certificates))
for i, asn1Data := range certMsg.certificates {
cert, err := x509.ParseCertificate(asn1Data);
cert, err := x509.ParseCertificate(asn1Data)
if err != nil {
h.error(alertBadCertificate);
return;
h.error(alertBadCertificate)
return
}
certs[i] = cert;
certs[i] = cert
}
// TODO(agl): do better validation of certs: max path length, name restrictions etc.
for i := 1; i < len(certs); i++ {
if certs[i-1].CheckSignatureFrom(certs[i]) != nil {
h.error(alertBadCertificate);
return;
h.error(alertBadCertificate)
return
}
}
if config.RootCAs != nil {
root := config.RootCAs.FindParent(certs[len(certs)-1]);
root := config.RootCAs.FindParent(certs[len(certs)-1])
if root == nil {
h.error(alertBadCertificate);
return;
h.error(alertBadCertificate)
return
}
if certs[len(certs)-1].CheckSignatureFrom(root) != nil {
h.error(alertBadCertificate);
return;
h.error(alertBadCertificate)
return
}
}
pub, ok := certs[0].PublicKey.(*rsa.PublicKey);
pub, ok := certs[0].PublicKey.(*rsa.PublicKey)
if !ok {
h.error(alertUnsupportedCertificate);
return;
h.error(alertUnsupportedCertificate)
return
}
shd, ok := h.readHandshakeMsg().(*serverHelloDoneMsg);
shd, ok := h.readHandshakeMsg().(*serverHelloDoneMsg)
if !ok {
h.error(alertUnexpectedMessage);
return;
h.error(alertUnexpectedMessage)
return
}
finishedHash.Write(shd.marshal());
finishedHash.Write(shd.marshal())
ckx := new(clientKeyExchangeMsg);
preMasterSecret := make([]byte, 48);
ckx := new(clientKeyExchangeMsg)
preMasterSecret := make([]byte, 48)
// Note that the version number in the preMasterSecret must be the
// version offered in the ClientHello.
preMasterSecret[0] = defaultMajor;
preMasterSecret[1] = defaultMinor;
_, err = io.ReadFull(config.Rand, preMasterSecret[2:]);
preMasterSecret[0] = defaultMajor
preMasterSecret[1] = defaultMinor
_, err = io.ReadFull(config.Rand, preMasterSecret[2:])
if err != nil {
h.error(alertInternalError);
return;
h.error(alertInternalError)
return
}
ckx.ciphertext, err = rsa.EncryptPKCS1v15(config.Rand, pub, preMasterSecret);
ckx.ciphertext, err = rsa.EncryptPKCS1v15(config.Rand, pub, preMasterSecret)
if err != nil {
h.error(alertInternalError);
return;
h.error(alertInternalError)
return
}
finishedHash.Write(ckx.marshal());
writeChan <- ckx;
finishedHash.Write(ckx.marshal())
writeChan <- ckx
suite := cipherSuites[0];
suite := cipherSuites[0]
masterSecret, clientMAC, serverMAC, clientKey, serverKey :=
keysFromPreMasterSecret11(preMasterSecret, hello.random, serverHello.random, suite.hashLength, suite.cipherKeyLength);
keysFromPreMasterSecret11(preMasterSecret, hello.random, serverHello.random, suite.hashLength, suite.cipherKeyLength)
cipher, _ := rc4.NewCipher(clientKey);
writeChan <- writerChangeCipherSpec{cipher, hmac.New(sha1.New(), clientMAC)};
cipher, _ := rc4.NewCipher(clientKey)
writeChan <- writerChangeCipherSpec{cipher, hmac.New(sha1.New(), clientMAC)}
finished := new(finishedMsg);
finished.verifyData = finishedHash.clientSum(masterSecret);
finishedHash.Write(finished.marshal());
writeChan <- finished;
finished := new(finishedMsg)
finished.verifyData = finishedHash.clientSum(masterSecret)
finishedHash.Write(finished.marshal())
writeChan <- finished
// TODO(agl): this is cut-through mode which should probably be an option.
writeChan <- writerEnableApplicationData{};
writeChan <- writerEnableApplicationData{}
_, ok = h.readHandshakeMsg().(changeCipherSpec);
_, ok = h.readHandshakeMsg().(changeCipherSpec)
if !ok {
h.error(alertUnexpectedMessage);
return;
h.error(alertUnexpectedMessage)
return
}
cipher2, _ := rc4.NewCipher(serverKey);
controlChan <- &newCipherSpec{cipher2, hmac.New(sha1.New(), serverMAC)};
cipher2, _ := rc4.NewCipher(serverKey)
controlChan <- &newCipherSpec{cipher2, hmac.New(sha1.New(), serverMAC)}
serverFinished, ok := h.readHandshakeMsg().(*finishedMsg);
serverFinished, ok := h.readHandshakeMsg().(*finishedMsg)
if !ok {
h.error(alertUnexpectedMessage);
return;
h.error(alertUnexpectedMessage)
return
}
verify := finishedHash.serverSum(masterSecret);
verify := finishedHash.serverSum(masterSecret)
if len(verify) != len(serverFinished.verifyData) ||
subtle.ConstantTimeCompare(verify, serverFinished.verifyData) != 1 {
h.error(alertHandshakeFailure);
return;
h.error(alertHandshakeFailure)
return
}
controlChan <- ConnectionState{true, "TLS_RSA_WITH_RC4_128_SHA", 0};
controlChan <- ConnectionState{true, "TLS_RSA_WITH_RC4_128_SHA", 0}
// This should just block forever.
_ = h.readHandshakeMsg();
h.error(alertUnexpectedMessage);
return;
_ = h.readHandshakeMsg()
h.error(alertUnexpectedMessage)
return
}
func (h *clientHandshake) readHandshakeMsg() interface{} {
v := <-h.msgChan;
v := <-h.msgChan
if closed(h.msgChan) {
// If the channel closed then the processor received an error
// from the peer and we don't want to echo it back to them.
h.msgChan = nil;
return 0;
h.msgChan = nil
return 0
}
if _, ok := v.(alert); ok {
// We got an alert from the processor. We forward to the writer
// and shutdown.
h.writeChan <- v;
h.msgChan = nil;
return 0;
h.writeChan <- v
h.msgChan = nil
return 0
}
return v;
return v
}
func (h *clientHandshake) error(e alertType) {
@ -217,9 +217,9 @@ func (h *clientHandshake) error(e alertType) {
go func() {
for _ = range h.msgChan {
}
}();
h.controlChan <- ConnectionState{false, "", e};
close(h.controlChan);
h.writeChan <- alert{alertLevelError, e};
}()
h.controlChan <- ConnectionState{false, "", e}
close(h.controlChan)
h.writeChan <- alert{alertLevelError, e}
}
}