Skip to content

Commit 32e1b46

Browse files
authored
Revert "Xdb 402 decode password (#201)" (#202)
This reverts commit 8530321.
1 parent 8530321 commit 32e1b46

3 files changed

Lines changed: 3 additions & 100 deletions

File tree

fdbcli/fdbcli.actor.cpp

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ enum {
104104
OPT_DEBUG_TLS,
105105
OPT_API_VERSION,
106106
OPT_MEMORY,
107-
OPT_USE_FUTURE_PROTOCOL_VERSION,
108-
OPT_ENCRYPT
107+
OPT_USE_FUTURE_PROTOCOL_VERSION
109108
};
110109

111110
CSimpleOpt::SOption g_rgOptions[] = { { OPT_CONNFILE, "-C", SO_REQ_SEP },
@@ -131,7 +130,6 @@ CSimpleOpt::SOption g_rgOptions[] = { { OPT_CONNFILE, "-C", SO_REQ_SEP },
131130
{ OPT_API_VERSION, "--api-version", SO_REQ_SEP },
132131
{ OPT_MEMORY, "--memory", SO_REQ_SEP },
133132
{ OPT_USE_FUTURE_PROTOCOL_VERSION, "--use-future-protocol-version", SO_NONE },
134-
{ OPT_ENCRYPT, "--encrypt", SO_REQ_SEP },
135133
TLS_OPTION_FLAGS,
136134
SO_END_OF_OPTIONS };
137135

@@ -505,11 +503,6 @@ static void printProgramUsage(const char* name) {
505503
" --use-future-protocol-version\n"
506504
" Use the simulated future protocol version to connect to the cluster.\n"
507505
" This option can be used testing purposes only!\n"
508-
" --encrypt PASSWORD\n"
509-
" Encrypts the specified password and prints the encrypted password\n"
510-
" with the `encrypted:' prefix. The encrypted password can be used\n"
511-
" with --tls-password option. This option causes fdbcli to encrypt\n"
512-
" the password and exit.\n"
513506
" -v, --version Print FoundationDB CLI version information and exit.\n"
514507
" -h, --help Display this help and exit.\n");
515508
}
@@ -906,6 +899,7 @@ void LogCommand(std::string line, UID randomID, std::string errMsg) {
906899
printf("%s\n", errMsg.c_str());
907900
TraceEvent(SevInfo, "CLICommandLog", randomID).detail("Command", line).detail("Error", errMsg);
908901
}
902+
909903
struct CLIOptions {
910904
std::string program_name;
911905
int exit_code = -1;
@@ -929,7 +923,6 @@ struct CLIOptions {
929923
std::string tlsCAPath;
930924
std::string tlsPassword;
931925
uint64_t memLimit = 8uLL << 30;
932-
Optional<std::string> encrypt;
933926

934927
std::vector<std::pair<std::string, std::string>> knobs;
935928

@@ -1069,9 +1062,6 @@ struct CLIOptions {
10691062
knobs.emplace_back(knobName.get(), args.OptionArg());
10701063
break;
10711064
}
1072-
case OPT_ENCRYPT:
1073-
encrypt = args.OptionArg();
1074-
break;
10751065
case OPT_DEBUG_TLS:
10761066
debugTLS = true;
10771067
break;
@@ -2395,16 +2385,6 @@ int main(int argc, char** argv) {
23952385
if (opt.exit_code != -1)
23962386
return opt.exit_code;
23972387

2398-
if (opt.encrypt.present()) {
2399-
std::string encrypted;
2400-
if (!TLSConfig::encodePassword(opt.encrypt.get(), encrypted)) {
2401-
fprintf(stderr, "ERROR: Failed to encrypt password\n");
2402-
return 1;
2403-
}
2404-
printf("%s\n", encrypted.c_str());
2405-
return 0;
2406-
}
2407-
24082388
if (opt.trace) {
24092389
if (opt.traceDir.empty())
24102390
setNetworkOption(FDBNetworkOptions::TRACE_ENABLE);

flow/TLSConfig.actor.cpp

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -832,78 +832,3 @@ bool TLSPolicy::verify_peer(bool preverified, X509_STORE_CTX* store_ctx) {
832832
}
833833
return rc;
834834
}
835-
struct CryptoLibHandle {
836-
void* lib = nullptr;
837-
void* func = nullptr;
838-
839-
CryptoLibHandle(std::string_view funcName) {
840-
const char* libName = "libnscipher-crypto.so";
841-
lib = loadLibrary(libName);
842-
if (!lib) {
843-
TraceEvent(SevError, "ExternalLibLoadError").detail("Library", libName);
844-
return;
845-
}
846-
func = loadFunction(lib, funcName.data());
847-
if (!func) {
848-
TraceEvent(SevError, "ExternalLibFunctionLoadError")
849-
.detail("Function", funcName)
850-
.detail("Library", libName);
851-
fprintf(stderr, "ERROR: Failed to load '%s' function\n", funcName.data());
852-
closeLibrary(lib);
853-
lib = nullptr;
854-
}
855-
}
856-
explicit operator bool() const { return func != nullptr; }
857-
~CryptoLibHandle() {
858-
if (lib)
859-
closeLibrary(lib);
860-
}
861-
};
862-
863-
static bool processWithCrypto(std::string_view funcName, const std::string& input, std::string& output) {
864-
constexpr int bufLen = 1024; // Assume max size of encrypted and decrypted password is 1024
865-
CryptoLibHandle cryptoHandle(funcName);
866-
867-
if (!cryptoHandle) {
868-
return false;
869-
}
870-
871-
int outputLen = bufLen;
872-
873-
char buf[bufLen]{};
874-
875-
auto func = reinterpret_cast<int (*)(const char*, char*, int*)>(cryptoHandle.func);
876-
if (int rc = func(input.c_str(), buf, &outputLen); rc != 0) {
877-
fprintf(stderr, "ERROR: Failed to exec function (rc=%d)\n", rc);
878-
TraceEvent(SevError, "ErrorExecFunction").detail("ReturnCode", rc);
879-
return false;
880-
}
881-
output.assign(buf, outputLen);
882-
return true;
883-
}
884-
885-
constexpr std::string_view encryptedPrefix = "encrypted:";
886-
887-
bool TLSConfig::encodePassword(const std::string& plainPassword, std::string& encoded) {
888-
if (processWithCrypto("crypt", plainPassword, encoded)) {
889-
encoded.insert(0, encryptedPrefix);
890-
return true;
891-
}
892-
return false;
893-
}
894-
895-
void TLSConfig::setPassword(const std::string& password) {
896-
if (password.size() > encryptedPrefix.size() && password.starts_with(encryptedPrefix)) {
897-
898-
std::string decoded;
899-
900-
if (processWithCrypto("decrypt", password.substr(encryptedPrefix.size()), decoded)) {
901-
tlsPassword = std::move(decoded);
902-
} else {
903-
tlsPassword.clear();
904-
TraceEvent(SevError, "FailedToDecryptPassword");
905-
}
906-
} else {
907-
tlsPassword = password;
908-
}
909-
}

flow/include/flow/TLSConfig.actor.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,7 @@ class TLSConfig {
173173
tlsCAPath = "";
174174
}
175175

176-
void setPassword(const std::string& password);
177-
178-
static bool encodePassword(const std::string& plainPassword, std::string& encoded);
176+
void setPassword(const std::string& password) { tlsPassword = password; }
179177

180178
void clearVerifyPeers() { tlsVerifyPeers.clear(); }
181179

0 commit comments

Comments
 (0)