Implement webfinger and basic owner actor

master
teknomunk 1 year ago
parent b7bbc71eee
commit 076053dbb2

@ -2,6 +2,8 @@
#include "controller/mastodon_api.h"
#include "controller/oauth.h"
#include "controller/webfinger.h"
#include "controller/owner.h"
bool route_asset( struct http_request* req )
{
@ -30,14 +32,15 @@ bool route_request( struct http_request* req )
{
if( http_request_route( req, "/api/v1/" ) ) {
return route_mastodon_api( req );
}
if( http_request_route( req, "/oauth" ) ) {
} else if( http_request_route( req, "/oauth" ) ) {
return route_oauth( req );
}
if( http_request_route( req, "/.well-known" ) ) {
return false;
}
if( http_request_route( req, "/assets/" ) ) {
} else if( http_request_route( req, "/owner" ) ) {
return route_owner( req );
} else if( http_request_route( req, "/.well-known" ) ) {
if( http_request_route( req, "/webfinger?" ) ) {
return route_well_known( req );
}
} else if( http_request_route( req, "/assets/" ) ) {
printf( "handling asset\n" );
return route_asset(req);
}

@ -0,0 +1,41 @@
#include "owner.h"
#include "http_server/http_request.h"
#include <stdio.h>
static void write_public_key( FILE* f )
{
FILE* pubkey = fopen( "data/owner/public.pem", "r" );
char ch;
while( (ch = fgetc(pubkey)) != EOF ) {
if( ch == '\n' ) {
fprintf( f, "\\n" );
} else {
fputc(ch,f);
}
}
}
static void handle_owner_actor( struct http_request* req )
{
const char* server = "apogee.polaris-1.work";
struct account* owner_account = account_from_id(0);
http_request_send_headers( req, 200, "application/activity+json", true );
FILE* f = http_request_get_response_body(req);
#define RENDER
#include "src/controller/owner_actor.json.inc"
#undef RENDER
}
bool route_owner( struct http_request* req )
{
if( http_request_route( req, "/actor" ) ) {
handle_owner_actor(req);
return true;
}
return false;
}

@ -0,0 +1,10 @@
#pragma once
#include "model/account.h"
#include <stdbool.h>
struct http_request;
bool route_owner( struct http_request* req );

@ -0,0 +1,17 @@
{
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1"
],
"id": "https://%s{server}/owner/actor",
"type": "Person",
"preferredUsername": "%s{owner_account->handle}",
"inbox": "https://%s{server}/inbox",
"publicKey": {
"id": "https://%s{server}/owner/actor#main-key",
"owner": "https://%s{server}/owner/actor",
"publicKeyPem": "%( write_public_key(f); )"
}
}

@ -0,0 +1,36 @@
#include "webfinger.h"
#include "http_server/http_request.h"
#include <string.h>
bool route_well_known( struct http_request* req )
{
// /.well-known/webfinger?resource=acct:teknomunk@apogee.polaris-1.work
const char* key;
char* resource;
while( key = http_request_route_query_key( req ) ) {
if( 0 == strcmp(key,"resource") ) {
resource = strdup(http_request_route_query_value(req) );
} else {
http_request_route_query_value(req);
}
}
char* server;
strtok_r( resource, ":", &resource );
char* account_name = strtok_r( resource, "@", &server );
// Verify the server name matches this instance
// if( 0 != strcmp( server, this_server_hostname() ) ) { return false; }
http_request_send_headers( req, 200, "application/json", true );
FILE* f = http_request_get_response_body(req);
#define RENDER
#include "src/controller/webfinger.json.inc"
#undef RENDER
return true;
}

@ -0,0 +1,8 @@
#pragma once
#include <stdbool.h>
struct http_request;
bool route_well_known( struct http_request* );

@ -0,0 +1,11 @@
{
"subject": "acct:%s{resource}@%s{server}",
"links": [
{
"rel": "self",
"type": "application/activity+json",
"href": "https://%s{server}/owner/actor"
}
]
}
Loading…
Cancel
Save