Exemplo n.º 1
0
// tests whether encryption and decryption are symmetrical operations
func (s *SecureStringSuite) TestEncryptDecryptSymmetry(c *gc.C) {
	for _, input := range testInputs {
		enc, err := securestring.Encrypt(input)
		c.Assert(err, gc.IsNil)
		dec, err := securestring.Decrypt(enc)
		c.Assert(err, gc.IsNil)
		c.Assert(dec, gc.Equals, input)
	}
}
Exemplo n.º 2
0
// tests whether the output of ConvertFrom-SecureString is compatible with the module and can be decrypted
func (s *SecureStringSuite) TestDecryptFromCFSS(c *gc.C) {
	for _, input := range testInputs {
		psenc, err := runPowerShellCommands(fmt.Sprintf("ConvertTo-SecureString \"%s\" -AsPlainText -Force | ConvertFrom-SecureString", input))
		c.Assert(err, gc.IsNil)

		dec, err := securestring.Decrypt(psenc)
		c.Assert(err, gc.IsNil)
		c.Assert(fmt.Sprintf("%s", dec), gc.Equals, input)
	}
}
Exemplo n.º 3
0
// getPassword attempts to read the password for the jujud user. We define it as
// a variable to allow us to mock it out for testing
var getPassword = func() (string, error) {
	k, err := registry.OpenKey(registry.LOCAL_MACHINE, osenv.JujuRegistryKey[6:], registry.QUERY_VALUE)
	if err != nil {
		return "", errors.Annotate(err, "Failed to open juju registry key")
	}
	defer k.Close()

	f, _, err := k.GetBinaryValue(osenv.JujuRegistryPasswordKey)
	if err != nil {
		return "", errors.Annotate(err, "Failed to read password registry entry")
	}
	encryptedPasswd := strings.TrimSpace(string(f))
	passwd, err := securestring.Decrypt(encryptedPasswd)
	if err != nil {
		return "", errors.Annotate(err, "Failed to decrypt password")
	}
	return passwd, nil
}

// listServices returns an array of strings containing all the services on
// the current system. It is defined as a variable to allow us to mock it out
// for testing
var listServices = func() (services []string, err error) {
	host := syscall.StringToUTF16Ptr(".")

	sc, err := windows.OpenSCManager(host, nil, windows.SC_MANAGER_ALL_ACCESS)
	defer func() {
		// The close service handle error is less important than others