Skip to content
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

Readpassphrase #692 #156

Merged
merged 10 commits into from
Jun 8, 2017
Merged

Readpassphrase #692 #156

merged 10 commits into from
Jun 8, 2017

Conversation

bagajjal
Copy link

@bagajjal bagajjal commented Jun 2, 2017


/* prompt user */
wchar_t* wtmp = utf8_to_utf16(prompt);

Choose a reason for hiding this comment

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

the general guidance of openssh code suggest declare variables at the beginning.


if (outBufLen == 0) {
errno = EINVAL;
return(NULL);

Choose a reason for hiding this comment

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

no need to pull NULL in (), right?

int retr = 0;
char *
readpassphrase(const char *prompt, char *outBuf, size_t outBufLen, int flags) {
int currentIndex = 0;

Choose a reason for hiding this comment

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

name the variable like current_index for consistency with bsd code

size_t len = 0;
int retr = 0;
char *
readpassphrase(const char *prompt, char *outBuf, size_t outBufLen, int flags) {
Copy link

@bingbing8 bingbing8 Jun 6, 2017

Choose a reason for hiding this comment

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

I saw RPP_REQUIRE_TTY-- fail if there is no tty at: https://linux.die.net/man/3/readpassphras
is there case where this function is called from virtual tty?

Copy link
Author

Choose a reason for hiding this comment

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

Unix has the concept of reading from /dev/tty..
if we fail to open /dev/tty and RPP_REQUIRE_TTY is set to false then unix reads the input from STDIN..

since in windows there is no concept of /dev/tty this flag and the corresponding logic is ignored..

Choose a reason for hiding this comment

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

@bagajjal the equivalent of /dev/tty in Windows is the console handle (CreateFile("CONIN")).
We need to map open(/dev/tty) to the above.

Copy link
Author

Choose a reason for hiding this comment

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

fixed this.

return(NULL);
}

while (_kbhit()) _getch();

Choose a reason for hiding this comment

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

What does this line do? flush out previous console input?

Copy link
Author

Choose a reason for hiding this comment

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

_kbhit() returns a nonzero value, a keystroke is waiting in the buffer..
before we read from user.. we are clearing the keystroke in the waiting buffer.. Ideally this should never happen but the existing code has it and it doesn't harm so I kept it..

Copy link

@manojampalam manojampalam Jun 6, 2017

Choose a reason for hiding this comment

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

Why should we read on a character basis? Why not call an API that reads an entire line (ReadFile on a console handle with console )?
Checkout console APIs on msdn, there are way to control a console handle for echoing, raw mode, etc that could be used for this purpose. We also use these APIs in enter_raw_mode, exit_raw_mode. check them out.


currentIndex--; /* overwrite last character */
}
} else if (ch == '\003') { /* exit on Ctrl+C */
Copy link

@bingbing8 bingbing8 Jun 6, 2017

Choose a reason for hiding this comment

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

what if user hit ESC (27)?

Copy link
Author

Choose a reason for hiding this comment

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

Unix doesn't have special treatment for ESC.. so it will be read as any other input character..

Copy link

@manojampalam manojampalam Jun 6, 2017

Choose a reason for hiding this comment

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

If we use console APIs, as I described above, there is no need to handle and treat individual key strokes

Copy link
Author

Choose a reason for hiding this comment

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

as we discussed, we will read character by character to align with the unix code and to treat the control+c for stopping the process.

Choose a reason for hiding this comment

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

I am not familar with key stroke. but some characters like ESC, the logic will fall to this line printf("%c", ch); what will be displayed?

Copy link
Author

Choose a reason for hiding this comment

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

It doesn't fail.. ESC is printed as [?].. here is the screenshot
image

@manojampalam
Copy link

manojampalam commented Jun 6, 2017

Can you add a unit test case for open(tty)?

@manojampalam manojampalam merged commit 45de6ba into latestw_all Jun 8, 2017
@manojampalam manojampalam deleted the readpassphrase_#692 branch June 8, 2017 18:48
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