Exemplo n.º 1
0
func loadCrypter(optCrypter string) dkeyczar.Crypter {
	if optCrypter == "" {
		return nil
	}

	//fmt.Println("using crypter:", optCrypter)
	r := dkeyczar.NewFileReader(optCrypter)
	crypter, err := dkeyczar.NewCrypter(r)
	if err != nil {
		panic(fmt.Sprintf("failed to load crypter: %s", err))
		//return nil
	}
	return crypter
}
Exemplo n.º 2
0
func loadReader(optLocation string, crypter dkeyczar.Crypter) dkeyczar.KeyReader {
	if optLocation == "" {
		panic("missing required location argument")
		//return nil
	}

	lr := dkeyczar.NewFileReader(optLocation)

	if crypter != nil {
		//fmt.Println("decrypting keys..")
		lr = dkeyczar.NewEncryptedReader(lr, crypter)
	}

	return lr
}
Exemplo n.º 3
0
func writeVerifyTest(dir string) {

	fulldir := TESTDATA + dir

	r := dkeyczar.NewFileReader(fulldir)

	signer, _ := dkeyczar.NewSigner(r)

	signature, _ := signer.Sign([]byte(PLAINTEXT))

	fmt.Println(`
check_verify(readers.FileReader("` + fulldir + `"),
    "` + dir + `",
    "` + PLAINTEXT + `",
    "` + signature + `",
)`)

	attachedSig, _ := signer.AttachedSign([]byte(PLAINTEXT), []byte{0, 1, 2, 3, 4, 5, 6, 7})

	fmt.Println(`
check_attached_verify(readers.FileReader("` + fulldir + `"),
    "` + dir + `",
    "` + PLAINTEXT + `",
    "` + attachedSig + `",
    "\x00\x01\x02\x03\x04\x05\x06\x07",
)`)

	attachedSig, _ = signer.AttachedSign([]byte(PLAINTEXT), nil)

	fmt.Println(`
check_attached_verify(readers.FileReader("` + fulldir + `"),
    "` + dir + `",
    "` + PLAINTEXT + `",
    "` + attachedSig + `",
    None
)`)

	unversionedSig, _ := signer.UnversionedSign([]byte(PLAINTEXT))

	fmt.Println(`
check_unversioned_verify(readers.FileReader("` + fulldir + `"),
    "` + dir + `",
    "` + PLAINTEXT + `",
    "` + unversionedSig + `",
)`)

}
Exemplo n.º 4
0
func writeDecryptTest(dir string) {

	fulldir := TESTDATA + dir

	r := dkeyczar.NewFileReader(fulldir)
	crypter, _ := dkeyczar.NewCrypter(r)

	ciphertext, _ := crypter.Encrypt([]byte(PLAINTEXT))
	fmt.Println(`
check_decrypt(readers.FileReader("` + fulldir + `"),
    "` + dir + `",
    "` + PLAINTEXT + `",
    "` + ciphertext + `",
)
`)

}
Exemplo n.º 5
0
func writeKeyczartTest(dir string) {

	fulldir := TESTDATA + dir

	km := dkeyczar.NewKeyManager()

	r := dkeyczar.NewFileReader(fulldir)

	km.Load(r)

	json := km.ToJSONs(nil)

	fmt.Println(`

meta = """` + json[0] + `"""
keys={`)

	for i := 1; i < len(json); i++ {
		fmt.Println("    " + strconv.Itoa(i) + `: """` + json[i] + `""",`)
	}
	fmt.Println(`}
r = JSONReader(meta, keys)`)
	signer, _ := dkeyczar.NewSigner(r)
	if signer != nil {

		signature, _ := signer.Sign([]byte(PLAINTEXT))

		fmt.Println(
			`check_verify(r,
        "json ` + dir + `",
        "` + PLAINTEXT + `",
        "` + signature + `",
)`)
	} else {
		crypter, _ := dkeyczar.NewCrypter(r)

		ciphertext, _ := crypter.Encrypt([]byte(PLAINTEXT))
		fmt.Println(
			`check_decrypt(r,
    "json ` + dir + `",
    "` + PLAINTEXT + `",
    "` + ciphertext + `",
)`)
	}

}
Exemplo n.º 6
0
func loadLocationReader(km dkeyczar.KeyManager, location string, crypter dkeyczar.Crypter) error {
	if location == "" {
		panic("missing required location argument")
	}

	lr := dkeyczar.NewFileReader(location)

	if crypter != nil {
		//fmt.Println("decrypting keys..")
		lr = dkeyczar.NewEncryptedReader(lr, crypter)
	}

	err := km.Load(lr)
	if err != nil {
		return fmt.Errorf("failed to load key: %s", err)
	}
	return nil
}
Exemplo n.º 7
0
func loadLocationReader(km dkeyczar.KeyManager, optLocation string, crypter dkeyczar.Crypter) bool {
	if optLocation == "" {
		fmt.Println("missing required --location argument")
		return false
	}

	lr := dkeyczar.NewFileReader(optLocation)

	if crypter != nil {
		fmt.Println("decrypting keys..")
		lr = dkeyczar.NewEncryptedReader(lr, crypter)
	}

	err := km.Load(lr)
	if err != nil {
		fmt.Println("failed to load key:", err)
		return false
	}
	return true
}