Skip to content

Commit a838861

Browse files
authored
Remove ra.validateContacts because it is unused (#8666)
This helper method is unused, so we can remove it. This also breaks the RA package's dependence on the policy package, which is nice.
1 parent a5929e6 commit a838861

2 files changed

Lines changed: 0 additions & 143 deletions

File tree

ra/ra.go

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ import (
77
"crypto/x509"
88
"crypto/x509/pkix"
99
"encoding/asn1"
10-
"encoding/json"
1110
"errors"
1211
"fmt"
13-
"net/url"
1412
"os"
1513
"slices"
1614
"strconv"
@@ -42,7 +40,6 @@ import (
4240
"github.com/letsencrypt/boulder/issuance"
4341
blog "github.com/letsencrypt/boulder/log"
4442
"github.com/letsencrypt/boulder/metrics"
45-
"github.com/letsencrypt/boulder/policy"
4643
"github.com/letsencrypt/boulder/probs"
4744
pubpb "github.com/letsencrypt/boulder/publisher/proto"
4845
rapb "github.com/letsencrypt/boulder/ra/proto"
@@ -515,69 +512,6 @@ func (ra *RegistrationAuthorityImpl) NewRegistration(ctx context.Context, reques
515512
return res, nil
516513
}
517514

518-
// validateContacts checks the provided list of contacts, returning an error if
519-
// any are not acceptable. Unacceptable contacts lists include:
520-
// * An empty list
521-
// * A list has more than maxContactsPerReg contacts
522-
// * A list containing an empty contact
523-
// * A list containing a contact that does not parse as a URL
524-
// * A list containing a contact that has a URL scheme other than mailto
525-
// * A list containing a mailto contact that contains hfields
526-
// * A list containing a contact that has non-ascii characters
527-
// * A list containing a contact that doesn't pass `policy.ValidEmail`
528-
func (ra *RegistrationAuthorityImpl) validateContacts(contacts []string) error {
529-
if len(contacts) == 0 {
530-
return nil // Nothing to validate
531-
}
532-
if ra.maxContactsPerReg > 0 && len(contacts) > ra.maxContactsPerReg {
533-
return berrors.MalformedError(
534-
"too many contacts provided: %d > %d",
535-
len(contacts),
536-
ra.maxContactsPerReg,
537-
)
538-
}
539-
540-
for _, contact := range contacts {
541-
if contact == "" {
542-
return berrors.InvalidEmailError("empty contact")
543-
}
544-
parsed, err := url.Parse(contact)
545-
if err != nil {
546-
return berrors.InvalidEmailError("unparsable contact")
547-
}
548-
if parsed.Scheme != "mailto" {
549-
return berrors.UnsupportedContactError("only contact scheme 'mailto:' is supported")
550-
}
551-
if parsed.RawQuery != "" || contact[len(contact)-1] == '?' {
552-
return berrors.InvalidEmailError("contact email contains a question mark")
553-
}
554-
if parsed.Fragment != "" || contact[len(contact)-1] == '#' {
555-
return berrors.InvalidEmailError("contact email contains a '#'")
556-
}
557-
if !core.IsASCII(contact) {
558-
return berrors.InvalidEmailError("contact email contains non-ASCII characters")
559-
}
560-
err = policy.ValidEmail(parsed.Opaque)
561-
if err != nil {
562-
return err
563-
}
564-
}
565-
566-
// NOTE(@cpu): For historical reasons (</3) we store ACME account contact
567-
// information de-normalized in a fixed size `contact` field on the
568-
// `registrations` table. At the time of writing this field is VARCHAR(191)
569-
// That means the largest marshalled JSON value we can store is 191 bytes.
570-
const maxContactBytes = 191
571-
if jsonBytes, err := json.Marshal(contacts); err != nil {
572-
return fmt.Errorf("failed to marshal reg.Contact to JSON: %w", err)
573-
} else if len(jsonBytes) >= maxContactBytes {
574-
return berrors.InvalidEmailError(
575-
"too many/too long contact(s). Please use shorter or fewer email addresses")
576-
}
577-
578-
return nil
579-
}
580-
581515
// matchesCSR tests the contents of a generated certificate to make sure
582516
// that the PublicKey, CommonName, and identifiers match those provided in
583517
// the CSR that was used to generate the certificate. It also checks the

ra/ra_test.go

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -390,83 +390,6 @@ func initAuthorities(t *testing.T) (*DummyValidationAuthority, sapb.StorageAutho
390390
return dummyVA, sa, ra, rlSource, fc, registration, cleanUp
391391
}
392392

393-
func TestValidateContacts(t *testing.T) {
394-
_, _, ra, _, _, _, cleanUp := initAuthorities(t)
395-
defer cleanUp()
396-
397-
ansible := "ansible:earth.sol.milkyway.laniakea/letsencrypt"
398-
validEmail := "mailto:admin@email.com"
399-
otherValidEmail := "mailto:other-admin@email.com"
400-
malformedEmail := "mailto:admin.com"
401-
nonASCII := "mailto:señor@email.com"
402-
unparsable := "mailto:a@email.com, b@email.com"
403-
forbidden := "mailto:a@example.org"
404-
405-
err := ra.validateContacts([]string{})
406-
test.AssertNotError(t, err, "No Contacts")
407-
408-
err = ra.validateContacts([]string{validEmail, otherValidEmail})
409-
test.AssertError(t, err, "Too Many Contacts")
410-
411-
err = ra.validateContacts([]string{validEmail})
412-
test.AssertNotError(t, err, "Valid Email")
413-
414-
err = ra.validateContacts([]string{malformedEmail})
415-
test.AssertError(t, err, "Malformed Email")
416-
417-
err = ra.validateContacts([]string{ansible})
418-
test.AssertError(t, err, "Unknown scheme")
419-
420-
err = ra.validateContacts([]string{""})
421-
test.AssertError(t, err, "Empty URL")
422-
423-
err = ra.validateContacts([]string{nonASCII})
424-
test.AssertError(t, err, "Non ASCII email")
425-
426-
err = ra.validateContacts([]string{unparsable})
427-
test.AssertError(t, err, "Unparsable email")
428-
429-
err = ra.validateContacts([]string{forbidden})
430-
test.AssertError(t, err, "Forbidden email")
431-
432-
err = ra.validateContacts([]string{"mailto:admin@localhost"})
433-
test.AssertError(t, err, "Forbidden email")
434-
435-
err = ra.validateContacts([]string{"mailto:admin@example.not.a.iana.suffix"})
436-
test.AssertError(t, err, "Forbidden email")
437-
438-
err = ra.validateContacts([]string{"mailto:admin@1.2.3.4"})
439-
test.AssertError(t, err, "Forbidden email")
440-
441-
err = ra.validateContacts([]string{"mailto:admin@[1.2.3.4]"})
442-
test.AssertError(t, err, "Forbidden email")
443-
444-
err = ra.validateContacts([]string{"mailto:admin@a.com?no-reminder-emails"})
445-
test.AssertError(t, err, "No hfields in email")
446-
447-
err = ra.validateContacts([]string{"mailto:example@a.com?"})
448-
test.AssertError(t, err, "No hfields in email")
449-
450-
err = ra.validateContacts([]string{"mailto:example@a.com#"})
451-
test.AssertError(t, err, "No fragment")
452-
453-
err = ra.validateContacts([]string{"mailto:example@a.com#optional"})
454-
test.AssertError(t, err, "No fragment")
455-
456-
// The registrations.contact field is VARCHAR(191). 175 'a' characters plus
457-
// the prefix "mailto:" and the suffix "@a.com" makes exactly 191 bytes of
458-
// encoded JSON. The correct size to hit our maximum DB field length.
459-
var longStringBuf strings.Builder
460-
longStringBuf.WriteString("mailto:")
461-
for range 175 {
462-
longStringBuf.WriteRune('a')
463-
}
464-
longStringBuf.WriteString("@a.com")
465-
466-
err = ra.validateContacts([]string{longStringBuf.String()})
467-
test.AssertError(t, err, "Too long contacts")
468-
}
469-
470393
func TestNewRegistration(t *testing.T) {
471394
_, sa, ra, _, _, _, cleanUp := initAuthorities(t)
472395
defer cleanUp()

0 commit comments

Comments
 (0)