func (r *reconcile) obtainAuthorization(name string, a *storage.Account, trc *storage.TargetRequestChallenge) error { cl := r.getClientForAccount(a) ccfg := responder.ChallengeConfig{ WebPaths: trc.WebrootPaths, HTTPPorts: trc.HTTPPorts, PriorKeyFunc: r.getPriorKey, } az, err := solver.Authorize(cl, name, ccfg, nil, context.TODO()) if err != nil { return err } err = cl.LoadAuthorization(az, context.TODO()) if err != nil { // Try proceeding anyway. return nil } if a.Authorizations == nil { a.Authorizations = map[string]*storage.Authorization{} } a.Authorizations[az.Identifier.Value] = &storage.Authorization{ URL: az.URI, Name: az.Identifier.Value, Expires: az.Expires, } err = r.store.SaveAccount(a) if err != nil { return err } return nil }
func (r *reconcile) obtainAuthorization(name string, a *storage.Account, targetFilename string, trc *storage.TargetRequestChallenge) error { cl := r.getClientForAccount(a) startHookFunc := func(challengeInfo interface{}) error { switch v := challengeInfo.(type) { case *responder.HTTPChallengeInfo: _, err := hooks.ChallengeHTTPStart("", r.store.Path(), name, targetFilename, v.Filename, v.Body) return err case *responder.TLSSNIChallengeInfo: hookPEM, err := generateHookPEM(v) if err != nil { return err } _, err = hooks.ChallengeTLSSNIStart("", r.store.Path(), name, targetFilename, v.Hostname1, v.Hostname2, hookPEM) return err case *responder.DNSChallengeInfo: installed, err := hooks.ChallengeDNSStart("", r.store.Path(), name, targetFilename, v.Body) if err == nil && !installed { return fmt.Errorf("could not install DNS challenge, no hooks succeeded") } return err default: return nil } } stopHookFunc := func(challengeInfo interface{}) error { switch v := challengeInfo.(type) { case *responder.HTTPChallengeInfo: return hooks.ChallengeHTTPStop("", r.store.Path(), name, targetFilename, v.Filename, v.Body) case *responder.TLSSNIChallengeInfo: hookPEM, err := generateHookPEM(v) if err != nil { return err } _, err = hooks.ChallengeTLSSNIStop("", r.store.Path(), name, targetFilename, v.Hostname1, v.Hostname2, hookPEM) return err case *responder.DNSChallengeInfo: uninstalled, err := hooks.ChallengeDNSStop("", r.store.Path(), name, targetFilename, v.Body) if err == nil && !uninstalled { return fmt.Errorf("could not uninstall DNS challenge, no hooks succeeded") } return err default: return nil } } ccfg := responder.ChallengeConfig{ WebPaths: trc.WebrootPaths, HTTPPorts: trc.HTTPPorts, PriorKeyFunc: r.getPriorKey, StartHookFunc: startHookFunc, StopHookFunc: stopHookFunc, } az, err := solver.Authorize(cl, name, ccfg, context.TODO()) if err != nil { return err } err = cl.LoadAuthorization(az, context.TODO()) if err != nil { // Try proceeding anyway. return nil } if a.Authorizations == nil { a.Authorizations = map[string]*storage.Authorization{} } a.Authorizations[az.Identifier.Value] = &storage.Authorization{ URL: az.URI, Name: az.Identifier.Value, Expires: az.Expires, } err = r.store.SaveAccount(a) if err != nil { return err } return nil }