MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / GetValidSecretKeyAndUpdatePublicKey

Method GetValidSecretKeyAndUpdatePublicKey

src/network/network_crypto.cpp:334–349  ·  view source on GitHub ↗

* Get the secret key from the given string. If that is not a valid secret key, reset it with a random one. * Furthermore update the public key so it is always in sync with the private key. * @param secret_key The secret key to read/validate/fix. * @param public_key The public key to update. * @return The valid secret key. */ static */

Source from the content-addressed store, hash-verified

332 * @return The valid secret key.
333 */
334/* static */ X25519SecretKey X25519AuthorizedKeyClientHandler::GetValidSecretKeyAndUpdatePublicKey(std::string &secret_key, std::string &public_key)
335{
336 X25519SecretKey key{};
337 if (!ConvertHexToBytes(secret_key, key)) {
338 if (secret_key.empty()) {
339 Debug(net, 3, "[crypto] Creating a new random key");
340 } else {
341 Debug(net, 0, "[crypto] Found invalid secret key, creating a new random key");
342 }
343 key = X25519SecretKey::CreateRandom();
344 secret_key = FormatArrayAsHex(key);
345 }
346
347 public_key = FormatArrayAsHex(key.CreatePublicKey());
348 return key;
349}
350
351/* virtual */ NetworkAuthenticationServerHandler::ResponseResult X25519AuthorizedKeyServerHandler::ReceiveResponse(Packet &p)
352{

Callers

nothing calls this directly

Calls 4

ConvertHexToBytesFunction · 0.85
FormatArrayAsHexFunction · 0.85
CreatePublicKeyMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected