diff options
| -rw-r--r-- | Cargo.lock | 348 | ||||
| -rw-r--r-- | Cargo.toml | 4 | ||||
| -rw-r--r-- | src/key_handling/encryption.rs | 155 | ||||
| -rw-r--r-- | test_utils/Cargo.toml | 4 | ||||
| -rw-r--r-- | test_utils/src/lib.rs | 10 | ||||
| -rw-r--r-- | tests/login.rs | 2 |
6 files changed, 172 insertions, 351 deletions
| @@ -330,20 +330,20 @@ dependencies = [ | |||
| 330 | 330 | ||
| 331 | [[package]] | 331 | [[package]] |
| 332 | name = "async-wsocket" | 332 | name = "async-wsocket" |
| 333 | version = "0.3.0" | 333 | version = "0.4.0" |
| 334 | source = "registry+https://github.com/rust-lang/crates.io-index" | 334 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 335 | checksum = "d253e375ea899cb131b92a474587e217634e7ea927c24d8098eecbcad0c5c97a" | 335 | checksum = "5c38341e6ee670913fb9dc3aba40c22d616261da4dc0928326d3168ebf576fb0" |
| 336 | dependencies = [ | 336 | dependencies = [ |
| 337 | "async-utility", | 337 | "async-utility", |
| 338 | "futures-util", | 338 | "futures-util", |
| 339 | "thiserror", | 339 | "thiserror", |
| 340 | "tokio", | 340 | "tokio", |
| 341 | "tokio-rustls 0.25.0", | 341 | "tokio-rustls", |
| 342 | "tokio-socks", | 342 | "tokio-socks", |
| 343 | "tokio-tungstenite 0.21.0", | 343 | "tokio-tungstenite 0.21.0", |
| 344 | "url", | 344 | "url", |
| 345 | "wasm-ws", | 345 | "wasm-ws", |
| 346 | "webpki-roots 0.26.1", | 346 | "webpki-roots", |
| 347 | ] | 347 | ] |
| 348 | 348 | ||
| 349 | [[package]] | 349 | [[package]] |
| @@ -400,6 +400,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
| 400 | checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" | 400 | checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" |
| 401 | 401 | ||
| 402 | [[package]] | 402 | [[package]] |
| 403 | name = "base64" | ||
| 404 | version = "0.22.0" | ||
| 405 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 406 | checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51" | ||
| 407 | |||
| 408 | [[package]] | ||
| 403 | name = "base64ct" | 409 | name = "base64ct" |
| 404 | version = "1.6.0" | 410 | version = "1.6.0" |
| 405 | source = "registry+https://github.com/rust-lang/crates.io-index" | 411 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| @@ -407,9 +413,9 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" | |||
| 407 | 413 | ||
| 408 | [[package]] | 414 | [[package]] |
| 409 | name = "bech32" | 415 | name = "bech32" |
| 410 | version = "0.9.1" | 416 | version = "0.10.0-beta" |
| 411 | source = "registry+https://github.com/rust-lang/crates.io-index" | 417 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 412 | checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" | 418 | checksum = "98f7eed2b2781a6f0b5c903471d48e15f56fb4e1165df8a9a2337fd1a59d45ea" |
| 413 | 419 | ||
| 414 | [[package]] | 420 | [[package]] |
| 415 | name = "bip39" | 421 | name = "bip39" |
| @@ -424,23 +430,27 @@ dependencies = [ | |||
| 424 | 430 | ||
| 425 | [[package]] | 431 | [[package]] |
| 426 | name = "bitcoin" | 432 | name = "bitcoin" |
| 427 | version = "0.30.2" | 433 | version = "0.31.2" |
| 428 | source = "registry+https://github.com/rust-lang/crates.io-index" | 434 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 429 | checksum = "1945a5048598e4189e239d3f809b19bdad4845c4b2ba400d304d2dcf26d2c462" | 435 | checksum = "6c85783c2fe40083ea54a33aa2f0ba58831d90fcd190f5bdc47e74e84d2a96ae" |
| 430 | dependencies = [ | 436 | dependencies = [ |
| 431 | "bech32", | 437 | "bech32", |
| 432 | "bitcoin-private", | 438 | "bitcoin-internals", |
| 433 | "bitcoin_hashes 0.12.0", | 439 | "bitcoin_hashes 0.13.0", |
| 440 | "hex-conservative", | ||
| 434 | "hex_lit", | 441 | "hex_lit", |
| 435 | "secp256k1", | 442 | "secp256k1", |
| 436 | "serde", | 443 | "serde", |
| 437 | ] | 444 | ] |
| 438 | 445 | ||
| 439 | [[package]] | 446 | [[package]] |
| 440 | name = "bitcoin-private" | 447 | name = "bitcoin-internals" |
| 441 | version = "0.1.0" | 448 | version = "0.2.0" |
| 442 | source = "registry+https://github.com/rust-lang/crates.io-index" | 449 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 443 | checksum = "73290177011694f38ec25e165d0387ab7ea749a4b81cd4c80dae5988229f7a57" | 450 | checksum = "9425c3bf7089c983facbae04de54513cce73b41c7f9ff8c845b54e7bc64ebbfb" |
| 451 | dependencies = [ | ||
| 452 | "serde", | ||
| 453 | ] | ||
| 444 | 454 | ||
| 445 | [[package]] | 455 | [[package]] |
| 446 | name = "bitcoin_hashes" | 456 | name = "bitcoin_hashes" |
| @@ -450,11 +460,12 @@ checksum = "90064b8dee6815a6470d60bad07bbbaee885c0e12d04177138fa3291a01b7bc4" | |||
| 450 | 460 | ||
| 451 | [[package]] | 461 | [[package]] |
| 452 | name = "bitcoin_hashes" | 462 | name = "bitcoin_hashes" |
| 453 | version = "0.12.0" | 463 | version = "0.13.0" |
| 454 | source = "registry+https://github.com/rust-lang/crates.io-index" | 464 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 455 | checksum = "5d7066118b13d4b20b23645932dfb3a81ce7e29f95726c2036fa33cd7b092501" | 465 | checksum = "1930a4dabfebb8d7d9992db18ebe3ae2876f0a305fab206fd168df931ede293b" |
| 456 | dependencies = [ | 466 | dependencies = [ |
| 457 | "bitcoin-private", | 467 | "bitcoin-internals", |
| 468 | "hex-conservative", | ||
| 458 | "serde", | 469 | "serde", |
| 459 | ] | 470 | ] |
| 460 | 471 | ||
| @@ -849,15 +860,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
| 849 | checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" | 860 | checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" |
| 850 | 861 | ||
| 851 | [[package]] | 862 | [[package]] |
| 852 | name = "encoding_rs" | ||
| 853 | version = "0.8.34" | ||
| 854 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 855 | checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" | ||
| 856 | dependencies = [ | ||
| 857 | "cfg-if", | ||
| 858 | ] | ||
| 859 | |||
| 860 | [[package]] | ||
| 861 | name = "enumflags2" | 863 | name = "enumflags2" |
| 862 | version = "0.7.9" | 864 | version = "0.7.9" |
| 863 | source = "registry+https://github.com/rust-lang/crates.io-index" | 865 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| @@ -1185,25 +1187,6 @@ dependencies = [ | |||
| 1185 | ] | 1187 | ] |
| 1186 | 1188 | ||
| 1187 | [[package]] | 1189 | [[package]] |
| 1188 | name = "h2" | ||
| 1189 | version = "0.3.26" | ||
| 1190 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1191 | checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" | ||
| 1192 | dependencies = [ | ||
| 1193 | "bytes", | ||
| 1194 | "fnv", | ||
| 1195 | "futures-core", | ||
| 1196 | "futures-sink", | ||
| 1197 | "futures-util", | ||
| 1198 | "http 0.2.12", | ||
| 1199 | "indexmap", | ||
| 1200 | "slab", | ||
| 1201 | "tokio", | ||
| 1202 | "tokio-util", | ||
| 1203 | "tracing", | ||
| 1204 | ] | ||
| 1205 | |||
| 1206 | [[package]] | ||
| 1207 | name = "hashbrown" | 1190 | name = "hashbrown" |
| 1208 | version = "0.14.3" | 1191 | version = "0.14.3" |
| 1209 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1192 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| @@ -1238,6 +1221,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
| 1238 | checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" | 1221 | checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" |
| 1239 | 1222 | ||
| 1240 | [[package]] | 1223 | [[package]] |
| 1224 | name = "hex-conservative" | ||
| 1225 | version = "0.1.1" | ||
| 1226 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1227 | checksum = "30ed443af458ccb6d81c1e7e661545f94d3176752fb1df2f543b902a1e0f51e2" | ||
| 1228 | |||
| 1229 | [[package]] | ||
| 1241 | name = "hex_lit" | 1230 | name = "hex_lit" |
| 1242 | version = "0.1.1" | 1231 | version = "0.1.1" |
| 1243 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1232 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| @@ -1285,12 +1274,24 @@ dependencies = [ | |||
| 1285 | 1274 | ||
| 1286 | [[package]] | 1275 | [[package]] |
| 1287 | name = "http-body" | 1276 | name = "http-body" |
| 1288 | version = "0.4.6" | 1277 | version = "1.0.0" |
| 1289 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1278 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1290 | checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" | 1279 | checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" |
| 1291 | dependencies = [ | 1280 | dependencies = [ |
| 1292 | "bytes", | 1281 | "bytes", |
| 1293 | "http 0.2.12", | 1282 | "http 1.1.0", |
| 1283 | ] | ||
| 1284 | |||
| 1285 | [[package]] | ||
| 1286 | name = "http-body-util" | ||
| 1287 | version = "0.1.1" | ||
| 1288 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1289 | checksum = "0475f8b2ac86659c21b64320d5d653f9efe42acd2a4e560073ec61a155a34f1d" | ||
| 1290 | dependencies = [ | ||
| 1291 | "bytes", | ||
| 1292 | "futures-core", | ||
| 1293 | "http 1.1.0", | ||
| 1294 | "http-body", | ||
| 1294 | "pin-project-lite", | 1295 | "pin-project-lite", |
| 1295 | ] | 1296 | ] |
| 1296 | 1297 | ||
| @@ -1301,47 +1302,59 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
| 1301 | checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" | 1302 | checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" |
| 1302 | 1303 | ||
| 1303 | [[package]] | 1304 | [[package]] |
| 1304 | name = "httpdate" | ||
| 1305 | version = "1.0.3" | ||
| 1306 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1307 | checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" | ||
| 1308 | |||
| 1309 | [[package]] | ||
| 1310 | name = "hyper" | 1305 | name = "hyper" |
| 1311 | version = "0.14.28" | 1306 | version = "1.3.0" |
| 1312 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1307 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1313 | checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" | 1308 | checksum = "9f24ce812868d86d19daa79bf3bf9175bc44ea323391147a5e3abde2a283871b" |
| 1314 | dependencies = [ | 1309 | dependencies = [ |
| 1315 | "bytes", | 1310 | "bytes", |
| 1316 | "futures-channel", | 1311 | "futures-channel", |
| 1317 | "futures-core", | ||
| 1318 | "futures-util", | 1312 | "futures-util", |
| 1319 | "h2", | 1313 | "http 1.1.0", |
| 1320 | "http 0.2.12", | ||
| 1321 | "http-body", | 1314 | "http-body", |
| 1322 | "httparse", | 1315 | "httparse", |
| 1323 | "httpdate", | ||
| 1324 | "itoa", | 1316 | "itoa", |
| 1325 | "pin-project-lite", | 1317 | "pin-project-lite", |
| 1326 | "socket2 0.5.6", | 1318 | "smallvec", |
| 1327 | "tokio", | 1319 | "tokio", |
| 1328 | "tower-service", | ||
| 1329 | "tracing", | ||
| 1330 | "want", | 1320 | "want", |
| 1331 | ] | 1321 | ] |
| 1332 | 1322 | ||
| 1333 | [[package]] | 1323 | [[package]] |
| 1334 | name = "hyper-rustls" | 1324 | name = "hyper-rustls" |
| 1335 | version = "0.24.2" | 1325 | version = "0.26.0" |
| 1336 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1326 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1337 | checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" | 1327 | checksum = "a0bea761b46ae2b24eb4aef630d8d1c398157b6fc29e6350ecf090a0b70c952c" |
| 1338 | dependencies = [ | 1328 | dependencies = [ |
| 1339 | "futures-util", | 1329 | "futures-util", |
| 1340 | "http 0.2.12", | 1330 | "http 1.1.0", |
| 1341 | "hyper", | 1331 | "hyper", |
| 1342 | "rustls 0.21.10", | 1332 | "hyper-util", |
| 1333 | "rustls", | ||
| 1334 | "rustls-pki-types", | ||
| 1343 | "tokio", | 1335 | "tokio", |
| 1344 | "tokio-rustls 0.24.1", | 1336 | "tokio-rustls", |
| 1337 | "tower-service", | ||
| 1338 | ] | ||
| 1339 | |||
| 1340 | [[package]] | ||
| 1341 | name = "hyper-util" | ||
| 1342 | version = "0.1.3" | ||
| 1343 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1344 | checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa" | ||
| 1345 | dependencies = [ | ||
| 1346 | "bytes", | ||
| 1347 | "futures-channel", | ||
| 1348 | "futures-util", | ||
| 1349 | "http 1.1.0", | ||
| 1350 | "http-body", | ||
| 1351 | "hyper", | ||
| 1352 | "pin-project-lite", | ||
| 1353 | "socket2 0.5.6", | ||
| 1354 | "tokio", | ||
| 1355 | "tower", | ||
| 1356 | "tower-service", | ||
| 1357 | "tracing", | ||
| 1345 | ] | 1358 | ] |
| 1346 | 1359 | ||
| 1347 | [[package]] | 1360 | [[package]] |
| @@ -1549,9 +1562,9 @@ checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" | |||
| 1549 | 1562 | ||
| 1550 | [[package]] | 1563 | [[package]] |
| 1551 | name = "lnurl-pay" | 1564 | name = "lnurl-pay" |
| 1552 | version = "0.3.0" | 1565 | version = "0.5.0" |
| 1553 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1566 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1554 | checksum = "b628658116d331c9567f6cb22415d726125ff6e328d1fb1b422b1b58afeaec21" | 1567 | checksum = "02c042191c2e3f27147decfad8182eea2c7dd1c6c1733562e25d3d401369669d" |
| 1555 | dependencies = [ | 1568 | dependencies = [ |
| 1556 | "bech32", | 1569 | "bech32", |
| 1557 | "reqwest", | 1570 | "reqwest", |
| @@ -1763,12 +1776,11 @@ checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" | |||
| 1763 | 1776 | ||
| 1764 | [[package]] | 1777 | [[package]] |
| 1765 | name = "nostr" | 1778 | name = "nostr" |
| 1766 | version = "0.29.1" | 1779 | version = "0.30.0" |
| 1767 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1780 | source = "git+https://github.com/DanConwayDev/nostr?branch=expose-nip49-log-n#6ef397b6c4cd5edd6e6c31ff33d8a978b5b04f8c" |
| 1768 | checksum = "25e4e34578e8cc2b4050c6224a0c422b23ba1e61f2602b4e320c221ac3cbbc2e" | ||
| 1769 | dependencies = [ | 1781 | dependencies = [ |
| 1770 | "aes 0.8.4", | 1782 | "aes 0.8.4", |
| 1771 | "base64", | 1783 | "base64 0.21.7", |
| 1772 | "bip39", | 1784 | "bip39", |
| 1773 | "bitcoin", | 1785 | "bitcoin", |
| 1774 | "cbc", | 1786 | "cbc", |
| @@ -1793,9 +1805,8 @@ dependencies = [ | |||
| 1793 | 1805 | ||
| 1794 | [[package]] | 1806 | [[package]] |
| 1795 | name = "nostr-database" | 1807 | name = "nostr-database" |
| 1796 | version = "0.29.0" | 1808 | version = "0.30.0" |
| 1797 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1809 | source = "git+https://github.com/DanConwayDev/nostr?branch=expose-nip49-log-n#6ef397b6c4cd5edd6e6c31ff33d8a978b5b04f8c" |
| 1798 | checksum = "8e15ab55f96ea5e560af0c75f1d942b1064266d443d11b2afbe51ca9ad78a018" | ||
| 1799 | dependencies = [ | 1810 | dependencies = [ |
| 1800 | "async-trait", | 1811 | "async-trait", |
| 1801 | "lru", | 1812 | "lru", |
| @@ -1807,9 +1818,8 @@ dependencies = [ | |||
| 1807 | 1818 | ||
| 1808 | [[package]] | 1819 | [[package]] |
| 1809 | name = "nostr-relay-pool" | 1820 | name = "nostr-relay-pool" |
| 1810 | version = "0.29.4" | 1821 | version = "0.30.0" |
| 1811 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1822 | source = "git+https://github.com/DanConwayDev/nostr?branch=expose-nip49-log-n#6ef397b6c4cd5edd6e6c31ff33d8a978b5b04f8c" |
| 1812 | checksum = "e8efc437bcf8c433887a9897dfb6f99914170f656a2a66398e737b3050c2aa34" | ||
| 1813 | dependencies = [ | 1823 | dependencies = [ |
| 1814 | "async-utility", | 1824 | "async-utility", |
| 1815 | "async-wsocket", | 1825 | "async-wsocket", |
| @@ -1823,9 +1833,8 @@ dependencies = [ | |||
| 1823 | 1833 | ||
| 1824 | [[package]] | 1834 | [[package]] |
| 1825 | name = "nostr-sdk" | 1835 | name = "nostr-sdk" |
| 1826 | version = "0.29.0" | 1836 | version = "0.30.0" |
| 1827 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1837 | source = "git+https://github.com/DanConwayDev/nostr?branch=expose-nip49-log-n#6ef397b6c4cd5edd6e6c31ff33d8a978b5b04f8c" |
| 1828 | checksum = "81ed0ab9cbc3b20d3dba99337f2e0739f052ebe32133d690e212022a06a22044" | ||
| 1829 | dependencies = [ | 1838 | dependencies = [ |
| 1830 | "async-utility", | 1839 | "async-utility", |
| 1831 | "lnurl-pay", | 1840 | "lnurl-pay", |
| @@ -1842,22 +1851,21 @@ dependencies = [ | |||
| 1842 | 1851 | ||
| 1843 | [[package]] | 1852 | [[package]] |
| 1844 | name = "nostr-signer" | 1853 | name = "nostr-signer" |
| 1845 | version = "0.29.0" | 1854 | version = "0.30.0" |
| 1846 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1855 | source = "git+https://github.com/DanConwayDev/nostr?branch=expose-nip49-log-n#6ef397b6c4cd5edd6e6c31ff33d8a978b5b04f8c" |
| 1847 | checksum = "307bdc7c26887d7e65632e66872989a19892dfe9f2c6dbd9a1d3f959c5c524d5" | ||
| 1848 | dependencies = [ | 1856 | dependencies = [ |
| 1849 | "async-utility", | 1857 | "async-utility", |
| 1850 | "nostr", | 1858 | "nostr", |
| 1851 | "nostr-relay-pool", | 1859 | "nostr-relay-pool", |
| 1852 | "thiserror", | 1860 | "thiserror", |
| 1853 | "tokio", | 1861 | "tokio", |
| 1862 | "tracing", | ||
| 1854 | ] | 1863 | ] |
| 1855 | 1864 | ||
| 1856 | [[package]] | 1865 | [[package]] |
| 1857 | name = "nostr-zapper" | 1866 | name = "nostr-zapper" |
| 1858 | version = "0.29.0" | 1867 | version = "0.30.0" |
| 1859 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1868 | source = "git+https://github.com/DanConwayDev/nostr?branch=expose-nip49-log-n#6ef397b6c4cd5edd6e6c31ff33d8a978b5b04f8c" |
| 1860 | checksum = "061d5eb00b430747a984ea9e41cd82c849832151b4263d8230c9c220dc2c62f8" | ||
| 1861 | dependencies = [ | 1869 | dependencies = [ |
| 1862 | "async-trait", | 1870 | "async-trait", |
| 1863 | "nostr", | 1871 | "nostr", |
| @@ -1957,9 +1965,8 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" | |||
| 1957 | 1965 | ||
| 1958 | [[package]] | 1966 | [[package]] |
| 1959 | name = "nwc" | 1967 | name = "nwc" |
| 1960 | version = "0.29.0" | 1968 | version = "0.30.0" |
| 1961 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1969 | source = "git+https://github.com/DanConwayDev/nostr?branch=expose-nip49-log-n#6ef397b6c4cd5edd6e6c31ff33d8a978b5b04f8c" |
| 1962 | checksum = "d1894ffe54a1e5adf8dbb22b5a290c0748ec4a88aa07fa69c4359010edea49ed" | ||
| 1963 | dependencies = [ | 1970 | dependencies = [ |
| 1964 | "async-utility", | 1971 | "async-utility", |
| 1965 | "nostr", | 1972 | "nostr", |
| @@ -2413,20 +2420,20 @@ checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" | |||
| 2413 | 2420 | ||
| 2414 | [[package]] | 2421 | [[package]] |
| 2415 | name = "reqwest" | 2422 | name = "reqwest" |
| 2416 | version = "0.11.27" | 2423 | version = "0.12.3" |
| 2417 | source = "registry+https://github.com/rust-lang/crates.io-index" | 2424 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 2418 | checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62" | 2425 | checksum = "3e6cc1e89e689536eb5aeede61520e874df5a4707df811cd5da4aa5fbb2aae19" |
| 2419 | dependencies = [ | 2426 | dependencies = [ |
| 2420 | "base64", | 2427 | "base64 0.22.0", |
| 2421 | "bytes", | 2428 | "bytes", |
| 2422 | "encoding_rs", | ||
| 2423 | "futures-core", | 2429 | "futures-core", |
| 2424 | "futures-util", | 2430 | "futures-util", |
| 2425 | "h2", | 2431 | "http 1.1.0", |
| 2426 | "http 0.2.12", | ||
| 2427 | "http-body", | 2432 | "http-body", |
| 2433 | "http-body-util", | ||
| 2428 | "hyper", | 2434 | "hyper", |
| 2429 | "hyper-rustls", | 2435 | "hyper-rustls", |
| 2436 | "hyper-util", | ||
| 2430 | "ipnet", | 2437 | "ipnet", |
| 2431 | "js-sys", | 2438 | "js-sys", |
| 2432 | "log", | 2439 | "log", |
| @@ -2434,22 +2441,22 @@ dependencies = [ | |||
| 2434 | "once_cell", | 2441 | "once_cell", |
| 2435 | "percent-encoding", | 2442 | "percent-encoding", |
| 2436 | "pin-project-lite", | 2443 | "pin-project-lite", |
| 2437 | "rustls 0.21.10", | 2444 | "rustls", |
| 2438 | "rustls-pemfile", | 2445 | "rustls-pemfile", |
| 2446 | "rustls-pki-types", | ||
| 2439 | "serde", | 2447 | "serde", |
| 2440 | "serde_json", | 2448 | "serde_json", |
| 2441 | "serde_urlencoded", | 2449 | "serde_urlencoded", |
| 2442 | "sync_wrapper", | 2450 | "sync_wrapper", |
| 2443 | "system-configuration", | ||
| 2444 | "tokio", | 2451 | "tokio", |
| 2445 | "tokio-rustls 0.24.1", | 2452 | "tokio-rustls", |
| 2446 | "tokio-socks", | 2453 | "tokio-socks", |
| 2447 | "tower-service", | 2454 | "tower-service", |
| 2448 | "url", | 2455 | "url", |
| 2449 | "wasm-bindgen", | 2456 | "wasm-bindgen", |
| 2450 | "wasm-bindgen-futures", | 2457 | "wasm-bindgen-futures", |
| 2451 | "web-sys", | 2458 | "web-sys", |
| 2452 | "webpki-roots 0.25.4", | 2459 | "webpki-roots", |
| 2453 | "winreg", | 2460 | "winreg", |
| 2454 | ] | 2461 | ] |
| 2455 | 2462 | ||
| @@ -2537,18 +2544,6 @@ dependencies = [ | |||
| 2537 | 2544 | ||
| 2538 | [[package]] | 2545 | [[package]] |
| 2539 | name = "rustls" | 2546 | name = "rustls" |
| 2540 | version = "0.21.10" | ||
| 2541 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2542 | checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba" | ||
| 2543 | dependencies = [ | ||
| 2544 | "log", | ||
| 2545 | "ring", | ||
| 2546 | "rustls-webpki 0.101.7", | ||
| 2547 | "sct", | ||
| 2548 | ] | ||
| 2549 | |||
| 2550 | [[package]] | ||
| 2551 | name = "rustls" | ||
| 2552 | version = "0.22.3" | 2547 | version = "0.22.3" |
| 2553 | source = "registry+https://github.com/rust-lang/crates.io-index" | 2548 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 2554 | checksum = "99008d7ad0bbbea527ec27bddbc0e432c5b87d8175178cee68d2eec9c4a1813c" | 2549 | checksum = "99008d7ad0bbbea527ec27bddbc0e432c5b87d8175178cee68d2eec9c4a1813c" |
| @@ -2556,18 +2551,19 @@ dependencies = [ | |||
| 2556 | "log", | 2551 | "log", |
| 2557 | "ring", | 2552 | "ring", |
| 2558 | "rustls-pki-types", | 2553 | "rustls-pki-types", |
| 2559 | "rustls-webpki 0.102.2", | 2554 | "rustls-webpki", |
| 2560 | "subtle", | 2555 | "subtle", |
| 2561 | "zeroize", | 2556 | "zeroize", |
| 2562 | ] | 2557 | ] |
| 2563 | 2558 | ||
| 2564 | [[package]] | 2559 | [[package]] |
| 2565 | name = "rustls-pemfile" | 2560 | name = "rustls-pemfile" |
| 2566 | version = "1.0.4" | 2561 | version = "2.1.2" |
| 2567 | source = "registry+https://github.com/rust-lang/crates.io-index" | 2562 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 2568 | checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" | 2563 | checksum = "29993a25686778eb88d4189742cd713c9bce943bc54251a33509dc63cbacf73d" |
| 2569 | dependencies = [ | 2564 | dependencies = [ |
| 2570 | "base64", | 2565 | "base64 0.22.0", |
| 2566 | "rustls-pki-types", | ||
| 2571 | ] | 2567 | ] |
| 2572 | 2568 | ||
| 2573 | [[package]] | 2569 | [[package]] |
| @@ -2578,16 +2574,6 @@ checksum = "ecd36cc4259e3e4514335c4a138c6b43171a8d61d8f5c9348f9fc7529416f247" | |||
| 2578 | 2574 | ||
| 2579 | [[package]] | 2575 | [[package]] |
| 2580 | name = "rustls-webpki" | 2576 | name = "rustls-webpki" |
| 2581 | version = "0.101.7" | ||
| 2582 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2583 | checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" | ||
| 2584 | dependencies = [ | ||
| 2585 | "ring", | ||
| 2586 | "untrusted", | ||
| 2587 | ] | ||
| 2588 | |||
| 2589 | [[package]] | ||
| 2590 | name = "rustls-webpki" | ||
| 2591 | version = "0.102.2" | 2577 | version = "0.102.2" |
| 2592 | source = "registry+https://github.com/rust-lang/crates.io-index" | 2578 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 2593 | checksum = "faaa0a62740bedb9b2ef5afa303da42764c012f743917351dc9a237ea1663610" | 2579 | checksum = "faaa0a62740bedb9b2ef5afa303da42764c012f743917351dc9a237ea1663610" |
| @@ -2631,22 +2617,12 @@ dependencies = [ | |||
| 2631 | ] | 2617 | ] |
| 2632 | 2618 | ||
| 2633 | [[package]] | 2619 | [[package]] |
| 2634 | name = "sct" | ||
| 2635 | version = "0.7.1" | ||
| 2636 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2637 | checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" | ||
| 2638 | dependencies = [ | ||
| 2639 | "ring", | ||
| 2640 | "untrusted", | ||
| 2641 | ] | ||
| 2642 | |||
| 2643 | [[package]] | ||
| 2644 | name = "secp256k1" | 2620 | name = "secp256k1" |
| 2645 | version = "0.27.0" | 2621 | version = "0.28.2" |
| 2646 | source = "registry+https://github.com/rust-lang/crates.io-index" | 2622 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 2647 | checksum = "25996b82292a7a57ed3508f052cfff8640d38d32018784acd714758b43da9c8f" | 2623 | checksum = "d24b59d129cdadea20aea4fb2352fa053712e5d713eee47d700cd4b2bc002f10" |
| 2648 | dependencies = [ | 2624 | dependencies = [ |
| 2649 | "bitcoin_hashes 0.12.0", | 2625 | "bitcoin_hashes 0.13.0", |
| 2650 | "rand", | 2626 | "rand", |
| 2651 | "secp256k1-sys", | 2627 | "secp256k1-sys", |
| 2652 | "serde", | 2628 | "serde", |
| @@ -2654,9 +2630,9 @@ dependencies = [ | |||
| 2654 | 2630 | ||
| 2655 | [[package]] | 2631 | [[package]] |
| 2656 | name = "secp256k1-sys" | 2632 | name = "secp256k1-sys" |
| 2657 | version = "0.8.1" | 2633 | version = "0.9.2" |
| 2658 | source = "registry+https://github.com/rust-lang/crates.io-index" | 2634 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 2659 | checksum = "70a129b9e9efbfb223753b9163c4ab3b13cff7fd9c7f010fbac25ab4099fa07e" | 2635 | checksum = "e5d1746aae42c19d583c3c1a8c646bfad910498e2051c551a7f2e3c0c9fbb7eb" |
| 2660 | dependencies = [ | 2636 | dependencies = [ |
| 2661 | "cc", | 2637 | "cc", |
| 2662 | ] | 2638 | ] |
| @@ -2956,27 +2932,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
| 2956 | checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" | 2932 | checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" |
| 2957 | 2933 | ||
| 2958 | [[package]] | 2934 | [[package]] |
| 2959 | name = "system-configuration" | ||
| 2960 | version = "0.5.1" | ||
| 2961 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2962 | checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" | ||
| 2963 | dependencies = [ | ||
| 2964 | "bitflags 1.3.2", | ||
| 2965 | "core-foundation", | ||
| 2966 | "system-configuration-sys", | ||
| 2967 | ] | ||
| 2968 | |||
| 2969 | [[package]] | ||
| 2970 | name = "system-configuration-sys" | ||
| 2971 | version = "0.5.0" | ||
| 2972 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2973 | checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" | ||
| 2974 | dependencies = [ | ||
| 2975 | "core-foundation-sys", | ||
| 2976 | "libc", | ||
| 2977 | ] | ||
| 2978 | |||
| 2979 | [[package]] | ||
| 2980 | name = "tempfile" | 2935 | name = "tempfile" |
| 2981 | version = "3.10.1" | 2936 | version = "3.10.1" |
| 2982 | source = "registry+https://github.com/rust-lang/crates.io-index" | 2937 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| @@ -3080,21 +3035,11 @@ dependencies = [ | |||
| 3080 | 3035 | ||
| 3081 | [[package]] | 3036 | [[package]] |
| 3082 | name = "tokio-rustls" | 3037 | name = "tokio-rustls" |
| 3083 | version = "0.24.1" | ||
| 3084 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3085 | checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" | ||
| 3086 | dependencies = [ | ||
| 3087 | "rustls 0.21.10", | ||
| 3088 | "tokio", | ||
| 3089 | ] | ||
| 3090 | |||
| 3091 | [[package]] | ||
| 3092 | name = "tokio-rustls" | ||
| 3093 | version = "0.25.0" | 3038 | version = "0.25.0" |
| 3094 | source = "registry+https://github.com/rust-lang/crates.io-index" | 3039 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 3095 | checksum = "775e0c0f0adb3a2f22a00c4745d728b479985fc15ee7ca6a2608388c5569860f" | 3040 | checksum = "775e0c0f0adb3a2f22a00c4745d728b479985fc15ee7ca6a2608388c5569860f" |
| 3096 | dependencies = [ | 3041 | dependencies = [ |
| 3097 | "rustls 0.22.3", | 3042 | "rustls", |
| 3098 | "rustls-pki-types", | 3043 | "rustls-pki-types", |
| 3099 | "tokio", | 3044 | "tokio", |
| 3100 | ] | 3045 | ] |
| @@ -3131,26 +3076,12 @@ checksum = "c83b561d025642014097b66e6c1bb422783339e0909e4429cde4749d1990bc38" | |||
| 3131 | dependencies = [ | 3076 | dependencies = [ |
| 3132 | "futures-util", | 3077 | "futures-util", |
| 3133 | "log", | 3078 | "log", |
| 3134 | "rustls 0.22.3", | 3079 | "rustls", |
| 3135 | "rustls-pki-types", | 3080 | "rustls-pki-types", |
| 3136 | "tokio", | 3081 | "tokio", |
| 3137 | "tokio-rustls 0.25.0", | 3082 | "tokio-rustls", |
| 3138 | "tungstenite 0.21.0", | 3083 | "tungstenite 0.21.0", |
| 3139 | "webpki-roots 0.26.1", | 3084 | "webpki-roots", |
| 3140 | ] | ||
| 3141 | |||
| 3142 | [[package]] | ||
| 3143 | name = "tokio-util" | ||
| 3144 | version = "0.7.10" | ||
| 3145 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3146 | checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" | ||
| 3147 | dependencies = [ | ||
| 3148 | "bytes", | ||
| 3149 | "futures-core", | ||
| 3150 | "futures-sink", | ||
| 3151 | "pin-project-lite", | ||
| 3152 | "tokio", | ||
| 3153 | "tracing", | ||
| 3154 | ] | 3085 | ] |
| 3155 | 3086 | ||
| 3156 | [[package]] | 3087 | [[package]] |
| @@ -3171,6 +3102,28 @@ dependencies = [ | |||
| 3171 | ] | 3102 | ] |
| 3172 | 3103 | ||
| 3173 | [[package]] | 3104 | [[package]] |
| 3105 | name = "tower" | ||
| 3106 | version = "0.4.13" | ||
| 3107 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3108 | checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" | ||
| 3109 | dependencies = [ | ||
| 3110 | "futures-core", | ||
| 3111 | "futures-util", | ||
| 3112 | "pin-project", | ||
| 3113 | "pin-project-lite", | ||
| 3114 | "tokio", | ||
| 3115 | "tower-layer", | ||
| 3116 | "tower-service", | ||
| 3117 | "tracing", | ||
| 3118 | ] | ||
| 3119 | |||
| 3120 | [[package]] | ||
| 3121 | name = "tower-layer" | ||
| 3122 | version = "0.3.2" | ||
| 3123 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3124 | checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" | ||
| 3125 | |||
| 3126 | [[package]] | ||
| 3174 | name = "tower-service" | 3127 | name = "tower-service" |
| 3175 | version = "0.3.2" | 3128 | version = "0.3.2" |
| 3176 | source = "registry+https://github.com/rust-lang/crates.io-index" | 3129 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| @@ -3182,6 +3135,7 @@ version = "0.1.40" | |||
| 3182 | source = "registry+https://github.com/rust-lang/crates.io-index" | 3135 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 3183 | checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" | 3136 | checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" |
| 3184 | dependencies = [ | 3137 | dependencies = [ |
| 3138 | "log", | ||
| 3185 | "pin-project-lite", | 3139 | "pin-project-lite", |
| 3186 | "tracing-attributes", | 3140 | "tracing-attributes", |
| 3187 | "tracing-core", | 3141 | "tracing-core", |
| @@ -3245,7 +3199,7 @@ dependencies = [ | |||
| 3245 | "httparse", | 3199 | "httparse", |
| 3246 | "log", | 3200 | "log", |
| 3247 | "rand", | 3201 | "rand", |
| 3248 | "rustls 0.22.3", | 3202 | "rustls", |
| 3249 | "rustls-pki-types", | 3203 | "rustls-pki-types", |
| 3250 | "sha1", | 3204 | "sha1", |
| 3251 | "thiserror", | 3205 | "thiserror", |
| @@ -3500,12 +3454,6 @@ dependencies = [ | |||
| 3500 | 3454 | ||
| 3501 | [[package]] | 3455 | [[package]] |
| 3502 | name = "webpki-roots" | 3456 | name = "webpki-roots" |
| 3503 | version = "0.25.4" | ||
| 3504 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3505 | checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" | ||
| 3506 | |||
| 3507 | [[package]] | ||
| 3508 | name = "webpki-roots" | ||
| 3509 | version = "0.26.1" | 3457 | version = "0.26.1" |
| 3510 | source = "registry+https://github.com/rust-lang/crates.io-index" | 3458 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 3511 | checksum = "b3de34ae270483955a94f4b21bdaaeb83d508bb84a01435f393818edb0012009" | 3459 | checksum = "b3de34ae270483955a94f4b21bdaaeb83d508bb84a01435f393818edb0012009" |
| @@ -3685,9 +3633,9 @@ dependencies = [ | |||
| 3685 | 3633 | ||
| 3686 | [[package]] | 3634 | [[package]] |
| 3687 | name = "winreg" | 3635 | name = "winreg" |
| 3688 | version = "0.50.0" | 3636 | version = "0.52.0" |
| 3689 | source = "registry+https://github.com/rust-lang/crates.io-index" | 3637 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 3690 | checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" | 3638 | checksum = "a277a57398d4bfa075df44f501a17cfdf8542d224f0d36095a2adc7aee4ef0a5" |
| 3691 | dependencies = [ | 3639 | dependencies = [ |
| 3692 | "cfg-if", | 3640 | "cfg-if", |
| 3693 | "windows-sys 0.48.0", | 3641 | "windows-sys 0.48.0", |
| @@ -23,8 +23,8 @@ futures = "0.3.28" | |||
| 23 | git2 = "0.18.1" | 23 | git2 = "0.18.1" |
| 24 | indicatif = "0.17.7" | 24 | indicatif = "0.17.7" |
| 25 | keyring = "2.0.5" | 25 | keyring = "2.0.5" |
| 26 | nostr = "0.29" | 26 | nostr = { git = "https://github.com/DanConwayDev/nostr", branch="expose-nip49-log-n" } |
| 27 | nostr-sdk = "0.29" | 27 | nostr-sdk = { git = "https://github.com/DanConwayDev/nostr", branch="expose-nip49-log-n" } |
| 28 | passwords = "3.1.13" | 28 | passwords = "3.1.13" |
| 29 | scrypt = "0.11.0" | 29 | scrypt = "0.11.0" |
| 30 | serde = { version = "1.0.181", features = ["derive"] } | 30 | serde = { version = "1.0.181", features = ["derive"] } |
diff --git a/src/key_handling/encryption.rs b/src/key_handling/encryption.rs index 54002fa..3f4ee41 100644 --- a/src/key_handling/encryption.rs +++ b/src/key_handling/encryption.rs | |||
| @@ -1,16 +1,7 @@ | |||
| 1 | use std::str::FromStr; | 1 | use anyhow::Result; |
| 2 | |||
| 3 | use anyhow::{anyhow, bail, ensure, Context, Result}; | ||
| 4 | use chacha20poly1305::{ | ||
| 5 | aead::{rand_core::RngCore, Aead, AeadCore, KeyInit, OsRng, Payload}, | ||
| 6 | XChaCha20Poly1305, | ||
| 7 | }; | ||
| 8 | #[cfg(test)] | 2 | #[cfg(test)] |
| 9 | use mockall::*; | 3 | use mockall::*; |
| 10 | use nostr::{prelude::*, Keys}; | 4 | use nostr::{prelude::*, Keys}; |
| 11 | use nostr_sdk::bech32::{self, FromBase32, ToBase32}; | ||
| 12 | use rand::{distributions::Alphanumeric, thread_rng, Rng}; | ||
| 13 | use zeroize::Zeroize; | ||
| 14 | 5 | ||
| 15 | #[derive(Default)] | 6 | #[derive(Default)] |
| 16 | pub struct Encryptor; | 7 | pub struct Encryptor; |
| @@ -20,143 +11,38 @@ pub trait EncryptDecrypt { | |||
| 20 | /// requires less CPU time if the password is long | 11 | /// requires less CPU time if the password is long |
| 21 | fn encrypt_key(&self, keys: &Keys, password: &str) -> Result<String>; | 12 | fn encrypt_key(&self, keys: &Keys, password: &str) -> Result<String>; |
| 22 | fn decrypt_key(&self, encrypted_key: &str, password: &str) -> Result<Keys>; | 13 | fn decrypt_key(&self, encrypted_key: &str, password: &str) -> Result<Keys>; |
| 23 | /// generates a long random string | ||
| 24 | fn random_token(&self) -> String; | ||
| 25 | } | 14 | } |
| 26 | 15 | ||
| 27 | /// approach and code adapted from nostr gossip client | 16 | /// approach and code adapted from nostr gossip client |
| 28 | impl EncryptDecrypt for Encryptor { | 17 | impl EncryptDecrypt for Encryptor { |
| 29 | fn encrypt_key(&self, keys: &Keys, password: &str) -> Result<String> { | 18 | fn encrypt_key(&self, keys: &Keys, password: &str) -> Result<String> { |
| 30 | // Generate a random 16-byte salt | ||
| 31 | let salt = { | ||
| 32 | let mut salt: [u8; 16] = [0; 16]; | ||
| 33 | OsRng.fill_bytes(&mut salt); | ||
| 34 | salt | ||
| 35 | }; | ||
| 36 | |||
| 37 | let nonce = XChaCha20Poly1305::generate_nonce(&mut OsRng); | ||
| 38 | |||
| 39 | let log2_rounds: u8 = if password.len() > 20 { | 19 | let log2_rounds: u8 = if password.len() > 20 { |
| 40 | // we have enough of entropy - no need to spend CPU time adding much more | 20 | // we have enough of entropy - no need to spend CPU time adding much more |
| 41 | 1 | 21 | 1 |
| 42 | } else { | 22 | } else { |
| 23 | println!("this may take a few seconds..."); | ||
| 43 | // default (scrypt::Params::RECOMMENDED_LOG_N) is 17 but 30s is too long to wait | 24 | // default (scrypt::Params::RECOMMENDED_LOG_N) is 17 but 30s is too long to wait |
| 44 | 15 | 25 | 15 |
| 45 | }; | 26 | }; |
| 46 | 27 | Ok(nostr::nips::nip49::EncryptedSecretKey::new( | |
| 47 | let associated_data: Vec<u8> = vec![1]; | 28 | keys.secret_key()?, |
| 48 | 29 | password, | |
| 49 | let ciphertext = { | 30 | log2_rounds, |
| 50 | let cipher = { | 31 | KeySecurity::Medium, |
| 51 | let symmetric_key = password_to_key(password, &salt, log2_rounds) | 32 | )? |
| 52 | .context("failed create encryption key from password")?; | 33 | .to_bech32()?) |
| 53 | XChaCha20Poly1305::new((&symmetric_key).into()) | ||
| 54 | }; | ||
| 55 | cipher | ||
| 56 | .encrypt( | ||
| 57 | &nonce, | ||
| 58 | Payload { | ||
| 59 | msg: keys | ||
| 60 | .secret_key() | ||
| 61 | .context( | ||
| 62 | "supplied key should reveal secret key. Is this a public key only?", | ||
| 63 | )? | ||
| 64 | .display_secret() | ||
| 65 | .to_string() | ||
| 66 | .as_bytes(), | ||
| 67 | aad: &associated_data, | ||
| 68 | }, | ||
| 69 | ) | ||
| 70 | .map_err(|_| anyhow!("ChaChaPoly1305 failed to encrypt nsec with password"))? | ||
| 71 | }; | ||
| 72 | // Combine salt, IV and ciphertext | ||
| 73 | let mut concatenation: Vec<u8> = Vec::new(); | ||
| 74 | concatenation.push(0x1); // 1 byte version number | ||
| 75 | concatenation.push(log2_rounds); // 1 byte for scrypt N (rounds) | ||
| 76 | concatenation.extend(salt); // 16 bytes of salt | ||
| 77 | concatenation.extend(nonce); // 24 bytes of nonce | ||
| 78 | concatenation.extend(associated_data); // 1 byte of key security | ||
| 79 | concatenation.extend(ciphertext); // 48 bytes of ciphertext expected | ||
| 80 | // Total length is 91 = 1 + 1 + 16 + 24 + 1 + 48 | ||
| 81 | |||
| 82 | bech32::encode( | ||
| 83 | "ncryptsec", | ||
| 84 | concatenation.to_base32(), | ||
| 85 | bech32::Variant::Bech32, | ||
| 86 | ) | ||
| 87 | .context("encrypted nsec failed to encode") | ||
| 88 | } | 34 | } |
| 89 | 35 | ||
| 90 | fn decrypt_key(&self, encrypted_key: &str, password: &str) -> Result<nostr::Keys> { | 36 | fn decrypt_key(&self, encrypted_key: &str, password: &str) -> Result<nostr::Keys> { |
| 91 | let data = | 37 | let encrypted_key = nostr::nips::nip49::EncryptedSecretKey::from_bech32(encrypted_key)?; |
| 92 | bech32::decode(encrypted_key).context("failed to decode encrypted key as bech32")?; | 38 | // to request that log_n gets exposed |
| 93 | if data.0 != "ncryptsec" { | 39 | if encrypted_key.log_n() > 14 { |
| 94 | bail!("encrypted key is in the wrong format - it doesnt start with ncryptsec"); | 40 | println!("this may take a few seconds..."); |
| 95 | } | ||
| 96 | let concatenation = Vec::<u8>::from_base32(&data.1) | ||
| 97 | .context("failed to convert bech32::decode output to Vec<u8>")?; | ||
| 98 | |||
| 99 | // Break into parts | ||
| 100 | let version: u8 = concatenation[0]; | ||
| 101 | ensure!(version == 0x1, "encryption version is incorrect"); | ||
| 102 | let log2_rounds: u8 = concatenation[1]; | ||
| 103 | let salt: [u8; 16] = concatenation[2..2 + 16].try_into()?; | ||
| 104 | let nonce = &concatenation[2 + 16..2 + 16 + 24]; | ||
| 105 | let associated_data = &concatenation[(2 + 16 + 24)..=(2 + 16 + 24)]; | ||
| 106 | let ciphertext = &concatenation[2 + 16 + 24 + 1..]; | ||
| 107 | |||
| 108 | let cipher = { | ||
| 109 | let symmetric_key = password_to_key(password, &salt, log2_rounds)?; | ||
| 110 | XChaCha20Poly1305::new((&symmetric_key).into()) | ||
| 111 | }; | ||
| 112 | |||
| 113 | let payload = Payload { | ||
| 114 | msg: ciphertext, | ||
| 115 | aad: associated_data, | ||
| 116 | }; | ||
| 117 | |||
| 118 | let mut inner_secret = cipher | ||
| 119 | .decrypt(nonce.into(), payload) | ||
| 120 | .map_err(|_| anyhow!("failed to decrypt"))?; | ||
| 121 | |||
| 122 | if associated_data.is_empty() { | ||
| 123 | bail!("invalid encrypted key"); | ||
| 124 | } | 41 | } |
| 125 | 42 | Ok(nostr::Keys::new(encrypted_key.to_secret_key(password)?)) | |
| 126 | let key = | ||
| 127 | Keys::from_str(std::str::from_utf8(&inner_secret).context("inner secret is not [u8]")?) | ||
| 128 | .context( | ||
| 129 | "incorrect password. Key decrypted with password did not produce a valid nsec.", | ||
| 130 | )?; | ||
| 131 | |||
| 132 | inner_secret.zeroize(); | ||
| 133 | |||
| 134 | Ok(key) | ||
| 135 | } | ||
| 136 | |||
| 137 | fn random_token(&self) -> String { | ||
| 138 | thread_rng() | ||
| 139 | .sample_iter(&Alphanumeric) | ||
| 140 | .take(32) | ||
| 141 | .map(char::from) | ||
| 142 | .collect() | ||
| 143 | } | 43 | } |
| 144 | } | 44 | } |
| 145 | 45 | ||
| 146 | /// uses scrypt to stretch password into key | ||
| 147 | fn password_to_key(password: &str, salt: &[u8; 16], log_n: u8) -> Result<[u8; 32]> { | ||
| 148 | let params = scrypt::Params::new(log_n, 8, 1, 32) | ||
| 149 | .context("scrypt failed to generate params to stretch password")?; | ||
| 150 | let mut key: [u8; 32] = [0; 32]; | ||
| 151 | if log_n > 14 { | ||
| 152 | println!("this may take a few seconds..."); | ||
| 153 | } | ||
| 154 | |||
| 155 | scrypt::scrypt(password.as_bytes(), salt, ¶ms, &mut key) | ||
| 156 | .context("scrypt failed to stretch password")?; | ||
| 157 | Ok(key) | ||
| 158 | } | ||
| 159 | |||
| 160 | #[cfg(test)] | 46 | #[cfg(test)] |
| 161 | mod tests { | 47 | mod tests { |
| 162 | use test_utils::*; | 48 | use test_utils::*; |
| @@ -235,17 +121,4 @@ mod tests { | |||
| 235 | ); | 121 | ); |
| 236 | Ok(()) | 122 | Ok(()) |
| 237 | } | 123 | } |
| 238 | |||
| 239 | #[test] | ||
| 240 | fn password_to_key_returns_ok_with_standard_password() { | ||
| 241 | let salt = { | ||
| 242 | let mut salt: [u8; 16] = [0; 16]; | ||
| 243 | OsRng.fill_bytes(&mut salt); | ||
| 244 | salt | ||
| 245 | }; | ||
| 246 | |||
| 247 | let log2_rounds: u8 = 1; | ||
| 248 | |||
| 249 | assert!(password_to_key(TEST_PASSWORD, &salt, log2_rounds).is_ok()); | ||
| 250 | } | ||
| 251 | } | 124 | } |
diff --git a/test_utils/Cargo.toml b/test_utils/Cargo.toml index c4e1b1a..0784b1a 100644 --- a/test_utils/Cargo.toml +++ b/test_utils/Cargo.toml | |||
| @@ -9,8 +9,8 @@ assert_cmd = "2.0.12" | |||
| 9 | dialoguer = "0.10.4" | 9 | dialoguer = "0.10.4" |
| 10 | directories = "5.0.1" | 10 | directories = "5.0.1" |
| 11 | git2 = "0.18.1" | 11 | git2 = "0.18.1" |
| 12 | nostr = "0.29" | 12 | nostr = { git = "https://github.com/DanConwayDev/nostr", branch="expose-nip49-log-n" } |
| 13 | nostr-sdk = "0.29" | 13 | nostr-sdk = { git = "https://github.com/DanConwayDev/nostr", branch="expose-nip49-log-n" } |
| 14 | once_cell = "1.18.0" | 14 | once_cell = "1.18.0" |
| 15 | rand = "0.8" | 15 | rand = "0.8" |
| 16 | rexpect = { git = "https://github.com/rust-cli/rexpect.git", rev = "9eb61dd" } | 16 | rexpect = { git = "https://github.com/rust-cli/rexpect.git", rev = "9eb61dd" } |
diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs index a693607..daed8fa 100644 --- a/test_utils/src/lib.rs +++ b/test_utils/src/lib.rs | |||
| @@ -24,8 +24,8 @@ pub static TEST_KEY_1_NPUB: &str = | |||
| 24 | pub static TEST_KEY_1_PUBKEY_HEX: &str = | 24 | pub static TEST_KEY_1_PUBKEY_HEX: &str = |
| 25 | "f53e4bcd7a9cdef049cf6467d638a1321958acd3b71eb09823fd6fadb023d768"; | 25 | "f53e4bcd7a9cdef049cf6467d638a1321958acd3b71eb09823fd6fadb023d768"; |
| 26 | pub static TEST_KEY_1_DISPLAY_NAME: &str = "bob"; | 26 | pub static TEST_KEY_1_DISPLAY_NAME: &str = "bob"; |
| 27 | pub static TEST_KEY_1_ENCRYPTED: &str = "ncryptsec1qyq607h3cykxc3f2a44u89cdk336fptccn3fm5pf3nmf93d3c86qpunc7r6klwcn6lyszjy72wxwqq9aljg4pm6atvjrds9e248yhv76xfnt464265kgnjsvg8rlg06wg4sp9uljzfpu8zuaztcvfn2j8ggdrg8mldh850cy75efsyqqansert9wqmn4e6khpgvfz7h5le9"; | 27 | pub static TEST_KEY_1_ENCRYPTED: &str = "ncryptsec1qgq77e3uftz8dh3jkjxwdms3v6gwqaqduxyzld82kskas8jcs5xup3sf2pc5tr0erqkqrtu0ptnjgjlgvx8lt7c0d7laryq2u7psfa6zm7mk7ln3ln58468shwatm7cx5wy5wvm7yk74ksrngygwxg74"; |
| 28 | pub static TEST_KEY_1_ENCRYPTED_WEAK: &str = "ncryptsec1qy8ke0tjqnn8wt3w6lnc86c27ry3qrptxctjfcgruryxy0at238kwyjwsswd7z88thysruzw3awlrsxjvw5uptcd7vt70ft9rtkx00m8cgy3khm4hxa5d2gfnc6athnfruy2eyl6pkas8k34jg85z7xjqqadzfzh9rp0fzxqtw0tvxksac3n8yc98uksvuf93e0lcvqy8j6"; | 28 | pub static TEST_KEY_1_ENCRYPTED_WEAK: &str = "ncryptsec1qg835almhlrmyxqtqeva44d5ugm9wk2ccmwspxrqv4wjsdpdlud9es5hsrvs0pas7dvsretm0mc26qwfc7v8986mqngnjshcplnqzj62lxf44a0kkdv788f6dh20x2eum96l2j8v37s5grrheu2hgrkf"; |
| 29 | pub static TEST_KEY_1_KEYS: Lazy<nostr::Keys> = | 29 | pub static TEST_KEY_1_KEYS: Lazy<nostr::Keys> = |
| 30 | Lazy::new(|| nostr::Keys::from_str(TEST_KEY_1_NSEC).unwrap()); | 30 | Lazy::new(|| nostr::Keys::from_str(TEST_KEY_1_NSEC).unwrap()); |
| 31 | 31 | ||
| @@ -121,13 +121,13 @@ pub fn make_event_old_or_change_user( | |||
| 121 | 121 | ||
| 122 | unsigned.created_at = | 122 | unsigned.created_at = |
| 123 | nostr::types::Timestamp::from(nostr::types::Timestamp::now().as_u64() - how_old_in_secs); | 123 | nostr::types::Timestamp::from(nostr::types::Timestamp::now().as_u64() - how_old_in_secs); |
| 124 | unsigned.id = nostr::EventId::new( | 124 | unsigned.id = Some(nostr::EventId::new( |
| 125 | &keys.public_key(), | 125 | &keys.public_key(), |
| 126 | unsigned.created_at, | 126 | &unsigned.created_at, |
| 127 | &unsigned.kind, | 127 | &unsigned.kind, |
| 128 | &unsigned.tags, | 128 | &unsigned.tags, |
| 129 | &unsigned.content, | 129 | &unsigned.content, |
| 130 | ); | 130 | )); |
| 131 | 131 | ||
| 132 | unsigned.sign(keys).unwrap() | 132 | unsigned.sign(keys).unwrap() |
| 133 | } | 133 | } |
diff --git a/tests/login.rs b/tests/login.rs index 351d099..371a7e7 100644 --- a/tests/login.rs +++ b/tests/login.rs | |||
| @@ -956,7 +956,7 @@ mod with_offline_flag { | |||
| 956 | p.expect(format!("login as {}\r\n", TEST_KEY_1_NPUB).as_str())? | 956 | p.expect(format!("login as {}\r\n", TEST_KEY_1_NPUB).as_str())? |
| 957 | .expect_password(EXPECTED_PASSWORD_PROMPT)? | 957 | .expect_password(EXPECTED_PASSWORD_PROMPT)? |
| 958 | .succeeds_with(TEST_INVALID_PASSWORD)?; | 958 | .succeeds_with(TEST_INVALID_PASSWORD)?; |
| 959 | p.expect_end_with(format!("Error: failed to log in as {}\r\n\r\nCaused by:\r\n 0: failed to decrypt key with provided password\r\n 1: failed to decrypt\r\n", TEST_KEY_1_NPUB).as_str()) | 959 | p.expect_end_with(format!("Error: failed to log in as {}\r\n\r\nCaused by:\r\n 0: failed to decrypt key with provided password\r\n 1: ChaCha20Poly1305: aead::Error\r\n", TEST_KEY_1_NPUB).as_str()) |
| 960 | }) | 960 | }) |
| 961 | } | 961 | } |
| 962 | } | 962 | } |