-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: do not require unlock password to recover encrypted scb (#768)
* feat: do not require unlock password to recover encrypted scb * fix: use seed as key to encrypt static channel backup * chore: move encrypted channel backup derivation to alby oauth service * chore: add extra test * chore: reduce duplicated code * fix: change key derivation paths * chore: simplify backup page copy for connected alby accounts * chore: improve copy * fix: initialize keys before starting ln backend * chore: improve test assertions
- Loading branch information
Showing
34 changed files
with
417 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package alby | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/getAlby/hub/config" | ||
"github.com/getAlby/hub/events" | ||
"github.com/getAlby/hub/tests" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"github.com/tyler-smith/go-bip32" | ||
"github.com/tyler-smith/go-bip39" | ||
) | ||
|
||
func TestExistingEncryptedBackup(t *testing.T) { | ||
defer tests.RemoveTestService() | ||
svc, err := tests.CreateTestService() | ||
require.NoError(t, err) | ||
|
||
mnemonic := "limit reward expect search tissue call visa fit thank cream brave jump" | ||
unlockPassword := "123" | ||
svc.Cfg.SetUpdate("Mnemonic", mnemonic, unlockPassword) | ||
err = svc.Keys.Init(svc.Cfg, unlockPassword) | ||
assert.NoError(t, err) | ||
|
||
encryptedBackup := "3fd21f9a393d8345ddbdd449-ba05c3dbafdfb7eea574373b7763d0c81c599b2cd1735e59a1c5571379498f4da8fe834c3403824ab02b61005abc1f563c638f425c65420e82941efe94794555c8b145a0603733ee115277f860011e6a17fd8c22f1d73a096ff7275582aac19b430940b40a2559c7ff59a063305290ef7c9ba46f9de17b0ddbac9030b0" | ||
|
||
masterKey, err := bip32.NewMasterKey(bip39.NewSeed(mnemonic, "")) | ||
assert.NoError(t, err) | ||
|
||
appKey, err := masterKey.NewChildKey(bip32.FirstHardenedChild + 128029 /* 🐝 */) | ||
assert.NoError(t, err) | ||
encryptedChannelsBackupKey, err := appKey.NewChildKey(bip32.FirstHardenedChild) | ||
assert.NoError(t, err) | ||
|
||
decrypted, err := config.AesGcmDecryptWithKey(encryptedBackup, encryptedChannelsBackupKey.Key) | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, "{\"node_id\":\"037e702144c4fa485d42f0f69864e943605823763866cf4bf619d2d2cf2eda420b\",\"channels\":[],\"monitors\":[]}\n", decrypted) | ||
} | ||
|
||
func TestEncryptedBackup(t *testing.T) { | ||
defer tests.RemoveTestService() | ||
svc, err := tests.CreateTestService() | ||
require.NoError(t, err) | ||
|
||
mnemonic := "limit reward expect search tissue call visa fit thank cream brave jump" | ||
unlockPassword := "123" | ||
svc.Cfg.SetUpdate("Mnemonic", mnemonic, unlockPassword) | ||
err = svc.Keys.Init(svc.Cfg, unlockPassword) | ||
assert.NoError(t, err) | ||
|
||
albyOAuthSvc := NewAlbyOAuthService(svc.DB, svc.Cfg, svc.Keys, svc.EventPublisher) | ||
encryptedBackup, err := albyOAuthSvc.createEncryptedChannelBackup(&events.StaticChannelsBackupEvent{ | ||
NodeID: "037e702144c4fa485d42f0f69864e943605823763866cf4bf619d2d2cf2eda420b", | ||
Channels: []events.ChannelBackup{}, | ||
Monitors: []events.EncodedChannelMonitorBackup{}, | ||
}) | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, "channels_v2", encryptedBackup.Description) | ||
|
||
masterKey, err := bip32.NewMasterKey(bip39.NewSeed(mnemonic, "")) | ||
assert.NoError(t, err) | ||
|
||
appKey, err := masterKey.NewChildKey(bip32.FirstHardenedChild + 128029 /* 🐝 */) | ||
assert.NoError(t, err) | ||
encryptedChannelsBackupKey, err := appKey.NewChildKey(bip32.FirstHardenedChild) | ||
assert.NoError(t, err) | ||
|
||
decrypted, err := config.AesGcmDecryptWithKey(encryptedBackup.Data, encryptedChannelsBackupKey.Key) | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, "{\"node_id\":\"037e702144c4fa485d42f0f69864e943605823763866cf4bf619d2d2cf2eda420b\",\"channels\":[],\"monitors\":[]}\n", decrypted) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package config | ||
|
||
import ( | ||
"encoding/hex" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/tyler-smith/go-bip32" | ||
"github.com/tyler-smith/go-bip39" | ||
) | ||
|
||
func TestDecryptExistingCiphertextWithPassword(t *testing.T) { | ||
value, err := AesGcmDecryptWithPassword("323f41394d3175b72454ccae9c0081f94df5fb4c2fb0b9283a87e5aafba81839-c335b9eeea75c28a6f823354-5055b90dadbdd01c52fbdbb7efb80609e4410357481651e89ceb1501c8e1dea1f33a8e3322a1cef4f641773667423bca5154dfeccac390cfcd719b36965adc3e6ae56fd5d6c82819596e9ef4ff07193ae345eb291fa412a1ce6066864b", "123") | ||
assert.NoError(t, err) | ||
assert.Equal(t, "connect maximum march lava ignore resist visa kind kiwi kidney develop animal", value) | ||
} | ||
|
||
func TestEncryptDecryptWithPassword(t *testing.T) { | ||
mnemonic := "connect maximum march lava ignore resist visa kind kiwi kidney develop animal" | ||
encrypted, err := AesGcmEncryptWithPassword(mnemonic, "123") | ||
assert.NoError(t, err) | ||
value, err := AesGcmDecryptWithPassword(encrypted, "123") | ||
assert.NoError(t, err) | ||
assert.Equal(t, mnemonic, value) | ||
} | ||
|
||
func TestDecryptExistingCiphertextWithKey(t *testing.T) { | ||
mnemonic := "connect maximum march lava ignore resist visa kind kiwi kidney develop animal" | ||
masterKey, err := bip32.NewMasterKey(bip39.NewSeed(mnemonic, "")) | ||
assert.NoError(t, err) | ||
value, err := AesGcmDecryptWithKey("22ad485dea4f49696594c7c4-afe35ce65fc5a45249bf1b9078472fb28395fc88c30a79c76c7d8d37cf", masterKey.Key) | ||
assert.NoError(t, err) | ||
assert.Equal(t, "Hello, world!", value) | ||
} | ||
|
||
func TestEncryptDecryptWithKey(t *testing.T) { | ||
plaintext := "Hello, world!" | ||
mnemonic := "connect maximum march lava ignore resist visa kind kiwi kidney develop animal" | ||
masterKey, err := bip32.NewMasterKey(bip39.NewSeed(mnemonic, "")) | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, "409e902eafba273b21dff921f0eb4bec6cbb0b657fdce8d245ca78d2920f8b73", hex.EncodeToString(masterKey.Key)) | ||
|
||
encrypted, err := AesGcmEncryptWithKey(plaintext, masterKey.Key) | ||
assert.NoError(t, err) | ||
value, err := AesGcmDecryptWithKey(encrypted, masterKey.Key) | ||
assert.NoError(t, err) | ||
assert.Equal(t, plaintext, value) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.