Skip to content

Commit

Permalink
tg
Browse files Browse the repository at this point in the history
  • Loading branch information
pya789 committed Jul 4, 2024
1 parent 1e4bcb9 commit a15171b
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions certificate/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,61 @@ func NewCertifier(core *api.Core, resolver resolver, options CertifierOptions) *

return c
}
func (c *Certifier) GenerateOrder(request ObtainRequest) (*acme.ExtendedOrder, []acme.Authorization, error) {
if len(request.Domains) == 0 {
return nil, nil, errors.New("no domains to obtain a certificate for")
}

domains := sanitizeDomain(request.Domains)

if request.Bundle {
log.Infof("[%s] acme: Obtaining bundled SAN certificate", strings.Join(domains, ", "))
} else {
log.Infof("[%s] acme: Obtaining SAN certificate", strings.Join(domains, ", "))
}

orderOpts := &api.OrderOptions{
NotBefore: request.NotBefore,
NotAfter: request.NotAfter,
ReplacesCertID: request.ReplacesCertID,
}

order, err := c.core.Orders.NewWithOptions(domains, orderOpts)
if err != nil {
return nil, nil, err
}

authz, err := c.getAuthorizations(order)
if err != nil {
// If any challenge fails, return. Do not generate partial SAN certificates.
c.deactivateAuthorizations(order, request.AlwaysDeactivateAuthorizations)
return nil, nil, err
}
return &order, authz, nil
}
func (c *Certifier) Challenge(order *acme.ExtendedOrder, authz []acme.Authorization, force bool) error {
if err := c.resolver.Solve(authz); err != nil {
// If any challenge fails, return. Do not generate partial SAN certificates.
c.deactivateAuthorizations(*order, force)
return err
}
return nil
}
func (c *Certifier) Finalize(order *acme.ExtendedOrder, authz []acme.Authorization, request ObtainRequest) (*Resource, error) {
domains := sanitizeDomain(request.Domains)
failures := newObtainError()
cert, err := c.getForOrder(domains, *order, request.Bundle, request.PrivateKey, request.MustStaple, request.PreferredChain)
if err != nil {
for _, auth := range authz {
failures.Add(challenge.GetTargetedDomain(auth), err)
}
}

if request.AlwaysDeactivateAuthorizations {
c.deactivateAuthorizations(*order, true)
}
return cert, failures.Join()
}

// Obtain tries to obtain a single certificate using all domains passed into it.
//
Expand Down

0 comments on commit a15171b

Please sign in to comment.