Skip to content

Commit 5ff0bd5

Browse files
authored
Display X509 fingerprint after hash (#2444)
1 parent 7b9a58e commit 5ff0bd5

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

tool-openssl/x509.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,14 @@ bool X509Tool(const args_list_t &args) {
304304
BIO_printf(output_bio.get(), "\n");
305305
}
306306

307+
if (subject_hash) {
308+
BIO_printf(output_bio.get(), "%08x\n", X509_subject_name_hash(x509.get()));
309+
}
310+
311+
if(subject_hash_old) {
312+
BIO_printf(output_bio.get(), "%08x\n", X509_subject_name_hash_old(x509.get()));
313+
}
314+
307315
if (fingerprint) {
308316
unsigned int out_len;
309317
unsigned char md[EVP_MAX_MD_SIZE];
@@ -321,14 +329,6 @@ bool X509Tool(const args_list_t &args) {
321329
}
322330
}
323331

324-
if (subject_hash) {
325-
BIO_printf(output_bio.get(), "%08x\n", X509_subject_name_hash(x509.get()));
326-
}
327-
328-
if(subject_hash_old) {
329-
BIO_printf(output_bio.get(), "%08x\n", X509_subject_name_hash_old(x509.get()));
330-
}
331-
332332
if (dates) {
333333
BIO_printf(output_bio.get(), "notBefore=");
334334
ASN1_TIME_print(output_bio.get(), X509_get_notBefore(x509.get()));

tool-openssl/x509_test.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,16 @@ TEST_F(X509ComparisonTest, X509ToolCompareFingerprintOpenSSL) {
474474
ASSERT_EQ(tool_output_str, openssl_output_str);
475475
}
476476

477+
// Test against OpenSSL output "openssl x509 -in file -fingerprint -subject_hash -subject_hash_old"
478+
TEST_F(X509ComparisonTest, X509ToolCompareHashFingerprintOpenSSL) {
479+
std::string tool_command = std::string(tool_executable_path) + " x509 -subject_hash -fingerprint -noout -in " + in_path + " > " + out_path_tool;
480+
std::string openssl_command = std::string(openssl_executable_path) + " x509 -subject_hash -fingerprint -noout -in " + in_path + " > " + out_path_openssl;
481+
482+
RunCommandsAndCompareOutput(tool_command, openssl_command, out_path_tool, out_path_openssl, tool_output_str, openssl_output_str);
483+
484+
ASSERT_EQ(tool_output_str, openssl_output_str);
485+
}
486+
477487
// Test against OpenSSL output "openssl x509 -in file -noout -subject -fingerprint"
478488
TEST_F(X509ComparisonTest, X509ToolCompareSubjectFingerprintOpenSSL) {
479489
std::string tool_command = std::string(tool_executable_path) + " x509 -in " + in_path + " -noout -subject -fingerprint > " + out_path_tool;

0 commit comments

Comments
 (0)