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

WIP: vault implemention #378

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,16 @@ endif()
target_link_libraries(pgagroal-admin-bin pgagroal)

install(TARGETS pgagroal-admin-bin DESTINATION ${CMAKE_INSTALL_BINDIR})

#
# Build pgagroal-vault
#
add_executable(pgagroal-vault-bin vault.c ${RESOURCE_OBJECT})
if (CMAKE_C_LINK_PIE_SUPPORTED)
set_target_properties(pgagroal-vault-bin PROPERTIES LINKER_LANGUAGE C POSITION_INDEPENDENT_CODE TRUE OUTPUT_NAME pgagroal-vault)
else()
set_target_properties(pgagroal-vault-bin PROPERTIES LINKER_LANGUAGE C POSITION_INDEPENDENT_CODE FALSE OUTPUT_NAME pgagroal-vault)
endif()
target_link_libraries(pgagroal-vault-bin pgagroal)

install(TARGETS pgagroal-vault-bin DESTINATION ${CMAKE_INSTALL_BINDIR})
37 changes: 0 additions & 37 deletions src/admin.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,18 @@
#include <sys/stat.h>
#include <err.h>

#define DEFAULT_PASSWORD_LENGTH 64
#define MIN_PASSWORD_LENGTH 8

#define ACTION_UNKNOWN 0
#define ACTION_MASTER_KEY 1
#define ACTION_ADD_USER 2
#define ACTION_UPDATE_USER 3
#define ACTION_REMOVE_USER 4
#define ACTION_LIST_USERS 5

static char CHARS[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '=', '+', '[', '{', ']', '}', '\\', '|', ';', ':',
'\'', '\"', ',', '<', '.', '>', '/', '?'};

static int master_key(char* password, bool generate_pwd, int pwd_length);
static int add_user(char* users_path, char* username, char* password, bool generate_pwd, int pwd_length);
static int update_user(char* users_path, char* username, char* password, bool generate_pwd, int pwd_length);
static int remove_user(char* users_path, char* username);
static int list_users(char* users_path);
static char* generate_password(int pwd_length);

static void
version(void)
Expand Down Expand Up @@ -906,30 +896,3 @@ list_users(char* users_path)

return 1;
}

static char*
generate_password(int pwd_length)
{
char* pwd;
size_t s;
time_t t;

s = pwd_length + 1;

pwd = calloc(1, s);
if (pwd == NULL)
{
pgagroal_log_fatal("Couldn't allocate memory while generating password");
return NULL;
}

srand((unsigned)time(&t));

for (int i = 0; i < s; i++)
{
*((char*)(pwd + i)) = CHARS[rand() % sizeof(CHARS)];
}
*((char*)(pwd + pwd_length)) = '\0';

return pwd;
}
23 changes: 23 additions & 0 deletions src/include/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,32 @@ pgagroal_create_startup_message(char* username, char* database, struct message**
* @param msg The resulting message
* @return 0 upon success, otherwise 1
*/

int
pgagroal_create_cancel_request_message(int pid, int secret, struct message** msg);

/**
* @brief
*
* @param ssl
* @param socket
* @param username
* @return int
*/
int
pgagroal_write_frontend_password_request(SSL* ssl, int socket, char* username);

/**
* @brief
*
* @param ssl
* @param socket
* @param password
* @return int
*/
int
pgagroal_write_frontend_password_response(SSL* ssl, int socket, char* password);

/**
* Is the connection valid
* @param socket The socket descriptor
Expand Down
4 changes: 4 additions & 0 deletions src/include/pgagroal.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ extern "C" {
#define MAX_DATABASE_LENGTH 256
#define MAX_TYPE_LENGTH 16
#define MAX_ADDRESS_LENGTH 64
#define DEFAULT_PASSWORD_LENGTH 64
#define MIN_PASSWORD_LENGTH 8
#define MAX_PASSWORD_LENGTH 1024
#define MAX_APPLICATION_NAME 64

Expand Down Expand Up @@ -493,6 +495,8 @@ struct configuration
struct user admins[NUMBER_OF_ADMINS]; /**< The admins */
struct user superuser; /**< The superuser */
struct connection connections[]; /**< The connections (FMA) */


} __attribute__ ((aligned (64)));

#ifdef __cplusplus
Expand Down
13 changes: 13 additions & 0 deletions src/include/security.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,19 @@ pgagroal_user_known(char* user);
int
pgagroal_tls_valid(void);

/**
* @brief Generate a random ASCII password have size of pwd_length
* @param pwd_length length of the password
* @return Generated password
*/
char*
generate_password(int pwd_length);

/**
* @brief Initialize RNG
*
*/
void initialize_random(void);
#ifdef __cplusplus
}
#endif
Expand Down
Loading