Run gofmt

Signed-off-by: Jonathan Rudenberg <jonathan@titanous.com>
This commit is contained in:
Jonathan Rudenberg 2016-07-28 14:55:46 -04:00
parent 38b9c920eb
commit acc6781f29
16 changed files with 451 additions and 410 deletions

View File

@ -10,10 +10,10 @@
package certspotter
import (
"errors"
"bytes"
"encoding/binary"
"encoding/asn1"
"encoding/binary"
"errors"
"unicode/utf8"
)
@ -75,4 +75,3 @@ func decodeASN1String (value *asn1.RawValue) (string, error) {
}
return "", errors.New("Not a string")
}

View File

@ -10,11 +10,11 @@
package certspotter
import (
"time"
"strconv"
"errors"
"unicode"
"encoding/asn1"
"errors"
"strconv"
"time"
"unicode"
)
func isDigit(b byte) bool {
@ -36,19 +36,29 @@ func parseUTCTime (bytes []byte) (time.Time, error) {
return time.Time{}, errors.New("UTCTime is too short")
}
year, err = bytesToInt(bytes[0:2])
if err != nil { return time.Time{}, errors.New("UTCTime contains invalid integer: " + err.Error()) }
if err != nil {
return time.Time{}, errors.New("UTCTime contains invalid integer: " + err.Error())
}
month, err = bytesToInt(bytes[2:4])
if err != nil { return time.Time{}, errors.New("UTCTime contains invalid integer: " + err.Error()) }
if err != nil {
return time.Time{}, errors.New("UTCTime contains invalid integer: " + err.Error())
}
day, err = bytesToInt(bytes[4:6])
if err != nil { return time.Time{}, errors.New("UTCTime contains invalid integer: " + err.Error()) }
if err != nil {
return time.Time{}, errors.New("UTCTime contains invalid integer: " + err.Error())
}
hour, err = bytesToInt(bytes[6:8])
if err != nil { return time.Time{}, errors.New("UTCTime contains invalid integer: " + err.Error()) }
if err != nil {
return time.Time{}, errors.New("UTCTime contains invalid integer: " + err.Error())
}
min, err = bytesToInt(bytes[8:10])
if err != nil { return time.Time{}, errors.New("UTCTime contains invalid integer: " + err.Error()) }
if err != nil {
return time.Time{}, errors.New("UTCTime contains invalid integer: " + err.Error())
}
bytes = bytes[10:]
@ -72,10 +82,14 @@ func parseUTCTime (bytes []byte) (time.Time, error) {
return time.Time{}, errors.New("UTCTime positive timezone offset is too short")
}
tzHour, err := bytesToInt(bytes[1:3])
if err != nil { return time.Time{}, errors.New("UTCTime contains invalid integer: " + err.Error()) }
if err != nil {
return time.Time{}, errors.New("UTCTime contains invalid integer: " + err.Error())
}
tzMin, err := bytesToInt(bytes[3:5])
if err != nil { return time.Time{}, errors.New("UTCTime contains invalid integer: " + err.Error()) }
if err != nil {
return time.Time{}, errors.New("UTCTime contains invalid integer: " + err.Error())
}
tz = time.FixedZone("", tzHour*3600+tzMin*60)
bytes = bytes[5:]
@ -85,10 +99,14 @@ func parseUTCTime (bytes []byte) (time.Time, error) {
return time.Time{}, errors.New("UTCTime negative timezone offset is too short")
}
tzHour, err := bytesToInt(bytes[1:3])
if err != nil { return time.Time{}, errors.New("UTCTime contains invalid integer: " + err.Error()) }
if err != nil {
return time.Time{}, errors.New("UTCTime contains invalid integer: " + err.Error())
}
tzMin, err := bytesToInt(bytes[3:5])
if err != nil { return time.Time{}, errors.New("UTCTime contains invalid integer: " + err.Error()) }
if err != nil {
return time.Time{}, errors.New("UTCTime contains invalid integer: " + err.Error())
}
tz = time.FixedZone("", -1*(tzHour*3600+tzMin*60))
bytes = bytes[5:]
@ -122,16 +140,24 @@ func parseGeneralizedTime (bytes []byte) (time.Time, error) {
return time.Time{}, errors.New("GeneralizedTime is too short")
}
year, err = bytesToInt(bytes[0:4])
if err != nil { return time.Time{}, errors.New("GeneralizedTime contains invalid integer: " + err.Error()) }
if err != nil {
return time.Time{}, errors.New("GeneralizedTime contains invalid integer: " + err.Error())
}
month, err = bytesToInt(bytes[4:6])
if err != nil { return time.Time{}, errors.New("GeneralizedTime contains invalid integer: " + err.Error()) }
if err != nil {
return time.Time{}, errors.New("GeneralizedTime contains invalid integer: " + err.Error())
}
day, err = bytesToInt(bytes[6:8])
if err != nil { return time.Time{}, errors.New("GeneralizedTime contains invalid integer: " + err.Error()) }
if err != nil {
return time.Time{}, errors.New("GeneralizedTime contains invalid integer: " + err.Error())
}
hour, err = bytesToInt(bytes[8:10])
if err != nil { return time.Time{}, errors.New("GeneralizedTime contains invalid integer: " + err.Error()) }
if err != nil {
return time.Time{}, errors.New("GeneralizedTime contains invalid integer: " + err.Error())
}
bytes = bytes[10:]
@ -174,10 +200,14 @@ func parseGeneralizedTime (bytes []byte) (time.Time, error) {
return time.Time{}, errors.New("GeneralizedTime positive timezone offset is too short")
}
tzHour, err := bytesToInt(bytes[1:3])
if err != nil { return time.Time{}, errors.New("GeneralizedTime contains invalid integer: " + err.Error()) }
if err != nil {
return time.Time{}, errors.New("GeneralizedTime contains invalid integer: " + err.Error())
}
tzMin, err := bytesToInt(bytes[3:5])
if err != nil { return time.Time{}, errors.New("GeneralizedTime contains invalid integer: " + err.Error()) }
if err != nil {
return time.Time{}, errors.New("GeneralizedTime contains invalid integer: " + err.Error())
}
tz = time.FixedZone("", tzHour*3600+tzMin*60)
bytes = bytes[5:]
@ -187,10 +217,14 @@ func parseGeneralizedTime (bytes []byte) (time.Time, error) {
return time.Time{}, errors.New("GeneralizedTime negative timezone offset is too short")
}
tzHour, err := bytesToInt(bytes[1:3])
if err != nil { return time.Time{}, errors.New("GeneralizedTime contains invalid integer: " + err.Error()) }
if err != nil {
return time.Time{}, errors.New("GeneralizedTime contains invalid integer: " + err.Error())
}
tzMin, err := bytesToInt(bytes[3:5])
if err != nil { return time.Time{}, errors.New("GeneralizedTime contains invalid integer: " + err.Error()) }
if err != nil {
return time.Time{}, errors.New("GeneralizedTime contains invalid integer: " + err.Error())
}
tz = time.FixedZone("", -1*(tzHour*3600+tzMin*60))
bytes = bytes[5:]

View File

@ -94,7 +94,6 @@ var generalizedTimeTests = []timeTest{
{"20150210152542.1-0835", false, time.Time{}},
{"20150210152542.-0835", false, time.Time{}},
{"", false, time.Time{}},
{"123", false, time.Time{}},
{"2015021015+1000Z", false, time.Time{}},

View File

@ -10,9 +10,9 @@
package certspotter
import (
"software.sslmate.com/src/certspotter/ct"
"bytes"
"crypto/sha256"
"software.sslmate.com/src/certspotter/ct"
)
func reverseHashes(hashes []ct.MerkleTreeNode) {

View File

@ -10,19 +10,19 @@
package main
import (
"bufio"
"flag"
"fmt"
"os"
"io"
"bufio"
"strings"
"os"
"path/filepath"
"strings"
"golang.org/x/net/idna"
"software.sslmate.com/src/certspotter"
"software.sslmate.com/src/certspotter/ct"
"software.sslmate.com/src/certspotter/cmd"
"software.sslmate.com/src/certspotter/ct"
)
func defaultStateDir() string {
@ -55,6 +55,7 @@ type watchlistItem struct {
Domain []string
AcceptSuffix bool
}
var watchlist []watchlistItem
func parseWatchlistItem(str string) (watchlistItem, error) {

View File

@ -10,18 +10,18 @@
package cmd
import (
"bytes"
"encoding/json"
"flag"
"fmt"
"log"
"os"
"bytes"
"os/user"
"encoding/json"
"sync"
"strings"
"path/filepath"
"time"
"strconv"
"strings"
"sync"
"time"
"software.sslmate.com/src/certspotter"
"software.sslmate.com/src/certspotter/ct"

View File

@ -14,8 +14,8 @@ import (
"os"
"software.sslmate.com/src/certspotter"
"software.sslmate.com/src/certspotter/ct"
"software.sslmate.com/src/certspotter/cmd"
"software.sslmate.com/src/certspotter/ct"
)
func DefaultStateDir() string {

View File

@ -13,8 +13,8 @@ import (
"net/http"
"time"
"software.sslmate.com/src/certspotter/ct"
"github.com/mreiferson/go-httpclient"
"software.sslmate.com/src/certspotter/ct"
)
// URI paths for CT Log endpoints

View File

@ -10,21 +10,21 @@
package certspotter
import (
"fmt"
"time"
"os"
"os/exec"
"bytes"
"crypto/sha256"
"encoding/hex"
"encoding/json"
"encoding/pem"
"fmt"
"io"
"io/ioutil"
"math/big"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
"crypto/sha256"
"encoding/hex"
"encoding/pem"
"encoding/json"
"time"
"software.sslmate.com/src/certspotter/ct"
)

View File

@ -11,10 +11,10 @@ package certspotter
import (
"bytes"
"strings"
"net"
"unicode/utf8"
"golang.org/x/net/idna"
"net"
"strings"
"unicode/utf8"
)
const UnparsableDNSLabelPlaceholder = "<unparsable>"

View File

@ -10,9 +10,9 @@
package certspotter
import (
"encoding/base64"
"crypto"
"crypto/x509"
"encoding/base64"
)
type LogInfoFile struct {

View File

@ -10,10 +10,10 @@
package certspotter
import (
"fmt"
"errors"
"bytes"
"encoding/asn1"
"errors"
"fmt"
)
func bitStringEqual(a, b *asn1.BitString) bool {
@ -25,6 +25,7 @@ var (
oidExtensionSCT = []int{1, 3, 6, 1, 4, 1, 11129, 2, 4, 2}
oidExtensionCTPoison = []int{1, 3, 6, 1, 4, 1, 11129, 2, 4, 3}
)
func ValidatePrecert(precertBytes []byte, tbsBytes []byte) error {
precert, err := ParseCertificate(precertBytes)
if err != nil {

View File

@ -14,13 +14,13 @@ package certspotter
import (
// "container/list"
"crypto"
"errors"
"fmt"
"log"
"sync"
"sync/atomic"
"time"
"crypto"
"errors"
"software.sslmate.com/src/certspotter/ct"
"software.sslmate.com/src/certspotter/ct/client"
@ -233,7 +233,7 @@ func (s *Scanner) CheckConsistency(first *ct.SignedTreeHead, second *ct.SignedTr
}
func (s *Scanner) Scan(startIndex int64, endIndex int64, processCert ProcessCallback, treeBuilder *MerkleTreeBuilder) error {
s.Log("Starting scan...");
s.Log("Starting scan...")
s.certsProcessed = 0
startTime := time.Now()

37
x509.go
View File

@ -10,13 +10,13 @@
package certspotter
import (
"fmt"
"bytes"
"errors"
"encoding/asn1"
"errors"
"fmt"
"math/big"
"time"
"net"
"time"
)
var (
@ -60,6 +60,7 @@ const (
sanIPAddress = 7
sanRegisteredID = 8
)
type SubjectAltName struct {
Type int
Value []byte
@ -95,7 +96,6 @@ type Certificate struct {
SignatureValue asn1.RawValue
}
func (rdns RDNSequence) ParseCNs() ([]string, error) {
var cns []string
@ -118,15 +118,24 @@ func (rdns RDNSequence) ParseCNs () ([]string, error) {
func rdnLabel(oid asn1.ObjectIdentifier) string {
switch {
case oid.Equal(oidCountry): return "C"
case oid.Equal(oidOrganization): return "O"
case oid.Equal(oidOrganizationalUnit): return "OU"
case oid.Equal(oidCommonName): return "CN"
case oid.Equal(oidSerialNumber): return "serialNumber"
case oid.Equal(oidLocality): return "L"
case oid.Equal(oidProvince): return "ST"
case oid.Equal(oidStreetAddress): return "street"
case oid.Equal(oidPostalCode): return "postalCode"
case oid.Equal(oidCountry):
return "C"
case oid.Equal(oidOrganization):
return "O"
case oid.Equal(oidOrganizationalUnit):
return "OU"
case oid.Equal(oidCommonName):
return "CN"
case oid.Equal(oidSerialNumber):
return "serialNumber"
case oid.Equal(oidLocality):
return "L"
case oid.Equal(oidProvince):
return "ST"
case oid.Equal(oidStreetAddress):
return "street"
case oid.Equal(oidPostalCode):
return "postalCode"
}
return oid.String()
}
@ -319,7 +328,6 @@ func (tbs *TBSCertificate) GetExtension (id asn1.ObjectIdentifier) []Extension {
return exts
}
func ParseCertificate(certBytes []byte) (*Certificate, error) {
var cert Certificate
if rest, err := asn1.Unmarshal(certBytes, &cert); err != nil {
@ -366,4 +374,3 @@ func parseSANExtension (sans []SubjectAltName, value []byte) ([]SubjectAltName,
return sans, nil
}