From 0750b9714eeeec2305c89cbf5ddcf2dff642537e Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 3 Jul 2021 22:38:45 -0400 Subject: [PATCH] add sites or whateva --- src/api/comm.libraryofcode.org/routes/keys.ts | 94 +++++++++++++++++++ src/commands/apply.ts | 2 +- src/commands/eris.ts | 2 +- src/commands/pgp.ts | 4 +- src/commands/x509.ts | 4 +- 5 files changed, 101 insertions(+), 5 deletions(-) diff --git a/src/api/comm.libraryofcode.org/routes/keys.ts b/src/api/comm.libraryofcode.org/routes/keys.ts index 26354a3..38f7d13 100644 --- a/src/api/comm.libraryofcode.org/routes/keys.ts +++ b/src/api/comm.libraryofcode.org/routes/keys.ts @@ -1,5 +1,9 @@ +import axios, { AxiosResponse } from 'axios'; import { Route, Server } from '../../../class'; +import { X509Certificate } from '../../../commands/x509'; +import { PGPKey, PublicKeyAlgorithm } from '../../../commands/pgp'; + export default class Keys extends Route { constructor(server: Server) { super(server); @@ -29,5 +33,95 @@ export default class Keys extends Route { if (!member || !memberDoc || !memberDoc?.pgp) return res.status(404).json({ code: this.constants.codes.NOT_FOUND, message: this.constants.messages.NOT_FOUND }); return res.status(200).send(memberDoc.pgp); }); + + // this.router.get('/confirm/pgp/:jwt', async (req, res) => { + // const data: { pgp: string, userID: string } = jwt.verify(req.params.jwt, this.server.client.config.internalKey); + // }) + + this.router.get('/~/x509/:userID', async (req, res) => { + const memberDoc = await this.server.client.db.Member.findOne({ userID: req.params.userID }).lean().exec(); + const member = this.mainGuild.members.get(req.params.userID); + if (!member || !memberDoc || !memberDoc?.x509) return res.status(404).json({ code: this.constants.codes.NOT_FOUND, message: this.constants.messages.NOT_FOUND }); + + const x509: AxiosResponse = await axios.post('https://certapi.libraryofcode.org/parse', memberDoc.x509); + + res.status(200).send(` + + + + + + + + +

Discord Username + Discriminator ${member.username}#${member.discriminator} (${member.id})

+ +

Common Name: ${x509.data.subject.commonName}

+

Email Address: ${x509.data.emailAddresses[0]}

+

Expires on: ${x509.data.notAfter.toLocaleString('en-us')}

+ +

Public Key Algorithm ${x509.data.publicKeyAlgorithm}

+

Key Bit Length ${x509.data.bitLength}

+

Signature Algorithm ${x509.data.signatureAlgorithm}

+

Serial Number ${x509.data.serialNumber}

+

Fingerprint ${x509.data.fingerprint}

+ +

Issuer: ${x509.data.issuer.organization} (${x509.data.issuer.commonName})

+


+ ${memberDoc.pgp} + `); + }); + + this.router.get('/~/pgp/:userID', async (req, res) => { + const memberDoc = await this.server.client.db.Member.findOne({ userID: req.params.userID }).lean().exec(); + const member = this.mainGuild.members.get(req.params.userID); + if (!member || !memberDoc || !memberDoc?.pgp) return res.status(404).json({ code: this.constants.codes.NOT_FOUND, message: this.constants.messages.NOT_FOUND }); + + const pgp: AxiosResponse = await axios.post('https://certapi.libraryofcode.org/pgp', memberDoc.pgp); + + let algo: string; + switch (pgp.data.publicKeyAlgorithm) { + case PublicKeyAlgorithm.DSA: + algo = 'DSA'; + break; + case PublicKeyAlgorithm.ECDH: + algo = 'ECDH'; + break; + case PublicKeyAlgorithm.ECDSA: + algo = 'ECDSA'; + break; + case PublicKeyAlgorithm.ElGamal: + algo = 'ElGamal'; + break; + case PublicKeyAlgorithm.RSA: + algo = 'RSA'; + break; + default: + algo = 'N/A'; + break; + } + + res.status(200).send(` + + + + + + + + +

Discord Username + Discriminator ${member.username}#${member.discriminator} (${member.id})

+ +

Name: ${pgp.data.name}

+

Email Address: ${pgp.data.email}

+

Comment: ${pgp.data.comment}

+ +

Public Key Algorithm: ${algo}

+

Key ID: ${pgp.data.keyID}

+

Fingerprint: ${pgp.data.fingerprint}

+


+ ${memberDoc.x509} + `); + }); } } diff --git a/src/commands/apply.ts b/src/commands/apply.ts index 54079a3..e0ca373 100644 --- a/src/commands/apply.ts +++ b/src/commands/apply.ts @@ -10,7 +10,7 @@ export default class Apply extends Command { constructor(client: Client) { super(client); this.name = 'apply'; - this.description = 'apply'; + this.description = 'Application frontend for EDS.'; this.usage = `${this.client.config.prefix}apply [serviceName]\n${this.client.config.prefix}apply full`; this.permissions = 0; this.guildOnly = true; diff --git a/src/commands/eris.ts b/src/commands/eris.ts index a80ea1f..a91fcdc 100644 --- a/src/commands/eris.ts +++ b/src/commands/eris.ts @@ -7,7 +7,7 @@ export default class Eris extends Command { super(client); this.name = 'eris'; this.description = 'Get information about Eris.'; - this.usage = 'eris '; + this.usage = `${this.client.config.prefix}eris