84 lines
1.8 KiB
Go
84 lines
1.8 KiB
Go
|
package applications
|
||
|
|
||
|
import (
|
||
|
"crypto/rand"
|
||
|
"encoding/json"
|
||
|
"git.openprivacy.ca/openprivacy/libricochet-go/identity"
|
||
|
"golang.org/x/crypto/ed25519"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
type MockConnection struct {
|
||
|
id identity.Identity
|
||
|
outbound bool
|
||
|
}
|
||
|
|
||
|
func (mc *MockConnection) Init(outbound bool) {
|
||
|
pubkey, privateKey, _ := ed25519.GenerateKey(rand.Reader)
|
||
|
sk := ed25519.PrivateKey(privateKey)
|
||
|
pk := ed25519.PublicKey(pubkey)
|
||
|
mc.id = identity.InitializeV3("", &sk, &pk)
|
||
|
mc.outbound = outbound
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func (MockConnection) Hostname() string {
|
||
|
panic("implement me")
|
||
|
}
|
||
|
|
||
|
func (mc MockConnection) IsOutbound() bool {
|
||
|
return mc.outbound
|
||
|
}
|
||
|
|
||
|
func (mc MockConnection) ID() *identity.Identity {
|
||
|
return &mc.id
|
||
|
}
|
||
|
|
||
|
func (mc MockConnection) Expect() []byte {
|
||
|
longTermPubKey := ed25519.PublicKey(mc.id.PublicKeyBytes())
|
||
|
epk, _, _ := ed25519.GenerateKey(rand.Reader)
|
||
|
ephemeralPublicKey := ed25519.PublicKey(epk)
|
||
|
//ephemeralPrivateKey := ed25519.PrivateKey(esk)
|
||
|
//ephemeralIdentity := identity.InitializeV3("", &ephemeralPrivateKey, &ephemeralPublicKey)
|
||
|
authMessage := AuthMessage{LongTermPublicKey: longTermPubKey, EphemeralPublicKey: ephemeralPublicKey}
|
||
|
serialized, _ := json.Marshal(authMessage)
|
||
|
return serialized
|
||
|
}
|
||
|
|
||
|
func (MockConnection) SetHostname(hostname string) {
|
||
|
panic("implement me")
|
||
|
}
|
||
|
|
||
|
func (MockConnection) HasCapability(name string) bool {
|
||
|
panic("implement me")
|
||
|
}
|
||
|
|
||
|
func (MockConnection) SetCapability(name string) {
|
||
|
panic("implement me")
|
||
|
}
|
||
|
|
||
|
func (MockConnection) SetEncryptionKey(key [32]byte) {
|
||
|
// no op
|
||
|
}
|
||
|
|
||
|
func (MockConnection) Send(message []byte) {
|
||
|
// no op
|
||
|
}
|
||
|
|
||
|
func (MockConnection) Close() {
|
||
|
// no op
|
||
|
}
|
||
|
|
||
|
func (MockConnection) IsClosed() bool {
|
||
|
panic("implement me")
|
||
|
}
|
||
|
|
||
|
func TestAuthApp_Failed(t *testing.T) {
|
||
|
var authApp AuthApp
|
||
|
ai := authApp.NewInstance()
|
||
|
|
||
|
mc := new(MockConnection)
|
||
|
mc.Init(true)
|
||
|
ai.Init(mc)
|
||
|
}
|