Ejemplo n.º 1
0
Archivo: cloud.go Proyecto: nf/vanity
// Cache caches letsencrypt data for the given Manager in the Google Cloud
// Storage object identified by the getURL and putURL values.
// See the package comment for details on obtaining these values.
func Cache(m *letsencrypt.Manager, getURL, putURL string) error {
	var data []byte
	r, err := http.Get(getURL)
	if err != nil {
		return fmt.Errorf("letscloud: reading cache: %v", err)
	}
	data, err = ioutil.ReadAll(r.Body)
	r.Body.Close()
	if err != nil {
		return fmt.Errorf("letscloud: reading cache: %v", err)
	}
	if r.StatusCode == http.StatusOK && len(data) > 0 {
		if err := m.Unmarshal(string(data)); err != nil {
			return fmt.Errorf("letscloud: reading cache: %v", err)
		}
	}

	go func() {
		for range m.Watch() {
			req, err := http.NewRequest("PUT", putURL, strings.NewReader(m.Marshal()))
			if err != nil {
				log.Printf("letscloud: writing cache: %v", err)
				continue
			}
			r, err := http.DefaultClient.Do(req)
			if err != nil {
				log.Printf("letscloud: writing cache: %v", err)
				continue
			}
			if r.StatusCode != http.StatusOK {
				log.Printf("letscloud: writing cache: %v", r.Status)
			}
		}
	}()

	return nil
}
Ejemplo n.º 2
0
func GetLEState(m *letsencrypt.Manager) {
	checkKey := "cache"

	thisStore := &RedisClusterStorageManager{KeyPrefix: LEKeyPrefix, HashKeys: false}

	connected := thisStore.Connect()
	log.Debug("[SSL] --> Connected to DB")

	if !connected {
		log.Error("[SSL] --> SSL Backup recovery failed: redis connection failed")
		return
	}

	cryptoText, rErr := thisStore.GetKey(checkKey)
	if rErr != nil {
		log.Warning("[SSL] --> No SSL backup: ", rErr)
		return
	}

	secret := rightPad2Len(config.Secret, "=", 32)
	sslState := decrypt([]byte(secret), cryptoText)

	m.Unmarshal(sslState)
}