Tapir provides a framework for building Anonymous / metadata resistant Services
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

auth_test.go 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package applications
  2. import (
  3. "crypto/rand"
  4. "cwtch.im/tapir/primitives"
  5. "encoding/json"
  6. "golang.org/x/crypto/ed25519"
  7. "testing"
  8. )
  9. type MockConnection struct {
  10. id primitives.Identity
  11. outbound bool
  12. }
  13. func (mc *MockConnection) Init(outbound bool) {
  14. mc.id, _ = primitives.InitializeEphemeral()
  15. mc.outbound = outbound
  16. return
  17. }
  18. func (MockConnection) Hostname() string {
  19. panic("implement me")
  20. }
  21. func (mc MockConnection) IsOutbound() bool {
  22. return mc.outbound
  23. }
  24. func (mc MockConnection) ID() *primitives.Identity {
  25. return &mc.id
  26. }
  27. func (mc MockConnection) Expect() []byte {
  28. longTermPubKey := ed25519.PublicKey(mc.id.PublicKeyBytes())
  29. epk, _, _ := ed25519.GenerateKey(rand.Reader)
  30. ephemeralPublicKey := ed25519.PublicKey(epk)
  31. //ephemeralPrivateKey := ed25519.PrivateKey(esk)
  32. //ephemeralIdentity := identity.InitializeV3("", &ephemeralPrivateKey, &ephemeralPublicKey)
  33. authMessage := AuthMessage{LongTermPublicKey: longTermPubKey, EphemeralPublicKey: ephemeralPublicKey}
  34. serialized, _ := json.Marshal(authMessage)
  35. return serialized
  36. }
  37. func (MockConnection) SetHostname(hostname string) {
  38. panic("implement me")
  39. }
  40. func (MockConnection) HasCapability(name string) bool {
  41. panic("implement me")
  42. }
  43. func (MockConnection) SetCapability(name string) {
  44. panic("implement me")
  45. }
  46. func (MockConnection) SetEncryptionKey(key [32]byte) {
  47. // no op
  48. }
  49. func (MockConnection) Send(message []byte) {
  50. // no op
  51. }
  52. func (MockConnection) Close() {
  53. // no op
  54. }
  55. func (MockConnection) IsClosed() bool {
  56. panic("implement me")
  57. }
  58. func TestAuthApp_Failed(t *testing.T) {
  59. var authApp AuthApp
  60. ai := authApp.NewInstance()
  61. mc := new(MockConnection)
  62. mc.Init(true)
  63. ai.Init(mc)
  64. }