Skip to content

Add password prompting support & EVP_read_pw_string #2419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 35 commits into
base: main
Choose a base branch
from

Conversation

smittals2
Copy link
Contributor

Issues:

CryptoAlg-3060

Description of changes:

  1. Add console* suite of functions to interact with the terminal on both linux and windows with fallbacks to stdin and stdout
  2. Add EVP_read_pw_string
  3. Align PEM_def_callback's behavior with OpenSSL. Previously, this function would fail if the userdata param was NULL. This is different from openSSL which would prompt a user for a password in the same scenario. Now PEM_def_callback will correctly prompt the user if userdata is NULL.
  4. Remove temp workaround in the OpenSSL req tool and use prompting from PEM_def_callback. Add carriage return support so this tool works on windows.

Call-outs:

  • The tests are disabled on android, tmpfile() doesn't work on androids when running form APK.

Testing:

We only test the stdin stdout routes in GTest. Console functionality was manually tested.

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.

@smittals2 smittals2 requested a review from a team as a code owner May 13, 2025 22:09
@smittals2 smittals2 requested a review from justsmth May 13, 2025 22:10
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

@smittals2 smittals2 requested a review from skmcgrail May 14, 2025 20:20
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

@codecov-commenter
Copy link

codecov-commenter commented May 14, 2025

Codecov Report

Attention: Patch coverage is 60.75949% with 93 lines in your changes missing coverage. Please review.

Project coverage is 78.87%. Comparing base (6c961b6) to head (78ed56b).
Report is 17 commits behind head on main.

Files with missing lines Patch % Lines
crypto/fipsmodule/evp/evp.c 0.00% 37 Missing ⚠️
crypto/console/console.c 69.74% 36 Missing ⚠️
crypto/pem/pem_lib.c 0.00% 15 Missing ⚠️
crypto/thread_pthread.c 66.66% 3 Missing ⚠️
crypto/console/console_test.cc 96.49% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2419      +/-   ##
==========================================
+ Coverage   78.81%   78.87%   +0.05%     
==========================================
  Files         621      623       +2     
  Lines      108431   108874     +443     
  Branches    15398    15442      +44     
==========================================
+ Hits        85462    85875     +413     
- Misses      22299    22325      +26     
- Partials      670      674       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

@smittals2 smittals2 requested review from skmcgrail and justsmth May 22, 2025 00:53
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

// if there is not enough room. If either |buf| or |userdata| is NULL, 0 is
// returned. Note that this is different from OpenSSL, which prompts for a
// password.
// PEM_def_callback provides a password for PEM encryption/decryption operations.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should mention that this function is used as the default callback to provide a password for PEM functions such as PEM_do_header and PEM_ASN1_write_bio. Currently, the documentation for PEM_ASN1_write_bio makes no mention of this, and PEM_do_header is undocumented.

Copy link
Contributor Author

@smittals2 smittals2 May 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, there's more use cases for the PEM_def_callback. I'll update the comments here to talk about the other 2 funcs as well. Looks like both PEM_do_header and PEM_ASN1_write_bio are undocumented, wrote new stuff for them

@smittals2 smittals2 requested a review from justsmth May 23, 2025 20:56
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

}

// Proactively zeroize |buf| and verify_buf
OPENSSL_cleanse(buf, sizeof(buf));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
OPENSSL_cleanse(buf, sizeof(buf));
OPENSSL_cleanse(buf, length);

This should be length I think? Otherwise you are just getting the size of the pointer no?

#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <string.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include <string.h>

Already imported on line 7

// Read password with echo disabled, returns 1 on success, 0 on error, -2 on interrupt
ret = openssl_console_read(buf, min_length, length, 0);
if (ret != 0) {
OPENSSL_cleanse(buf, sizeof(buf));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
OPENSSL_cleanse(buf, sizeof(buf));
OPENSSL_cleanse(buf, length);

Same question if this should be length

Comment on lines +213 to +216
if (strncmp(buf, verify_buf, length >= 1024 ? 1024 : length) != 0) {
openssl_console_write("Verify failure\n");
ret = -1;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a weird behavior to me? We only verify the first 1024 characters if the input length is longer then 1024? Should we just set a hard limit that length can't exceed 1024?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I guess is there any constant time concerns around comparing this value in memory?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants