Use AthShield for mod verification

Implemented mod verification using AthShield when enabled. Added detailed mod identity extraction and validation logic for better integrity checks. Added logs for each verification step and fallback to hash-based identity if the manifest is missing.

Grande ligne : quand tu actives ath shield alors il utilise le système Athena's Shield.
This commit is contained in:
Sandro Soria 2024-10-24 16:10:14 +02:00
parent 5f3e229360
commit 886b29e356

View File

@ -66,11 +66,15 @@ async function dlAsync(login = true) {
} }
// --------- Mod Verification Logic --------- // --------- Mod Verification Logic ---------
if (athShield.status) {
loggerLanding.info(Lang.queryJS('landing.dlAsync.AthShield.usingAthShield'))
const modsDir = path.join(ConfigManager.getDataDirectory(), 'instances', serv.rawServer.id, 'mods') const modsDir = path.join(ConfigManager.getDataDirectory(), 'instances', serv.rawServer.id, 'mods')
// Check if mods directory exists, if not, create it // Check if mods directory exists, if not, create it
if (!fs.existsSync(modsDir)) { if (!fs.existsSync(modsDir)) {
fs.mkdirSync(modsDir, { recursive: true }) fs.mkdirSync(modsDir, {recursive: true})
} }
const distroMods = {} const distroMods = {}
@ -81,7 +85,10 @@ async function dlAsync(login = true) {
if (mdl.rawModule.name.endsWith('.jar')) { if (mdl.rawModule.name.endsWith('.jar')) {
const modPath = path.join(modsDir, mdl.rawModule.name) const modPath = path.join(modsDir, mdl.rawModule.name)
const modIdentity = mdl.rawModule.identity || mdl.rawModule.MD5 const modIdentity = mdl.rawModule.identity || mdl.rawModule.MD5
loggerLanding.info(Lang.queryJS('landing.dlAsync.AthShield.distributionIdentityError', {'moduleName': mdl.rawModule.name, 'moduleIdentity': modIdentity})) loggerLanding.info(Lang.queryJS('landing.dlAsync.AthShield.distributionIdentityError', {
'moduleName': mdl.rawModule.name,
'moduleIdentity': modIdentity
}))
distroMods[modPath] = modIdentity distroMods[modPath] = modIdentity
} }
}) })
@ -97,7 +104,10 @@ async function dlAsync(login = true) {
const lines = manifestContent.split('\n') const lines = manifestContent.split('\n')
const identityLine = lines.find(line => line.startsWith('Mod-Id:') || line.startsWith('Implementation-Title:')) const identityLine = lines.find(line => line.startsWith('Mod-Id:') || line.startsWith('Implementation-Title:'))
if (identityLine) { if (identityLine) {
loggerLanding.info(Lang.queryJS('landing.dlAsync.AthShield.manifestIdentityFound', {'filePath': filePath, 'identityLine': identityLine})) loggerLanding.info(Lang.queryJS('landing.dlAsync.AthShield.manifestIdentityFound', {
'filePath': filePath,
'identityLine': identityLine
}))
return identityLine.split(':')[1].trim() return identityLine.split(':')[1].trim()
} }
} }
@ -107,7 +117,10 @@ async function dlAsync(login = true) {
const hashSum = crypto.createHash('md5') // Use MD5 to match the distribution configuration const hashSum = crypto.createHash('md5') // Use MD5 to match the distribution configuration
hashSum.update(fileBuffer) hashSum.update(fileBuffer)
const hash = hashSum.digest('hex') const hash = hashSum.digest('hex')
loggerLanding.info(Lang.queryJS('landing.dlAsync.AthShield.identityNotFoundInManifest', {'filePath': filePath, 'hash': hash})) loggerLanding.info(Lang.queryJS('landing.dlAsync.AthShield.identityNotFoundInManifest', {
'filePath': filePath,
'hash': hash
}))
return hash return hash
} }
@ -131,10 +144,18 @@ async function dlAsync(login = true) {
if (expectedIdentity) { if (expectedIdentity) {
const modIdentity = extractModIdentity(modPath) const modIdentity = extractModIdentity(modPath)
loggerLanding.info(Lang.queryJS('landing.dlAsync.AthShield.expectedAndCalculatedIdentity', {'expectedIdentity': expectedIdentity, 'mod': mod, 'modIdentity': modIdentity})) loggerLanding.info(Lang.queryJS('landing.dlAsync.AthShield.expectedAndCalculatedIdentity', {
'expectedIdentity': expectedIdentity,
'mod': mod,
'modIdentity': modIdentity
}))
if (modIdentity !== expectedIdentity) { if (modIdentity !== expectedIdentity) {
loggerLanding.error(Lang.queryJS('landing.dlAsync.AthShield.modIdentityMismatchError', {'mod': mod, 'expectedIdentity': expectedIdentity, 'modIdentity': modIdentity})) loggerLanding.error(Lang.queryJS('landing.dlAsync.AthShield.modIdentityMismatchError', {
'mod': mod,
'expectedIdentity': expectedIdentity,
'modIdentity': modIdentity
}))
valid = false valid = false
break break
} }
@ -156,6 +177,11 @@ async function dlAsync(login = true) {
showLaunchFailure(errorMessage, null) showLaunchFailure(errorMessage, null)
return return
} }
} else {
loggerLanding.info(Lang.queryJS('landing.dlAsync.AthShield.notUsingAthShield'))
}
// --------- End of Mod Verification Logic --------- // --------- End of Mod Verification Logic ---------
setLaunchDetails(Lang.queryJS('landing.dlAsync.pleaseWait')) setLaunchDetails(Lang.queryJS('landing.dlAsync.pleaseWait'))