diff --git a/.gitignore b/.gitignore index 1684394..4f8f1f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ yarn-error.log node_modules -production \ No newline at end of file +production +**/*.key +**/*.pem \ No newline at end of file diff --git a/README.MD b/README.MD index 1a0ae7d..68fbf4c 100644 --- a/README.MD +++ b/README.MD @@ -18,14 +18,14 @@ - [ ] 基础世界树 API + [x] /authserver + [x] /sessionserver - + [ ] 测试 + + [x] 测试 + [ ] /api - [ ] 进阶 API - [ ] 皮肤上传和安全检查 + [ ] 皮肤数据的RSA签名 - [ ] 兼容S3后端 - - [ ] 服务器状态接口 - - [ ] authlib-injector 元数据接口 + - [x] 服务器状态接口 + - [x] authlib-injector 元数据接口 #### Release 1.0 - [ ] TGbot前端 diff --git a/src/config.js b/src/config.js index 46c32ce..fc2db05 100644 --- a/src/config.js +++ b/src/config.js @@ -3,11 +3,24 @@ export const config = { url: 'mongodb://localhost:27017/yggdrasil?readPreference=primary&appname=MongoDB%20Compass&directConnection=true&ssl=false', }, server: { - port: 3000 + port: 3000, + skinDomain: [ "assets.lama.icu" ], + serverName: "老色批世界树", + advanced: { // 详情可见 -> https://github.com/yushijinhun/authlib-injector/wiki/Yggdrasil-%E6%9C%8D%E5%8A%A1%E7%AB%AF%E6%8A%80%E6%9C%AF%E8%A7%84%E8%8C%83#meta-%E4%B8%AD%E7%9A%84%E5%85%83%E6%95%B0%E6%8D%AE + links: { + homepage: "", + register: "" + }, + "feature.non_email_login": false, + "feature.legacy_skin_api": false, + "feature.no_mojang_namespace": false, + "feature.enable_mojang_anti_features": false, + "feature.enable_profile_key": false + } }, signing: { // 签名材质信息使用 - public: '/path/to/public.pem', - private: '/path/to/private.key' + public: 'public.pem', + private: 'private.key' }, custom: { override: { diff --git a/src/index.js b/src/index.js index 8d0b5b4..4245afa 100644 --- a/src/index.js +++ b/src/index.js @@ -4,7 +4,9 @@ import { registerModels } from './models/index.js'; import * as Hooks from './hooks.js' import * as AuthenticateRoutings from './routes/authenticate.js' import * as SessionServerRoutings from './routes/session.js' +import * as AdvancedRoutings from './routes/advanced.js' import { config } from './config.js' +import { readFileSync } from 'fs' export const server = fastify({ logger: { @@ -19,9 +21,12 @@ export const server = fastify({ export const setup = async () => { const mongooseClient = await mongoose.connect(config.database.url) const models = registerModels(mongooseClient) + const publicKey = readFileSync(config.signing.public).toString() + const privateKey = readFileSync(config.signing.private).toString() server.decorate('mongoose', mongooseClient) server.decorate('models', models) + server.decorate('keys', { publicKey, privateKey }) config.custom.preHooks(server) server.addHook('preHandler', Hooks.headerValidation) @@ -39,6 +44,9 @@ export const setup = async () => { server.route(SessionServerRoutings.hasJoined) server.route(SessionServerRoutings.profile) + server.route(AdvancedRoutings.meta) + server.route(AdvancedRoutings.status) + config.custom.postRouting(server) /* diff --git a/src/routes/advanced.js b/src/routes/advanced.js new file mode 100644 index 0000000..caa61cd --- /dev/null +++ b/src/routes/advanced.js @@ -0,0 +1,75 @@ +import { config, getOverrideHandler, getOverridePreHandler } from "../config.js" + +export const meta = { + method: "GET", + url: "/", + schema: { + response: { + 200: { + "type": "object", + "properties": { + "meta": { + "type": "object", + "properties": { + "serverName": { + "type": "string" + }, + "implementationName": { + "type": "string" + }, + "implementationVersion": { + "type": "string" + } + } + }, + "skinDomains": { + "type": "string" + }, + "signaturePublickey": { + "type": "string" + } + } + } + } + }, + preHandler: getOverridePreHandler("/"), + handler: getOverrideHandler("/") ?? async function(req, rep) { + rep.code(200).send({ + meta: { + serverName: config.server.serverName, + implementationName: "lsp-yggdrasil", + implementationVersion: "1.0", + + }, + skinDomains: config.server.skinDomain, + signaturePublickey: this.keys.publicKey + }) + } +} + +export const status = { + method: "GET", + url: "/status", + schema: { + response: { + 200: { + "type": "object", + "properties": { + "public": { + "type": "string" + }, + "version": { + "type": "string" + } + } + } + } + }, + preHandler: getOverridePreHandler("/status"), + handler: getOverrideHandler("/status") ?? async function(req, rep) { + rep.code(200).send({ + public: this.keys.publicKey, + version: "1.0" + }) + } +} \ No newline at end of file diff --git a/src/secure.js b/src/secure.js new file mode 100644 index 0000000..ebcc744 --- /dev/null +++ b/src/secure.js @@ -0,0 +1,3 @@ +export { + +} \ No newline at end of file