Extend email parsing

This commit is contained in:
Roland Shoemaker 2015-06-06 02:46:51 +01:00
parent 84f187da96
commit 23b0cfa29f
3 changed files with 19 additions and 5 deletions

View File

@ -9,6 +9,8 @@ import (
"crypto/x509"
"fmt"
"math/big"
"net"
"net/mail"
"net/url"
"regexp"
"strconv"
@ -75,15 +77,27 @@ func (ra *RegistrationAuthorityImpl) NewRegistration(init core.Registration) (re
for _, contact := range reg.Contact {
// If contact email provided check MX records exist for the domain
if !strings.HasPrefix(contact.Scheme, "mailto") && !strings.HasPrefix(contact.Scheme, "tel") {
err = core.MalformedRequestError(fmt.Sprintf("Contact method %s is not supported", contact.Scheme))
return
}
if contact.Scheme == "mailto" {
_, err = mail.ParseAddress(contact.Opaque)
if err != nil {
err = core.MalformedRequestError(err.Error())
return
}
splitEmail := strings.SplitN(contact.Opaque, "@", -1)
domain := strings.ToLower(splitEmail[len(splitEmail)-1])
mx, err := net.LookupMX(domain)
var mx []*net.MX
mx, err = net.LookupMX(domain)
if err != nil {
err = core.InternalServerError(err.Error())
return
}
if len(mx) == 0 {
err = core.MalformedRequestError(fmt.Sprintf("No MX record for domain %s", domain))
return
}
}
}

View File

@ -194,7 +194,7 @@ func assertAuthzEqual(t *testing.T, a1, a2 core.Authorization) {
func TestNewRegistration(t *testing.T) {
_, _, sa, ra := initAuthorities(t)
mailto, _ := url.Parse("mailto:foo@bar.com")
mailto, _ := url.Parse("mailto:foo@letsencrypt.org")
input := core.Registration{
Contact: []core.AcmeURL{core.AcmeURL(*mailto)},
Key: AccountKey,
@ -217,7 +217,7 @@ func TestNewRegistration(t *testing.T) {
func TestNewRegistrationNoFieldOverwrite(t *testing.T) {
_, _, _, ra := initAuthorities(t)
mailto, _ := url.Parse("mailto:foo@bar.com")
mailto, _ := url.Parse("mailto:foo@letsencrypt.org")
input := core.Registration{
ID: 23,
Key: AccountKey,
@ -247,7 +247,7 @@ func TestNewRegistrationNoFieldOverwrite(t *testing.T) {
func TestNewRegistrationBadKey(t *testing.T) {
_, _, _, ra := initAuthorities(t)
mailto, _ := url.Parse("mailto:foo@bar.com")
mailto, _ := url.Parse("mailto:foo@letsencrypt.org")
input := core.Registration{
Contact: []core.AcmeURL{core.AcmeURL(*mailto)},
Key: ShortKey,

View File

@ -67,7 +67,7 @@ def run_test():
print("\n Installing NPM modules failed")
die()
if subprocess.Popen('''
node test.js --email foo@bar.com --agree true \
node test.js --email foo@letsencrypt.org --agree true \
--domains foo.com --new-reg http://localhost:4300/acme/new-reg \
--certKey %s/key.pem --cert %s/cert.der
''' % (tempdir, tempdir), shell=True).wait() != 0: