Пример #1
0
func (s *EtcdSuite) SetUpSuite(c *C) {
	key, err := secret.NewKeyString()
	if err != nil {
		panic(err)
	}
	s.key = key

	nodes_string := os.Getenv("VULCAND_TEST_ETCD_NODES")
	if nodes_string == "" {
		// Skips the entire suite
		c.Skip("This test requires etcd, provide comma separated nodes in VULCAND_TEST_ETCD_NODES environment variable")
		return
	}

	s.nodes = strings.Split(nodes_string, ",")
}
Пример #2
0
func (cmd *Command) generateKeyAction(c *cli.Context) error {
	key, err := secret.NewKeyString()
	if err != nil {
		return fmt.Errorf("unable to generate key: %v", err)
	}
	stream, closer, err := getStream(c)
	if err != nil {
		return err
	}
	if closer != nil {
		defer closer.Close()
	}
	_, err = stream.Write([]byte(key))
	if err != nil {
		return fmt.Errorf("failed writing to output stream, error %s", err)
	}
	return nil
}
Пример #3
0
func (s *CmdSuite) TestReadKeyPair(c *C) {
	keyPair := testutils.NewTestKeyPair()

	key, err := secret.NewKeyString()
	c.Assert(err, IsNil)

	fKey, err := ioutil.TempFile("", "vulcand")
	c.Assert(err, IsNil)
	defer fKey.Close()
	fKey.Write(keyPair.Key)

	fCert, err := ioutil.TempFile("", "vulcand")
	c.Assert(err, IsNil)
	defer fCert.Close()
	fCert.Write(keyPair.Cert)

	fSealed, err := ioutil.TempFile("", "vulcand")
	c.Assert(err, IsNil)
	fSealed.Close()

	s.run("secret", "seal_keypair", "-privateKey", fKey.Name(), "-cert", fCert.Name(), "-sealKey", key, "-f", fSealed.Name())

	bytes, err := ioutil.ReadFile(fSealed.Name())
	c.Assert(err, IsNil)

	box, err := secret.NewBoxFromKeyString(key)
	c.Assert(err, IsNil)

	sealed, err := secret.SealedValueFromJSON(bytes)
	data, err := box.Open(sealed)
	c.Assert(err, IsNil)

	outKeyPair, err := engine.KeyPairFromJSON(data)
	c.Assert(err, IsNil)

	c.Assert(outKeyPair, DeepEquals, keyPair)
}