feat: pass additional stuff to views

This commit is contained in:
b1ek 2024-07-28 14:52:03 +10:00
parent b50649b454
commit 75751f7a17
Signed by: blek
GPG Key ID: 14546221E3595D0C
6 changed files with 83 additions and 24 deletions

View File

@ -1,9 +1,8 @@
import { KeysModule } from './keys/keys.module.js'
import { Module } from '@nestjs/common'
import { ViewsController } from './views.controller.js'
import { ViewsModule } from './views/views.module.js'
@Module({
controllers: [ViewsController],
imports: [KeysModule],
imports: [KeysModule, ViewsModule],
})
export class AppModule {}

View File

@ -1,18 +0,0 @@
import { Controller, Get, Render } from '@nestjs/common'
import { AllKeysProvider } from './keys/providers/all.provider.js'
@Controller()
export class ViewsController {
constructor(private allKeysProvider: AllKeysProvider) {}
@Get()
@Render('index.html')
index() {
return {
keys: this.allKeysProvider.getAll()
.map(x => x.url)
.map(x => ({ url: x, domain: x.replace(/^\S+:\/\//, '') }))
}
}
}

View File

@ -0,0 +1,15 @@
import { Controller, Get, Render, Req } from '@nestjs/common'
import type { FastifyRequest } from 'fastify'
import { ViewsProvider } from './views.provider.js'
@Controller()
export class ViewsController {
constructor(private viewsProvider: ViewsProvider) {}
@Get()
@Render('index.html')
index(@Req() req: FastifyRequest) {
return this.viewsProvider.getData(req)
}
}

11
src/views/views.module.ts Normal file
View File

@ -0,0 +1,11 @@
import { Module } from '@nestjs/common'
import { ViewsController } from './views.controller.js'
import { ViewsProvider } from './views.provider.js'
import { KeysModule } from 'src/keys/keys.module.js'
@Module({
controllers: [ViewsController],
providers: [ViewsProvider],
imports: [KeysModule],
})
export class ViewsModule {}

View File

@ -0,0 +1,21 @@
import { Get, Injectable, Req } from '@nestjs/common'
import type { FastifyRequest } from 'fastify'
import { AllKeysProvider } from 'src/keys/providers/all.provider.js'
@Injectable({})
export class ViewsProvider {
constructor(private allKeysProvider: AllKeysProvider) {}
@Get()
getData(@Req() req: FastifyRequest) {
return {
keys: this.allKeysProvider
.getAll()
.map((x) => x.url)
.map((x) => ({ url: x, domain: x.replace(/^\S+:\/\//, '') })),
host: req.hostname,
protocol: req.protocol,
}
}
}

View File

@ -2,23 +2,54 @@
<html>
<head>
<meta charset="utf-8">
<title>Cupid GPG server</title>
<title>Cupid GPG keyserver</title>
</head>
<body>
<h1>Cupid</h1>
<p>
this is a GPG keyserver that serves keys from all the following servers combined:
this is a GPG keyserver proxy that serves keys from all the following servers combined:
</p>
<ul id="keyservers">
{{#each keys}}
<li><a href="{{ url }}">{{ domain }}</a></li>
{{/each}}
<li>this list is dynamic - it differs with different Cupid versions that implement different keyservers</li>
</ul>
<p>
point is to reduce situations when one keyserver has a key but another one which you use, doesnt
</p>
<h2>compilance</h2>
<p>
this proxy implements some methods from the latest (as of july 2024) &nbsp;<a target='_blank' href='https://www.ietf.org/archive/id/draft-gallagher-openpgp-hkp-05.html'>OpenPGP HTTP Keyserver Protocol</a>:
</p>
<ul>
<li>
<a href="https://www.ietf.org/archive/id/draft-gallagher-openpgp-hkp-05.html#name-legacy-request-format">Legacy request format</a>
</li>
<li>
<a href="https://www.ietf.org/archive/id/draft-gallagher-openpgp-hkp-05.html#name-the-get-operation">"get" operation</a>
</li>
<li>
<a href="https://www.ietf.org/archive/id/draft-gallagher-openpgp-hkp-05.html#name-the-index-operation">"index" operation</a>
</li>
</ul>
<h2>usage</h2>
<p>
to set this as your keyserver, add this to &nbsp;<code>~/.gnupg/gpg.conf</code>&nbsp; (create if doesnt exist):
<pre>keyserver {{host}}</pre>
</p>
<p>
to search for &nbsp;<code>someone@example.com</code>
<pre>curl {{protocol}}://{{host}}/pks/lookup\?search\=someone@example.com\&op\=index</pre>
</p>
<p>
to get key with ID &nbsp;<code>00000000000000000000000000000000000000000</code>
<pre>curl {{protocol}}://{{host}}/pks/lookup\?search\=00000000000000000000000000000000000000000\&op\=get</pre>
</p>
<h2>privacy</h2>
<p>
your requests are fairly private as nothing but your IP is exposed to keyservers to circumvent DoS attacks via this service. you can use an http proxy if that concerns you