@@ -104,7 +104,8 @@ enum {
104104 OPT_DEBUG_TLS ,
105105 OPT_API_VERSION ,
106106 OPT_MEMORY ,
107- OPT_USE_FUTURE_PROTOCOL_VERSION
107+ OPT_USE_FUTURE_PROTOCOL_VERSION ,
108+ OPT_ENCRYPT
108109};
109110
110111CSimpleOpt::SOption g_rgOptions[] = { { OPT_CONNFILE , " -C" , SO_REQ_SEP },
@@ -130,6 +131,7 @@ CSimpleOpt::SOption g_rgOptions[] = { { OPT_CONNFILE, "-C", SO_REQ_SEP },
130131 { OPT_API_VERSION , " --api-version" , SO_REQ_SEP },
131132 { OPT_MEMORY , " --memory" , SO_REQ_SEP },
132133 { OPT_USE_FUTURE_PROTOCOL_VERSION , " --use-future-protocol-version" , SO_NONE },
134+ { OPT_ENCRYPT , " --encrypt" , SO_REQ_SEP },
133135 TLS_OPTION_FLAGS ,
134136 SO_END_OF_OPTIONS };
135137
@@ -503,6 +505,11 @@ static void printProgramUsage(const char* name) {
503505 " --use-future-protocol-version\n "
504506 " Use the simulated future protocol version to connect to the cluster.\n "
505507 " 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 "
506513 " -v, --version Print FoundationDB CLI version information and exit.\n "
507514 " -h, --help Display this help and exit.\n " );
508515}
@@ -903,7 +910,6 @@ void LogCommand(std::string line, UID randomID, std::string errMsg) {
903910 printf (" %s\n " , errMsg.c_str ());
904911 TraceEvent (SevInfo, " CLICommandLog" , randomID).detail (" Command" , line).detail (" Error" , errMsg);
905912}
906-
907913struct CLIOptions {
908914 std::string program_name;
909915 int exit_code = -1 ;
@@ -928,6 +934,7 @@ struct CLIOptions {
928934 std::string tlsPassword;
929935 bool tlsDisablePlainTextConnection = false ;
930936 uint64_t memLimit = 8uLL << 30 ;
937+ Optional<std::string> encrypt;
931938
932939 std::vector<std::pair<std::string, std::string>> knobs;
933940
@@ -1070,6 +1077,9 @@ struct CLIOptions {
10701077 knobs.emplace_back (knobName.get (), args.OptionArg ());
10711078 break ;
10721079 }
1080+ case OPT_ENCRYPT :
1081+ encrypt = args.OptionArg ();
1082+ break ;
10731083 case OPT_DEBUG_TLS :
10741084 debugTLS = true ;
10751085 break ;
@@ -2450,6 +2460,16 @@ int main(int argc, char** argv) {
24502460 if (opt.exit_code != -1 )
24512461 return opt.exit_code ;
24522462
2463+ if (opt.encrypt .present ()) {
2464+ std::string encrypted;
2465+ if (!TLSConfig::encodePassword (opt.encrypt .get (), encrypted)) {
2466+ fprintf (stderr, " ERROR: Failed to encrypt password\n " );
2467+ return 1 ;
2468+ }
2469+ printf (" %s\n " , encrypted.c_str ());
2470+ return 0 ;
2471+ }
2472+
24532473 if (opt.trace ) {
24542474 if (opt.traceDir .empty ())
24552475 setNetworkOption (FDBNetworkOptions::TRACE_ENABLE );
0 commit comments