|
|
|
@ -10,12 +10,15 @@
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
|
|
static bool process_one( int id )
|
|
|
|
|
{
|
|
|
|
|
bool result = false;
|
|
|
|
|
struct crypto_keys* keys = crypto_keys_new();
|
|
|
|
|
FILE* f = NULL;
|
|
|
|
|
ARRAY_OF(char*) inboxes;
|
|
|
|
|
memset( &inboxes, 0, sizeof(inboxes) );
|
|
|
|
|
|
|
|
|
|
if( !crypto_keys_load_private( keys, "data/owner/private.pem" ) ) {
|
|
|
|
|
printf( "Failed to load private key\n" );
|
|
|
|
@ -43,9 +46,6 @@ static bool process_one( int id )
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ARRAY_OF(char*) inboxes;
|
|
|
|
|
memset( &inboxes, 0, sizeof(inboxes) );
|
|
|
|
|
|
|
|
|
|
char* remainder = NULL;
|
|
|
|
|
char* iter = strtok_r( &toline[4],",",&remainder);
|
|
|
|
|
|
|
|
|
@ -69,11 +69,52 @@ static bool process_one( int id )
|
|
|
|
|
free(toline);
|
|
|
|
|
|
|
|
|
|
for( int i = 0; i < inboxes.count; ++i ) {
|
|
|
|
|
printf( "item[%d] = %s\n", i, inboxes.items[i] );
|
|
|
|
|
}
|
|
|
|
|
const char* inbox = inboxes.items[i];
|
|
|
|
|
printf( "item[%d] = %s\n", i, inbox );
|
|
|
|
|
|
|
|
|
|
void release( void* item ) { free( *(char**)item ); }
|
|
|
|
|
array_free( &inboxes, sizeof(char*), release );
|
|
|
|
|
if( 0 != strncmp( "https://", inbox, 8 ) ) {
|
|
|
|
|
printf( "Invalid inbox: %s\n", inbox );
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Separate host and path from inbox
|
|
|
|
|
char* path = index( &inbox[8], '/' );
|
|
|
|
|
char* host = strndup( &inbox[8], path - &inbox[8] );
|
|
|
|
|
|
|
|
|
|
// Build HTTP date
|
|
|
|
|
time_t utc_time = time(NULL);
|
|
|
|
|
struct tm gmtime_data;
|
|
|
|
|
gmtime_r( &utc_time, &gmtime_data );
|
|
|
|
|
static const char* day_of_week[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
|
|
|
|
|
static const char* month_of_year[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
|
|
|
|
|
char date[32];
|
|
|
|
|
snprintf( date, sizeof(date),
|
|
|
|
|
"%s, %d %s %d %02d:%02d:%02d GMT",
|
|
|
|
|
day_of_week[ gmtime_data.tm_wday ],
|
|
|
|
|
gmtime_data.tm_mday,
|
|
|
|
|
month_of_year[ gmtime_data.tm_mon ],
|
|
|
|
|
gmtime_data.tm_year + 1900,
|
|
|
|
|
gmtime_data.tm_hour,
|
|
|
|
|
gmtime_data.tm_min,
|
|
|
|
|
gmtime_data.tm_sec
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Build hash line
|
|
|
|
|
char hash_line[512];
|
|
|
|
|
snprintf( hash_line, 512, "(request-target): post %s\nhost: %s\ndate: %s", path, host, date );
|
|
|
|
|
printf( "hash_line = %s\n", hash_line );
|
|
|
|
|
|
|
|
|
|
// Hash and sign
|
|
|
|
|
char hash[32];
|
|
|
|
|
sha256_easy_hash( hash_line, strlen(hash_line), hash );
|
|
|
|
|
char* signature = crypto_keys_sign( keys, hash, 32 );
|
|
|
|
|
printf( "signature = %s\n", signature );
|
|
|
|
|
free(signature);
|
|
|
|
|
|
|
|
|
|
// TODO: HTTP POST request
|
|
|
|
|
|
|
|
|
|
free(host);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NOT FINISHED DEVELOPING
|
|
|
|
|
goto failed;
|
|
|
|
@ -81,6 +122,9 @@ static bool process_one( int id )
|
|
|
|
|
discard:
|
|
|
|
|
result = true;
|
|
|
|
|
cleanup:
|
|
|
|
|
void release( void* item ) { free( *(char**)item ); }
|
|
|
|
|
array_free( &inboxes, sizeof(char*), release );
|
|
|
|
|
|
|
|
|
|
crypto_keys_free(keys);
|
|
|
|
|
if( f ) { fclose(f); }
|
|
|
|
|
|
|
|
|
@ -102,17 +146,5 @@ void process_outbox()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
char hash[32];
|
|
|
|
|
sha256_easy_hash( "Hello, World!", 13, hash );
|
|
|
|
|
|
|
|
|
|
char* signature = crypto_keys_sign( keys, hash, 32 );
|
|
|
|
|
printf( "signature = %s\n", signature );
|
|
|
|
|
free(signature);
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|