Esempio n. 1
0
// TestNewSessionFailures validates some of the failure modes for NewSession.
func TestNewSessionFailures(t *testing.T) {
	r := util.PRNG()
	b := &bytes.Buffer{}
	util.SetPRNG(b)

	if _, _, err := NewSession(peer); err == nil {
		util.SetPRNG(r)
		t.Fatal("auth: expected new session failure with PRNG failure")
	}

	tmp := make([]byte, sessionLength)
	b.Write(tmp)

	if _, _, err := NewSession(peer); err == nil {
		util.SetPRNG(r)
		t.Fatal("auth: expected new session failure with PRNG failure")
	}
	util.SetPRNG(r)

	tmp = make([]byte, 16)
	if _, _, err := NewSession(tmp); err == nil {
		t.Fatal("auth: expected new session failure with invalid public key")
	}

}
Esempio n. 2
0
// TestTOTPPRNGFailure validates failures when the PRNG fails.
func TestTOTPPRNGFailure(t *testing.T) {
	oldPRNG := util.PRNG()
	util.SetPRNG(&bytes.Buffer{})

	_, _, err := NewGoogleTOTP("")
	if err == nil {
		t.Fatal("auth: expect TOTP generation failure in the face of a PRNG failure")
	}

	util.SetPRNG(oldPRNG)
}
Esempio n. 3
0
// GenerateKey creates a new set of encryption and signature keys
// using the operating system's random number generator.
func GenerateKey() (*PrivateKey, error) {
	var priv PrivateKey
	var err error
	prng := util.PRNG()

	priv.PublicKey = &PublicKey{}
	priv.E, priv.D, err = box.GenerateKey(prng)
	if err != nil {
		return nil, err
	}

	priv.V, priv.S, err = ed25519.GenerateKey(prng)
	if err != nil {
		return nil, err
	}

	return &priv, nil
}
Esempio n. 4
0
// encrypt the message without encoding it
func testEncryptBare(pub *PublicKey, message []byte) (out []byte, ok bool) {
	if !pub.Valid() {
		return nil, false
	}

	prng := util.PRNG()
	epub, epriv, err := box.GenerateKey(prng)
	if err != nil {
		return nil, false
	}

	out = epub[:]
	nonce := util.NewNonce()
	out = append(out, nonce[:]...)

	out = box.Seal(out, message, nonce, pub.E, epriv)
	ok = true
	return
}
Esempio n. 5
0
// write the message two times to PT
func testEncryptTwo(pub *PublicKey, message []byte) (out []byte, ok bool) {
	if !pub.Valid() {
		return nil, false
	}

	prng := util.PRNG()
	epub, epriv, err := box.GenerateKey(prng)
	if err != nil {
		return nil, false
	}

	enc := &tlv.Encoder{}
	enc.Encode(message)
	enc.Encode(message)

	out = epub[:]
	nonce := util.NewNonce()
	out = append(out, nonce[:]...)

	out = box.Seal(out, enc.Bytes(), nonce, pub.E, epriv)
	ok = true
	return
}