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.

51 lines
1.8 KiB

  1. package applications
  2. import (
  3. "cwtch.im/tapir"
  4. "cwtch.im/tapir/primitives/core"
  5. "git.openprivacy.ca/openprivacy/log"
  6. )
  7. // TranscriptApp defines a Tapir Meta-App which provides a global cryptographic transcript
  8. type TranscriptApp struct {
  9. transcript *core.Transcript
  10. }
  11. // NewInstance creates a new TranscriptApp
  12. func (TranscriptApp) NewInstance() tapir.Application {
  13. ta := new(TranscriptApp)
  14. return ta
  15. }
  16. // Init initializes the cryptographic transcript
  17. func (ta *TranscriptApp) Init(connection tapir.Connection) {
  18. if ta.transcript != nil {
  19. ta.panic()
  20. }
  21. ta.transcript = core.NewTranscript("tapir-transcript")
  22. }
  23. // Transcript returns a pointer to the cryptographic transcript
  24. func (ta *TranscriptApp) Transcript() *core.Transcript {
  25. return ta.transcript
  26. }
  27. // PropagateTranscript overrides the default transcript and propagates a transcript from a previous session
  28. func (ta *TranscriptApp) PropagateTranscript(transcript *core.Transcript) {
  29. if ta.transcript != nil {
  30. ta.panic()
  31. }
  32. ta.transcript = transcript
  33. }
  34. func (ta *TranscriptApp) panic() {
  35. // Note: if this is ever happens it is a critical application bug
  36. // This will prevent a misuse of application chains that cause an earlier
  37. // transcript to be overwritten. Since we expect the security of many higher level applications
  38. // to be reliant on the randomness provided by the transcript we want to be actively hostile to any potential
  39. // misuse.
  40. log.Errorf("apps should not attempt to intitalize or overwrite a transcript once one has been initialized - this is a CRITICAL bug and so we have safely crashed")
  41. // We could silently fail to do anything here, but that is likely more dangerous in the long run...
  42. panic("apps should not attempt to intitalize or overwrite a transcript a transcript once one has been initialized - this is a CRITICAL bug and so we have safely crashed")
  43. }