fix: qr code size validation
This commit is contained in:
parent
ed33993a42
commit
75e2444541
3 changed files with 10 additions and 4 deletions
|
|
@ -8,7 +8,7 @@ import qrcode from "qrcode-generator";
|
||||||
|
|
||||||
import { auth } from "@/lib/auth";
|
import { auth } from "@/lib/auth";
|
||||||
import { prisma } from "@/lib/prisma";
|
import { prisma } from "@/lib/prisma";
|
||||||
import { MII_DECRYPTION_KEY, MII_QR_SIZES } from "@/lib/constants";
|
import { MII_DECRYPTION_KEY } from "@/lib/constants";
|
||||||
import { nameSchema, tagsSchema } from "@/lib/schemas";
|
import { nameSchema, tagsSchema } from "@/lib/schemas";
|
||||||
|
|
||||||
const uploadsDirectory = path.join(process.cwd(), "public", "uploads");
|
const uploadsDirectory = path.join(process.cwd(), "public", "uploads");
|
||||||
|
|
@ -28,7 +28,7 @@ export async function POST(request: Request) {
|
||||||
if (!tagsValidation.success) return Response.json({ error: tagsValidation.error.errors[0].message }, { status: 400 });
|
if (!tagsValidation.success) return Response.json({ error: tagsValidation.error.errors[0].message }, { status: 400 });
|
||||||
|
|
||||||
// Validate QR code size
|
// Validate QR code size
|
||||||
if (!MII_QR_SIZES.includes(qrBytesRaw.length)) return Response.json({ error: "QR code is not a valid Mii QR code size" }, { status: 400 });
|
if (qrBytesRaw.length !== 372) return Response.json({ error: "QR code size is not a valid Tomodachi Life QR code" }, { status: 400 });
|
||||||
|
|
||||||
const qrBytes = new Uint8Array(qrBytesRaw);
|
const qrBytes = new Uint8Array(qrBytesRaw);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,14 @@ export default function SubmitForm() {
|
||||||
const decode = async () => {
|
const decode = async () => {
|
||||||
setError("");
|
setError("");
|
||||||
|
|
||||||
// Decrypt the QR code
|
// Validate QR code size
|
||||||
|
if (qrBytesRaw.length !== 372) {
|
||||||
|
setError("QR code size is not a valid Tomodachi Life QR code");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decrypt the Mii part of the QR code
|
||||||
|
// (Credits to kazuki-4ys)
|
||||||
const nonce = qrBytes.subarray(0, 8);
|
const nonce = qrBytes.subarray(0, 8);
|
||||||
const content = qrBytes.subarray(8, 0x70);
|
const content = qrBytes.subarray(8, 0x70);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1 @@
|
||||||
export const MII_DECRYPTION_KEY = new Uint8Array([0x59, 0xfc, 0x81, 0x7e, 0x64, 0x46, 0xea, 0x61, 0x90, 0x34, 0x7b, 0x20, 0xe9, 0xbd, 0xce, 0x52]);
|
export const MII_DECRYPTION_KEY = new Uint8Array([0x59, 0xfc, 0x81, 0x7e, 0x64, 0x46, 0xea, 0x61, 0x90, 0x34, 0x7b, 0x20, 0xe9, 0xbd, 0xce, 0x52]);
|
||||||
export const MII_QR_SIZES = [0x70, 172, 324, 372];
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue