beltram 3 лет назад
Родитель
Сommit
d32a3e23f0
3 измененных файлов с 44 добавлено и 0 удалено
  1. 41 0
      acme/api/order.go
  2. 1 0
      acme/challenge.go
  3. 2 0
      authority/provisioner/dpop_options.go

+ 41 - 0
acme/api/order.go

@@ -1,13 +1,16 @@
 package api
 
 import (
+	"bytes"
 	"context"
 	"crypto/x509"
 	"encoding/base64"
+	"encoding/hex"
 	"encoding/json"
 	"net"
 	"net/http"
 	"strings"
+	"text/template"
 	"time"
 
 	"github.com/go-chi/chi/v5"
@@ -272,12 +275,50 @@ func newAuthorization(ctx context.Context, az *acme.Authorization) error {
 			continue
 		}
 
+		targetTemplate := prov.GetOptions().GetDPOPOptions().DpopTarget
+
+		var target = ""
+
+		switch az.Identifier.Type {
+		case acme.WireID:
+			wireId, err := wire.ParseID([]byte(az.Identifier.Value))
+			if err != nil {
+				if err != nil {
+					return acme.NewError(acme.ErrorMalformedType, "DeviceId cannot be parsed")
+				}
+			}
+			clientID := wireId.ClientID
+			deviceId := strings.Split(strings.Split(clientID, "@")[0], "/")[1]
+			decoded, err := hex.DecodeString(deviceId)
+			if err != nil {
+				return acme.NewError(acme.ErrorMalformedType, "DeviceId is not hexadecimal")
+			}
+			_ = decoded
+			tmpl, err := template.New("DevideId").Parse(targetTemplate)
+			if err != nil {
+				return acme.NewError(acme.ErrorMalformedType, "Misconfigured target template configuration")
+			}
+			type ClientIdTmpl struct {
+				DeviceId string
+			}
+			clientIdTmpl := ClientIdTmpl{deviceId}
+
+			var buff bytes.Buffer
+			if err := tmpl.Execute(&buff, clientIdTmpl); err != nil {
+				return acme.NewError(acme.ErrorMalformedType, "Invalid Go template registered for 'target'")
+			}
+			target = buff.String()
+
+		default:
+		}
+
 		ch := &acme.Challenge{
 			AccountID: az.AccountID,
 			Value:     az.Identifier.Value,
 			Type:      typ,
 			Token:     az.Token,
 			Status:    acme.StatusPending,
+			Target:    target,
 		}
 		if err := db.CreateChallenge(ctx, ch); err != nil {
 			return acme.WrapErrorISE(err, "error creating challenge")

+ 1 - 0
acme/challenge.go

@@ -81,6 +81,7 @@ type Challenge struct {
 	Token           string        `json:"token"`
 	ValidatedAt     string        `json:"validated,omitempty"`
 	URL             string        `json:"url"`
+	Target          string        `json:"target"`
 	Error           *Error        `json:"error,omitempty"`
 }
 

+ 2 - 0
authority/provisioner/dpop_options.go

@@ -6,6 +6,8 @@ type DPOPOptions struct {
 	ValidationExecPath string `json:"validation-exec-path,omitempty"`
 	// Backend signing key for DPoP access token
 	SigningKey string `json:"key"`
+	// URI template acme client must call to fetch the challenge proof
+	DpopTarget string `json:"dpop-target"`
 }
 
 func (o *DPOPOptions) GetValidationExecPath() string {