Просмотр исходного кода

Show same UI, but start string based on ASN1

Eric Betts 9 месяцев назад
Родитель
Сommit
f945906976
8 измененных файлов с 55 добавлено и 53 удалено
  1. 1 1
      eMRTD.asn1
  2. 3 3
      lib/asn1/DG1.c
  3. 1 1
      lib/asn1/DG1.h
  4. 13 0
      passy_common.c
  5. 1 0
      passy_common.h
  6. 0 43
      passy_reader.c
  7. 0 3
      passy_reader.h
  8. 36 2
      scenes/passy_scene_read_success.c

+ 1 - 1
eMRTD.asn1

@@ -4,7 +4,7 @@ BEGIN
 MRZ ::= VisibleString
 
 DG1 ::= [APPLICATION 1] IMPLICIT SEQUENCE {
-  mdz [APPLICATION 31] IMPLICIT MRZ
+  mrz [APPLICATION 31] IMPLICIT MRZ
 }
 
 END

+ 3 - 3
lib/asn1/DG1.c

@@ -8,14 +8,14 @@
 #include "DG1.h"
 
 static asn_TYPE_member_t asn_MBR_DG1_1[] = {
-	{ ATF_NOFLAGS, 0, offsetof(struct DG1, mdz),
+	{ ATF_NOFLAGS, 0, offsetof(struct DG1, mrz),
 		(ASN_TAG_CLASS_APPLICATION | (31 << 2)),
 		-1,	/* IMPLICIT tag at current level */
 		&asn_DEF_MRZ,
 		0,
 		{ 0, 0, 0 },
 		0, 0, /* No default value */
-		"mdz"
+		"mrz"
 		},
 };
 static const ber_tlv_tag_t asn_DEF_DG1_tags_1[] = {
@@ -23,7 +23,7 @@ static const ber_tlv_tag_t asn_DEF_DG1_tags_1[] = {
 	(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
 };
 static const asn_TYPE_tag2member_t asn_MAP_DG1_tag2el_1[] = {
-    { (ASN_TAG_CLASS_APPLICATION | (31 << 2)), 0, 0, 0 } /* mdz */
+    { (ASN_TAG_CLASS_APPLICATION | (31 << 2)), 0, 0, 0 } /* mrz */
 };
 static asn_SEQUENCE_specifics_t asn_SPC_DG1_specs_1 = {
 	sizeof(struct DG1),

+ 1 - 1
lib/asn1/DG1.h

@@ -21,7 +21,7 @@ extern "C" {
 
 /* DG1 */
 typedef struct DG1 {
-	MRZ_t	 mdz;
+	MRZ_t	 mrz;
 	
 	/* Context for parsing across buffer boundaries */
 	asn_struct_ctx_t _asn_ctx;

+ 13 - 0
passy_common.c

@@ -4,6 +4,19 @@
 
 #define TAG "PassyCommon"
 
+static char asn1_log[PASSY_WORKER_MAX_BUFFER_SIZE];
+int print_struct_callback(const void* buffer, size_t size, void* app_key) {
+    if(app_key) {
+        char* str = (char*)app_key;
+        size_t next = strlen(str);
+        strncpy(str + next, buffer, size);
+    } else {
+        uint8_t next = strlen(asn1_log);
+        strncpy(asn1_log + next, buffer, size);
+    }
+    return 0;
+}
+
 void passy_log_bitbuffer(char* tag, char* prefix, BitBuffer* buffer) {
     furi_assert(buffer);
 

+ 1 - 0
passy_common.h

@@ -14,3 +14,4 @@ void passy_log_bitbuffer(char* tag, char* prefix, BitBuffer* buffer);
 void passy_log_buffer(char* tag, char* prefix, uint8_t* buffer, size_t buffer_len);
 void passy_mac(uint8_t* key, uint8_t* data, size_t data_length, uint8_t* mac, bool prepadded);
 char passy_checksum(char* str);
+int print_struct_callback(const void* buffer, size_t size, void* app_key);

+ 0 - 43
passy_reader.c

@@ -26,19 +26,6 @@ size_t asn1_length(uint8_t data[3]) {
     return 0;
 }
 
-char asn1_log[PASSY_READER_MAX_BUFFER_SIZE];
-static int print_struct_callback(const void* buffer, size_t size, void* app_key) {
-    if(app_key) {
-        char* str = (char*)app_key;
-        size_t next = strlen(str);
-        strncpy(str + next, buffer, size);
-    } else {
-        uint8_t next = strlen(asn1_log);
-        strncpy(asn1_log + next, buffer, size);
-    }
-    return 0;
-}
-
 PassyReader* passy_reader_alloc(Passy* passy, Iso14443_4bPoller* iso14443_4b_poller) {
     PassyReader* passy_reader = malloc(sizeof(PassyReader));
     memset(passy_reader, 0, sizeof(PassyReader));
@@ -413,36 +400,6 @@ NfcCommand passy_reader_state_machine(Passy* passy, PassyReader* passy_reader) {
             } while(body_offset < body_size);
             passy_log_bitbuffer(TAG, "DG1", passy_reader->DG1);
 
-            DG1_t* dg1 = 0;
-            dg1 = calloc(1, sizeof *dg1);
-            assert(dg1);
-            asn_dec_rval_t rval = asn_decode(
-                0,
-                ATS_DER,
-                &asn_DEF_DG1,
-                (void**)&dg1,
-                bit_buffer_get_data(passy_reader->DG1),
-                bit_buffer_get_size_bytes(passy_reader->DG1));
-
-            if(rval.code == RC_OK) {
-                FURI_LOG_I(TAG, "ASN.1 decode success");
-
-                char payloadDebug[384] = {0};
-                memset(payloadDebug, 0, sizeof(payloadDebug));
-                (&asn_DEF_DG1)
-                    ->op->print_struct(&asn_DEF_DG1, dg1, 1, print_struct_callback, payloadDebug);
-                if(strlen(payloadDebug) > 0) {
-                    FURI_LOG_D(TAG, "DG1: %s", payloadDebug);
-                } else {
-                    FURI_LOG_D(TAG, "Received empty Payload");
-                }
-            } else {
-                FURI_LOG_E(TAG, "ASN.1 decode failed: %d.  %d consumed", rval.code, rval.consumed);
-            }
-
-            free(dg1);
-            dg1 = 0;
-
         } else if(passy->read_type == PassyReadDG2) {
             ret = passy_reader_select_file(passy_reader, 0x0102);
             if(ret != NfcCommandContinue) {

+ 0 - 3
passy_reader.h

@@ -8,9 +8,6 @@
 #include <lib/toolbox/stream/stream.h>
 #include <lib/toolbox/stream/file_stream.h>
 
-#define ASN_EMIT_DEBUG 0
-#include <lib/asn1/DG1.h>
-
 #include "passy_i.h"
 #include "passy_common.h"
 #include "secure_messaging.h"

+ 36 - 2
scenes/passy_scene_read_success.c

@@ -1,6 +1,9 @@
 #include "../passy_i.h"
 #include <dolphin/dolphin.h>
 
+#define ASN_EMIT_DEBUG 0
+#include <lib/asn1/DG1.h>
+
 #define TAG "PassySceneReadCardSuccess"
 
 void passy_scene_read_success_on_enter(void* context) {
@@ -12,8 +15,39 @@ void passy_scene_read_success_on_enter(void* context) {
     furi_string_reset(passy->text_box_store);
     FuriString* str = passy->text_box_store;
     if(passy->read_type == PassyReadDG1) {
-        // +5 is derived epirically, but really should be from parsing the ASN.1
-        furi_string_cat_printf(str, "%s\n", bit_buffer_get_data(passy->DG1) + 5);
+        DG1_t* dg1 = 0;
+        dg1 = calloc(1, sizeof *dg1);
+        assert(dg1);
+        asn_dec_rval_t rval = asn_decode(
+            0,
+            ATS_DER,
+            &asn_DEF_DG1,
+            (void**)&dg1,
+            bit_buffer_get_data(passy->DG1),
+            bit_buffer_get_size_bytes(passy->DG1));
+
+        if(rval.code == RC_OK) {
+            FURI_LOG_I(TAG, "ASN.1 decode success");
+
+            char payloadDebug[384] = {0};
+            memset(payloadDebug, 0, sizeof(payloadDebug));
+            (&asn_DEF_DG1)
+                ->op->print_struct(&asn_DEF_DG1, dg1, 1, print_struct_callback, payloadDebug);
+            if(strlen(payloadDebug) > 0) {
+                FURI_LOG_D(TAG, "DG1: %s", payloadDebug);
+            } else {
+                FURI_LOG_D(TAG, "Received empty Payload");
+            }
+
+            furi_string_cat_printf(str, "%s\n", dg1->mrz.buf);
+        } else {
+            FURI_LOG_E(TAG, "ASN.1 decode failed: %d.  %d consumed", rval.code, rval.consumed);
+            furi_string_cat_printf(str, "%s\n", bit_buffer_get_data(passy->DG1));
+        }
+
+        free(dg1);
+        dg1 = 0;
+
     } else if(passy->read_type == PassyReadDG2) {
         furi_string_cat_printf(str, "Saved to disk");
     }