Skip to content

Commit

Permalink
Merge branch 'main' of github.com:letsencrypt/boulder into updatereg-2
Browse files Browse the repository at this point in the history
  • Loading branch information
jprenken committed Nov 21, 2024
2 parents 8d8b465 + 01c1488 commit 06503fb
Show file tree
Hide file tree
Showing 39 changed files with 1,363 additions and 1,933 deletions.
16 changes: 0 additions & 16 deletions canceled/canceled.go

This file was deleted.

22 changes: 0 additions & 22 deletions canceled/canceled_test.go

This file was deleted.

33 changes: 13 additions & 20 deletions cmd/contact-auditor/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package notmain
import (
"context"
"fmt"
"net"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -133,37 +132,31 @@ func (tc testCtx) addRegistrations(t *testing.T) {
"e":"AQAB"
}`)

initialIP, err := net.ParseIP("127.0.0.1").MarshalText()
test.AssertNotError(t, err, "Couldn't create initialIP")

regA = &corepb.Registration{
Id: 1,
Contact: []string{emailA},
Key: jsonKeyA,
InitialIP: initialIP,
Id: 1,
Contact: []string{emailA},
Key: jsonKeyA,
}
regB = &corepb.Registration{
Id: 2,
Contact: []string{emailB},
Key: jsonKeyB,
InitialIP: initialIP,
Id: 2,
Contact: []string{emailB},
Key: jsonKeyB,
}
regC = &corepb.Registration{
Id: 3,
Contact: []string{emailC},
Key: jsonKeyC,
InitialIP: initialIP,
Id: 3,
Contact: []string{emailC},
Key: jsonKeyC,
}
// Reg D has a `tel:` contact ACME URL
regD = &corepb.Registration{
Id: 4,
Contact: []string{tel},
Key: jsonKeyD,
InitialIP: initialIP,
Id: 4,
Contact: []string{tel},
Key: jsonKeyD,
}

// Add the four test registrations
ctx := context.Background()
var err error
regA, err = tc.ssa.NewRegistration(ctx, regA)
test.AssertNotError(t, err, "Couldn't store regA")
regB, err = tc.ssa.NewRegistration(ctx, regB)
Expand Down
17 changes: 3 additions & 14 deletions cmd/expiration-mailer/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"errors"
"fmt"
"math/big"
"net"
"strings"
"testing"
"text/template"
Expand Down Expand Up @@ -462,20 +461,10 @@ func TestFindExpiringCertificates(t *testing.T) {
}

func makeRegistration(sac sapb.StorageAuthorityClient, id int64, jsonKey []byte, contacts []string) (*corepb.Registration, error) {
var ip [4]byte
_, err := rand.Reader.Read(ip[:])
if err != nil {
return nil, err
}
ipText, err := net.IP(ip[:]).MarshalText()
if err != nil {
return nil, fmt.Errorf("formatting IP address: %s", err)
}
reg, err := sac.NewRegistration(context.Background(), &corepb.Registration{
Id: id,
Contact: contacts,
Key: jsonKey,
InitialIP: ipText,
Id: id,
Contact: contacts,
Key: jsonKey,
})
if err != nil {
return nil, fmt.Errorf("storing registration: %s", err)
Expand Down
33 changes: 13 additions & 20 deletions cmd/id-exporter/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"encoding/base64"
"fmt"
"math/big"
"net"
"os"
"testing"
"time"
Expand Down Expand Up @@ -276,38 +275,32 @@ func (tc testCtx) addRegistrations(t *testing.T) {
"e":"AQAB"
}`)

initialIP, err := net.ParseIP("127.0.0.1").MarshalText()
test.AssertNotError(t, err, "Couldn't create initialIP")

// Regs A through C have `mailto:` contact ACME URL's
regA = &corepb.Registration{
Id: 1,
Contact: []string{emailA},
Key: jsonKeyA,
InitialIP: initialIP,
Id: 1,
Contact: []string{emailA},
Key: jsonKeyA,
}
regB = &corepb.Registration{
Id: 2,
Contact: []string{emailB},
Key: jsonKeyB,
InitialIP: initialIP,
Id: 2,
Contact: []string{emailB},
Key: jsonKeyB,
}
regC = &corepb.Registration{
Id: 3,
Contact: []string{emailC},
Key: jsonKeyC,
InitialIP: initialIP,
Id: 3,
Contact: []string{emailC},
Key: jsonKeyC,
}
// Reg D has a `tel:` contact ACME URL
regD = &corepb.Registration{
Id: 4,
Contact: []string{tel},
Key: jsonKeyD,
InitialIP: initialIP,
Id: 4,
Contact: []string{tel},
Key: jsonKeyD,
}

// Add the four test registrations
ctx := context.Background()
var err error
regA, err = tc.ssa.NewRegistration(ctx, regA)
test.AssertNotError(t, err, "Couldn't store regA")
regB, err = tc.ssa.NewRegistration(ctx, regB)
Expand Down
21 changes: 0 additions & 21 deletions core/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ type Registration struct {
// Agreement with terms of service
Agreement string `json:"agreement,omitempty"`

// InitialIP is the IP address from which the registration was created
InitialIP net.IP `json:"initialIp"`

// CreatedAt is the time the registration was created.
CreatedAt *time.Time `json:"createdAt,omitempty"`

Expand Down Expand Up @@ -150,24 +147,6 @@ type ValidationRecord struct {
// lookup for AddressUsed. During recursive A and AAAA lookups, a record may
// instead look like A:host:port or AAAA:host:port
ResolverAddrs []string `json:"resolverAddrs,omitempty"`

// Perspective uniquely identifies the Network Perspective used to perform
// the validation, as specified in BRs Section 5.4.1, Requirement 2.7
// ("Multi-Perspective Issuance Corroboration attempts from each Network
// Perspective"). It should uniquely identify either the Primary Perspective
// (VA) or a group of RVAs deployed in the same datacenter.
Perspective string `json:"perspective,omitempty"`

// RIR indicates the Regional Internet Registry where this RVA is located.
// This field is used to identify the RIR region from which a given
// validation was performed, as specified in the "Phased Implementation
// Timeline" in BRs Section 3.2.2.9. It must be one of the following values:
// - ARIN
// - RIPE
// - APNIC
// - LACNIC
// - AfriNIC
RIR string `json:"rir,omitempty"`
}

// Challenge is an aggregate of all data needed for any challenges.
Expand Down
14 changes: 13 additions & 1 deletion core/util.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package core

import (
"context"
"crypto"
"crypto/ecdsa"
"crypto/rand"
Expand All @@ -27,9 +28,12 @@ import (
"unicode"

"github.com/go-jose/go-jose/v4"
"github.com/letsencrypt/boulder/identifier"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/durationpb"
"google.golang.org/protobuf/types/known/timestamppb"

"github.com/letsencrypt/boulder/identifier"
)

const Unspecified = "Unspecified"
Expand Down Expand Up @@ -395,6 +399,14 @@ func IsASCII(str string) bool {
return true
}

// IsCanceled returns true if err is non-nil and is either context.Canceled, or
// has a grpc code of Canceled. This is useful because cancellations propagate
// through gRPC boundaries, and if we choose to treat in-process cancellations a
// certain way, we usually want to treat cross-process cancellations the same way.
func IsCanceled(err error) bool {
return errors.Is(err, context.Canceled) || status.Code(err) == codes.Canceled
}

func Command() string {
return path.Base(os.Args[0])
}
16 changes: 16 additions & 0 deletions core/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package core

import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"math"
"math/big"
Expand All @@ -13,6 +15,8 @@ import (
"time"

"github.com/go-jose/go-jose/v4"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/durationpb"
"google.golang.org/protobuf/types/known/timestamppb"

Expand Down Expand Up @@ -362,3 +366,15 @@ func TestHashNames(t *testing.T) {
h2 = HashNames([]string{"a"})
test.AssertByteEquals(t, h1, h2)
}

func TestIsCanceled(t *testing.T) {
if !IsCanceled(context.Canceled) {
t.Errorf("Expected context.Canceled to be canceled, but wasn't.")
}
if !IsCanceled(status.Errorf(codes.Canceled, "hi")) {
t.Errorf("Expected gRPC cancellation to be canceled, but wasn't.")
}
if IsCanceled(errors.New("hi")) {
t.Errorf("Expected random error to not be canceled, but was.")
}
}
8 changes: 4 additions & 4 deletions db/map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func TestTableFromQuery(t *testing.T) {
expectedTable string
}{
{
query: "SELECT id, jwk, jwk_sha256, contact, agreement, initialIP, createdAt, LockCol, status FROM registrations WHERE jwk_sha256 = ?",
query: "SELECT id, jwk, jwk_sha256, contact, agreement, createdAt, LockCol, status FROM registrations WHERE jwk_sha256 = ?",
expectedTable: "registrations",
},
{
Expand All @@ -134,15 +134,15 @@ func TestTableFromQuery(t *testing.T) {
expectedTable: "authz2",
},
{
query: "insert into `registrations` (`id`,`jwk`,`jw k_sha256`,`contact`,`agreement`,`initialIp`,`createdAt`,`LockCol`,`status`) values (null,?,?,?,?,?,?,?,?);",
query: "insert into `registrations` (`id`,`jwk`,`jw k_sha256`,`contact`,`agreement`,`createdAt`,`LockCol`,`status`) values (null,?,?,?,?,?,?,?,?);",
expectedTable: "`registrations`",
},
{
query: "update `registrations` set `jwk`=?, `jwk_sh a256`=?, `contact`=?, `agreement`=?, `initialIp`=?, `createdAt`=?, `LockCol` =?, `status`=? where `id`=? and `LockCol`=?;",
query: "update `registrations` set `jwk`=?, `jwk_sh a256`=?, `contact`=?, `agreement`=?, `createdAt`=?, `LockCol` =?, `status`=? where `id`=? and `LockCol`=?;",
expectedTable: "`registrations`",
},
{
query: "SELECT COUNT(*) FROM registrations WHERE initialIP = ? AND ? < createdAt AND createdAt <= ?",
query: "SELECT COUNT(*) FROM registrations WHERE ? < createdAt AND createdAt <= ?",
expectedTable: "registrations",
},
{
Expand Down
19 changes: 5 additions & 14 deletions grpc/pb-marshalling.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func PBToValidationRecord(in *corepb.ValidationRecord) (record core.ValidationRe
}, nil
}

func ValidationResultToPB(records []core.ValidationRecord, prob *probs.ProblemDetails) (*vapb.ValidationResult, error) {
func ValidationResultToPB(records []core.ValidationRecord, prob *probs.ProblemDetails, perspective, rir string) (*vapb.ValidationResult, error) {
recordAry := make([]*corepb.ValidationRecord, len(records))
var err error
for i, v := range records {
Expand All @@ -193,8 +193,10 @@ func ValidationResultToPB(records []core.ValidationRecord, prob *probs.ProblemDe
return nil, err
}
return &vapb.ValidationResult{
Records: recordAry,
Problems: marshalledProbs,
Records: recordAry,
Problems: marshalledProbs,
Perspective: perspective,
Rir: rir,
}, nil
}

Expand Down Expand Up @@ -222,10 +224,6 @@ func RegistrationToPB(reg core.Registration) (*corepb.Registration, error) {
if err != nil {
return nil, err
}
ipBytes, err := reg.InitialIP.MarshalText()
if err != nil {
return nil, err
}
var contacts []string
// Since the default value of corepb.Registration.Contact is a slice
// we need a indicator as to if the value is actually important on
Expand All @@ -248,7 +246,6 @@ func RegistrationToPB(reg core.Registration) (*corepb.Registration, error) {
Contact: contacts,
ContactsPresent: contactsPresent,
Agreement: reg.Agreement,
InitialIP: ipBytes,
CreatedAt: createdAt,
Status: string(reg.Status),
}, nil
Expand All @@ -260,11 +257,6 @@ func PbToRegistration(pb *corepb.Registration) (core.Registration, error) {
if err != nil {
return core.Registration{}, err
}
var initialIP net.IP
err = initialIP.UnmarshalText(pb.InitialIP)
if err != nil {
return core.Registration{}, err
}
var createdAt *time.Time
if !core.IsAnyNilOrZero(pb.CreatedAt) {
c := pb.CreatedAt.AsTime()
Expand All @@ -289,7 +281,6 @@ func PbToRegistration(pb *corepb.Registration) (core.Registration, error) {
Key: &key,
Contact: contacts,
Agreement: pb.Agreement,
InitialIP: initialIP,
CreatedAt: createdAt,
Status: core.AcmeStatus(pb.Status),
}, nil
Expand Down
Loading

0 comments on commit 06503fb

Please sign in to comment.