Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Sumner Evans <[email protected]>
  • Loading branch information
sumnerevans committed Nov 18, 2024
1 parent 9609bad commit eb2fb7f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions crypto/goolm/account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion crypto/goolm/cipher/pickle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions crypto/sql_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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
}
Expand Down

0 comments on commit eb2fb7f

Please sign in to comment.