Compare commits

...

2 commits

Author SHA1 Message Date
07c0aec7d8 fix inconsistent tabs and spaces 2022-03-15 22:51:26 -04:00
1ee0b7e2a3 attempt to always zero key in ram before exiting 2022-03-15 22:50:12 -04:00

View file

@ -27,6 +27,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <signal.h>
#include <openssl/err.h> #include <openssl/err.h>
#include <openssl/rsa.h> #include <openssl/rsa.h>
#include <openssl/pem.h> #include <openssl/pem.h>
@ -35,6 +36,8 @@
#include <sys/time.h> #include <sys/time.h>
#include <sys/resource.h> #include <sys/resource.h>
RSA *rsa = NULL;
void nodumps() void nodumps()
{ {
struct rlimit r; struct rlimit r;
@ -42,31 +45,37 @@ void nodumps()
setrlimit(RLIMIT_CORE, &r); setrlimit(RLIMIT_CORE, &r);
} }
void byebye(int sig)
{
memset(rsa, 0, sizeof rsa);
exit(0);
}
static int called_passcb = 0; static int called_passcb = 0;
static int pass_cb(char *buf, int size, int rwflag, void *u) static int pass_cb(char *buf, int size, int rwflag, void *u)
{ {
int len; int len;
char *tmp; char *tmp;
called_passcb++; called_passcb++;
if(!isatty(fileno(stdin))) if(!isatty(fileno(stdin)))
{ {
if(fgets(buf, size, stdin) == NULL) if(fgets(buf, size, stdin) == NULL)
return 0; return 0;
tmp = strpbrk(buf, "\r\n"); tmp = strpbrk(buf, "\r\n");
if(tmp != NULL) if(tmp != NULL)
*tmp = '\0'; *tmp = '\0';
return strlen(buf); return strlen(buf);
} }
tmp = getpass("Enter passphrase for private key: "); tmp = getpass("Enter passphrase for private key: ");
len = strlen(tmp); len = strlen(tmp);
if (len <= 0) if (len <= 0)
return 0; return 0;
if (len > size) if (len > size)
len = size; len = size;
memcpy(buf, tmp, len); memcpy(buf, tmp, len);
return len; return len;
} }
@ -210,7 +219,7 @@ read_challenge(FILE *f)
} }
} }
fgets((char *)buf, sizeof(buf), stdin); fgets((char *)buf, sizeof(buf), stdin);
tmp = strpbrk((char *)buf, "\r\n"); tmp = strpbrk((char *)buf, "\r\n");
if(tmp != NULL) if(tmp != NULL)
@ -224,10 +233,17 @@ read_challenge(FILE *f)
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
struct sigaction act;
act.sa_handler = byebye;
sigaction(SIGHUP, &act, 0);
sigaction(SIGINT, &act, 0);
sigaction(SIGTERM, &act, 0);
nodumps(); nodumps();
FILE *kfile; FILE *kfile;
RSA *rsa = NULL;
SHA_CTX ctx; SHA_CTX ctx;
unsigned char *ptr; unsigned char *ptr;
unsigned char *ndata, ddata[512]; unsigned char *ndata, ddata[512];
@ -283,5 +299,5 @@ main(int argc, char **argv)
puts((char *)ndata); puts((char *)ndata);
fflush(NULL); fflush(NULL);
} }
return 0; byebye(0);
} }