Skip to content

Commit a75e930

Browse files
authored
Add openssl version -a and -p flag support (#3092)
### Description of changes: For compatibility, we should implement these CLI flags to prevent certain test scripts from erroring out. Add -a (all) and -p (platform) boolean flags to the version subcommand: - No flags: print version line only (preserves existing behavior) - -a: print version, built on, platform, compiler, OPENSSLDIR - -p: print platform line only ### Call-outs: This doesn't actually print anything useful, but it does call the OpenSSL APIs and prints the stub strings that we had in place. If I had to hazard a guess this was either an intentional attempt to avoid leaking implementation details or they were lazy (Occam's razor suggests the latter). ### Testing: How is this change tested (unit tests, fuzz tests, etc.)? Are there any testing steps to be verified by the reviewer? ``` # Sample outputs ➜ aws-lc git:(version-a) ✗ ./build/tool-openssl/openssl version -p platform: n/a ➜ aws-lc git:(version-a) ✗ ./build/tool-openssl/openssl version -a OpenSSL 1.1.1 (compatible; AWS-LC 1.69.0) built on: n/a platform: n/a compiler: n/a OPENSSLDIR: n/a ``` By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.
1 parent 474a12c commit a75e930

1 file changed

Lines changed: 32 additions & 2 deletions

File tree

tool-openssl/version.cc

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,51 @@
22
// SPDX-License-Identifier: Apache-2.0 OR ISC
33

44
#include <openssl/base.h>
5+
#include <openssl/crypto.h>
56
#include "internal.h"
67

78
static const argument_t kArguments[] = {
8-
{ "", kOptionalArgument, "" }
9+
{"-help", kBooleanArgument, "Display option summary"},
10+
{"-a", kBooleanArgument, "Print all version information"},
11+
{"-p", kBooleanArgument, "Print platform"},
12+
{"", kOptionalArgument, ""}
913
};
1014

1115
bool VersionTool(const args_list_t &args) {
1216
using namespace ordered_args;
1317
ordered_args_map_t parsed_args;
1418
args_list_t extra_args;
15-
if (!ParseOrderedKeyValueArguments(parsed_args, extra_args, args, kArguments) ||
19+
if (!ParseOrderedKeyValueArguments(parsed_args, extra_args, args,
20+
kArguments) ||
1621
extra_args.size() > 0) {
1722
PrintUsage(kArguments);
1823
return false;
1924
}
25+
26+
if (HasArgument(parsed_args, "-help")) {
27+
PrintUsage(kArguments);
28+
return true;
29+
}
30+
31+
bool all = false;
32+
bool platform = false;
33+
GetBoolArgument(&all, "-a", parsed_args);
34+
GetBoolArgument(&platform, "-p", parsed_args);
35+
36+
if (all) {
37+
printf("%s\n", OPENSSL_VERSION_TEXT);
38+
printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
39+
printf("%s\n", OpenSSL_version(OPENSSL_PLATFORM));
40+
printf("%s\n", OpenSSL_version(OPENSSL_CFLAGS));
41+
printf("%s\n", OpenSSL_version(OPENSSL_DIR));
42+
return true;
43+
}
44+
45+
if (platform) {
46+
printf("%s\n", OpenSSL_version(OPENSSL_PLATFORM));
47+
return true;
48+
}
49+
2050
printf("%s\n", OPENSSL_VERSION_TEXT);
2151
return true;
2252
}

0 commit comments

Comments
 (0)