Get first message federating

master
teknomunk 1 year ago
parent c36c52de5c
commit 5955acaeec

@ -3,8 +3,10 @@
// Submodules
#include "ffdb/fs_list.h"
#include "collections/array.h"
#include "http_client/client.h"
// Model
#include "model/server.h"
#include "model/crypto/keys.h"
#include "model/crypto/http_sign.h"
#include "model/account.h"
@ -19,6 +21,7 @@
static bool process_one( int id )
{
bool result = false;
char* postdata = NULL;
struct crypto_keys* keys = crypto_keys_new();
FILE* f = NULL;
struct ap_activity* act = NULL;
@ -38,6 +41,8 @@ static bool process_one( int id )
goto discard;
}
// TODO: REWORK to no longer have multiple target inboxes
char* toline = NULL;
size_t n;
if( -1 == getline( &toline, &n, f ) ) {
@ -80,33 +85,75 @@ static bool process_one( int id )
} while( iter );
free(toline);
if( inboxes.count > 1 ) {
goto failed;
}
ap_activity_create_rsa_signature_2017( act, keys );
size_t size;
{
FILE* f2 = open_memstream( &postdata, &size );
ap_activity_write_to_FILE( act, f2 );
fclose(f2);
}
for( int i = 0; i < inboxes.count; ++i ) {
const char* inbox = inboxes.items[i];
printf( "item[%d] = %s\n", i, inbox );
// Force null termination
postdata = realloc( postdata, size + 1 );
postdata[size] = '\0';
printf( "post: %s\n", postdata );
struct http_signature hs;
if( !http_signature_make( inboxes.items[i], keys, &hs ) ) {
goto failed;
}
int i = 0;
const char* inbox = inboxes.items[i];
printf( "item[%d] = %s\n", i, inbox );
// TODO: HTTP POST request
ap_activity_write_to_FILE( act, stdout );
struct http_signature hs;
if( !http_signature_make( inboxes.items[i], keys, &hs ) ) {
goto failed;
}
http_signature_free( &hs );
char date_line[512];
snprintf( date_line, sizeof(date_line), "Date: %s", hs.date );
char sign_line[512];
snprintf( sign_line, sizeof(sign_line), "Signature: keyId=\"https://%s/owner/actor\",headers=\"(request-target) host date\",signature=\"%s\"",
g_server_name,
hs.signature
);
char user_agent[512];
snprintf( user_agent, sizeof(user_agent), "User-Agent: curl (Apogee/0.1; +https://%s/)", g_server_name );
long status_code = -1;
const void* request[] = {
HTTP_REQ_URL, inbox,
HTTP_REQ_HEADER, user_agent,
HTTP_REQ_HEADER, date_line,
HTTP_REQ_HEADER, sign_line,
HTTP_REQ_HEADER, "Content-Type: application/activity+json",
HTTP_REQ_POSTDATA, postdata,
HTTP_REQ_RESULT_STATUS, &status_code,
NULL
};
// POST to inbox
printf( "\n\nRequest result:\n" );
http_client_do(request);
printf( "\n\n" );
http_signature_free( &hs );
if( status_code == 200 ) {
printf( "Submitted successfully\n" );
goto discard;
}
printf( "\n\nNOT FINISHED DEVELOPING\n\n" );
goto failed;
discard:
result = true;
cleanup:
void release( void* item ) { free( *(char**)item ); }
array_free( &inboxes, sizeof(char*), release );
ap_activity_free(act);
free(postdata);
crypto_keys_free(keys);
if( f ) { fclose(f); }
@ -115,6 +162,9 @@ cleanup:
failed:
result = false;
goto cleanup;
discard:
result = true;
goto cleanup;
}
void process_outbox()
@ -122,8 +172,8 @@ void process_outbox()
int head = fs_list_get("data/outbox/HEAD");
int tail = fs_list_get("data/outbox/TAIL");
if( tail < head ) {
printf( "Processing outbox/%d.json\n", tail );
if( process_one(tail) ) {
printf( "Processing outbox/%d.json\n", tail+1 );
if( process_one(tail+1) ) {
printf( "Done with outbox/%d.json\n", tail );
fs_list_set( "data/outbox/TAIL", tail + 1 );
}

@ -50,12 +50,15 @@ static bool show_owner_profile_page( struct http_request* req )
bool route_owner( struct http_request* req )
{
if( http_request_route_term( req, "/actor" ) ) {
/*
const char* accept = http_request_get_header( req, "Accept" );
if( 0 == strcmp(accept,"application/ld+json")) {
return handle_owner_actor(req);
}
return show_owner_profile_page(req);
*/
return handle_owner_actor(req);
} else if( http_request_route_term( req, "" ) ) {
return show_owner_profile_page(req);
}

@ -1 +1 @@
Subproject commit 70ceed0c73c2c5518b236058d2405f8fe260b71d
Subproject commit 4ea04a07127532702b142e699d9e6a0c8559cd10

@ -1 +1 @@
Subproject commit 5bbdf1dc077088775e4ad3c67737d8ea90cc82f2
Subproject commit daf2a866fe238c6f916bff85e776518e7ae2656f

@ -1 +1 @@
Subproject commit 451767866d52ee435e0c8894d0f4ead36b5d5676
Subproject commit d90a7bdd6d814df9c6260da5d8c7d2423675a2ff

@ -182,7 +182,7 @@ struct account* account_fetch_from_uri( const char* uri )
HTTP_REQ_OUTFILE, f,
NULL,
};
if( !http_get( request ) ) {
if( !http_client_do( request ) ) {
printf( "Unable to fetch %s\n", uri );
return NULL;
}

@ -193,6 +193,7 @@ struct json_object_field signature_types[] = {
};
struct json_object_field ap_activity_layout[] = {
{ "@context", 0, false, &json_field_fixed_string, "https://www.w3.org/ns/activitystreams" },
{ "id", offsetof( struct ap_activity, id ), true, &json_field_string },
{ "actor", offsetof( struct ap_activity, actor ), true, &json_field_string },
{ "state", offsetof( struct ap_activity, state ), false, &json_field_string },

@ -1,17 +1,53 @@
{
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1"
{"@language":"und"}
],
"alsoKnownAs":[],
"attachment":[
{
"name":"blog",
"type":"PropertyValue",
"value":"<a href=\"http://blog.polaris-1.work\" rel=\"ugc\">blog.polaris-1.work</a>"
},
{
"name":"git repo",
"type":"PropertyValue",
"value":"<a href=\"https://git.polaris-1.work/\" rel=\"ugc\">https://git.polaris-1.work/</a>"
}
],
"capabilities":{
"acceptsChatMessages":false
},
"discoverable":false,
"endpoints":{
"sharedInbox":"https://%s{g_server_name}/inbox",
},
"featured":"https://%s{g_server_name}/owner/collections/featured",
"followers":"https://%s{g_server_name}/owner/followers",
"following":"https://%s{g_server_name}/owner/following",
"icon":{
"type":"Image",
"url":"https://pl.polaris-1.work/media/167d2f4b1176e30dffcfe29b25faddd5a2336d3c1b2baf2bc337101e29f7d48f.blob"
},
"id": "https://%s{g_server_name}/owner/actor",
"type": "Person",
"preferredUsername": "%s{owner_account->handle}",
"inbox": "https://%s{g_server_name}/inbox",
"publicKey": {
"id": "https://%s{g_server_name}/owner/actor#main-key",
"owner": "https://%s{g_server_name}/owner/actor",
"publicKeyPem": "%( write_public_key(f); )"
}
"image":{
"type":"Image",
"url":"https://pl.polaris-1.work/media/8374fc3fece3646babd9d160e5f0b41231950b706f51de964e9dfb77157c7f6b.png"
},
"inbox":"https://%s{g_server_name}/inbox",
"manuallyApprovesFollowers":false,
"name":"%s{owner_account->display_name}",
"outbox":"https://%s{g_server_name}/outbox",
"preferredUsername":"%s{owner_account->handle}",
"publicKey":{
"id":"https://%s{g_server_name}/owner/actor#main-key",
"owner":"https://%s{g_server_name}/owner/actor",
"publicKeyPem":"%( write_public_key(f); )"
},
"summary":"",
"tag":[
],
"type":"Person",
"url":"https://%s{g_server_name}/owner"
}

Loading…
Cancel
Save