1
0
mirror of https://github.com/go-acme/lego.git synced 2024-12-23 01:07:23 +02:00

selectelv2: fix non-ASCII domain (#2322)

Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
This commit is contained in:
Artem Chirkov 2024-11-06 16:32:22 +03:00 committed by GitHub
parent b41079b912
commit 40bf2b0ece
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 13 deletions

View File

@ -26,10 +26,10 @@ Configuration for [Selectel v2](https://selectel.ru).
Here is an example bash command using the Selectel v2 provider:
```bash
SELECTEL_USERNAME=trex \
SELECTEL_PASSWORD=xxxxx \
SELECTEL_ACCOUNT_ID=1234567 \
SELECTEL_PROJECT_ID=111a11111aaa11aa1a11aaa11111aa1a \
SELECTELV2_USERNAME=trex \
SELECTELV2_PASSWORD=xxxxx \
SELECTELV2_ACCOUNT_ID=1234567 \
SELECTELV2_PROJECT_ID=111a11111aaa11aa1a11aaa11111aa1a \
lego --email you@example.com --dns selectelv2 --domains my.example.org run
```

View File

@ -14,6 +14,7 @@ import (
"github.com/go-acme/lego/v4/providers/dns/internal/useragent"
selectelapi "github.com/selectel/domains-go/pkg/v2"
"github.com/selectel/go-selvpcclient/v3/selvpcclient"
"golang.org/x/net/idna"
)
const tokenHeader = "X-Auth-Token"
@ -252,7 +253,12 @@ type clientWrapper struct {
}
func (w *clientWrapper) getZone(ctx context.Context, name string) (*selectelapi.Zone, error) {
params := &map[string]string{"filter": name}
unicodeName, err := idna.ToUnicode(name)
if err != nil {
return nil, fmt.Errorf("to unicode: %w", err)
}
params := &map[string]string{"filter": unicodeName}
zones, err := w.ListZones(ctx, params)
if err != nil {
@ -260,13 +266,13 @@ func (w *clientWrapper) getZone(ctx context.Context, name string) (*selectelapi.
}
for _, zone := range zones.GetItems() {
if zone.Name == dns01.ToFqdn(name) {
if zone.Name == dns01.ToFqdn(unicodeName) {
return zone, nil
}
}
if len(strings.Split(dns01.UnFqdn(name), ".")) == 1 {
return nil, errors.New("zone for challenge has not been found")
return nil, fmt.Errorf("zone '%s' for challenge has not been found", name)
}
// -1 can not be returned since if no dots present we exit above
@ -276,7 +282,12 @@ func (w *clientWrapper) getZone(ctx context.Context, name string) (*selectelapi.
}
func (w *clientWrapper) getRRset(ctx context.Context, name, zoneID string) (*selectelapi.RRSet, error) {
params := &map[string]string{"name": name, "rrset_types": string(selectelapi.TXT)}
unicodeName, err := idna.ToUnicode(name)
if err != nil {
return nil, fmt.Errorf("to unicode: %w", err)
}
params := &map[string]string{"name": unicodeName, "rrset_types": string(selectelapi.TXT)}
resp, err := w.ListRRSets(ctx, zoneID, params)
if err != nil {
@ -284,7 +295,7 @@ func (w *clientWrapper) getRRset(ctx context.Context, name, zoneID string) (*sel
}
for _, rrset := range resp.GetItems() {
if rrset.Name == dns01.ToFqdn(name) {
if rrset.Name == dns01.ToFqdn(unicodeName) {
return rrset, nil
}
}

View File

@ -5,10 +5,10 @@ Code = "selectelv2"
Since = "v4.17.0"
Example = '''
SELECTEL_USERNAME=trex \
SELECTEL_PASSWORD=xxxxx \
SELECTEL_ACCOUNT_ID=1234567 \
SELECTEL_PROJECT_ID=111a11111aaa11aa1a11aaa11111aa1a \
SELECTELV2_USERNAME=trex \
SELECTELV2_PASSWORD=xxxxx \
SELECTELV2_ACCOUNT_ID=1234567 \
SELECTELV2_PROJECT_ID=111a11111aaa11aa1a11aaa11111aa1a \
lego --email you@example.com --dns selectelv2 --domains my.example.org run
'''