diff --git a/src/cert/main.go b/src/cert/main.go index c465178..fc68d34 100644 --- a/src/cert/main.go +++ b/src/cert/main.go @@ -4,13 +4,13 @@ import "time" // Entry is the main struct for stored certificates type Entry struct { - ID int `xorm:"pk autoincr"` - Domains string `xorm:"notnull"` - Certificate string `xorm:"text notnull"` - PrivateKey string `xorm:"text notnull"` - AuthURL string - ValidityBegin time.Time - ValidityEnd time.Time + ID int `xorm:"pk autoincr"` + Domains string `xorm:"notnull"` + Certificate string `xorm:"text notnull"` + PrivateKey string `xorm:"text notnull"` + AuthURL string `xorm:"notnull"` + ValidityBegin time.Time `xorm:"notnull"` + ValidityEnd time.Time `xorm:"notnull"` Created time.Time `xorm:"created notnull"` Updated time.Time `xorm:"updated notnull"` } diff --git a/src/pki/acme.go b/src/pki/acme.go index edbd1b0..b2c4ca3 100644 --- a/src/pki/acme.go +++ b/src/pki/acme.go @@ -81,12 +81,12 @@ func (u *User) RequestNewCert(cfg *config.Config, domains []string) (certificate client, err := lego.NewClient(legoconfig) if err != nil { - log.Fatal(err) + log.Println(err) } err = client.Challenge.SetDNS01Provider(ovhprovider) if err != nil { - log.Fatal(err) + log.Println(err) } // If PKICtx doesn't exists, get existing of fetch registration @@ -104,7 +104,7 @@ func (u *User) RequestNewCert(cfg *config.Config, domains []string) (certificate certificates, err = client.Certificate.Obtain(request) if err != nil { - log.Fatal(err) + log.Println(err) } return } diff --git a/src/pkiws/serverhandle.go b/src/pkiws/serverhandle.go index 3255c8d..73a2336 100644 --- a/src/pkiws/serverhandle.go +++ b/src/pkiws/serverhandle.go @@ -39,7 +39,7 @@ func GetCertificate(cfg *config.Config, user *pki.User, domains []string) (resul ValidityBegin: NotBefore, ValidityEnd: NotAfter, AuthURL: cfg.ACME.AuthURL} - cfg.Db.Insert(entry) + cfg.Db.Insert(&entry) result = convertEntryToResponse(entry) return result, err } @@ -49,11 +49,16 @@ func GetCertificate(cfg *config.Config, user *pki.User, domains []string) (resul // CheckDomains check if requested domains are valid func CheckDomains(domains []string) (err error) { + domainRegex, err := regexp.Compile(`^[a-z0-9\*]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}$`) + + if err != nil { + return + } + for _, d := range domains { - res, err := regexp.Match(`^[a-z0-9\*]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}$`, []byte(d)) + res := domainRegex.Match([]byte(d)) if !res { - fmt.Println(res, err) - return fmt.Errorf(fmt.Sprintf("Domain has not a valid syntax %s, please verify", err)) + return fmt.Errorf(fmt.Sprintf("Domain %s has not a valid syntax %s, please verify", d, err)) } } return @@ -65,7 +70,7 @@ func GetDates(cert []byte) (NotBefore time.Time, NotAfter time.Time, err error) if block.Type == "CERTIFICATE" { ce, err := x509.ParseCertificate(block.Bytes) if err != nil { - log.Fatal("Error when parsing certificate") + log.Println("Error when parsing certificate") } NotBefore = ce.NotBefore NotAfter = ce.NotAfter