簡體   English   中英

Android上的Mifare Ultralight C身份驗證

[英]Mifare Ultralight C Authentication on Android

我有一些Mifare Ultralight C標簽用於測試身份驗證。

第一次使用NXP TagInfo應用程序閱讀時,我可以看到以下信息:

(...)
Page 04 - Page 27: FULL OF 0s **(empty tag)**
Page 28: 00 00 -- --
Page 29: 00 00 -- --
Page 2A: 30 -- -- --
Page 2B: 00 -- -- --
Page 2C: 42 52 45 41
PAGE 2D: 4B 4D 45 49
PAGE 2E: 46 59 4F 55
PAGE 2F: 43 41 4E 21

頁面2C-2F表示它具有默認鍵“ BREAKMEIFYOUCAN!”。 425245414b4d454946594f5543414e21 )。

然后,我運行了我的Android應用,該應用基本上是這樣做的:

  1. 從第2C​​頁到第2F頁寫49454D4B41455242214E4143554F5946 (用於身份驗證)。

  2. 在第2A頁上寫入0x04(42); 表示來自2A的所有頁面都需要認證。

  3. 在第2B頁上寫入0x00(43); 這意味着讀和寫都需要身份驗證。

//Start authenticating
byte[] result1 = mifare.transceive(new byte[] {
                (byte)0xA2,  /* CMD = WRITE */
                (byte)0x2C,  /* PAGE = 44    */
                (byte)0x49, (byte)0x45, (byte)0x4D, (byte)0x4B  /* 49 45 4D 4B */
        });

byte[] result2 = mifare.transceive(new byte[] {
                (byte)0xA2,  /* CMD = WRITE */
                (byte)0x2D,  /* PAGE = 45    */
                (byte)0x41, (byte)0x45, (byte)0x52, (byte)0x42  /* 41 45 52 42 */
        });

byte[] result3 = mifare.transceive(new byte[] {
                (byte)0xA2,  /* CMD = WRITE */
                (byte)0x2E,  /* PAGE = 46    */
                (byte)0x21, (byte)0x4E, (byte)0X41, (byte)0X43  /* 21 4E 41 43 */
        });

byte[] result4 = mifare.transceive(new byte[] {
                (byte)0xA2,  /* CMD = WRITE */
                (byte)0x2F,  /* PAGE = 47    */
                (byte)0X55, (byte)0X4F, (byte)0X59, (byte)0X46  /* 55 4F 59 46 */
        });
//Finish authenticating

//Say the pages the card needs authentication
byte[] result5 = mifare.transceive(new byte[] {
                (byte)0xA2,  /* CMD = WRITE */
                (byte)0x2A,  /* PAGE = 42    */
                (byte)0x04, (byte)0x00, (byte)0x00, (byte)0x00  /* Message = All pages after 04 needs authentication */
        });

byte[] result6 = mifare.transceive(new byte[] {
                (byte)0xA2,  /* CMD = WRITE */
                (byte)0x2B,  /* PAGE = 43    */
                (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00  /* Message = authentication is required both for reading and writing */
        });
//Finish "card activition"

完成此操作后,我使用NXP TagInfo應用再次讀取了標簽,並且按預期方式,我再也看不到標簽信息。 取而代之的是,它在所有字段(從04開始)上均顯示.p XX XX XX XX ,這表明它需要密碼才能讀取數據。

在那之后(這是我看不到我的錯誤的地方),我嘗試再次驗證標簽(通過寫入2C-2F頁),但是在驗證部分的開頭出現了此錯誤:

\n System.err:java.io.IOException:收發失敗\n System.err:位於android.nfc.TransceiveResult.getResponseOrThrow(TransceiveResult.java:52)\n         在android.nfc.tech.BasicTagTechnology.transceive(BasicTagTechnology.java:151)\n         在android.nfc.tech.MifareUltralight.transceive(MifareUltralight.java:215)**\n

我看不到我在做什么錯...

您做錯的是您實際上沒有實現MIFARE Ultralight C身份驗證。 在MIFARE Ultralight C標簽上,寫入頁面0x2C..0x2F完全按照命令的指示進行操作:它寫入該頁面,但執行任何身份驗證。

取而代之的是,MIFARE Ultralight C實現了一種三向相互質詢-響應身份驗證協議。 通過發送AUTHENTICATE命令來啟動此協議:

byte[] result1 = mifare.transceive(new byte[] {
            (byte)0xA1,  /* CMD = AUTHENTICATE */
            (byte)0x00
});

響應該命令,您將面臨一個挑戰,您需要使用身份驗證密鑰進行解密,操作,加密並發送回標簽,以證明您實際構成了身份驗證密鑰。 您可以在以下問答中找到一些實現MIFARE Ultralight C身份驗證的代碼: Android:使用NXP MiFare Ultralight C進行身份驗證

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM