MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / performHandshakeForSSHAuth

Method performHandshakeForSSHAuth

src/Client/Connection.cpp:526–563  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

524
525#if USE_SSH
526void Connection::performHandshakeForSSHAuth()
527{
528 String challenge;
529 {
530 writeVarUInt(Protocol::Client::SSHChallengeRequest, *out);
531 out->next();
532 UInt64 packet_type = 0;
533 if (in->eof())
534 throw Poco::Net::NetException("Connection reset by peer");
535
536 readVarUInt(packet_type, *in);
537 if (packet_type == Protocol::Server::SSHChallenge)
538 {
539 readStringBinary(challenge, *in);
540 }
541 else if (packet_type == Protocol::Server::Exception)
542 receiveException()->rethrow();
543 else
544 throwUnexpectedPacket(packet_type, "SSHChallenge or Exception");
545 }
546
547 writeVarUInt(Protocol::Client::SSHChallengeResponse, *out);
548
549 auto pack_string_for_ssh_sign = [&](String challenge_)
550 {
551 String message;
552 message.append(std::to_string(DBMS_TCP_PROTOCOL_VERSION));
553 message.append(default_database);
554 message.append(user);
555 message.append(challenge_);
556 return message;
557 };
558
559 String to_sign = pack_string_for_ssh_sign(challenge);
560 String signature = ssh_private_key.signString(to_sign);
561 writeStringBinary(signature, *out);
562 out->next();
563}
564#endif
565
566

Callers

nothing calls this directly

Calls 10

writeVarUIntFunction · 0.85
NetExceptionClass · 0.85
readStringBinaryFunction · 0.85
writeStringBinaryFunction · 0.85
to_stringFunction · 0.50
nextMethod · 0.45
eofMethod · 0.45
rethrowMethod · 0.45
appendMethod · 0.45
signStringMethod · 0.45

Tested by

no test coverage detected