提交 fb5d9f1d 编写于 作者: A Andy Polyakov 提交者: Matt Caswell

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: NRichard Levitte <levitte@openssl.org>
上级 647ac8d3
...@@ -145,6 +145,9 @@ void win32_utf8argv(int *argc, char **argv[]) ...@@ -145,6 +145,9 @@ void win32_utf8argv(int *argc, char **argv[])
int wlen, ulen, valid = 1; int wlen, ulen, valid = 1;
char *arg; char *arg;
if (GetEnvironmentVariableW(L"OPENSSL_WIN32_UTF8", NULL, 0) == 0)
return;
newargc = 0; newargc = 0;
newargv = NULL; newargv = NULL;
if (!validate_argv(newargc)) if (!validate_argv(newargc))
......
...@@ -305,23 +305,26 @@ static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl) ...@@ -305,23 +305,26 @@ static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl)
if (is_a_tty) { if (is_a_tty) {
DWORD numread; DWORD numread;
# if defined(CP_UTF8) # 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)) { wresult, maxsize, &numread, NULL)) {
if (numread >= 2 && if (numread >= 2 &&
wresult[numread-2] == L'\r' && wresult[numread-1] == L'\n') { wresult[numread-2] == L'\r' &&
wresult[numread-2] = L'\n'; wresult[numread-1] == L'\n') {
numread--; 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'; } else
if (WideCharToMultiByte(CP_UTF8, 0, wresult, -1, # endif
result, sizeof(result), NULL, 0) > 0)
p = result;
OPENSSL_cleanse(wresult, sizeof(wresult));
}
# else
if (ReadConsoleA(GetStdHandle(STD_INPUT_HANDLE), if (ReadConsoleA(GetStdHandle(STD_INPUT_HANDLE),
result, maxsize, &numread, NULL)) { result, maxsize, &numread, NULL)) {
if (numread >= 2 && if (numread >= 2 &&
...@@ -332,7 +335,6 @@ static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl) ...@@ -332,7 +335,6 @@ static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl)
result[numread] = '\0'; result[numread] = '\0';
p = result; p = result;
} }
# endif
} else } else
# elif defined(OPENSSL_SYS_MSDOS) # elif defined(OPENSSL_SYS_MSDOS)
if (!echo) { if (!echo) {
......
...@@ -53,6 +53,7 @@ if (eval { require Win32::API; 1; }) { ...@@ -53,6 +53,7 @@ if (eval { require Win32::API; 1; }) {
} }
} }
} }
$ENV{OPENSSL_WIN32_UTF8}=1;
plan tests => 1; plan tests => 1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册