From eb2fb7f256540ee59592b54793358c6652829427 Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Sun, 17 Nov 2024 19:55:07 -0700 Subject: [PATCH] wip Signed-off-by: Sumner Evans --- crypto/goolm/account/account.go | 2 ++ crypto/goolm/cipher/pickle.go | 2 +- crypto/sql_store.go | 6 ++++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/crypto/goolm/account/account.go b/crypto/goolm/account/account.go index 099cc493..d32e5760 100644 --- a/crypto/goolm/account/account.go +++ b/crypto/goolm/account/account.go @@ -338,8 +338,10 @@ func (a *Account) UnpickleLibOlm(buf []byte) error { } else if pickledVersion != accountPickleVersionLibOLM && pickledVersion != 3 && pickledVersion != 2 { return fmt.Errorf("unpickle account: %w (found version %d)", olm.ErrBadVersion, pickledVersion) } else if err = a.IdKeys.Ed25519.UnpickleLibOlm(decoder); err != nil { // read the ed25519 key pair + fmt.Printf("123 %+v\n", err) return err } else if err = a.IdKeys.Curve25519.UnpickleLibOlm(decoder); err != nil { // read curve25519 key pair + fmt.Printf("456 %+v\n", err) return err } diff --git a/crypto/goolm/cipher/pickle.go b/crypto/goolm/cipher/pickle.go index 754c7963..6ca65e77 100644 --- a/crypto/goolm/cipher/pickle.go +++ b/crypto/goolm/cipher/pickle.go @@ -35,11 +35,11 @@ func Pickle(key, input []byte) ([]byte, error) { // Unpickle decodes the input from base64 and decrypts the decoded input with the key and the cipher AESSHA256. func Unpickle(key, input []byte) ([]byte, error) { - pickleCipher := NewAESSHA256([]byte(kdfPickle)) ciphertext, err := goolmbase64.Decode(input) if err != nil { return nil, err } + pickleCipher := NewAESSHA256([]byte(kdfPickle)) //remove mac and check verified, err := pickleCipher.Verify(key, ciphertext[:len(ciphertext)-pickleMACLength], ciphertext[len(ciphertext)-pickleMACLength:]) if err != nil { diff --git a/crypto/sql_store.go b/crypto/sql_store.go index fa929a38..c41903c3 100644 --- a/crypto/sql_store.go +++ b/crypto/sql_store.go @@ -22,6 +22,7 @@ import ( "go.mau.fi/util/dbutil" "maunium.net/go/mautrix" + "maunium.net/go/mautrix/crypto/goolm/account" "maunium.net/go/mautrix/crypto/goolm/cipher" "maunium.net/go/mautrix/crypto/olm" "maunium.net/go/mautrix/crypto/sql_store_upgrade" @@ -154,7 +155,7 @@ func (store *SQLCryptoStore) GetAccount(ctx context.Context) (*OlmAccount, error row := store.DB.QueryRow(ctx, "SELECT shared, sync_token, account, key_backup_version FROM crypto_account WHERE account_id=$1", store.AccountID) acc := &OlmAccount{ InternalLibolm: olm.NewBlankAccount(), - InternalGoolm: olm.NewBlankAccount(), + InternalGoolm: &account.Account{}, } var accountBytes []byte err := row.Scan(&acc.Shared, &store.SyncToken, &accountBytes, &acc.KeyBackupVersion) @@ -167,9 +168,10 @@ func (store *SQLCryptoStore) GetAccount(ctx context.Context) (*OlmAccount, error if err != nil { return nil, err } + fmt.Printf("%s\n", accountBytes) err = acc.InternalGoolm.Unpickle(accountBytes, store.PickleKey) if err != nil { - panic("failed to unpickle account using goolm") + panic(fmt.Sprintf("failed to unpickle account using goolm: %+v", err)) } store.Account = acc }