diff options
author | Andy Polyakov <appro@openssl.org> | 2016-08-25 08:06:26 +0200 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2016-08-25 11:56:28 +0100 |
commit | fb5d9f1db5552facbc5269bc2856b58f5e4e2d13 (patch) | |
tree | f574742694791f8237d5583856bcd1b484d61bfa /crypto/ui | |
parent | 647ac8d3d7143e3721d55e1f57730b6f26e72fc9 (diff) |
Windows: UTF-8 opt-in for command-line arguments and console input.
User can make Windows openssl.exe to treat command-line arguments
and console input as UTF-8 By setting OPENSSL_WIN32_UTF8 environment
variable (to any value). This is likely to be required for data
interchangeability with other OSes and PKCS#12 containers generated
with Windows CryptoAPI.
Reviewed-by: Richard Levitte <levitte@openssl.org>
Diffstat (limited to 'crypto/ui')
-rw-r--r-- | crypto/ui/ui_openssl.c | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/crypto/ui/ui_openssl.c b/crypto/ui/ui_openssl.c index 98fb0e192e..befe97386e 100644 --- a/crypto/ui/ui_openssl.c +++ b/crypto/ui/ui_openssl.c @@ -305,23 +305,26 @@ static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl) if (is_a_tty) { DWORD numread; # if defined(CP_UTF8) - WCHAR wresult[BUFSIZ]; + if (GetEnvironmentVariableW(L"OPENSSL_WIN32_UTF8", NULL, 0) != 0) { + WCHAR wresult[BUFSIZ]; - if (ReadConsoleW(GetStdHandle(STD_INPUT_HANDLE), + if (ReadConsoleW(GetStdHandle(STD_INPUT_HANDLE), wresult, maxsize, &numread, NULL)) { - if (numread >= 2 && - wresult[numread-2] == L'\r' && wresult[numread-1] == L'\n') { - wresult[numread-2] = L'\n'; - numread--; + if (numread >= 2 && + wresult[numread-2] == L'\r' && + wresult[numread-1] == L'\n') { + wresult[numread-2] = L'\n'; + numread--; + } + wresult[numread] = '\0'; + if (WideCharToMultiByte(CP_UTF8, 0, wresult, -1, + result, sizeof(result), NULL, 0) > 0) + p = result; + + OPENSSL_cleanse(wresult, sizeof(wresult)); } - wresult[numread] = '\0'; - if (WideCharToMultiByte(CP_UTF8, 0, wresult, -1, - result, sizeof(result), NULL, 0) > 0) - p = result; - - OPENSSL_cleanse(wresult, sizeof(wresult)); - } -# else + } else +# endif if (ReadConsoleA(GetStdHandle(STD_INPUT_HANDLE), result, maxsize, &numread, NULL)) { if (numread >= 2 && @@ -332,7 +335,6 @@ static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl) result[numread] = '\0'; p = result; } -# endif } else # elif defined(OPENSSL_SYS_MSDOS) if (!echo) { |