Пример #1
0
func (s *Store) obtainAuthorization(name string, a *Account, trc *TargetRequestChallenge) error {
	cl := s.getAccountClient(a)

	ccfg := responder.ChallengeConfig{
		WebPaths:     trc.WebrootPaths,
		HTTPPorts:    trc.HTTPPorts,
		PriorKeyFunc: s.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
	}

	c := s.db.Collection("accounts/" + a.ID() + "/authorizations/" + name)

	err = fdb.WriteBytes(c, "expiry", []byte(az.Expires.Format(time.RFC3339)))
	if err != nil {
		return err
	}

	err = fdb.WriteBytes(c, "url", []byte(az.URI))
	if err != nil {
		return err
	}

	saz := &Authorization{
		URL:     az.URI,
		Name:    az.Identifier.Value,
		Expires: az.Expires,
	}

	a.Authorizations[az.Identifier.Value] = saz

	return nil
}
Пример #2
0
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
}
Пример #3
0
func (s *Store) obtainAuthorization(name string, a *Account) error {
	cl := s.getAccountClient(a)

	az, err := solver.Authorize(cl, name, s.webrootPaths, nil, s.getPriorKey, context.TODO())
	if err != nil {
		return err
	}

	err = cl.LoadAuthorization(az, context.TODO())
	if err != nil {
		// Try proceeding anyway.
		return nil
	}

	c := s.db.Collection("accounts/" + a.ID() + "/authorizations/" + name)

	err = fdb.WriteBytes(c, "expiry", []byte(az.Expires.Format(time.RFC3339)))
	if err != nil {
		return err
	}

	err = fdb.WriteBytes(c, "url", []byte(az.URI))
	if err != nil {
		return err
	}

	saz := &Authorization{
		URL:     az.URI,
		Name:    az.Identifier.Value,
		Expires: az.Expires,
	}

	a.Authorizations[az.Identifier.Value] = saz

	return nil
}
Пример #4
0
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
}