Run `go fmt` for PR #186

This commit is contained in:
J.C. Jones 2015-05-18 18:44:38 -07:00
parent 39a61774e7
commit 42302541bd
18 changed files with 152 additions and 162 deletions

View File

@ -7,16 +7,16 @@ package ca
import (
"bytes"
"crypto/x509"
"crypto"
"crypto/x509"
"encoding/asn1"
"encoding/hex"
"fmt"
"io/ioutil"
"net/http"
"os"
"testing"
"time"
"os"
apisign "github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/cloudflare/cfssl/api/sign"
"github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/cloudflare/cfssl/auth"
@ -260,7 +260,6 @@ func TestMain(m *testing.M) {
caCertPEM, _ := ioutil.ReadFile(caCertFile)
caCert, _ := helpers.ParseCertificatePEM(caCertPEM)
// Create an online CFSSL instance
// This is designed to mimic what LE plans to do
authHandler, _ := auth.New(authKey, nil)
@ -330,19 +329,18 @@ func setup(t *testing.T) (cadb core.CertificateAuthorityDatabase, storageAuthori
ssa.InitTables()
storageAuthority = ssa
cadb, _ = NewMockCertificateAuthorityDatabase()
// Create a CA
// Uncomment to test with a remote signer
caConfig = Config{
Server: hostPort,
AuthKey: authKey,
Profile: profileName,
Server: hostPort,
AuthKey: authKey,
Profile: profileName,
SerialPrefix: 17,
IssuerCert: "../test/test-ca.pem",
IssuerKey: "../test/test-ca.key",
TestMode: true,
IssuerCert: "../test/test-ca.pem",
IssuerKey: "../test/test-ca.key",
TestMode: true,
}
return cadb, storageAuthority, caConfig
}

View File

@ -37,9 +37,9 @@ import (
_ "github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/cloudflare/cfssl/cmd/cfssl"
"github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/codegangsta/cli"
"github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/streadway/amqp"
"github.com/letsencrypt/boulder/ca"
blog "github.com/letsencrypt/boulder/log"
"github.com/letsencrypt/boulder/rpc"
"github.com/letsencrypt/boulder/ca"
)
// Config stores configuration parameters that applications

View File

@ -6,12 +6,12 @@
package core
import (
"strings"
"crypto/x509"
"encoding/base64"
"encoding/hex"
"encoding/json"
jose "github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/square/go-jose"
"strings"
"time"
)
@ -69,8 +69,8 @@ type CertificateRequest struct {
}
type rawCertificateRequest struct {
CSR JsonBuffer `json:"csr"` // The encoded CSR
Authorizations []AcmeURL `json:"authorizations"` // Authorizations
CSR JsonBuffer `json:"csr"` // The encoded CSR
Authorizations []AcmeURL `json:"authorizations"` // Authorizations
}
func (cr *CertificateRequest) UnmarshalJSON(data []byte) error {
@ -288,19 +288,19 @@ type Authorization struct {
// Fields of this type get encoded and decoded JOSE-style, in base64url encoding
// with stripped padding.
type JsonBuffer []byte;
type JsonBuffer []byte
// Url-safe base64 encode that strips padding
func base64URLEncode(data []byte) string {
var result = base64.URLEncoding.EncodeToString(data)
return strings.TrimRight(result, "=")
var result = base64.URLEncoding.EncodeToString(data)
return strings.TrimRight(result, "=")
}
// Url-safe base64 decoder that adds padding
func base64URLDecode(data string) ([]byte, error) {
var missing = (4 - len(data)%4) % 4
data += strings.Repeat("=", missing)
return base64.URLEncoding.DecodeString(data)
var missing = (4 - len(data)%4) % 4
data += strings.Repeat("=", missing)
return base64.URLEncoding.DecodeString(data)
}
func (jb JsonBuffer) MarshalJSON() (result []byte, err error) {
@ -330,10 +330,10 @@ type Certificate struct {
// * "revoked" - revoked
Status AcmeStatus `db:"status"`
Serial string `db:"serial"`
Digest string `db:"digest"`
DER []byte `db:"der"`
Issued time.Time `db:"issued"`
Serial string `db:"serial"`
Digest string `db:"digest"`
DER []byte `db:"der"`
Issued time.Time `db:"issued"`
}
// CertificateStatus structs are internal to the server. They represent the
@ -346,58 +346,58 @@ type CertificateStatus struct {
// that they accept the certificate, otherwise 0.
SubscriberApproved bool `db:"subscriberApproved"`
// status: 'good' or 'revoked'. Note that good, expired certificates remain
// status: 'good' or 'revoked'. Note that good, expired certificates remain
// with status 'good' but don't necessarily get fresh OCSP responses.
Status OCSPStatus `db:"status"`
// ocspLastUpdated: The date and time of the last time we generated an OCSP
// response. If we have never generated one, this has the zero value of
// ocspLastUpdated: The date and time of the last time we generated an OCSP
// response. If we have never generated one, this has the zero value of
// time.Time, i.e. Jan 1 1970.
OCSPLastUpdated time.Time `db:"ocspLastUpdated"`
// revokedDate: If status is 'revoked', this is the date and time it was
// revokedDate: If status is 'revoked', this is the date and time it was
// revoked. Otherwise it has the zero value of time.Time, i.e. Jan 1 1970.
RevokedDate time.Time `db:"revokedDate"`
RevokedDate time.Time `db:"revokedDate"`
// revokedReason: If status is 'revoked', this is the reason code for the
// revocation. Otherwise it is zero (which happens to be the reason
// revokedReason: If status is 'revoked', this is the reason code for the
// revocation. Otherwise it is zero (which happens to be the reason
// code for 'unspecified').
RevokedReason int `db:"revokedReason"`
RevokedReason int `db:"revokedReason"`
LockCol int64 `json:"-"`
}
// A large table of OCSP responses. This contains all historical OCSP
// responses we've signed, is append-only, and is likely to get quite
// A large table of OCSP responses. This contains all historical OCSP
// responses we've signed, is append-only, and is likely to get quite
// large. We'll probably want administratively truncate it at some point.
type OcspResponse struct {
ID int `db:"id"`
ID int `db:"id"`
// serial: Same as certificate serial.
Serial string `db:"serial"`
Serial string `db:"serial"`
// createdAt: The date the response was signed.
CreatedAt time.Time `db:"createdAt"`
// response: The encoded and signed CRL.
Response []byte `db:"response"`
Response []byte `db:"response"`
}
// A large table of signed CRLs. This contains all historical CRLs
// A large table of signed CRLs. This contains all historical CRLs
// we've signed, is append-only, and is likely to get quite large.
type Crl struct {
// serial: Same as certificate serial.
Serial string `db:"serial"`
Serial string `db:"serial"`
// createdAt: The date the CRL was signed.
CreatedAt time.Time `db:"createdAt"`
// crl: The encoded and signed CRL.
Crl string `db:"crl"`
Crl string `db:"crl"`
}
type DeniedCsr struct {
ID int `db:"id"`
Names string `db:"names"`
}
}

View File

@ -58,4 +58,4 @@ func TestSanityCheck(t *testing.T) {
test.Assert(t, !chall.IsSane(true), "IsSane should be false")
chall.S = "KQqLsiS5j0CONR_eUXTUSUDNVaHODtc-0pD6ACif7U4"
test.Assert(t, chall.IsSane(true), "IsSane should be true")
}
}

View File

@ -19,8 +19,8 @@ import (
"encoding/json"
"errors"
"fmt"
blog "github.com/letsencrypt/boulder/log"
jose "github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/square/go-jose"
blog "github.com/letsencrypt/boulder/log"
"hash"
"io"
"math/big"
@ -98,19 +98,19 @@ func Fingerprint256(data []byte) string {
func KeyDigest(key crypto.PublicKey) (string, error) {
switch t := key.(type) {
case *jose.JsonWebKey:
return KeyDigest(t.Key)
case jose.JsonWebKey:
return KeyDigest(t.Key)
default:
keyDER, err := x509.MarshalPKIXPublicKey(key)
if err != nil {
logger := blog.GetAuditLogger()
logger.Debug(fmt.Sprintf("Problem marshaling public key: %s", err))
return "", err
}
spkiDigest := sha256.Sum256(keyDER)
return base64.StdEncoding.EncodeToString(spkiDigest[0:32]), nil
case *jose.JsonWebKey:
return KeyDigest(t.Key)
case jose.JsonWebKey:
return KeyDigest(t.Key)
default:
keyDER, err := x509.MarshalPKIXPublicKey(key)
if err != nil {
logger := blog.GetAuditLogger()
logger.Debug(fmt.Sprintf("Problem marshaling public key: %s", err))
return "", err
}
spkiDigest := sha256.Sum256(keyDER)
return base64.StdEncoding.EncodeToString(spkiDigest[0:32]), nil
}
}
@ -224,7 +224,7 @@ func SerialToString(serial *big.Int) string {
return fmt.Sprintf("%032x", serial)
}
func StringToSerial(serial string) (*big.Int, error) {
func StringToSerial(serial string) (*big.Int, error) {
var serialNum big.Int
if len(serial) != 32 {
return &serialNum, errors.New("Serial number should be 32 characters long")

View File

@ -6,11 +6,11 @@
package core
import (
"testing"
"fmt"
"github.com/letsencrypt/boulder/test"
"math"
"math/big"
"testing"
)
// challenges.go
@ -18,22 +18,22 @@ func TestNewToken(t *testing.T) {
token := NewToken()
fmt.Println(token)
tokenLength := int(math.Ceil(32 * 8 / 6.0)) // 32 bytes, b64 encoded
test.AssertIntEquals(t,len(token),tokenLength)
test.AssertIntEquals(t, len(token), tokenLength)
collider := map[string]bool{}
// Test for very blatant RNG failures:
// Try 2^20 birthdays in a 2^72 search space...
// our naive collision probability here is 2^-32...
for i:=0; i < 1000000; i++ {
for i := 0; i < 1000000; i++ {
token = NewToken()[:12] // just sample a portion
test.Assert(t,!collider[token],"Token collision!")
test.Assert(t, !collider[token], "Token collision!")
collider[token] = true
}
return
}
func TestRandString(t *testing.T) {
// This is covered by NewToken
return
// This is covered by NewToken
return
}
func TestSerialUtils(t *testing.T) {

View File

@ -31,7 +31,7 @@ const auditTag = "[AUDIT]"
const emergencyReturnValue = 13
// exitFunction closes the running system
type exitFunction func ()
type exitFunction func()
// Default to calling os.Exit()
func defaultEmergencyExit() {
@ -45,7 +45,7 @@ func defaultEmergencyExit() {
// to send a message as an audit event.
type AuditLogger struct {
*syslog.Writer
Stats statsd.Statter
Stats statsd.Statter
exitFunction exitFunction
}

View File

@ -152,7 +152,7 @@ func TestEmergencyExit(t *testing.T) {
called := false
audit.SetEmergencyExitFunc(func(){ called = true })
audit.SetEmergencyExitFunc(func() { called = true })
audit.EmergencyExit("Emergency!")
test.AssertEquals(t, called, true)
}

View File

@ -20,9 +20,9 @@ func NewMailer(server, port, username, password string) Mailer {
auth := smtp.PlainAuth("", username, password, server)
return Mailer{
Server: server,
Port: port,
Auth: auth,
From: username,
Port: port,
Auth: auth,
From: username,
}
}

View File

@ -15,8 +15,8 @@ import (
"strconv"
"time"
"github.com/letsencrypt/boulder/core"
jose "github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/square/go-jose"
"github.com/letsencrypt/boulder/core"
blog "github.com/letsencrypt/boulder/log"
"github.com/letsencrypt/boulder/policy"
)
@ -131,10 +131,10 @@ func (ra *RegistrationAuthorityImpl) NewCertificate(req core.CertificateRequest,
// Construct the log event
logEvent := certificateRequestEvent{
ID: core.NewToken(),
Requester: regID,
RequestMethod: "online",
RequestTime: time.Now(),
ID: core.NewToken(),
Requester: regID,
RequestMethod: "online",
RequestTime: time.Now(),
}
// No matter what, log the request
@ -216,7 +216,6 @@ func (ra *RegistrationAuthorityImpl) NewCertificate(req core.CertificateRequest,
}
logEvent.VerificationMethods = verificationMethods
// Validate that authorization key is authorized for all domains
names := csr.DNSNames
if len(csr.Subject.CommonName) > 0 {
@ -283,7 +282,7 @@ func (ra *RegistrationAuthorityImpl) UpdateAuthorization(base core.Authorization
func (ra *RegistrationAuthorityImpl) RevokeCertificate(cert x509.Certificate) error {
serialString := core.SerialToString(cert.SerialNumber)
err := ra.CA.RevokeCertificate(serialString);
err := ra.CA.RevokeCertificate(serialString)
// AUDIT[ Revocation Requests ] 4e85d791-09c0-4ab3-a837-d3d67e945134
if err != nil {

View File

@ -18,9 +18,9 @@ import (
"github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/cloudflare/cfssl/signer/local"
_ "github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/mattn/go-sqlite3"
jose "github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/square/go-jose"
"github.com/letsencrypt/boulder/ca"
"github.com/letsencrypt/boulder/core"
jose "github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/square/go-jose"
"github.com/letsencrypt/boulder/policy"
"github.com/letsencrypt/boulder/sa"
"github.com/letsencrypt/boulder/test"
@ -239,13 +239,13 @@ func TestCertificateKeyNotEqualAccountKey(t *testing.T) {
authz := core.Authorization{}
authz.ID, _ = sa.NewPendingAuthorization()
authz.Identifier = core.AcmeIdentifier{
Type: core.IdentifierDNS,
Type: core.IdentifierDNS,
Value: "www.example.com",
}
csr := x509.CertificateRequest{
SignatureAlgorithm: x509.SHA256WithRSA,
PublicKey: AccountKey.Key,
DNSNames: []string{"www.example.com"},
PublicKey: AccountKey.Key,
DNSNames: []string{"www.example.com"},
}
csrBytes, err := x509.CreateCertificateRequest(rand.Reader, &csr, AccountPrivateKey.Key)
test.AssertNotError(t, err, "Failed to sign CSR")

View File

@ -11,9 +11,9 @@ import (
"errors"
"fmt"
jose "github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/square/go-jose"
"github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/streadway/amqp"
"github.com/letsencrypt/boulder/core"
jose "github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/square/go-jose"
blog "github.com/letsencrypt/boulder/log"
)
@ -75,7 +75,7 @@ type authorizationRequest struct {
}
type certificateRequest struct {
Req core.CertificateRequest
Req core.CertificateRequest
RegID int64
}
@ -88,7 +88,6 @@ func errorCondition(method string, err error, obj interface{}) {
log.Audit(fmt.Sprintf("Error condition. method: %s err: %s data: %+v", method, err, obj))
}
func NewRegistrationAuthorityServer(serverQueue string, channel *amqp.Channel, impl core.RegistrationAuthority) (*AmqpRPCServer, error) {
log := blog.GetAuditLogger()
rpc := NewAmqpRPCServer(serverQueue, channel)
@ -381,7 +380,7 @@ func NewValidationAuthorityServer(serverQueue string, channel *amqp.Channel, imp
if err := impl.UpdateValidations(authz); err != nil {
// AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3
errorCondition(MethodUpdateValidations, err, authz)
errorCondition(MethodUpdateValidations, err, authz)
}
return nil
})
@ -626,10 +625,10 @@ func NewStorageAuthorityServer(serverQueue string, channel *amqp.Channel, impl c
return nil
}
if err := impl.UpdatePendingAuthorization(authz); err != nil {
if err := impl.UpdatePendingAuthorization(authz); err != nil {
// AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3
errorCondition(MethodUpdatePendingAuthorization, err, authz)
}
}
return nil
})

View File

@ -18,8 +18,8 @@ import (
gorp "github.com/letsencrypt/boulder/Godeps/_workspace/src/gopkg.in/gorp.v1"
"github.com/letsencrypt/boulder/core"
jose "github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/square/go-jose"
"github.com/letsencrypt/boulder/core"
blog "github.com/letsencrypt/boulder/log"
)
@ -51,7 +51,7 @@ type pendingauthzModel struct {
type authzModel struct {
core.Authorization
Sequence int64 `db:"sequence"`
Sequence int64 `db:"sequence"`
}
// Type converter
@ -293,21 +293,21 @@ func statusIsPending(status core.AcmeStatus) bool {
return status == core.StatusPending || status == core.StatusProcessing || status == core.StatusUnknown
}
func existingPending(tx *gorp.Transaction, id string) (bool) {
func existingPending(tx *gorp.Transaction, id string) bool {
var count int64
_ = tx.SelectOne(&count, "SELECT count(*) FROM pending_authz WHERE id = :id", map[string]interface{} {"id": id})
_ = tx.SelectOne(&count, "SELECT count(*) FROM pending_authz WHERE id = :id", map[string]interface{}{"id": id})
return count > 0
}
func existingFinal(tx *gorp.Transaction, id string) (bool) {
func existingFinal(tx *gorp.Transaction, id string) bool {
var count int64
_ = tx.SelectOne(&count, "SELECT count(*) FROM authz WHERE id = :id", map[string]interface{} {"id": id})
_ = tx.SelectOne(&count, "SELECT count(*) FROM authz WHERE id = :id", map[string]interface{}{"id": id})
return count > 0
}
func existingRegistration(tx *gorp.Transaction, id int64) (bool) {
func existingRegistration(tx *gorp.Transaction, id int64) bool {
var count int64
_ = tx.SelectOne(&count, "SELECT count(*) FROM registrations WHERE id = :id", map[string]interface{} {"id": id})
_ = tx.SelectOne(&count, "SELECT count(*) FROM registrations WHERE id = :id", map[string]interface{}{"id": id})
return count > 0
}
@ -330,7 +330,7 @@ func (ssa *SQLStorageAuthority) GetRegistrationByKey(key jose.JsonWebKey) (reg c
return
}
err = ssa.dbMap.SelectOne(&reg, "SELECT * FROM registrations WHERE key = :key", map[string]interface{} {"key": string(keyJson)})
err = ssa.dbMap.SelectOne(&reg, "SELECT * FROM registrations WHERE key = :key", map[string]interface{}{"key": string(keyJson)})
return
}
@ -383,7 +383,7 @@ func (ssa *SQLStorageAuthority) GetCertificateByShortSerial(shortSerial string)
var certificate core.Certificate
err = ssa.dbMap.SelectOne(&certificate, "SELECT * FROM certificates WHERE serial LIKE :shortSerial",
map[string]interface{} {"shortSerial": shortSerial+"%"})
map[string]interface{}{"shortSerial": shortSerial + "%"})
if err != nil {
return
}
@ -400,7 +400,7 @@ func (ssa *SQLStorageAuthority) GetCertificate(serial string) (cert []byte, err
var certificate core.Certificate
err = ssa.dbMap.SelectOne(&certificate, "SELECT * FROM certificates WHERE serial = :serial",
map[string]interface{} {"serial": serial})
map[string]interface{}{"serial": serial})
if err != nil {
return
}
@ -644,21 +644,21 @@ func (ssa *SQLStorageAuthority) AddCertificate(certDER []byte, regID int64) (dig
cert := &core.Certificate{
RegistrationID: regID,
Serial: serial,
Digest: digest,
DER: certDER,
Issued: time.Now(),
Serial: serial,
Digest: digest,
DER: certDER,
Issued: time.Now(),
}
certStatus := &core.CertificateStatus{
SubscriberApproved: false,
Status: core.OCSPStatus("good"),
OCSPLastUpdated: time.Time{},
Serial: serial,
RevokedDate: time.Time{},
RevokedReason: 0,
LockCol: 0,
Status: core.OCSPStatus("good"),
OCSPLastUpdated: time.Time{},
Serial: serial,
RevokedDate: time.Time{},
RevokedReason: 0,
LockCol: 0,
}
tx, err := ssa.dbMap.Begin()
if err != nil {
return
@ -706,7 +706,7 @@ func (ssa *SQLStorageAuthority) AlreadyDeniedCSR(names []string) (already bool,
err = ssa.dbMap.SelectOne(
&denied,
"SELECT count(*) FROM deniedCsrs WHERE names = :names",
map[string]interface{} {"names": strings.ToLower(strings.Join(names, ","))},
map[string]interface{}{"names": strings.ToLower(strings.Join(names, ","))},
)
if err != nil {
return
@ -714,7 +714,6 @@ func (ssa *SQLStorageAuthority) AlreadyDeniedCSR(names []string) (already bool,
if denied > 0 {
already = true
}
return
}
return
}

View File

@ -6,24 +6,24 @@
package sa
import (
"crypto/x509"
"crypto/x509/pkix"
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"crypto/x509/pkix"
"encoding/json"
"fmt"
"net/url"
"time"
_ "github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/mattn/go-sqlite3"
"github.com/letsencrypt/boulder/core"
jose "github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/square/go-jose"
"github.com/letsencrypt/boulder/core"
"github.com/letsencrypt/boulder/test"
"io/ioutil"
"testing"
)
func initSA(t *testing.T) (*SQLStorageAuthority) {
func initSA(t *testing.T) *SQLStorageAuthority {
sa, err := NewSQLStorageAuthority("sqlite3", ":memory:")
if err != nil {
t.Fatalf("Failed to create SA")
@ -60,7 +60,7 @@ func TestAddRegistration(t *testing.T) {
test.AssertNotError(t, err, fmt.Sprintf("Couldn't get registration with ID %v", reg.ID))
expectedReg := core.Registration{
ID: reg.ID,
ID: reg.ID,
Key: jwk,
}
test.AssertEquals(t, dbReg.ID, expectedReg.ID)
@ -107,8 +107,7 @@ func TestAddAuthorization(t *testing.T) {
chall := core.Challenge{Type: "simpleHttps", Status: core.StatusPending, URI: u, Token: "THISWOULDNTBEAGOODTOKEN", Path: "test-me"}
combos := make([][]int, 1)
combos[0] = []int{0,1}
combos[0] = []int{0, 1}
newPa := core.Authorization{ID: paID, Identifier: core.AcmeIdentifier{Type: core.IdentifierDNS, Value: "wut.com"}, RegistrationID: 0, Status: core.StatusPending, Expires: time.Now().AddDate(0, 0, 1), Challenges: []core.Challenge{chall}, Combinations: combos, Contact: []core.AcmeURL{u}}
err = sa.UpdatePendingAuthorization(newPa)
@ -187,7 +186,7 @@ func TestGetCertificateByShortSerial(t *testing.T) {
func TestDeniedCSR(t *testing.T) {
key, _ := rsa.GenerateKey(rand.Reader, 512)
template := &x509.CertificateRequest{
Subject: pkix.Name{CommonName: "google.com"},
Subject: pkix.Name{CommonName: "google.com"},
DNSNames: []string{"badguys.com", "reallybad.com"},
}
csrBytes, _ := x509.CreateCertificateRequest(rand.Reader, template, key)

View File

@ -32,7 +32,7 @@ func NewValidationAuthorityImpl(tm bool) ValidationAuthorityImpl {
// Validation methods
func (va ValidationAuthorityImpl) validateSimpleHTTPS(identifier core.AcmeIdentifier, input core.Challenge) (core.Challenge) {
func (va ValidationAuthorityImpl) validateSimpleHTTPS(identifier core.AcmeIdentifier, input core.Challenge) core.Challenge {
challenge := input
if len(challenge.Path) == 0 {
@ -105,7 +105,7 @@ func (va ValidationAuthorityImpl) validateSimpleHTTPS(identifier core.AcmeIdenti
return challenge
}
func (va ValidationAuthorityImpl) validateDvsni(identifier core.AcmeIdentifier, input core.Challenge) (core.Challenge) {
func (va ValidationAuthorityImpl) validateDvsni(identifier core.AcmeIdentifier, input core.Challenge) core.Challenge {
challenge := input
if identifier.Type != "dns" {

View File

@ -6,24 +6,24 @@
package va
import (
"testing"
"net"
"net/http"
"fmt"
"strings"
"math/big"
"crypto/rand"
"crypto/rsa"
"crypto/sha256"
"crypto/tls"
"crypto/x509"
"crypto/x509/pkix"
"crypto/sha256"
"encoding/base64"
"fmt"
"math/big"
"net"
"net/http"
"strings"
"testing"
"time"
jose "github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/square/go-jose"
"github.com/letsencrypt/boulder/core"
"github.com/letsencrypt/boulder/test"
jose "github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/square/go-jose"
)
func bigIntFromB64(b64 string) *big.Int {
@ -87,10 +87,10 @@ func dvsniSrv(t *testing.T, R, S []byte, waitChan chan bool) {
Organization: []string{"tests"},
},
NotBefore: time.Now(),
NotAfter: time.Now().AddDate(0, 0, 1),
NotAfter: time.Now().AddDate(0, 0, 1),
KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
BasicConstraintsValid: true,
DNSNames: []string{zName},
@ -99,12 +99,12 @@ func dvsniSrv(t *testing.T, R, S []byte, waitChan chan bool) {
certBytes, _ := x509.CreateCertificate(rand.Reader, template, template, &TheKey.PublicKey, &TheKey)
cert := &tls.Certificate{
Certificate: [][]byte{certBytes},
PrivateKey: &TheKey,
PrivateKey: &TheKey,
}
tlsConfig := &tls.Config{
Certificates: []tls.Certificate{*cert},
ClientAuth: tls.NoClientCert,
ClientAuth: tls.NoClientCert,
GetCertificate: func(clientHello *tls.ClientHelloInfo) (*tls.Certificate, error) {
fmt.Println(clientHello)
return cert, nil
@ -160,7 +160,7 @@ func TestSimpleHttps(t *testing.T) {
func TestDvsni(t *testing.T) {
va := NewValidationAuthorityImpl(true)
a := []byte{1,2,3,4,5,6,7,8,9,0}
a := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}
ba := core.B64enc(a)
chall := core.Challenge{R: ba, S: ba}

View File

@ -6,9 +6,9 @@
package wfe
import (
"database/sql"
"bytes"
"crypto/x509"
"database/sql"
"encoding/json"
"errors"
"fmt"
@ -67,7 +67,7 @@ func NewWebFrontEndImpl() WebFrontEndImpl {
AuthzPath: "/acme/authz/",
NewCertPath: "/acme/new-cert",
CertPath: "/acme/cert/",
RevokeCertPath: "/acme/revoke-cert/",
RevokeCertPath: "/acme/revoke-cert/",
TermsPath: "/terms",
IssuerPath: "/acme/issuer-cert",
}
@ -130,8 +130,8 @@ func parseIDFromPath(path string) string {
type ProblemType string
type problem struct {
Type ProblemType `json:"type,omitempty"`
Detail string `json:"detail,omitempty"`
Type ProblemType `json:"type,omitempty"`
Detail string `json:"detail,omitempty"`
}
const (
@ -219,7 +219,7 @@ func (wfe *WebFrontEndImpl) sendError(response http.ResponseWriter, details stri
problemDoc = []byte("{\"detail\": \"Problem marshalling error message.\"}")
}
switch(problem.Type) {
switch problem.Type {
case ServerInternalProblem:
// AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3
wfe.log.Audit(fmt.Sprintf("Internal error - %s - %s", details, debug))
@ -305,7 +305,6 @@ func (wfe *WebFrontEndImpl) NewAuthorization(response http.ResponseWriter, reque
return
}
var init core.Authorization
if err = json.Unmarshal(body, &init); err != nil {
wfe.sendError(response, "Error unmarshaling JSON", err, http.StatusBadRequest)
@ -433,7 +432,6 @@ func (wfe *WebFrontEndImpl) NewCertificate(response http.ResponseWriter, request
return
}
var init core.CertificateRequest
if err = json.Unmarshal(body, &init); err != nil {
fmt.Println(err)
@ -512,7 +510,6 @@ func (wfe *WebFrontEndImpl) Challenge(authz core.Authorization, response http.Re
return
}
var challengeResponse core.Challenge
if err = json.Unmarshal(body, &challengeResponse); err != nil {
wfe.sendError(response, "Error unmarshaling authorization", err, http.StatusBadRequest)

View File

@ -20,8 +20,8 @@ import (
"github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/cactus/go-statsd-client/statsd"
"github.com/letsencrypt/boulder/core"
jose "github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/square/go-jose"
"github.com/letsencrypt/boulder/core"
"github.com/letsencrypt/boulder/ra"
"github.com/letsencrypt/boulder/test"
@ -78,11 +78,11 @@ eROL1ve1vmQF3kjrMPhhK2kr6qdWnTE5XlPllVSZFQenSTzj98AO
)
func (sa *MockSA) GetRegistration(id int64) (core.Registration, error) {
if (id == 100) {
if id == 100 {
// Tag meaning "Missing"
return core.Registration{}, errors.New("missing")
}
if (id == 101) {
if id == 101 {
// Tag meaning "Malformed"
return core.Registration{}, nil
}
@ -100,11 +100,11 @@ func (sa *MockSA) GetRegistrationByKey(jwk jose.JsonWebKey) (core.Registration,
test1KeyPublic.UnmarshalJSON([]byte(test1KeyPublicJSON))
test2KeyPublic.UnmarshalJSON([]byte(test2KeyPublicJSON))
if (core.KeyDigestEquals(jwk, test1KeyPublic)) {
if core.KeyDigestEquals(jwk, test1KeyPublic) {
return core.Registration{Key: jwk}, nil
}
if (core.KeyDigestEquals(jwk, test2KeyPublic)) {
if core.KeyDigestEquals(jwk, test2KeyPublic) {
// No key found
return core.Registration{}, sql.ErrNoRows
}
@ -484,7 +484,7 @@ func TestNewRegistration(t *testing.T) {
responseWriter.Body.Reset()
wfe.NewRegistration(responseWriter, &http.Request{
Method: "POST",
Body: makeBody(signRequest(t, "{\"contact\":[\"tel:123456789\"]}")),
Body: makeBody(signRequest(t, "{\"contact\":[\"tel:123456789\"]}")),
})
test.AssertEquals(t, responseWriter.Body.String(), "{\"key\":{\"kty\":\"RSA\",\"n\":\"z2NsNdHeqAiGdPP8KuxfQXat_uatOK9y12SyGpfKw1sfkizBIsNxERjNDke6Wp9MugN9srN3sr2TDkmQ-gK8lfWo0v1uG_QgzJb1vBdf_hH7aejgETRGLNJZOdaKDsyFnWq1WGJq36zsHcd0qhggTk6zVwqczSxdiWIAZzEakIUZ13KxXvoepYLY0Q-rEEQiuX71e4hvhfeJ4l7m_B-awn22UUVvo3kCqmaRlZT-36vmQhDGoBsoUo1KBEU44jfeK5PbNRk7vDJuH0B7qinr_jczHcvyD-2TtPzKaCioMtNh_VZbPNDaG67sYkQlC15-Ff3HPzKKJW2XvkVG91qMvQ\",\"e\":\"AAEAAQ\"},\"recoveryToken\":\"\",\"contact\":[\"tel:123456789\"],\"thumbprint\":\"\"}")
@ -570,11 +570,10 @@ func TestAuthorization(t *testing.T) {
responseWriter.Body.String(),
"{\"type\":\"urn:acme:error:malformed\",\"detail\":\"Unable to read/verify body\"}")
responseWriter.Body.Reset()
wfe.NewAuthorization(responseWriter, &http.Request{
Method: "POST",
Body: makeBody(signRequest(t, "{\"identifier\":{\"type\":\"dns\",\"value\":\"test.com\"}}")),
Body: makeBody(signRequest(t, "{\"identifier\":{\"type\":\"dns\",\"value\":\"test.com\"}}")),
})
test.AssertEquals(t, responseWriter.Body.String(), "{\"identifier\":{\"type\":\"dns\",\"value\":\"test.com\"},\"expires\":\"0001-01-01T00:00:00Z\"}")
@ -595,8 +594,8 @@ func TestRegistration(t *testing.T) {
path, _ := url.Parse("/1")
wfe.Registration(responseWriter, &http.Request{
Method: "MAKE-COFFEE",
Body: makeBody("invalid"),
URL: path,
Body: makeBody("invalid"),
URL: path,
})
test.AssertEquals(t,
responseWriter.Body.String(),
@ -607,7 +606,7 @@ func TestRegistration(t *testing.T) {
path, _ = url.Parse("/100")
wfe.Registration(responseWriter, &http.Request{
Method: "GET",
URL: path,
URL: path,
})
test.AssertEquals(t,
responseWriter.Body.String(),
@ -618,7 +617,7 @@ func TestRegistration(t *testing.T) {
path, _ = url.Parse("/101")
wfe.Registration(responseWriter, &http.Request{
Method: "GET",
URL: path,
URL: path,
})
test.AssertEquals(t,
responseWriter.Body.String(),
@ -629,17 +628,17 @@ func TestRegistration(t *testing.T) {
path, _ = url.Parse("/1")
wfe.Registration(responseWriter, &http.Request{
Method: "GET",
URL: path,
URL: path,
})
test.AssertNotContains(t, responseWriter.Body.String(), "urn:acme:error")
test.AssertNotContains(t, responseWriter.Body.String(), "urn:acme:error")
responseWriter.Body.Reset()
// Test POST invalid JSON
path, _ = url.Parse("/2")
wfe.Registration(responseWriter, &http.Request{
Method: "POST",
Body: makeBody("invalid"),
URL: path,
Body: makeBody("invalid"),
URL: path,
})
test.AssertEquals(t,
responseWriter.Body.String(),
@ -673,6 +672,6 @@ func TestRegistration(t *testing.T) {
}`),
URL: path,
})
test.AssertNotContains(t, responseWriter.Body.String(), "urn:acme:error")
test.AssertNotContains(t, responseWriter.Body.String(), "urn:acme:error")
responseWriter.Body.Reset()
}
}