From 64d4ff65272687c3b16974120b5298f83b71e13c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Sat, 24 Feb 2024 09:47:36 -0300 Subject: [PATCH 01/12] [secrman] add arcade export for dongle auth --- iop/security/secrman/src/exports.tab | 3 +++ 1 file changed, 3 insertions(+) diff --git a/iop/security/secrman/src/exports.tab b/iop/security/secrman/src/exports.tab index dc47203b8e9..cc2eee1f8e5 100644 --- a/iop/security/secrman/src/exports.tab +++ b/iop/security/secrman/src/exports.tab @@ -21,4 +21,7 @@ DECLARE_EXPORT_TABLE(secrman, 0x01, 0x03) DECLARE_EXPORT(SecrDownloadGetKbit) /* 017 */ DECLARE_EXPORT(SecrDownloadGetKc) /* 018 */ DECLARE_EXPORT(SecrDownloadGetICVPS2) /* 019 */ +#ifdef BUILDING_SYSTEM2x6_SECRMAN + DECLARE_EXPORT(SecrAuthDongle) /* 020 */ +#endif END_EXPORT_TABLE From 992d9f23e07f6351595ea03c771efd7ab5612a1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Sat, 24 Feb 2024 10:28:29 -0300 Subject: [PATCH 02/12] Update secrman.h --- iop/kernel/include/secrman.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/iop/kernel/include/secrman.h b/iop/kernel/include/secrman.h index de3ec4a9baf..6a9792c04d3 100644 --- a/iop/kernel/include/secrman.h +++ b/iop/kernel/include/secrman.h @@ -57,6 +57,9 @@ extern void SecrResetAuthCard(int port, int slot, int cnum); #define I_SecrDownloadGetKc DECLARE_IMPORT(18, SecrDownloadGetKc) #define I_SecrDownloadGetICVPS2 DECLARE_IMPORT(19, SecrDownloadGetICVPS2) +/* FOLLOWING EXPORTS ARE ONLY AVAILABLE IN ARCADE SECRMAN */ +#define I_SecrAuthDongle DECLARE_IMPORT(20, SecrAuthDongle) + #ifdef __cplusplus } #endif From c99273c76131a189b8006d64419d13931f502c80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Sat, 24 Feb 2024 10:31:01 -0300 Subject: [PATCH 03/12] Update libsecr-common.h [skip actions] --- common/include/libsecr-common.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common/include/libsecr-common.h b/common/include/libsecr-common.h index 81b84cd32df..08dc74702b5 100644 --- a/common/include/libsecr-common.h +++ b/common/include/libsecr-common.h @@ -78,4 +78,6 @@ extern int SecrDownloadGetKbit(int port, int slot, void *kbit); extern int SecrDownloadGetKc(int port, int slot, void *kbit); extern int SecrDownloadGetICVPS2(void *icvps2); +/* FOLLOWING EXPORTS ARE ONLY AVAILABLE IN ARCADE SECRMAN */ +extern int SecrAuthDongle(int port,int slot,int cnum); #endif /* __LIBSECR_COMMON_H__ */ From a4573eea5eed161b77eb917b719357e1022e613f Mon Sep 17 00:00:00 2001 From: israpps <57065102+israpps@users.noreply.github.com> Date: Sat, 24 Feb 2024 12:54:33 -0300 Subject: [PATCH 04/12] push changes TODO: check if the cardauth func has some changes --- iop/security/Makefile | 1 + iop/security/secrman/src/DongleAuth.c | 175 ++++++++++++++++++++++++++ iop/security/secrman/src/DongleAuth.h | 1 + iop/security/secrman/src/MechaAuth.c | 18 +++ iop/security/secrman/src/MechaAuth.h | 3 + iop/security/secrman/src/main.h | 16 ++- iop/security/secrman_arcade/Makefile | 9 ++ 7 files changed, 219 insertions(+), 4 deletions(-) create mode 100644 iop/security/secrman/src/DongleAuth.c create mode 100644 iop/security/secrman/src/DongleAuth.h create mode 100644 iop/security/secrman_arcade/Makefile diff --git a/iop/security/Makefile b/iop/security/Makefile index c6689c6226e..36dad1eee07 100644 --- a/iop/security/Makefile +++ b/iop/security/Makefile @@ -8,6 +8,7 @@ SUBDIRS = \ secrman \ + secrman_arcade \ secrsif include $(PS2SDKSRC)/Defs.make diff --git a/iop/security/secrman/src/DongleAuth.c b/iop/security/secrman/src/DongleAuth.c new file mode 100644 index 00000000000..a335d99b496 --- /dev/null +++ b/iop/security/secrman/src/DongleAuth.c @@ -0,0 +1,175 @@ +#include +#include +#include "secrman.h" +#include "main.h" +#include "CardAuth.h" +#include "MechaAuth.h" +#include "DongleAuth.h" + + +int SecrAuthDongle(int port,int slot,int cnum) +{ + int x; + u8 CardIV[8]; + u8 CardMaterial[8]; + u8 CardNonce[8]; + u8 MechaChallenge3[7]; + u8 MechaChallenge2[5]; + u8 auStack_44[4]; + u8 MechaChallenge1[8]; + u8 CardResponse1[8]; + u8 CardResponse2[8]; + u8 CardResponse3[8]; + + if (GetMcCommandHandler() == NULL) { + _arcade_printf("mcCommand isn\'t assigned\n"); + } + else { + memset(MechaChallenge2, 0, sizeof(MechaChallenge2)); + _arcade_printf("SecrAuthDongle start\n"); + x = card_auth_60(port,slot); + if (x != 0) { + _arcade_printf("dongle auth 0x60\n"); + x = mechacon_auth_80(cnum); + if (x != 0) { + _arcade_printf("mechacon auth 0x80\n"); + x = card_auth(port,slot,0xf0,0); + if (x == 0) { + card_auth_60(port,slot); + } + else { + _arcade_printf("dongle auth 0x00\n"); + x = mechacon_auth_81(cnum | 0x40); + if (x == 0) { + card_auth_60(port,slot); + } + else { + _arcade_printf("mechacon auth 0x81\n"); + x = card_auth_read(port,slot,CardIV,0xf0,1); + if (x != 0) { + _arcade_printf("dongle auth 0x01\n"); + x = card_auth_read(port,slot,CardMaterial,0xf0,2); + if (x != 0) { + _arcade_printf("dongle auth 0x02\n"); + x = mechacon_auth_82(CardIV,CardMaterial); + if (x != 0) { + _arcade_printf("mechacon auth 0x82\n"); + x = card_auth(port,slot,0xf0,3); + if (x != 0) { + _arcade_printf("dongle auth 0x03\n"); + x = card_auth_read(port,slot,CardNonce,0xf0,4); + if (x != 0) { + _arcade_printf(0x3f80); + x = mechacon_auth_83(CardNonce); + if (x != 0) { + _arcade_printf("mechacon auth 0x83\n"); + x = card_auth(port,slot,0xf0,5); + if (x != 0) { + _arcade_printf("dongle auth 0x05\n"); + x = mechacon_auth_8F(); + if (x != 0) { + _arcade_printf("mechacon auth 0x8f\n"); + x = mechacon_auth_84(MechaChallenge1,MechaChallenge2 + 1); + if (x != 0) { + _arcade_printf("mechacon auth 0x84\n"); + x = mechacon_auth_85(auStack_44,MechaChallenge3); + if (x != 0) { + _arcade_printf("mechacon auth 0x85\n"); + x = card_auth_write(port,slot,MechaChallenge3,0xf0,6); + if (x != 0) { + _arcade_printf("dongle auth 0x06\n"); + x = card_auth_write(port,slot,MechaChallenge2 + 1,0xf0,7); + if (x != 0) { + _arcade_printf("dongle auth 0x07\n"); + x = card_auth(port,slot,0xf0,8); + if (x != 0) { + _arcade_printf("dongle auth 0x08\n"); + x = card_auth2(port,slot,0xf0,9); + if (x != 0) { + _arcade_printf("dongle auth 0x09\n"); + x = card_auth(port,slot,0xf0,10); + if (x != 0) { + _arcade_printf(0x3ff8); + x = card_auth_write(port,slot,MechaChallenge1,0xf0,0xb); + if (x != 0) { + _arcade_printf("dongle auth 0x0b\n"); + x = card_auth(port,slot,0xf0,0xc); + if (x != 0) { + _arcade_printf("dongle auth 0x0c\n"); + x = card_auth2(port,slot,0xf0,0xd); + if (x != 0) { + _arcade_printf("dongle auth 0x0d\n"); + x = card_auth(port,slot,0xf0,0xe); + if (x != 0) { + _arcade_printf("dongle auth 0x0e\n"); + x = card_auth_read(port,slot,CardResponse1,0xf0, + 0xf); + if (x != 0) { + _arcade_printf("dongle auth 0x0f\n"); + x = card_auth(port,slot,0xf0,0x10); + if (x != 0) { + _arcade_printf("dongle auth 0x10\n"); + x = card_auth_read(port,slot,CardResponse2,0xf0,0x11); + if (x != 0) { + _arcade_printf("dongle auth 0x11\n"); + x = mechacon_auth_86(CardResponse1,CardResponse2); + if (x != 0) { + _arcade_printf("mechacon auth 0x86\n"); + x = card_auth(port,slot,0xf0,0x12); + if (x != 0) { + _arcade_printf("dongle auth 0x12\n"); + x = card_auth_read(port,slot,CardResponse3,0xf0,0x13); + if (x != 0) { + _arcade_printf("dongle auth 0x13\n"); + x = mechacon_auth_87(CardResponse3); + if (x != 0) { + _arcade_printf("mechacon auth 0x87\n"); + x = mechacon_auth_8F(); + if (x != 0) { + _arcade_printf("mechacon auth 0x8f\n"); + x = card_auth(port,slot,0xf0,0x14); + if (x != 0) { + _arcade_printf("dongle auth 0x14\n"); + x = mechacon_auth_88(); + if (x != 0) { + _arcade_printf("mechacon auth 0x88\n"); + return 1; + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + card_auth_60(port,slot); + mechacon_auth_80(cnum); + } + } + } + } + } + return 0; +} + diff --git a/iop/security/secrman/src/DongleAuth.h b/iop/security/secrman/src/DongleAuth.h new file mode 100644 index 00000000000..65f32fcca02 --- /dev/null +++ b/iop/security/secrman/src/DongleAuth.h @@ -0,0 +1 @@ +int SecrAuthDongle(int port,int slot,int cnum); \ No newline at end of file diff --git a/iop/security/secrman/src/MechaAuth.c b/iop/security/secrman/src/MechaAuth.c index d958624f9b0..42e43d343ef 100644 --- a/iop/security/secrman/src/MechaAuth.c +++ b/iop/security/secrman/src/MechaAuth.c @@ -429,3 +429,21 @@ int func_00001ed8(void *icvps2) return 1; } + +/* + El_isra: amongst all the calls to 'SendMechaCommand' inside arcade SECRMAN. + this 0x8f mecha command is the only one done from a do{}while() + */ +int mechacon_auth_8F(void) +{ + int iVar1; + char out[16]; + + do { + iVar1 = SendMechaCommand(0x8f, NULL, 0, out); + if (iVar1 == 0) { + return 0; + } + } while (out[0] == 1); + return out[0] == 0; +} diff --git a/iop/security/secrman/src/MechaAuth.h b/iop/security/secrman/src/MechaAuth.h index 8ec4caca68f..812e2880426 100644 --- a/iop/security/secrman/src/MechaAuth.h +++ b/iop/security/secrman/src/MechaAuth.h @@ -9,6 +9,9 @@ int mechacon_auth_85(void *buffer, void *buffer2); int mechacon_auth_86(void *buffer, void *buffer2); int mechacon_auth_87(void *buffer); int mechacon_auth_88(void); +#ifdef BUILDING_SYSTEM2x6_SECRMAN +int mechacon_auth_8F(void); +#endif int write_HD_start(unsigned char mode, int cnum, int arg2, unsigned short int HeaderLength); int write_data(const void *buffer, unsigned short int length); diff --git a/iop/security/secrman/src/main.h b/iop/security/secrman/src/main.h index 35181229d2d..4c4bcafe8a7 100644 --- a/iop/security/secrman/src/main.h +++ b/iop/security/secrman/src/main.h @@ -6,13 +6,21 @@ */ #ifdef DEBUG -#define _printf(args...) printf("SECRMAN: "args) -#define _printf2(args...) printf("SECRMAN: "args) -#define _printf3(args...) printf("SECRMAN: "args) -#define _printf4(args...) printf("SECRMAN: "args) +#ifdef BUILDING_SYSTEM2x6_SECRMAN +#define LOGMODNAME "ARCADE_SECRMAN: " +#else +#define LOGMODNAME "SECRMAN: " +#endif + +#define _printf(args...) printf(LOGMODNAME args) +#define _printf2(args...) printf(LOGMODNAME args) +#define _printf3(args...) printf(LOGMODNAME args) +#define _printf4(args...) printf(LOGMODNAME args) +#define _arcade_printf(args...) printf(LOGMODNAME args) #else #define _printf(args...) #define _printf2(args...) #define _printf3(args...) #define _printf4(args...) +#define _arcade_printf(args...) #endif diff --git a/iop/security/secrman_arcade/Makefile b/iop/security/secrman_arcade/Makefile new file mode 100644 index 00000000000..5a81a3d3012 --- /dev/null +++ b/iop/security/secrman_arcade/Makefile @@ -0,0 +1,9 @@ +IOP_PARENT_DIR = $(PS2SDKSRC)/iop/security/secrman +IOP_SRC_DIR = $(IOP_PARENT_DIR)/src/ +IOP_INC_DIR = $(IOP_PARENT_DIR)/include/ + +IOP_BIN ?= secrman_arcade_namco.irx + +COH_SUPPORT ?= 1 + +include $(IOP_PARENT_DIR)/Makefile \ No newline at end of file From 881c8ebee9aac6da80481fabe372e08602b4b3df Mon Sep 17 00:00:00 2001 From: israpps <57065102+israpps@users.noreply.github.com> Date: Sat, 24 Feb 2024 12:58:27 -0300 Subject: [PATCH 05/12] Update Makefile --- iop/security/secrman/Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/iop/security/secrman/Makefile b/iop/security/secrman/Makefile index fd5a02a068e..d1da457e1c7 100644 --- a/iop/security/secrman/Makefile +++ b/iop/security/secrman/Makefile @@ -12,10 +12,15 @@ IOP_OBJS = secrman.o MechaAuth.o CardAuth.o keyman.o imports.o exports.o # Define to 1, to enable runtime support for both CEX and DEX units. DEX_SUPPORT ?= 1 +COH_SUPPORT ?= 0 ifneq (x$(DEX_SUPPORT),x9) IOP_CFLAGS += -DDEX_SUPPORT=1 endif +ifeq ($(COH_SUPPORT),1) +IOP_CFLAGS += -DBUILDING_SYSTEM2x6_SECRMAN=1 +IOP_OBJS += DongleAuth.o +endif include $(PS2SDKSRC)/Defs.make include $(PS2SDKSRC)/iop/Rules.bin.make From 3ce1aa6de840cda91e8a5cbb7ec8be0fcaf358cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Sat, 24 Feb 2024 14:26:30 -0300 Subject: [PATCH 06/12] Update DongleAuth.c --- iop/security/secrman/src/DongleAuth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iop/security/secrman/src/DongleAuth.c b/iop/security/secrman/src/DongleAuth.c index a335d99b496..d0020b52fa0 100644 --- a/iop/security/secrman/src/DongleAuth.c +++ b/iop/security/secrman/src/DongleAuth.c @@ -59,7 +59,7 @@ int SecrAuthDongle(int port,int slot,int cnum) _arcade_printf("dongle auth 0x03\n"); x = card_auth_read(port,slot,CardNonce,0xf0,4); if (x != 0) { - _arcade_printf(0x3f80); + _arcade_printf("dongle auth 0x04\n"); x = mechacon_auth_83(CardNonce); if (x != 0) { _arcade_printf("mechacon auth 0x83\n"); From 5174c5b21401433c3f8ead1418d4046c172992cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Sat, 24 Feb 2024 14:47:29 -0300 Subject: [PATCH 07/12] Update DongleAuth.c --- iop/security/secrman/src/DongleAuth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iop/security/secrman/src/DongleAuth.c b/iop/security/secrman/src/DongleAuth.c index d0020b52fa0..d2ea8f6fd36 100644 --- a/iop/security/secrman/src/DongleAuth.c +++ b/iop/security/secrman/src/DongleAuth.c @@ -89,7 +89,7 @@ int SecrAuthDongle(int port,int slot,int cnum) _arcade_printf("dongle auth 0x09\n"); x = card_auth(port,slot,0xf0,10); if (x != 0) { - _arcade_printf(0x3ff8); + _arcade_printf("dongle auth 0x10\n"); x = card_auth_write(port,slot,MechaChallenge1,0xf0,0xb); if (x != 0) { _arcade_printf("dongle auth 0x0b\n"); From c01f6d84db6123e5bb995cb1279ac1ca1db7ae39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Sun, 25 Feb 2024 21:08:29 -0300 Subject: [PATCH 08/12] Update MechaAuth.c [skip actions] --- iop/security/secrman/src/MechaAuth.c | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/iop/security/secrman/src/MechaAuth.c b/iop/security/secrman/src/MechaAuth.c index 42e43d343ef..d958624f9b0 100644 --- a/iop/security/secrman/src/MechaAuth.c +++ b/iop/security/secrman/src/MechaAuth.c @@ -429,21 +429,3 @@ int func_00001ed8(void *icvps2) return 1; } - -/* - El_isra: amongst all the calls to 'SendMechaCommand' inside arcade SECRMAN. - this 0x8f mecha command is the only one done from a do{}while() - */ -int mechacon_auth_8F(void) -{ - int iVar1; - char out[16]; - - do { - iVar1 = SendMechaCommand(0x8f, NULL, 0, out); - if (iVar1 == 0) { - return 0; - } - } while (out[0] == 1); - return out[0] == 0; -} From 8f8af9a921d0a291fb82d5252aa158d88990155a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Sun, 25 Feb 2024 21:09:14 -0300 Subject: [PATCH 09/12] Update DongleAuth.c --- iop/security/secrman/src/DongleAuth.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iop/security/secrman/src/DongleAuth.c b/iop/security/secrman/src/DongleAuth.c index d2ea8f6fd36..94bb1e90101 100644 --- a/iop/security/secrman/src/DongleAuth.c +++ b/iop/security/secrman/src/DongleAuth.c @@ -66,7 +66,7 @@ int SecrAuthDongle(int port,int slot,int cnum) x = card_auth(port,slot,0xf0,5); if (x != 0) { _arcade_printf("dongle auth 0x05\n"); - x = mechacon_auth_8F(); + x = pol_cal_cmplt(); if (x != 0) { _arcade_printf("mechacon auth 0x8f\n"); x = mechacon_auth_84(MechaChallenge1,MechaChallenge2 + 1); @@ -124,7 +124,7 @@ int SecrAuthDongle(int port,int slot,int cnum) x = mechacon_auth_87(CardResponse3); if (x != 0) { _arcade_printf("mechacon auth 0x87\n"); - x = mechacon_auth_8F(); + x = pol_cal_cmplt(); if (x != 0) { _arcade_printf("mechacon auth 0x8f\n"); x = card_auth(port,slot,0xf0,0x14); From 49f40d44cdf9377c757817aeb9a2834bed6b64e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Sun, 25 Feb 2024 21:13:57 -0300 Subject: [PATCH 10/12] Update secrman.c --- iop/security/secrman/src/secrman.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/iop/security/secrman/src/secrman.c b/iop/security/secrman/src/secrman.c index 9089120adda..190ccbc1aaf 100644 --- a/iop/security/secrman/src/secrman.c +++ b/iop/security/secrman/src/secrman.c @@ -582,7 +582,11 @@ int SecrAuthCard(int port, int slot, int cnum) #ifdef DEX_SUPPORT IsDEX || #endif +#ifdef BUILDING_SYSTEM2x6_SECRMAN + card_auth_key_change(port, slot, 3)) == 0) { +#else card_auth_key_change(port, slot, 1)) == 0) { +#endif card_auth_60(port, slot); return 0; } From 4412e4dfca9f08ea970c5a29e66cb6a1427a477c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Sun, 25 Feb 2024 21:25:32 -0300 Subject: [PATCH 11/12] Update main.h --- iop/security/secrman/src/main.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iop/security/secrman/src/main.h b/iop/security/secrman/src/main.h index 4c4bcafe8a7..46f1707f189 100644 --- a/iop/security/secrman/src/main.h +++ b/iop/security/secrman/src/main.h @@ -17,10 +17,12 @@ #define _printf3(args...) printf(LOGMODNAME args) #define _printf4(args...) printf(LOGMODNAME args) #define _arcade_printf(args...) printf(LOGMODNAME args) +#define _printf_no_modname(args...) printf(args) #else #define _printf(args...) #define _printf2(args...) #define _printf3(args...) #define _printf4(args...) #define _arcade_printf(args...) +#define _printf_no_modname(args...) #endif From 462ed9b6a0e28d7b021befa1cdadf7f9fa7be1f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Sun, 25 Feb 2024 21:26:16 -0300 Subject: [PATCH 12/12] Update MechaAuth.c --- iop/security/secrman/src/MechaAuth.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iop/security/secrman/src/MechaAuth.c b/iop/security/secrman/src/MechaAuth.c index d958624f9b0..a135a34e6d0 100644 --- a/iop/security/secrman/src/MechaAuth.c +++ b/iop/security/secrman/src/MechaAuth.c @@ -25,9 +25,9 @@ int SendMechaCommand(int command, const void *input, unsigned short int length, _printf3("mecha command:%02x param:", (unsigned char)command); for (i = 0; i < length; i++) { - _printf3(" %02x", ((unsigned char *)input)[i]); + _printf_no_modname(" %02x", ((unsigned char *)input)[i]); } - _printf3("\n"); + _printf_no_modname("\n"); return sceCdApplySCmd((unsigned char)command, (void *)input, length, output); }