Sample TR-31 PIN KEY BREAKUP | ||
B0096P0TB00E00005450948FD298FE32E418C3F0574CEE4FE3388FDFD722863C43CC24414025440C807AF25ABB07AAF3 | ||
Header |
|
|
| Key Block Version | B |
| Key Block Length | 0096 |
| Key Usage | P0 |
| Algorithm | T |
| Mode of Use | B |
| Key Version Number | 00 |
| Exportability | E |
| Number of Optional Blocks | 00 |
| Reserved | 00 |
ENCRYPTED DATA |
| 5450948FD298FE32E418C3F0574CEE4FE3388FDFD722863C43CC24414025440C807AF25A |
MAC |
| BB07AAF3 |
B0080P0TE00E0000 81C6985A61E12F2502C9F07C78290DA6D4DFCC36EC09713ACC07EA56FFC59A36 0EDB20C54B582CCD
Host Length = 0096 but My program = 0080
Host MAC = 4 bytes but my program = 8 bytes
Appreciate your support on this
I'm implementing dynamic key exchange for (PIN key and an Mac key ) with TR-31 key block.
And I'm using a java application to perform this. I have noticed the KB length issue with receiving messages from the host. And the length of MAC too.
Code you wrote?
What is the issue? You just noticed a difference in some of the payload or is something not working?
Are you producing a key or receiving one?
But my program
Perhaps you need to check the specification of this Host and match *your* code to it?
B0080P0TE00E0000 81C6985A61E12F2502C9F07C78290DA6D4DFCC36EC09713ACC07EA56FFC59A36 0EDB20C54B582CCD
Host Length = 0096 but My program = 0080
Their key component is longer - why is that, what does their key exchange specification say about it?
Host MAC = 4 bytes but my program = 8 bytes
Appreciate your support on this
It is unclear what you need or why you are asking here; can I suggest you read all the available documentation for this 'Host' and consult with it's owner's or administrators first.
Then please ask a smart question here.
--
Mark
test3TDEAKeyBlockTypeB();
public static void test3TDEAKeyBlockTypeB() throws Exception {
Header header = new Header(KeyblockType._B_TDEA_KEY_DERIVATION_BINDING, KeyUsage._P0_PIN_ENCRYPTION,
Export.E_EXPORTABLE_UNDER_TRUSTED_KEY, Algorithm._T_TRIPLE_DES,
KeyUseFor.E_ENCRYPT_ONLY, "00");
TR31KeyBlock kb = new TR31KeyBlock(header);
kb.setClearKey(Bytes.parseHex("F039121BEC83D26B169BDCD5B22AAF8FF039121BEC83D26B"));
kb.setKBPK("260892192061C8760BDF235E1619B057B334FED0EFA74F32");// triple length
kb.generate();
System.out.println(kb.toString());
}
Output as below
6C8AC1B7AE4E546239F16C051841F058E6AABBE85AF7FE1A5F918B3567C2343AB6ACC3F41B02C9654C2B73665A96D327
KBPK 260892192061C876 0BDF235E1619B057 B334FED0EFA74F32
KBPK[K1_CMAC]=92FF93B268C67876, KBPK[K2_CMAK]=25FF2764D18CF0F7
KBEK[kbek1]=C663C8FBDC5E1061 KBEK[kbek2]=12F7A014BDFC561D
KBEK[kbek3]=913C9F522283ADE6
KBEK=C663C8FBDC5E1061 12F7A014BDFC561D 913C9F522283ADE6
KBMK[kbmk1]=E157450719CC9B51 KBMK[kbmk2]=72C77B811B76DD0C
KBMK[kbmk2]=E95657F280A17E98
KBMK=E157450719CC9B51 72C77B811B76DD0C E95657F280A17E98
KBMK[KM1_CMAC]=99DD2D20F25D2ADD KBMK[KM2_CMAC]=33BA5A41E4BA55A1
KBMK MAC Key=99DD2D20F25D2ADD 33BA5A41E4BA55A1 99DD2D20F25D2ADD
ClearKey=F039121BEC83D26B169BDCD5B22AAF8FF039121BEC83D26B
Length Encoded ClearKey=00C0F039121BEC83D26B169BDCD5B22AAF8FF039121BEC83D26B
LengthEncode Padded Clear Key=00C0F039121BEC83D26B169BDCD5B22AAF8FF039121BEC83D26B000000000000
Encrypted Key=3A9EA40DC754C375E9418ABDEC39882F8B52E96352EB1CF66AEF61567F165850
Mac :4C2B73665A96D327
Header + encrypted key + mac
B0080P0TE00E0000 3A9EA40DC754C375E9418ABDEC39882F8B52E96352EB1CF66AEF61567F165850 4C2B73665A96D327
================================================================================================================
And above table content shared by the host vendor (no more any documents from the host vendor.
I have below 2 issues
Further I have used BP tool with triple DES same keys, I have got the 0096 Key block but again MAC value is 8 bytes.
Thanks
--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/50ea1415-f6c2-4262-92ba-6198d54f3151n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/CAKV%2BfV0j-fMDjmxHzZoJpR1xjiRwFZws8udX8j-o0w-4ce-pxQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/cb42d51d-3e7e-45cf-b51e-319e1e152a2an%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/cb42d51d-3e7e-45cf-b51e-319e1e152a2an%40googlegroups.com.
You received this message because you are subscribed to a topic in the Google Groups "jPOS Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jpos-users/fJGCmEdRSUo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jpos-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/cb42d51d-3e7e-45cf-b51e-319e1e152a2an%40googlegroups.com.
A temporary hack for it to work for you (Using KBPK - > 24 bytes and clear key 24 bytes) is to change
https://github.com/chhil/TR31Keyblock/blob/main/src/main/java/org/keyblock/tr31/Header.java#L119
In there add another 16. (Its specific to your current use case, it will break other combinations)
blocklength = 16 + optionalblocks + 48 + 16 +16;// #header, optional blocks,key len in ascii, mac
[2023-04-19 05:11:27 PM]
TR-31 Key Block: Key block decode operation finished
****************************************
KBPK: F039121BEC83D26B169BDCD5B22AAF8FF039121BEC83D26B
TR-31 Key block: B0096P0TB00E0000362D6B7B5D73969D3560CB6EE142206A34C9A0D5736619868843D35054F36B11C1BFFAA30E1EFB5D
----------------------------------------
TR-31 Header: B0096P0TB00E0000
----------------------------------------
Version Id: B - TDEA Key Derivation Binding Method
Block Length: 0096
Key Usage: P0 - PIN Encryption Key
Algorithm: T - Triple DES
Mode of Use: B - Both Encrypt & Decrypt / Wrap & Unwrap
Key Version No.: 00
Exportability: E - Exportable u. a KEK (meeting req. of X9.24 Pt. 1 or 2)
Num. of Opt. blocks: 00
Reserved: 00
Optional Blocks:
TR-31 Encrypted key: 362D6B7B5D73969D3560CB6EE142206A34C9A0D5736619868843D35054F36B11
TR-31 MAC: C1BFFAA30E1EFB5D
----------------------------------------
Plain Key: 260892192061C8760BDF235E1619B057B334FED0EFA74F32
Java test
Header header = new Header(KeyblockType._B_TDEA_KEY_DERIVATION_BINDING, KeyUsage._P0_PIN_ENCRYPTION,
Export.E_EXPORTABLE_UNDER_TRUSTED_KEY, Algorithm._T_TRIPLE_DES,
KeyUseFor.B_BOTH_ENCRYPT_AND_DECRYPT, "00");
TR31KeyBlock kb = new TR31KeyBlock(header);
kb.setClearKey(Bytes.parseHex("260892192061C8760BDF235E1619B057B334FED0EFA74F32"));
kb.setKBPK("F039121BEC83D26B169BDCD5B22AAF8FF039121BEC83D26B");
kb.generate();
System.out.println(kb);
You can see the plain key matching in EFT Sim and the TR31 code.
-chhil
Header + encrypted key + mac
B0080P0TE00E0000 3A9EA40DC754C375E9418ABDEC39882F8B52E96352EB1CF66AEF61567F165850 4C2B73665A96D327
Do you see what's wrong here ? the Header length + encrypted key length already 80, not counting any bytes of MAC. if you add 8 bytes MAC (16 hex), it must be 96, not 80.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/d6b9103d-fd06-4144-a924-c3c71b022279n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/CAKV%2BfV3bT21GD7kqj6gXSUYL8JHZvRNoXaOFD%2BwcmBEP%3D_kB3Q%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/CAPazefDt0Dfq3NHB1YGRUJM8OUsK%2BneCLAcZ%3DwyiwF6N8GiNDg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/CAKV%2BfV3bT21GD7kqj6gXSUYL8JHZvRNoXaOFD%2BwcmBEP%3D_kB3Q%40mail.gmail.com.
public static void decryptAndValidate() throws Exception {
TR31KeyBlock kb = new TR31KeyBlock();
String keyBlock = "B0096M1TC00E0000339021DE38A48262A8A78EE5B8F938A3E7321C940CCF1E6676DEB20CB4331C713AED12CA92F43F05";
String kbpkString = "260892192061C8760BDF235E1619B057B334FED0EFA74F32";
if (kb.decryptAndValidateEncryptedKeyblock(keyBlock, kbpkString)) {
System.out.println("VALID");
}
else {
System.out.println("INVALID");
}
}
OutPut
>>>>>>>>> MAC _B_TDEA_KEY_DERIVATION_BINDING
INVALID
Let me know how to extract clear key from KB?
thanks
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/MzBBYidx0lLka0-1U7PfrhhIgzX0tWgDzgvw8DLFh11hT9gLVr_ua4EzIj-hOVAAKLozsIRNX7UvciB7aFhhPcxg6rsGjzX12k_67zge-ok%3D%40pm.me.
You can try the following. Currently, if the mac mismatches, an exception is thrown (you can change the 5 at the end of the string in your keyblock to anything else and try it)
TR31KeyBlock kb = new TR31KeyBlock();
String keyBlock = "B0096M1TC00E0000339021DE38A48262A8A78EE5B8F938A3E7321C940CCF1E6676DEB20CB4331C713AED12CA92F43F05";
String kbpkString = "260892192061C8760BDF235E1619B057B334FED0EFA74F32";
kb.decryptKeyBlock(keyBlock, kbpkString);
System.out.println("C L E A R K E Y = " +kb.getClearKey().encodeHex(true));
System.out.println(kb);
-chhil
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/CAKV%2BfV2sTRBO-wsGLAidfPdAkb0NBcsmBf342uQZ2zytmBjifA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/CAPazefD81yryAuqnZq2q5phSBTJtb1XChVHSpzO4BDCOwat7-w%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/CAPazefDje73sUQYPn%3Dk-_0kgAhJ_2u-WC9Y2FPwDWyRGe60PBA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/CAKV%2BfV37L1hbE%3DN%3DwU-9T6dMN5uKtOqe5z7Q90DbyMZDK0WLrA%40mail.gmail.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/CAPazefDoAnF1gvN485kMjj0hgUf0dy1TP7qRtrGx%2BqSr5sERqw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/CAKV%2BfV0Hvgy9%2BbYmV7hHuwxchLSzM7-f11KQoY%2Bj1AQN2V4u6w%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/CAPazefCygN9j4sjCVdJ6rgU3Mp%2BH7GPvRJ72j5rC88YOWxSBVg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/CAKV%2BfV3DBNH3i_gdJt9S3JN9z5bpQQQZNdaxeLANkJwAMcy6fw%40mail.gmail.com.
|
'3': ISO 9797 MAC algorithm 3 (= ANSI X9.19 when used with a double-length key) (DES only) |
|
'2': ISO 9797 Padding method 2 |
RSM5
M6
0 : Only block of a single-block message
0 : Binary
1 : MAC size of 16 hex digits
1 : ISO 9797 MAC algorithm 1 (= ANSI X9.9 when used with a single-length key) (DES only)
1 : ISO 9797 Padding method 1
FFF : Ignored keytype
S00088M1TC00E000286B7CC40320693D98B22A116802E3D8F461B89FE165E92825270C580F85CCE8082C9225100583030303030303031303030303231363831303338383734353137313558595A414243313134343030383839??
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/CAKV%2BfV37L1hbE%3DN%3DwU-9T6dMN5uKtOqe5z7Q90DbyMZDK0WLrA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/Km96LM7R-slCe8HeNgjdee-hvaIjKsIZzZAyEsON59mQkosSp00Gvrd7ME3-H7AzldxbP25k501oSbvENNSW0VlwNyiRVwKqQUWz7HZMOao%3D%40pm.me.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/CAKV%2BfV2gMwfuWPgaVmtfabe9dv%3D-GY221Ft%3DccX4Og8%2B7dVcFA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/CAPazefA24oOjE4gwgzADGE6Lt-AEmdh6yWcEhmUfPfjrditaOA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/CAKV%2BfV1DxSBj_UY%3DsZmizXX8UAXE4MfPnFAd59qt-MjRMStztA%40mail.gmail.com.

--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/nqrPrrWyrhlgOKZ8VJBGUADmQPp_1ZULQX7TW2SFpcQgvZ7U9WQuK962RQnWUL8n9Y8FKGarlGfp-mjXz4EZ6TE9Io6eNw56PH-KIYUuzRw%3D%40pm.me.
--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
---
You received this message because you are subscribed to a topic in the Google Groups "jPOS Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jpos-users/fJGCmEdRSUo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jpos-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/nqrPrrWyrhlgOKZ8VJBGUADmQPp_1ZULQX7TW2SFpcQgvZ7U9WQuK962RQnWUL8n9Y8FKGarlGfp-mjXz4EZ6TE9Io6eNw56PH-KIYUuzRw%3D%40pm.me.
You received this message because you are subscribed to a topic in the Google Groups "jPOS Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jpos-users/fJGCmEdRSUo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jpos-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/CAKV%2BfV1L3GUP8LSQAqqS2iJXQM_DX_urFL1fDDWTq0%3DF5dy-XQ%40mail.gmail.com.
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/CAPazefDOsmLmfbek5T93AhWxr60M7vD23b%2B6QuPHj5VE8TAzMw%40mail.gmail.com.
public static void main(String[] args) throws
NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException,
BadPaddingException, InvalidAlgorithmParameterException {
//Data padded with 0's at the end to make it a multiple of 8
String hexData = "33303330333033303330333033303331333033303330333033323331333633383331333033333338333833373334333533313337333133353538353935413431343234333331333133343334333033303338333833390000";
String key = "85323286bc3d2910c12a49bfdad9ad85b67c62237301518a";
Key k = new SecretKeySpec(ISOUtil.hex2byte(key), "DESede");
Cipher c = Cipher.getInstance("DESede/CBC/NoPadding");
AlgorithmParameterSpec aps = new IvParameterSpec(new byte[8]);
c.init(Cipher.ENCRYPT_MODE, k, aps);
byte[] out = c.doFinal(ISOUtil.hex2byte(hexData));
System.out.println(ISOUtil.hexdump(out));
}
Output
0000 CD 09 2D 77 0E E1 3B 0C E1 12 20 14 71 3A E5 A3 ..-w..;... .q:..
0010 FD A4 B9 AD 4C 67 35 E9 11 BF CB 36 F6 14 84 DD ....Lg5....6....
0020 9F 48 16 AE C1 32 5B E3 A3 F7 37 0E A0 27 BE 73 .H...2[...7..'.s
0030 81 C6 CE DF 8B 6E 5F 76 AC 68 72 90 47 02 CF B7 .....n_v.hr.G...
0040 84 C2 F6 44 6E 8F 3D 80 4B 39 60 08 17 03 8E 81 ...Dn.=.K9`.....
0050 55 C5 31 69 BE F1 6C BB U.1i..l. <--- MAC

To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/DMxLjXZXzSp_wBsxNRdJTewTeW4dFoWXiFLkTL4s4sXG5YmN3cu8cAVNrfeWbQwqFknb_yBBa5Vjj255vIQGRFdjwmhUQOrdhVEDFQ82Ny4%3D%40pm.me.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/DMxLjXZXzSp_wBsxNRdJTewTeW4dFoWXiFLkTL4s4sXG5YmN3cu8cAVNrfeWbQwqFknb_yBBa5Vjj255vIQGRFdjwmhUQOrdhVEDFQ82Ny4%3D%40pm.me.
Mac data = 3030303030303031303030303231363831303338383734353137313558595A414243313134343030383839
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/CAKV%2BfV1wrcXB7mBMBsgrE1ew6%3DY1A9e7O7pS1ZDtEWcoVVr1FA%40mail.gmail.com.