added md5 checksum generation and salt generation
This commit is contained in:
parent
44150667f5
commit
eaabc877a0
6
Makefile
6
Makefile
|
@ -2,9 +2,9 @@ VERSION=1.1.9
|
|||
|
||||
CFLAGS+= -O2 -Wall -Wextra -Wshadow -rdynamic\
|
||||
-D_FILE_OFFSET_BITS=64 -DVERSION=\"$(VERSION)\" \
|
||||
`pkg-config --cflags-only-I gumbo libcurl fuse`
|
||||
LIBS = -pthread -lgumbo -lcurl -lfuse -lcrypto
|
||||
COBJS = main.o network.o fuse_local.o link.o cache.o util.o
|
||||
`pkg-config --cflags-only-I gumbo libcurl fuse uuid`
|
||||
LIBS = -pthread -lgumbo -lcurl -lfuse -lcrypto -luuid
|
||||
COBJS = network.o fuse_local.o link.o cache.o util.o sonic.o
|
||||
|
||||
prefix ?= /usr/local
|
||||
|
||||
|
|
|
@ -172,7 +172,7 @@ void Link_req_file_stat(Link *this_link)
|
|||
*
|
||||
* It gets freed in curl_multi_perform_once();
|
||||
*/
|
||||
TransferStruct *transfer = malloc(sizeof(TransferStruct));
|
||||
TransferStruct *transfer = calloc(1, sizeof(TransferStruct));
|
||||
if (!transfer) {
|
||||
fprintf(stderr, "Link_get_size(): malloc failed!\n");
|
||||
exit_failure();
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
#include "util.h"
|
||||
|
||||
#include <openssl/md5.h>
|
||||
#include <uuid/uuid.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define MD5_HASH_LEN 32
|
||||
#define SALT_LEN 36
|
||||
/**
|
||||
* \brief generate the salt for authentication string
|
||||
* \details this effectively generates a UUID string, which we use as the salt
|
||||
* \return a pointer to a 37-char array with the salt.
|
||||
*/
|
||||
char *generate_salt()
|
||||
{
|
||||
char *out;
|
||||
out = calloc(SALT_LEN + 1, sizeof(char));
|
||||
uuid_t uu;
|
||||
uuid_generate(uu);
|
||||
uuid_unparse(uu, out);
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief generate the md5sum of a string
|
||||
* \param[in] str a character array for the input string
|
||||
* \return a pointer to a 33-char array with the salt
|
||||
*/
|
||||
char *generate_md5sum(const char *str)
|
||||
{
|
||||
MD5_CTX c;
|
||||
unsigned char md5[MD5_DIGEST_LENGTH];
|
||||
size_t len = strnlen(str, MAX_PATH_LEN);
|
||||
char *out = calloc(MD5_HASH_LEN + 1, sizeof(char));
|
||||
|
||||
MD5_Init(&c);
|
||||
MD5_Update(&c, str, len);
|
||||
MD5_Final(md5, &c);
|
||||
|
||||
for(int i = 0; i < MD5_DIGEST_LENGTH; i++) {
|
||||
sprintf(out + 2 * i, "%02x", md5[i]);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
|
||||
char *salt = generate_salt();
|
||||
char *md5sum = generate_md5sum(salt);
|
||||
|
||||
printf("%s\n%s\n", salt, md5sum);
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
#ifndef SONIC_H
|
||||
#define SONIC_H
|
||||
|
||||
#endif
|
|
@ -15,7 +15,10 @@
|
|||
*/
|
||||
#define MAX_PATH_LEN 4096
|
||||
|
||||
/** \brief the maximum length of a filename. */
|
||||
/**
|
||||
* \brief the maximum length of a filename.
|
||||
* \details This corresponds the filename length under Ext4.
|
||||
*/
|
||||
#define MAX_FILENAME_LEN 255
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue