| 1 |
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 |
// SPDX-License-Identifier: Apache-2.0 OR ISC |
| 3 |
|
| 4 |
#include <openssl/base.h> |
| 5 |
|
| 6 |
#define MIN_LENGTH 4 |
| 7 |
#define MAX_PASSWORD_LENGTH 1024 |
| 8 |
|
| 9 |
#if defined(__cplusplus) |
| 10 |
extern "C" { |
| 11 |
#endif |
| 12 |
|
| 13 |
// Console Management API |
| 14 |
// |
| 15 |
// This API provides functions for secure console I/O operations, supporting both Unix/Linux |
| 16 |
// (termios) and Windows systems. It handles terminal operations like reading input with |
| 17 |
// optional echo suppression (for password entry) and signal handling. |
| 18 |
// |
| 19 |
// Usage requires proper lock management: |
| 20 |
// 1. Acquire the console mutex with openssl_console_acquire_mutex() |
| 21 |
// 2. Initialize console with openssl_console_open() |
| 22 |
// 3. Perform console operations (read/write) |
| 23 |
// 4. Clean up with openssl_console_close() |
| 24 |
// 5. Release the mutex with openssl_console_release_mutex() |
| 25 |
// |
| 26 |
// The global mutex must be held during all console operations and released after closing the console. |
| 27 |
OPENSSL_EXPORT void openssl_console_acquire_mutex(void); |
| 28 |
OPENSSL_EXPORT void openssl_console_release_mutex(void); |
| 29 |
OPENSSL_EXPORT int openssl_console_open(void); |
| 30 |
OPENSSL_EXPORT int openssl_console_close(void); |
| 31 |
OPENSSL_EXPORT int openssl_console_write(const char *str); |
| 32 |
OPENSSL_EXPORT int openssl_console_read(char *buf, int minsize, int maxsize, int echo); |
| 33 |
|
| 34 |
|
| 35 |
#if defined(__cplusplus) |
| 36 |
} // extern C |
| 37 |
#endif |