From b363cb566b9d21b6c607d18579232f9c79b15f4b Mon Sep 17 00:00:00 2001 From: "jordan@hack_attack" Date: Fri, 5 Aug 2016 12:38:56 -0700 Subject: [PATCH] apc initial implementation --- html/index.html | 4 + html/js/auth.js | 9 +- html/js/the_march.config.js | 38 ++++-- src/apc/.gitignore | 3 + src/apc/fileparser.y | 176 ++++++++++++++++++++++++ src/apc/fileparser_old.y | 223 +++++++++++++++++++++++++++++++ src/apc/filescanner.rl | 148 ++++++++++++++++++++ src/apc/filescannerparser_old.rl | 78 +++++++++++ src/apc/ragson | Bin 0 -> 22784 bytes src/apc/ragson.sh | 4 + src/apc/sprite.c | 5 + src/apc/sprite.h | 20 +++ src/apc/symbol.h | 14 ++ src/core/auth.c | 111 +++++++++++++++ 14 files changed, 822 insertions(+), 11 deletions(-) create mode 100644 src/apc/.gitignore create mode 100644 src/apc/fileparser.y create mode 100644 src/apc/fileparser_old.y create mode 100644 src/apc/filescanner.rl create mode 100644 src/apc/filescannerparser_old.rl create mode 100755 src/apc/ragson create mode 100755 src/apc/ragson.sh create mode 100644 src/apc/sprite.c create mode 100644 src/apc/sprite.h create mode 100644 src/apc/symbol.h create mode 100644 src/core/auth.c diff --git a/html/index.html b/html/index.html index 0834270..05d0d4a 100644 --- a/html/index.html +++ b/html/index.html @@ -5,6 +5,9 @@ + + + Usage: the_march [-opts]
@@ -16,5 +19,6 @@ + diff --git a/html/js/auth.js b/html/js/auth.js index d399d6f..3eb052a 100644 --- a/html/js/auth.js +++ b/html/js/auth.js @@ -1,7 +1,7 @@ /*!@file \brief Authorization Handling - \details Upon user submission of id/password, hashes password and saves - result in a file on VFS using hashing algorithm provided by libgcrypt.c + \details Upon user submission of id/password, hashes password and + saves result in a file on VFS using hashing algorithm prov ided by wolfcrypt, a subsystem of wolfSSL \author JEL \date 2016 -----------------------------------------------------------------------------*/ @@ -9,6 +9,9 @@ function userLogin() { var password = document.getElementById("password").value; - /* Call Module.execute on encrypt_password() */ + /* Virtual Filesystem is of type IDBFS and has been setup in preRun in Module via JVM runtime environment*/ + Module.execute(_auth_encrypt, password); + }; + document.getElementById("login").addEventListener("click", userLogin, false); diff --git a/html/js/the_march.config.js b/html/js/the_march.config.js index 7751827..4d4afd7 100644 --- a/html/js/the_march.config.js +++ b/html/js/the_march.config.js @@ -2,39 +2,61 @@ var Module = { 'noExitRuntime': true, 'arguments': [], + 'argc': 0, + 'argv_ptr': 0, - print: function(text) { for(var i=0; i");}, - printErr: function(text) { console.log("ERR: " + text); }, + //print: function(text) { for(var i=0; i + #include + #include + #include "sprite.h" + #include "symbol.h" + #include + + + extern void yyerror(); + extern int linit(); + extern int yylex(); + + + int handle_fname(char *); + int eval_png_file(char*); + int read_png_file(char*); + +%} +%define parse.error verbose +%union{ + char* str; + } + +/* %token EXT */ +/* %token FW */ +/* %token SPR */ +/* %token CC */ + +/* /\* Rules *\/ */ +/* %% */ +/* SS: SPR '/' MD '.' EXT */ +/* MD: CC '_' FW */ +/* | FW */ +/* | CC */ + + +%token FDAT + +/* Rules */ +%% +FLIST : FLIST FNAME {printf("reducing to flist\n");} /* Now output to asspack.o */ | FNAME +FNAME : FDAT {printf("handle_fname(%s)\n", $1);handle_fname(yylval.str);printf("handled fname\n");} + +%% +int +main(int argc, char** argv) +{ + /* Parse cmd line arguments */ + + linit(); + yyparse(); /* runs handle_fname for each filename */ + + + return 0; +} +void +yyerror (char const *s) +{ + fprintf(stderr, "%s\n", s); +} + + + +/* Analyze file_name for information on sprite sheet, + store sprite sheet and label into sprite then + push sprite onto sprites[]*/ +int +handle_fname(char* file_name) +{ + /* Parse the file_name for data */ + + + /* Get the specs of the PNG file */ + if(eval_png_file(file_name)) + { + printf("Failed in eval_png_file\n"); + return 1; + } + + /* Insert sprite sheet from PNG into sprite_sheets */ + push_sprite(); + + + + + /* Store dir/filename in label as well as any other data that fits */ +} +int eval_png_file(char* file_name) +{ + /* Evaluate file_name for metadata */ + + /* Extracts header info from png_file */ + read_png_file(file_name); + + /* Create the symbol and put it in symbol_table[]*/ + + return 0; +} + + + +/* variables for libPNG */ +int png_width,png_height; +png_byte bit_depth; +png_byte color_type; +png_structp png_ptr; +png_infop info_ptr; + +int +read_png_file( char* file_name) +{ + /* Setup PNG file */ + char header[8]; + int is_png = 0; + char* dir = "pngfiles"; + + /* TODO: Change this fopen to a real var! */ + FILE *fp = fopen("pngfiles/env_street_road03_0.png","rb"); + + if(!fp) + { printf("Could not read file %s in handle_fname()", file_name); + return 1; + } + + fread(header, 1, 8, fp); + + is_png = !png_sig_cmp(header, 0, 8); + if(!is_png) + return 1; + + png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + + if (!png_ptr) + { printf("Failed to allocate png_ptr\n"); + return 1; + } + info_ptr = png_create_info_struct(png_ptr); + + if (!info_ptr) + { printf("Failed to create info_ptr\n"); + png_destroy_read_struct(&png_ptr,(png_infopp)NULL, (png_infopp)NULL); + return 1; + } + + png_infop end_info = png_create_info_struct(png_ptr); + if (!end_info) + { printf("Failed to create end_info \n"); + png_destroy_read_struct(&png_ptr,(png_infopp)NULL, (png_infopp)NULL); + return 1; + } + + if(setjmp(png_jmpbuf(png_ptr))) + { printf("Failed in init_io\n"); + png_destroy_read_struct(&png_ptr,(png_infopp)NULL, (png_infopp)NULL); + fclose(fp); + return 1; + } + png_init_io(png_ptr, fp); + png_set_sig_bytes(png_ptr, 8); + + png_read_info(png_ptr, info_ptr); + + png_width = png_get_image_width(png_ptr, info_ptr); + png_height = png_get_image_height(png_ptr, info_ptr); + color_type = png_get_color_type(png_ptr, info_ptr); + bit_depth = png_get_bit_depth(png_ptr, info_ptr); + + png_read_update_info(png_ptr, info_ptr); + + printf("successfully read png file %s\n", file_name); + + return 0; + +} diff --git a/src/apc/fileparser_old.y b/src/apc/fileparser_old.y new file mode 100644 index 0000000..f7ca050 --- /dev/null +++ b/src/apc/fileparser_old.y @@ -0,0 +1,223 @@ +/* Asset Package Compiler */ +%{ + #include + #include + #include + #include "sprite.h" + #include "symbol.h" + #include + + + extern void yyerror(); + extern int rinit(); + extern int yylex(); + #define DIR_SIZE 128/* size when all files have been concatenated together */ + + char dir_files[DIR_SIZE]; + FILE* yyin; + + int populate_yyin(FILE*); + int handle_vdat(char *); + int eval_png_file(char*); + int read_png_file(char*); + +%} +%define parse.error verbose +%union{ + char* str; + } + +/* %token EXT */ +/* %token FW */ +/* %token SPR */ +/* %token CC */ + +/* /\* Rules *\/ */ +/* %% */ +/* SS: SPR '/' MD '.' EXT */ +/* MD: CC '_' FW */ +/* | FW */ +/* | CC */ + + +%token VDAT +%token ODAT +%token ADAT + +/* Rules */ +%% +FLIST : FNAME /* Now output to VDAT.o */ +FNAME : VDAT {printf("handle_vdat(%s)\n", $1);handle_vdat(yylval.str);printf("handled vdat\n");} + | ADAT + | ODAT + +%% +int +main(int argc, char** argv) +{ + /* Take arguments */ + + /* Concatenate all files into buf, they are null-terminated + by default */ + FILE *fp; + + fp = fopen("all_files", "w+"); + + if(!populate_yyin(fp)) + printf("error processing the directory"); + + yyin = fp; + rinit(); + yyparse(); /* runs handle_vdat after token is scanned */ + + + + return 0; +} +void +yyerror (char const *s) +{ + fprintf(stderr, "%s\n", s); +} + +/* TODO: READ INTO SINGLE BUFFER, NOT A FILE */ +int +populate_yyin(FILE* fp) +{ + int files_pos = 0; + int file_len = 0; + struct dirent* ep; + + DIR* dp = opendir("pngfiles"); + /* Concatenate all file names, seperated by '\0' + into files[] */ + if(dp != NULL) + { + while(ep = readdir(dp)) + { file_len = strlen(ep->d_name); + fwrite(ep->d_name, 1, file_len, fp); + printf("writing %s to file\n", ep->d_name); + } + fseek(fp, SEEK_SET, 0); + return 0; + } + else + {return 1; + } + closedir(dp); +} + + + + +/* Analyze file_name for information on sprite sheet, + store sprite sheet and label into sprite then + push sprite onto sprites[]*/ +int +handle_vdat(char* file_name) +{ + /* Parse the file_name for data */ + + + /* Get the specs of the PNG file */ + if(!eval_png_file(file_name)) + { + printf("Failed in read_png_file\n"); + return 1; + } + + /* Insert sprite sheet from PNG into sprite_sheets */ + push_sprite(); + + + + + /* Store dir/filename in label as well as any other data that fits */ +} +int eval_png_file(char* file_name) +{ + /* Evaluate file_name for metadata */ + + /* Extracts header info from png_file */ + read_png_file(file_name); + + + /* Create the symbol and put it in symbol_table[]*/ + + return 0; +} + + + +/* variables for libPNG */ +int png_width,png_height; +png_byte bit_depth; +png_byte color_type; +png_structp png_ptr; +png_infop info_ptr; + +int +read_png_file( char* file_name) +{ + /* Setup PNG file */ + char header[8]; + int is_png = 0; + char* dir = "pngfiles"; + + /* TODO: Change this fopen to a real var! */ + FILE *fp = fopen("pngfiles/env_street_road03_0.png","rb"); + + if(!fp) + { printf("Could not read file %s in handle_vdat()", file_name); + return 1; + } + + fread(header, 1, 8, fp); + + is_png = !png_sig_cmp(header, 0, 8); + if(!is_png) + return 1; + + png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + + if (!png_ptr) + { printf("Failed to allocate png_ptr\n"); + return 1; + } + info_ptr = png_create_info_struct(png_ptr); + + if (!info_ptr) + { printf("Failed to create info_ptr\n"); + png_destroy_read_struct(&png_ptr,(png_infopp)NULL, (png_infopp)NULL); + return 1; + } + + png_infop end_info = png_create_info_struct(png_ptr); + if (!end_info) + { printf("Failed to create end_info \n"); + png_destroy_read_struct(&png_ptr,(png_infopp)NULL, (png_infopp)NULL); + return 1; + } + + if(setjmp(png_jmpbuf(png_ptr))) + { printf("Failed in init_io\n"); + png_destroy_read_struct(&png_ptr,(png_infopp)NULL, (png_infopp)NULL); + fclose(fp); + return 1; + } + png_init_io(png_ptr, fp); + png_set_sig_bytes(png_ptr, 8); + + png_read_info(png_ptr, info_ptr); + + png_width = png_get_image_width(png_ptr, info_ptr); + png_height = png_get_image_height(png_ptr, info_ptr); + color_type = png_get_color_type(png_ptr, info_ptr); + bit_depth = png_get_bit_depth(png_ptr, info_ptr); + + png_read_update_info(png_ptr, info_ptr); + + + return 0; + +} diff --git a/src/apc/filescanner.rl b/src/apc/filescanner.rl new file mode 100644 index 0000000..c3a1baa --- /dev/null +++ b/src/apc/filescanner.rl @@ -0,0 +1,148 @@ +#include +#include +#include +#include +#include +#include "fileparser.tab.h" + +int linit(void); +int tok_dir(DIR*, char *); + +#define MAX_TOK_LEN 256 +#define MAX_DIR_DEP 8 +#define MAX_PATH_LEN 64 +static DIR* dp_stack[MAX_DIR_DEP]; +static DIR** dsp; +static char path[MAX_PATH_LEN]; + +/* Setup stack and first directory to read from */ +int +linit() +{ + DIR *dp; + char cwd[MAX_TOK_LEN]; + + dsp = dp_stack; + + getcwd(cwd, MAX_TOK_LEN); + + printf("|------cwd is %s------|\n", cwd); + if(!(dp = opendir(cwd))) + printf("opendir(cwd) failed in linit()\n"); + + *dsp = dp; + /* Dont use ADD_PATH because it concats a "/", which is already + present with cwd */ + strcat(path, cwd); + printf("dp_stack is %x, dsp is %x size is %d\n",*dp_stack, *dsp, sizeof dp); + + return 0; +} + +int +yylex() +{ + int tok_t = 0; + char buf[MAX_TOK_LEN]; + char* file_name; + + /* Each call to tok_dir will return a file_name to be + tokenized. tok_dir calls readdir(), which saves the + position in the directory after returning a file_name + for the next call. */ + printf("|------in yylex(), calling tok_dir------|\n"); + if((tok_t = tok_dir(*dsp, buf)) == -1) + printf("tok_dir returned -1, something is broken\n"); + yylval.str = strdup(buf); + + printf("|------in yylex(), returning tok_t = %d | err = %s------|\n", tok_t, strerror(errno)); + + return tok_t; +} + +#define DSP_PUSH(_val) *++dsp = (_val) + +int +tok_dir(DIR* dp, char buf[]) +{ + struct dirent* de; /* directory entry */ + static DIR *tmp_dp; + char *tmp_path; + int path_len; + + +tok_start: + if((*dsp == NULL) || (de = readdir(*dsp)) == NULL) + { + if(errno) + { printf("Error:%s in tok_dir\n", strerror(errno)); + return errno; + } + if( (dsp - dp_stack) >= 0) + { + printf("Current directory is null, pop one off "); +#define DSP_POP() *dsp-- + + dp = DSP_POP(); + + /* Remove directory that was popped from path */ +#define SUB_PATH() tmp_path = strrchr(path, '/'); \ + path_len = strlen(tmp_path); \ + memset(tmp_path, 0, path_len) + + SUB_PATH(); + + goto tok_start; + } + return 0; /* Done */ + } + + else if(de->d_type == DT_REG) + { printf("|------dir_ent is a file, "\ + "setting yylval to %s------|\n", de->d_name); + memmove(buf, de->d_name, MAX_TOK_LEN); + return FDAT; + } + else if (de->d_type == DT_DIR ) + { if ((dsp - dp_stack) >= MAX_DIR_DEP) /* We've opened to many directories */ + { + printf("Too many directories!\n"); + return 1; + } + if(strcmp(de->d_name,".") == 0 || strcmp(de->d_name,"..") == 0) + { + printf("directory is %s \n", de->d_name); + goto tok_start; + } + + printf("|------ dir_ent is directory %s, "\ + "cwd = %s, path = %s ------|\n", de->d_name, get_current_dir_name(), path); + + + /* Add directory name to path */ +#define ADD_PATH(_name) strcat(path, "/"); \ + strcat(path, _name) + + ADD_PATH(de->d_name); + + tmp_dp = opendir(path); + if(tmp_dp == 0) + { printf("opening the directory failed,"\ + "errno = %s\n", strerror(errno)); + return -1; + } + + DSP_PUSH(tmp_dp); + + goto tok_start; + + } + else + { + printf("A file that is not a diretory or a regular file is unable to be tokenized: %s\n", de->d_name); + return -1; + } + + + +} diff --git a/src/apc/filescannerparser_old.rl b/src/apc/filescannerparser_old.rl new file mode 100644 index 0000000..ecb2e80 --- /dev/null +++ b/src/apc/filescannerparser_old.rl @@ -0,0 +1,78 @@ +#include +#include +#include +#include +#include "fileparser.tab.h" +extern FILE* yyin; + +int rinit(void); + +#define MAX_TOK_LEN 32 +static char buf[MAX_TOK_LEN]; +static char *p, *pe; /* scanner points to p, pe points to end of buf */ + +%%{ + machine scanner; + + main := |* + + 'env_street_road03_0.png' => {ret=VDAT;memmove(rbuf, ts, (te-ts)); yylval.str=strdup(rbuf); printf("Lexer matched with %s\n",yylval.str);fbreak; }; + '.' => {printf("matched with .\n");fbreak;}; + '..' => {printf("matched with ..\n");fbreak;}; + + *|; + +}%% + +%%write data; + +int +rinit() +{ p = buf; + pe = p + fread(buf, 1, MAX_TOK_LEN, yyin); + printf("buf in rinit is %s\n", buf); + return 0; +} + +int +yylex() +{ int ret; + static char *eof; + char rbuf[MAX_TOK_LEN]; + int cs, act; + char *ts, *te; + + /*init cs, ts, te, act */ + %%write init; + ret = 0; + + %%write exec ; + if (te == 0) + { + if(eof == pe ){ + return 0; + } + printf("This is a lexical error, tokens can not be larger than max token length\n buf is = %s | ts = %s | te = %s\n", buf,ts,te); + return 0; + } + + + /* We matched a token, remove it from buf and set + buf to have rest of unmatched buf (buf - matchedtoken).*/ + if (!feof(yyin)) + { int r = pe-te; /* remainder length */ + memmove(buf, te, r); /* also the max more buf can hold */ + p = buf; + pe = p + r + fread(buf+r,1,MAX_TOK_LEN -r,yyin); + } + if((p+1) == pe && feof(yyin)) + eof = pe; + + return ret; +} + +/* 'sprites' => {}; + /0x[xdigit]{8}/ => {}; + '_' => {}; + /[digit]{2}/ => {}; /* CC */ + diff --git a/src/apc/ragson b/src/apc/ragson new file mode 100755 index 0000000000000000000000000000000000000000..d47463c16a703835348d296a5309ceb832cbe050 GIT binary patch literal 22784 zcmd^ndw7)9x$l}u24ciaxG4h4CxV9C7(i0M+XNUKD9}{F?F}bGWM@koJ& zDC3xxx~p}!-REJq*2C`Z)3U81Wor^HCDB9MXty@UOHI|<8G|-ei?IcAe($^1n)zm! z>C?TR=lpdR+$ab;Q0Zinyb9s`BBP47SdQr@ZvR;SD;I8|aOK_=}XK`JksoGL5f@fwM0 zD1^ZT(j#Ac6~DKpp6MEHBZrXoPn1yWk$a>!p!5cmo`yrpF%5P7sBZK(Rn>2*)d`Gn zCjqg7uUW{k0Ilx#F(2iJ7D$1i1y0Ur_?#pQ4Yl4Ep+|oHy{S?OUeg@dRCDb$&Axff zfna>wylsnX=G9#5h=v>s*ng6vD&D+q18eAb7{I9P3HYPX5x?ONXJ1(Hn>A-%xZt5h zyKbCz{l9+Y`-e$>F8*}tJA90ZtmULiB^MUx>b= zi2Q}18~Dpl-z{S2;v)XMTSWe|BJ{taz(RiRFCu?gk#ctw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Wc5sgVz zdFz%MI{&2xh@lv7OP~QhgkoeK6q+<0=(WOul|c*c_PHyk{~ktf9Q9BGG=}K9-Yp8qclT;%r#$s1vvOk zMM#Nf-nZ8)LY30QvX4_{ou=@0fbhYVFw>+5}kVWnTK1aAOC02 z%=-G=(gR9=L0$!Px!T_M^YryT$-C--R5gPZ=eEiq$o#9)&s1}cQ?lns@JAY4rev7% zl>K-7k^fp>@4E~wATHkHNRYYa$G;04v%cP+Ij~TwOrXJGO8N170X%9dEvDad>T^=_ z<@51Zpldhj>;0a-8W554<@531L5BR-NT1hA-{(-${acr> z`@!SjnakJvOnr-4t*HOn&L8vi^?p>p(!X7mFRf+cq4kIJ^!59z>ZMXc`8JnU5Z)p-x$hE`ON_7lj(>O8vEzc!DqtD_;k?$u?RMd#N^jP_Z~DG$x*yJop< i%KzKdJVN^?tMRAfHc1K7_$*X@pIZue^TuC(`TrM=T5+KO literal 0 HcmV?d00001 diff --git a/src/apc/ragson.sh b/src/apc/ragson.sh new file mode 100755 index 0000000..3da486d --- /dev/null +++ b/src/apc/ragson.sh @@ -0,0 +1,4 @@ +#!/bin/bash +bison -t -d fileparser.y +ragel filescanner.rl +gcc sprite.c fileparser.tab.c filescanner.c -o ragson -lm -lpng diff --git a/src/apc/sprite.c b/src/apc/sprite.c new file mode 100644 index 0000000..82e1911 --- /dev/null +++ b/src/apc/sprite.c @@ -0,0 +1,5 @@ +int +push_sprite(void) +{ + return 0; +} diff --git a/src/apc/sprite.h b/src/apc/sprite.h new file mode 100644 index 0000000..2d55988 --- /dev/null +++ b/src/apc/sprite.h @@ -0,0 +1,20 @@ +#ifndef _SPRITEH_ +#define _SPRITEH_ + +/* Sprite Sheet Header */ +/* Sprite Sheets can have 1-8 frames for each direction they are facing. */ +struct sprite_sheet +{ + int num_frames; /* Defaults to 0 */ + int frame_width; /*Found frome file name */ + int sprite_start; /* points to where first frame points */ +}; + + +extern struct sprite_sheet sprite_sheets[16]; /* stack of sprites */ +extern struct sprite_sheet* ssp; /* sprite sheets pointer */ + + +int push_sprite(); + +#endif diff --git a/src/apc/symbol.h b/src/apc/symbol.h new file mode 100644 index 0000000..8550a83 --- /dev/null +++ b/src/apc/symbol.h @@ -0,0 +1,14 @@ +/* Header file for Symbols */ +#ifndef _SYMBOLH_ +#define _SYMBOLH_ +#include "sprite.h" + +struct symbol +{ + struct sprite_sheet ss; + int ss_id; + char label[255]; +}; + +struct symbol symbol_table[16]; +#endif diff --git a/src/core/auth.c b/src/core/auth.c new file mode 100644 index 0000000..c556abc --- /dev/null +++ b/src/core/auth.c @@ -0,0 +1,111 @@ +/*!@file + \brief Password Encyption and Storing + \details hashes password using SHA256 and saves result in a file on VFS using + hashing algorithm provided by wolfcrypt(wc), a subsystem of wolfSSL + \author JEL + \date 2016 + -----------------------------------------------------------------------------*/ +#include +#include +#include +#include + +word32 str_len(const char*); +int auth_encrypt(int argc, char** argv); +void store_password(byte*); + +/* Should come with wolfcrypt type.h */ +/* typedef unsigned int word32; */ + +word32 +str_len (const char* str) +{ + const char* strl; + + for (strl = str; *strl != '\0'; ++strl) + { + /* nothing to be done */; + } + return strl - str; +} + + +/* Takes a string and hashes it, returning + the encrypted string as a result */ + +int +auth_encrypt(int argc, char** argv) +{ + /* Determine length of password */ + word32 len = 0; + char* password; + byte hash[32]; /* 32bytes * 8 = 256, the # bits of hash */ + const unsigned char c_password[32]; /* Passwords are between 8-32 chars */ + Sha256 sha256[1]; /* Init a Sha256 type for wc */ + + + password = argv[0]; + len = str_len(password); + + /* Converting password to unsigned const char* for wc_functions */ + memcpy( (void*) c_password, (void*) password, len+1); + + if (wc_InitSha256(sha256) != 0 ) + { + printf("wc_InitSha256 failed\n"); + } + else + { + wc_Sha256Update(sha256, c_password, len); + wc_Sha256Final(sha256, hash); + } + + printf("password is: %s\n", c_password); + printf("password length is: %d\n", len); + for(len = 0; len < 32; len++){ + printf("hash is %x\n",hash[len]); + } + + store_password(hash); + free((void*) c_password); + + + return 0; +} + +void +store_password(byte* hash) +{ + byte b; + /* Save hash to a file on emscripten VFS */ + FILE *fp; + int i; + byte buff[32] = {0}; + + printf("=====Storing Password in auth/password========\n"); + /* for(i = 0; i < 32; i++){ */ + /* printf("hash is %x\n",hash[i]); */ + /* } */ + + fp = fopen("/auth/password", "w+"); + if(!fp) + { + printf("cannot open file\n"); + } + else + { + fwrite(hash, 1, 32, fp); + } + + printf("========Stored Password=========\n"); + + fseek(fp, 0, SEEK_SET); + + for(i = 0; i < 32; i++) + { + fread(buff, 1, 32, fp) ; + printf("buff is %x\n",buff[i]); + } + + fclose(fp); +} -- 2.18.0