Skip to content

Commit 6ad2679

Browse files
steve-pexipmtrojnar
authored andcommitted
Read the password from stdin if desired
Use the common convention: "-" means to use stdin Signed-off-by: Steve McIntyre <[email protected]>
1 parent 4776f43 commit 6ad2679

File tree

1 file changed

+31
-26
lines changed

1 file changed

+31
-26
lines changed

osslsigncode.c

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3086,6 +3086,7 @@ static void usage(const char *argv0, const char *cmd)
30863086
printf("%1s [ -askpass ]", "");
30873087
#endif /* PROVIDE_ASKPASS */
30883088
printf("%1s[ -readpass <file> ]\n", "");
3089+
printf("%12s(use \"-\" with readpass to read from stdin)\n", "");
30893090
printf("%12s[ -ac <crosscertfile> ]\n", "");
30903091
printf("%12s[ -h {md5,sha1,sha2(56),sha384,sha512} ]\n", "");
30913092
printf("%12s[ -n <desc> ] [ -i <url> ] [ -jp <level> ] [ -comm ]\n", "");
@@ -3425,39 +3426,43 @@ static char *getpassword(const char *prompt)
34253426
*/
34263427
static int read_password(GLOBAL_OPTIONS *options)
34273428
{
3428-
char passbuf[4096];
3429+
char passbuf[4096] = {0};
34293430
int passlen;
34303431
const u_char utf8_bom[] = {0xef, 0xbb, 0xbf};
34313432

34323433
if (options->readpass) {
3434+
if (!strcmp(options->readpass, "-")) {
3435+
passlen = read(fileno(stdin), passbuf, sizeof(passbuf)-1);
3436+
} else {
34333437
#ifdef WIN32
3434-
HANDLE fhandle, fmap;
3435-
LPVOID faddress;
3436-
fhandle = CreateFile(options->readpass, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
3437-
if (fhandle == INVALID_HANDLE_VALUE) {
3438-
return 0; /* FAILED */
3439-
}
3440-
fmap = CreateFileMapping(fhandle, NULL, PAGE_READONLY, 0, 0, NULL);
3441-
if (fmap == NULL) {
3442-
return 0; /* FAILED */
3443-
}
3444-
faddress = MapViewOfFile(fmap, FILE_MAP_READ, 0, 0, 0);
3445-
CloseHandle(fmap);
3446-
if (faddress == NULL) {
3447-
return 0; /* FAILED */
3448-
}
3449-
passlen = (int)GetFileSize(fhandle, NULL);
3450-
memcpy(passbuf, faddress, passlen);
3451-
UnmapViewOfFile(faddress);
3452-
CloseHandle(fhandle);
3438+
HANDLE fhandle, fmap;
3439+
LPVOID faddress;
3440+
fhandle = CreateFile(options->readpass, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
3441+
if (fhandle == INVALID_HANDLE_VALUE) {
3442+
return 0; /* FAILED */
3443+
}
3444+
fmap = CreateFileMapping(fhandle, NULL, PAGE_READONLY, 0, 0, NULL);
3445+
if (fmap == NULL) {
3446+
return 0; /* FAILED */
3447+
}
3448+
faddress = MapViewOfFile(fmap, FILE_MAP_READ, 0, 0, 0);
3449+
CloseHandle(fmap);
3450+
if (faddress == NULL) {
3451+
return 0; /* FAILED */
3452+
}
3453+
passlen = (int)GetFileSize(fhandle, NULL);
3454+
memcpy(passbuf, faddress, passlen);
3455+
UnmapViewOfFile(faddress);
3456+
CloseHandle(fhandle);
34533457
#else /* WIN32 */
3454-
int passfd = open(options->readpass, O_RDONLY);
3455-
if (passfd < 0) {
3456-
return 0; /* FAILED */
3457-
}
3458-
passlen = (int)read(passfd, passbuf, sizeof passbuf - 1);
3459-
close(passfd);
3458+
int passfd = open(options->readpass, O_RDONLY);
3459+
if (passfd < 0) {
3460+
return 0; /* FAILED */
3461+
}
3462+
passlen = (int)read(passfd, passbuf, sizeof passbuf - 1);
3463+
close(passfd);
34603464
#endif /* WIN32 */
3465+
}
34613466
if (passlen <= 0) {
34623467
return 0; /* FAILED */
34633468
}

0 commit comments

Comments
 (0)