Exemple #1
0
func ReadSignature(c *cli.Context) {
	sigEncoded := c.String("signature")
	metaEncoded := c.String("metadata")

	if sigEncoded == "" || metaEncoded == "" {
		cli.ShowCommandHelp(c, "read")
		os.Exit(1)
	}

	crypto, err := common.CreateCrypto(c)
	if err != nil {
		os.Exit(1)
	}

	signature, err := route_service.SignatureFromHeaders(sigEncoded, metaEncoded, crypto)

	if err != nil {
		fmt.Printf("Failed to read signature: %s\n", err.Error())
		os.Exit(1)
	}

	printSignature(signature)
}
Exemple #2
0
			metadataStruct := route_service.Metadata{}
			err = json.Unmarshal([]byte(metadataDecoded), &metadataStruct)
			Expect(err).ToNot(HaveOccurred())
			Expect(metadataStruct.Nonce).To(Equal([]byte("some-nonce")))
			Expect(metadataStruct.IV).To(Equal([]byte("some-iv")))
		})

		Context("when unable to encrypt the signature", func() {
			BeforeEach(func() {
				crypto.EncryptReturns([]byte{}, []byte{}, []byte{}, errors.New("No entropy"))
			})

			It("returns an error", func() {
				_, _, err := route_service.BuildSignatureAndMetadata(crypto, signature)
				Expect(err).To(HaveOccurred())
			})
		})
	})

	Describe("Parse signature from headers", func() {
		It("parses signature from signature and metadata headers", func() {
			signatureHeader := "eyJyZXF1ZXN0ZWRfdGltZSI6IjIwMTUtMDctMjNUMTA6NDg6MDguMjQwMDMwNzIyLTA3OjAwIn1lbmNyeXB0ZWRzb21lLW5vbmNlc29tZS1pdg=="
			metadataHeader := "eyJpdiI6ImMyOXRaUzFwZGc9PSIsIm5vbmNlIjoiYzI5dFpTMXViMjVqWlE9PSJ9"
			signature, err := route_service.SignatureFromHeaders(signatureHeader, metadataHeader, crypto)
			Expect(err).ToNot(HaveOccurred())
			Expect(signature.RequestedTime.Sub(time.Unix(1437673688, 240030722))).To(Equal(time.Duration(0)))
		})
	})

})