예제 #1
0
func decrypt(ciphertext, keyBytes []byte) ([]byte, error) {
	privateKey, err := bletchley.PEMToPrivateKey(keyBytes)
	if err != nil {
		return []byte{}, err
	}

	var encrypted bletchley.EncryptedMessage
	err = json.Unmarshal(ciphertext, &encrypted)
	if err != nil {
		return []byte{}, fmt.Errorf("Expected JSON input: " + err.Error())
	}

	return bletchley.Decrypt(privateKey, encrypted)
}
예제 #2
0
var _ = Describe("Serialization of asymmetric keys", func() {
	var privateKey *rsa.PrivateKey

	BeforeEach(func() {
		nbits := 256
		var err error
		privateKey, err = rsa.GenerateKey(rand.Reader, nbits)
		Expect(err).To(BeNil())
	})

	Describe("private keys", func() {
		It("should serialize and deserialize losslessly", func() {
			pemBytes := bletchley.PrivateKeyToPEM(privateKey)

			Expect(bletchley.PEMToPrivateKey(pemBytes)).To(Equal(privateKey))
		})
	})

	Describe("public keys", func() {
		It("should serialize and deserialize losslessly", func() {
			publicKey := privateKey.Public().(*rsa.PublicKey)

			pemBytes, err := bletchley.PublicKeyToPEM(publicKey)
			Expect(err).NotTo(HaveOccurred())

			Expect(bletchley.PEMToPublicKey(pemBytes)).To(Equal(publicKey))
		})
	})
})
예제 #3
0
			Number int
			Hosts  map[string]string
		}
		session = run("describe", "-name", classroomName, "-format", "json")
		Eventually(session, 10).Should(gexec.Exit(0))
		Expect(json.Unmarshal(session.Out.Contents(), &info)).To(Succeed())
		Expect(info.Status).To(Equal("CREATE_IN_PROGRESS"))
		Expect(info.Number).To(Equal(instanceCount))

		resp, err := http.Get(info.SSHKey)
		Expect(err).NotTo(HaveOccurred())
		Expect(resp.StatusCode).To(Equal(http.StatusOK))
		Expect(resp.Header["Content-Type"]).To(Equal([]string{"application/x-pem-file"}))
		keyPEM, err := ioutil.ReadAll(resp.Body)
		Expect(err).NotTo(HaveOccurred())
		sshPrivateKey, err := bletchley.PEMToPrivateKey(keyPEM)
		Expect(err).NotTo(HaveOccurred())
		Expect(sshPrivateKey).NotTo(BeNil())

		Eventually(func() []byte {
			session = run("describe", "-name", classroomName, "-format", "plain")
			Eventually(session, "10s").Should(gexec.Exit(0))
			return session.Out.Contents()
		}, "10m", "10s").Should(ContainSubstring("status: CREATE_COMPLETE"))

		session = run("describe", "-name", classroomName)
		Eventually(session, "10s").Should(gexec.Exit(0))
		Expect(json.Unmarshal(session.Out.Contents(), &info)).To(Succeed())
		Expect(info.Status).To(Equal("CREATE_COMPLETE"))
		Expect(info.Hosts).To(HaveLen(instanceCount))
		for _, state := range info.Hosts {