Beispiel #1
0
func readNotificationParameters() bool {
	var smtpServer, authenticationType, username, password string
	var port int
	var continueProcessing bool

	if notificationModule {
		smtpServer, continueProcessing = readNotificationSMTPServer()
		if !continueProcessing {
			return false
		}

		port, continueProcessing = readNotificationPort()
		if !continueProcessing {
			return false
		}

		authenticationType, continueProcessing = readNotificationAuthType()
		if !continueProcessing {
			return false
		}

		if authenticationType != "None" {
			username, continueProcessing = readNotificationUsername()
			if !continueProcessing {
				return false
			}

			password, continueProcessing = readNotificationPassword()
			if !continueProcessing {
				return false
			}

			var err error
			password, err = secret.Encrypt(password)
			if err != nil {
				log.Println(err)
				return false
			}
		}
	}

	config.ShelterConfig.Notification.SMTPServer.Server = smtpServer
	config.ShelterConfig.Notification.SMTPServer.Port = port

	switch authenticationType {
	case "None":
		config.ShelterConfig.Notification.SMTPServer.Auth.Type = config.AuthenticationTypeNone
	case "Plain":
		config.ShelterConfig.Notification.SMTPServer.Auth.Type = config.AuthenticationTypePlain
	case "CRAM-MD5":
		config.ShelterConfig.Notification.SMTPServer.Auth.Type = config.AuthenticationTypeCRAMMD5Auth
	}

	config.ShelterConfig.Notification.SMTPServer.Auth.Username = username
	config.ShelterConfig.Notification.SMTPServer.Auth.Password = password
	return true
}
Beispiel #2
0
func main() {
	flag.Parse()

	if len(op) == 0 {
		fmt.Println("Operation not informed")
		flag.PrintDefaults()
		return
	}
	op = strings.ToLower(op)

	if len(password) == 0 {
		fmt.Println("Password not informed")
		flag.PrintDefaults()
		return
	}

	if operation(op) == operationEncrypt {
		var err error
		if password, err = secret.Encrypt(password); err == nil {
			fmt.Println("Encrypted password:"******"Decrypted password:"******"Invalid operation")
		flag.PrintDefaults()
	}
}
Beispiel #3
0
func readRESTSecret() bool {
	keyId, generateAutomatically, continueProcessing := readRESTSecretId()

	if !continueProcessing {
		return false
	}

	var s string
	if generateAutomatically {
		for i := 0; i < 30; i++ {
			randNumber, err := rand.Int(rand.Reader, big.NewInt(int64(len(secretAlphabet))))
			if err != nil {
				log.Println("Error generating random numbers. Details:", err)
				return false
			}

			s += string(secretAlphabet[randNumber.Int64()])
		}

	} else {
		s, continueProcessing = readRESTSecretContent(keyId)
		if !continueProcessing {
			return false
		}
	}

	var err error
	s, err = secret.Encrypt(s)
	if err != nil {
		log.Println("Error encrypting secret. Details:", err)
		return false
	}

	config.ShelterConfig.RESTServer.Secrets[keyId] = s
	return true
}