Beispiel #1
0
func cmdReconcile() {
	s, err := storage.New(*stateFlag)
	log.Fatale(err, "storage")

	err = s.Reconcile()
	log.Fatale(err, "reconcile")
}
Beispiel #2
0
func cmdImportKey() {
	s, err := storage.New(*stateFlag)
	log.Fatale(err, "storage")

	err = importKey(s, *importKeyArg)
	log.Fatale(err, "import key")
}
Beispiel #3
0
func cmdUnwant() {
	s, err := storage.New(*stateFlag)
	log.Fatale(err, "storage")

	for _, hn := range *unwantArg {
		err = s.RemoveTargetHostname(hn)
		log.Fatale(err, "remove target hostname ", hn)
	}
}
Beispiel #4
0
func cmdStatus() {
	s, err := storage.New(*stateFlag)
	log.Fatale(err, "storage")

	info, err := s.StatusString()
	log.Fatale(err, "status")

	fmt.Print(info)
}
Beispiel #5
0
func cmdQuickstart() {
	s, err := storage.New(*stateFlag)
	log.Fatale(err, "storage")

	serverURL := promptServerURL()
	err = s.SetDefaultProvider(serverURL)
	log.Fatale(err, "set provider URL")

	rsaKeySize := promptRSAKeySize()
	if rsaKeySize != 0 {
		err = s.SetPreferredRSAKeySize(rsaKeySize)
		log.Fatale(err, "set preferred RSA Key size")
	}

	method := promptHookMethod()
	webroot := ""
	switch method {
	case "webroot":
		webroot = promptWebrootDir()
	}

	if webroot != "" {
		err = os.MkdirAll(webroot, 0755)
		log.Fatale(err, "couldn't create webroot path")
	}

	err = s.SetWebrootPaths([]string{webroot})
	log.Fatale(err, "set webroot path")

	prog, err := interaction.Auto.Status(&interaction.StatusInfo{
		Title: "Registering account...",
	})
	log.Fatale(err, "status")
	prog.SetProgress(0, 1)

	err = s.EnsureRegistration()
	log.Fatale(err, "couldn't complete registration")

	prog.SetProgress(1, 1)
	prog.Close()

	if method == "redirector" {
		promptSystemd()
	}

	installDefaultHooks()
	if _, err := exec.LookPath("haproxy"); err == nil {
		if promptInstallHAProxyHooks() {
			installHAProxyHooks()
		}
	}

	promptCron()
	promptGettingStarted()
}
Beispiel #6
0
func cmdWant() {
	s, err := storage.New(*stateFlag)
	log.Fatale(err, "storage")

	tgt := storage.Target{
		Satisfy: storage.TargetSatisfy{
			Names: *wantArg,
		},
	}

	err = s.AddTarget(tgt)
	log.Fatale(err, "add target")
}
Beispiel #7
0
func cmdImportJWKAccount() {
	s, err := storage.New(*stateFlag)
	log.Fatale(err, "storage")

	f, err := os.Open(*importJWKPathArg)
	log.Fatale(err, "cannot open private key file")
	defer f.Close()

	b, err := ioutil.ReadAll(f)
	log.Fatale(err, "cannot read file")

	k := jose.JsonWebKey{}
	err = k.UnmarshalJSON(b)
	log.Fatale(err, "cannot unmarshal key")

	err = s.ImportAccountKey(*importJWKURLArg, k.Key)
	log.Fatale(err, "cannot import account key")
}
Beispiel #8
0
func cmdImportLE() {
	s, err := storage.New(*stateFlag)
	log.Fatale(err, "storage")

	lePath := *importLEArg
	accountNames, err := getLEAccountNames(lePath)
	log.Fatale(err, "cannot inspect accounts directory - do you have permissions to read the Let's Encrypt directory (i.e. are you root)?")

	// In order to import a Let's Encrypt state directory, we must:
	//   - import the account keys
	//   - import the certificate keys
	//   - import the certificates

	// Import account keys.
	for _, accountName := range accountNames {
		err := importLEAccount(s, lePath, accountName)
		log.Fatale(err, "import account")
	}

	keyFiles, err := filepath.Glob(filepath.Join(lePath, "keys", "*.pem"))
	log.Fatale(err)

	// Import certificate keys.
	for _, keyFile := range keyFiles {
		err := importKey(s, keyFile)
		log.Fatale(err, "import key")
	}

	// Import certificates.
	certFiles, err := filepath.Glob(filepath.Join(lePath, "archive", "*", "cert*.pem"))
	log.Fatale(err)

	for _, certFile := range certFiles {
		err := importCert(s, certFile)
		log.Fatale(err, "import certificate")
	}
}
Beispiel #9
0
func cmdQuickstart() {
	s, err := storage.New(*stateFlag)
	log.Fatale(err, "storage")

	serverURL := promptServerURL()
	err = s.SetDefaultProvider(serverURL)
	log.Fatale(err, "set provider URL")

	// key type
	keyType := promptKeyType()
	switch keyType {
	case "rsa":
		s.DefaultTarget().Request.Key.Type = "rsa"
		rsaKeySize := promptRSAKeySize()
		if rsaKeySize != 0 {
			s.DefaultTarget().Request.Key.RSASize = rsaKeySize
			err = s.SaveDefaultTarget()
			log.Fatale(err, "set preferred RSA Key size")
		}
	case "ecdsa":
		s.DefaultTarget().Request.Key.Type = "ecdsa"
		ecdsaCurve := promptECDSACurve()
		if ecdsaCurve != "" {
			s.DefaultTarget().Request.Key.ECDSACurve = ecdsaCurve
			err = s.SaveDefaultTarget()
			log.Fatale(err, "set preferred ECDSA curve")
		}
	}

	// hook method
	method := promptHookMethod()
	var webroot []string
	switch method {
	case "webroot":
		webroot = []string{promptWebrootDir()}
	}

	if len(webroot) != 0 {
		err = os.MkdirAll(webroot[0], 0755)
		log.Fatale(err, "couldn't create webroot path")
	}

	s.DefaultTarget().Request.Challenge.WebrootPaths = webroot
	err = s.SaveDefaultTarget()
	log.Fatale(err, "set webroot path")

	prog, err := interaction.Auto.Status(&interaction.StatusInfo{
		Title: "Registering account...",
	})
	log.Fatale(err, "status")
	prog.SetProgress(0, 1)

	err = s.EnsureRegistration()
	log.Fatale(err, "couldn't complete registration")

	prog.SetProgress(1, 1)
	prog.Close()

	if method == "redirector" {
		promptSystemd()
	}

	installDefaultHooks()
	if _, err := exec.LookPath("haproxy"); err == nil {
		if promptInstallHAProxyHooks() {
			installHAProxyHooks()
		}
	}

	promptCron()
	promptGettingStarted()
}