verificationhelper: add function to dismiss verification request without cancelling it
Some checks are pending
Go / Lint (latest) (push) Waiting to run
Go / Build (old, libolm) (push) Waiting to run
Go / Build (latest, libolm) (push) Waiting to run
Go / Build (old, goolm) (push) Waiting to run
Go / Build (latest, goolm) (push) Waiting to run

Signed-off-by: Sumner Evans <sumner.evans@automattic.com>
This commit is contained in:
Sumner Evans 2024-08-15 10:04:11 -06:00
commit d40aa8c7c6
No known key found for this signature in database
4 changed files with 49 additions and 9 deletions

View file

@ -35,16 +35,37 @@ type CryptoHelper interface {
}
type VerificationHelper interface {
// Init initializes the helper. This should be called before any other
// methods.
Init(context.Context) error
// StartVerification starts an interactive verification flow with the given
// user via a to-device event.
StartVerification(ctx context.Context, to id.UserID) (id.VerificationTransactionID, error)
// StartInRoomVerification starts an interactive verification flow with the
// given user in the given room.
StartInRoomVerification(ctx context.Context, roomID id.RoomID, to id.UserID) (id.VerificationTransactionID, error)
// AcceptVerification accepts a verification request.
AcceptVerification(ctx context.Context, txnID id.VerificationTransactionID) error
// DismissVerification dismisses a verification request. This will not send
// a cancellation to the other device. This method should only be called
// *before* the request has been accepted and will error otherwise.
DismissVerification(ctx context.Context, txnID id.VerificationTransactionID) error
// CancelVerification cancels a verification request. This method should
// only be called *after* the request has been accepted, although it will
// not error if called beforehand.
CancelVerification(ctx context.Context, txnID id.VerificationTransactionID, code event.VerificationCancelCode, reason string) error
// HandleScannedQRData handles the data from a QR code scan.
HandleScannedQRData(ctx context.Context, data []byte) error
// ConfirmQRCodeScanned confirms that our QR code has been scanned.
ConfirmQRCodeScanned(ctx context.Context, txnID id.VerificationTransactionID) error
// StartSAS starts a SAS verification flow.
StartSAS(ctx context.Context, txnID id.VerificationTransactionID) error
// ConfirmSAS indicates that the user has confirmed that the SAS matches
// SAS shown on the other user's device.
ConfirmSAS(ctx context.Context, txnID id.VerificationTransactionID) error
}

View file

@ -183,8 +183,11 @@ func (vh *VerificationHelper) HandleScannedQRData(ctx context.Context, data []by
return nil
}
// ConfirmQRCodeScanned confirms that our QR code has been scanned and sends the
// m.key.verification.done event to the other device.
// ConfirmQRCodeScanned confirms that our QR code has been scanned and sends
// the m.key.verification.done event to the other device for the given
// transaction ID. The transaction ID should be one received via the
// VerificationRequested callback in [RequiredCallbacks] or the
// [StartVerification] or [StartInRoomVerification] functions.
func (vh *VerificationHelper) ConfirmQRCodeScanned(ctx context.Context, txnID id.VerificationTransactionID) error {
log := vh.getLog(ctx).With().
Str("verification_action", "confirm QR code scanned").

View file

@ -28,9 +28,10 @@ import (
"maunium.net/go/mautrix/id"
)
// StartSAS starts a SAS verification flow. The transaction ID should be the
// transaction ID of a verification request that was received via the
// VerificationRequested callback in [RequiredCallbacks].
// StartSAS starts a SAS verification flow for the given transaction ID. The
// transaction ID should be one received via the VerificationRequested callback
// in [RequiredCallbacks] or the [StartVerification] or
// [StartInRoomVerification] functions.
func (vh *VerificationHelper) StartSAS(ctx context.Context, txnID id.VerificationTransactionID) error {
log := vh.getLog(ctx).With().
Str("verification_action", "accept verification").
@ -81,7 +82,10 @@ func (vh *VerificationHelper) StartSAS(ctx context.Context, txnID id.Verificatio
}
// ConfirmSAS indicates that the user has confirmed that the SAS matches SAS
// shown on the other user's device.
// shown on the other user's device for the given transaction ID. The
// transaction ID should be one received via the VerificationRequested callback
// in [RequiredCallbacks] or the [StartVerification] or
// [StartInRoomVerification] functions.
func (vh *VerificationHelper) ConfirmSAS(ctx context.Context, txnID id.VerificationTransactionID) error {
log := vh.getLog(ctx).With().
Str("verification_action", "confirm SAS").

View file

@ -482,9 +482,21 @@ func (vh *VerificationHelper) AcceptVerification(ctx context.Context, txnID id.V
return vh.generateAndShowQRCode(ctx, txn)
}
// CancelVerification cancels a verification request. The transaction ID should
// be the transaction ID of a verification request that was received via the
// VerificationRequested callback in [RequiredCallbacks].
// DismissVerification dismisses the verification request with the given
// transaction ID. The transaction ID should be one received via the
// VerificationRequested callback in [RequiredCallbacks] or the
// [StartVerification] or [StartInRoomVerification] functions.
func (vh *VerificationHelper) DismissVerification(ctx context.Context, txnID id.VerificationTransactionID) error {
vh.activeTransactionsLock.Lock()
defer vh.activeTransactionsLock.Unlock()
delete(vh.activeTransactions, txnID)
return nil
}
// DismissVerification cancels the verification request with the given
// transaction ID. The transaction ID should be one received via the
// VerificationRequested callback in [RequiredCallbacks] or the
// [StartVerification] or [StartInRoomVerification] functions.
func (vh *VerificationHelper) CancelVerification(ctx context.Context, txnID id.VerificationTransactionID, code event.VerificationCancelCode, reason string) error {
vh.activeTransactionsLock.Lock()
defer vh.activeTransactionsLock.Unlock()