taler-mailbox

Service for asynchronous wallet-to-wallet payment messages
Log | Files | Refs | Submodules | README | LICENSE

commit f318f3cf0b32e7cae1283bf3c968fbf330a7c8bd
parent ab142d76a6d9abac30260a6ee19fb89a7a0b4f33
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date:   Thu,  6 Nov 2025 11:17:39 +0100

use relative time and duration

Diffstat:
Mcmd/mailbox-server/main_test.go | 4++--
Mpkg/rest/mailbox.go | 114++++++++++++++++++++++++++++++++++++++++++-------------------------------------
2 files changed, 63 insertions(+), 55 deletions(-)

diff --git a/cmd/mailbox-server/main_test.go b/cmd/mailbox-server/main_test.go @@ -166,11 +166,11 @@ func TestPostKeys(t *testing.T) { aliceSigningKey := util.Base32CrockfordEncode(testAliceSigningKey) msg.Keys.EncryptionKey = util.Base32CrockfordEncode(encKey) msg.Keys.EncryptionKeyType = "X25519" - msg.Keys.Expiration = uint64(time.Now().UnixMicro()) + msg.Keys.Expiration = mailbox.Timestamp{T_s: uint64(time.Now().UnixMicro())} msg.Keys.SigningKey = aliceSigningKey msg.Keys.SigningKeyType = "EdDSA" expNbo := make([]byte, 8) - binary.BigEndian.PutUint64(expNbo, msg.Keys.Expiration) + binary.BigEndian.PutUint64(expNbo, msg.Keys.Expiration.T_s) h := sha512.New() h.Write([]byte(msg.Keys.EncryptionKeyType)) h.Write(encKey) diff --git a/pkg/rest/mailbox.go b/pkg/rest/mailbox.go @@ -119,6 +119,14 @@ type Mailbox struct { Logger *log.Logger } +type RelativeTime struct { + D_us uint64 `json:"d_us"` +} + +type Timestamp struct { + T_s uint64 `json:"t_s"` +} + // VersionResponse is the JSON response of the /config endpoint type VersionResponse struct { // libtool-style representation of the Mailbox protocol version, see @@ -137,13 +145,63 @@ type VersionResponse struct { // How long will the service store a message // before giving up - DeliveryPeriod uint64 `json:"delivery_period"` + DeliveryPeriod RelativeTime `json:"delivery_period" gorm:"embedded;embeddedPrefix:delivery_period_"` // How many messages will a single response // contain at maximum. MessageResponseLimit uint64 `json:"message_response_limit"` } +type MailboxMessageKeys struct { + // ORM + gorm.Model `json:"-"` + + // ORM helper hash of signing key + HashedSigningKey string `json:"-"` + + // The mailbox signing key. + // Note that $H_MAILBOX == H(singingKey). + // Note also how this key cannot be updated + // as it identifies the mailbox. + SigningKey string `json:"signingKey"` + + // Type of key. + // Optional, as currently only + // EdDSA keys are supported. + SigningKeyType string `json:"signingKeyType"` + + // The mailbox encryption key. + // This is an HPKE public key + // in the X25519 format for use + // in a X25519-DHKEM (RFC 9180). + // Base32 crockford-encoded. + EncryptionKey string `json:"encryptionKey"` + + // Type of key. + // Optional, as currently only + // X25519 keys are supported. + EncryptionKeyType string `json:"encryptionKeyType"` + + // Expiration of this mapping. + Expiration Timestamp `json:"expiration" gorm:"embedded;embeddedPrefix:expiration_"` +} + +type KeyUpdateRequest struct { + // ORM + gorm.Model `json:"-"` + + // Keys to add/update for a mailbox. + Keys MailboxMessageKeys `json:"keys"` + + // Signature by the mailbox's signing key affirming + // the update of keys, of purpuse + // TALER_SIGNATURE_WALLET_MAILBOX_KEYS_UPDATE. + // The signature is created over the SHA-512 hash + // of (encryptionKeyType||encryptionKey||expiration) + Signature string `json:"signature"` +} + + // MessageDeletionRequest is used to request the deletion of already received // messages from the mailbox. type MessageDeletionRequest struct { @@ -191,14 +249,13 @@ func (m *Mailbox) configResponse(w http.ResponseWriter, r *http.Request) { if err != nil { log.Fatal(err) } - cfg := VersionResponse{ Version: m.Cfg.LibtoolVersion, Name: "taler-mailbox", MessageBodyBytes: m.MessageBodyBytes, MessageResponseLimit: m.MessageResponseLimit, MessageFee: m.MessageFee.String(), - DeliveryPeriod: uint64(dp.Microseconds()), + DeliveryPeriod: RelativeTime{D_us: uint64(dp.Microseconds())}, } w.Header().Set("Content-Type", "application/json") response, _ := json.Marshal(cfg) @@ -315,55 +372,6 @@ func (m *Mailbox) sendMessageResponse(w http.ResponseWriter, r *http.Request) { } } -type MailboxMessageKeys struct { - // ORM - gorm.Model `json:"-"` - - // ORM helper hash of signing key - HashedSigningKey string `json:"-"` - - // The mailbox signing key. - // Note that $H_MAILBOX == H(singingKey). - // Note also how this key cannot be updated - // as it identifies the mailbox. - SigningKey string `json:"signingKey"` - - // Type of key. - // Optional, as currently only - // EdDSA keys are supported. - SigningKeyType string `json:"signingKeyType"` - - // The mailbox encryption key. - // This is an HPKE public key - // in the X25519 format for use - // in a X25519-DHKEM (RFC 9180). - // Base32 crockford-encoded. - EncryptionKey string `json:"encryptionKey"` - - // Type of key. - // Optional, as currently only - // X25519 keys are supported. - EncryptionKeyType string `json:"encryptionKeyType"` - - // Expiration of this mapping. - Expiration uint64 `json:"expiration"` -} - -type KeyUpdateRequest struct { - // ORM - gorm.Model `json:"-"` - - // Keys to add/update for a mailbox. - Keys MailboxMessageKeys `json:"keys"` - - // Signature by the mailbox's signing key affirming - // the update of keys, of purpuse - // TALER_SIGNATURE_WALLET_MAILBOX_KEYS_UPDATE. - // The signature is created over the SHA-512 hash - // of (encryptionKeyType||encryptionKey||expiration) - Signature string `json:"signature"` -} - func (m *Mailbox) getKeysResponse(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) var keyEntry MailboxMessageKeys @@ -409,7 +417,7 @@ func (m *Mailbox) updateKeysResponse(w http.ResponseWriter, r *http.Request) { } var expNbo [8]byte var signed_msg [72]byte - binary.BigEndian.PutUint64(expNbo[:], msg.Keys.Expiration) + binary.BigEndian.PutUint64(expNbo[:], msg.Keys.Expiration.T_s) size := signed_msg[0:4] binary.BigEndian.PutUint32(size, 64+4+4) purp := signed_msg[4:8]