Better password hiding, POSIX macro, updated header and BSD compatibility
This commit is contained in:
parent
ced58f8a85
commit
9f6d1ecdeb
10
Makefile
10
Makefile
@ -1,16 +1,16 @@
|
||||
CC = gcc
|
||||
CC = cc
|
||||
CFLAGS = -Wall -Wextra -std=c99 -O2
|
||||
LDFLAGS = -lsodium
|
||||
INCLUDES = -I/usr/include -I/usr/local/include -I/usr/pkg/include
|
||||
LIBS = -L/usr/lib -L/usr/local/lib -L/usr/pkg/lib
|
||||
BUILD_DIR = build
|
||||
PREFIX = /usr/local
|
||||
|
||||
all: $(BUILD_DIR)/salty
|
||||
|
||||
$(BUILD_DIR)/salty: salty.c pawstd.h | $(BUILD_DIR)
|
||||
$(CC) $(CFLAGS) -o $@ salty.c $(LDFLAGS)
|
||||
|
||||
$(BUILD_DIR):
|
||||
$(BUILD_DIR)/salty: salty.c pawstd.h
|
||||
mkdir -p $(BUILD_DIR)
|
||||
$(CC) $(CFLAGS) -o $@ salty.c $(INCLUDES) $(LIBS) $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
rm -rf $(BUILD_DIR)
|
||||
|
||||
1
pawstd.h
1
pawstd.h
@ -84,3 +84,4 @@
|
||||
#define NOR "[ --- ] "
|
||||
#define OK "[ "GRN"OK!"reset" ] "
|
||||
#define DBG "[ " YEL "DBG" reset " ] "
|
||||
#define WRN "[ " YEL "WRN" reset " ] "
|
||||
|
||||
21
salty.c
21
salty.c
@ -1,9 +1,11 @@
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sodium.h>
|
||||
#include <termios.h>
|
||||
#include "pawstd.h"
|
||||
#define KEY_SIZE crypto_secretbox_KEYBYTES
|
||||
#define SALT_SIZE crypto_pwhash_SALTBYTES
|
||||
@ -337,14 +339,16 @@ bool isFile(const char* filename) {
|
||||
}
|
||||
|
||||
bool getPassword(char *pw, int size) {
|
||||
struct termios term;
|
||||
tcgetattr(fileno(stdin), &term);
|
||||
int i = 0;
|
||||
char c;
|
||||
pw[0] = '\0';
|
||||
// Hide input
|
||||
printf("\033[8m");
|
||||
term.c_lflag &= ~ECHO;
|
||||
tcsetattr(fileno(stdin), 0, &term);
|
||||
// Get password from stdin
|
||||
while (true) {
|
||||
// Overwrite password in console
|
||||
c = fgetc(stdin);
|
||||
if (c == '\r' || c == '\n' || feof(stdin)) {
|
||||
break;
|
||||
@ -357,15 +361,9 @@ bool getPassword(char *pw, int size) {
|
||||
return false;
|
||||
i++;
|
||||
}
|
||||
printf ("\033[0A");
|
||||
printf ("\033[40C");
|
||||
fflush(stdout);
|
||||
while (i) {
|
||||
fprintf (stdout,"*");
|
||||
i--;
|
||||
}
|
||||
// Show input
|
||||
printf ("\033[28m\n");
|
||||
term.c_lflag |= ECHO;
|
||||
tcsetattr(fileno(stdin), 0, &term);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -477,9 +475,10 @@ int main(int argc, char *argv[]) {
|
||||
password = malloc(129);
|
||||
printf(NOR"Enter your encryption password: ");
|
||||
if (!getPassword(password,130)) {
|
||||
fprintf(stderr,ERR"Password is too long.");
|
||||
fprintf(stderr,"\n"ERR"Password is too long.");
|
||||
return 1;
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
if (decrypt) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user