Skip to content

Commit cac2bac

Browse files
committed
Add backwards compatibility for lokinet 0.9 private keyfiles
1 parent 91876a9 commit cac2bac

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

llarp/crypto/key_manager.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,23 @@ namespace llarp
1515
{
1616
log::trace(logcat, "{} called", __PRETTY_FUNCTION__);
1717

18-
auto tmp = util::file_to_string(fname, 130);
18+
auto tmp = util::file_to_string(fname);
1919
if ((tmp.size() == 128 or (tmp.size() == 129 and tmp.ends_with("\n"))
2020
or (tmp.size() == 130 and tmp.ends_with("\r\n")))
2121
and oxenc::is_hex(tmp.begin(), tmp.begin() + 128))
2222
oxenc::from_hex(tmp.begin(), tmp.begin() + 128, key.data());
2323
else if (tmp.size() == 64)
2424
std::memcpy(key.data(), tmp.data(), 64);
25+
else if (tmp.starts_with('d') and tmp.ends_with('e')) {
26+
// Old Lokinet keys were bt-dicts with the key we care about in the 's' key:
27+
oxenc::bt_dict_consumer old{tmp};
28+
auto oldkey = old.require_span<unsigned char, 64>("s");
29+
std::memcpy(key.data(), oldkey.data(), 64);
30+
old.finish();
31+
}
2532
else
2633
throw std::invalid_argument{
27-
"Invalid key file {}: Expected 64 bytes or 128 hex, not {}"_format(fname, tmp.size())};
34+
"Invalid key file {} ({}B): Expected 64 bytes, 128 hex, or legacy lokinet key file"_format(fname, tmp.size())};
2835

2936
if (!key.check_pubkey())
3037
throw std::invalid_argument{"Invalid key file {}: Keypair seed and pubkey do not match"};

0 commit comments

Comments
 (0)