@@ -42,9 +42,9 @@ is_latvian_eid(sc_pkcs15_card_t *p15card)
4242
4343static int sc_pkcs15emu_esteid2018_init (sc_pkcs15_card_t * p15card ) {
4444 sc_card_t * card = p15card -> card ;
45- u8 buff [11 ];
46- int r , i ;
47- size_t field_length = 0 , taglen ;
45+ u8 buff [11 ], * buf ;
46+ int r , i , cert_slot = 0 ;
47+ size_t field_length = 0 , taglen , buflen ;
4848 sc_path_t tmppath ;
4949
5050 /* Read documber number to be used as serial */
@@ -70,10 +70,42 @@ static int sc_pkcs15emu_esteid2018_init(sc_pkcs15_card_t *p15card) {
7070 p15card -> tokeninfo -> serial_number [taglen ] = '\0' ;
7171 p15card -> tokeninfo -> flags = SC_PKCS15_TOKEN_READONLY ;
7272
73+ if (is_latvian_eid (p15card )) {
74+ const u8 * ptr ;
75+ sc_pkcs15_object_t obj = {0 };
76+ sc_pkcs15_cert_info_t * cert_info = NULL ;
77+
78+ if (!p15card -> file_app ) {
79+ p15card -> file_app = sc_file_new ();
80+ }
81+ if (!p15card -> file_app ) {
82+ LOG_FUNC_RETURN (card -> ctx , SC_ERROR_OUT_OF_MEMORY );
83+ }
84+
85+ sc_format_path ("3F00adf1" , & p15card -> file_app -> path );
86+ sc_format_path ("3F00adf17005" , & tmppath );
87+ r = sc_pkcs15_read_file (p15card , & tmppath , & buf , & buflen , 0 );
88+ ptr = buf ;
89+ sc_pkcs15_decode_cdf_entry (p15card , & obj , & ptr , & buflen );
90+
91+ cert_info = (struct sc_pkcs15_cert_info * ) obj .data ;
92+ if (cert_info && cert_info -> path .len > 0 ) {
93+ cert_slot = cert_info -> path .value [cert_info -> path .len - 1 ] - 1 ;
94+ }
95+
96+ sc_pkcs15_free_cert_info (cert_info );
97+ sc_file_free (p15card -> file_app );
98+ p15card -> file_app = NULL ;
99+ free (buf );
100+ }
101+
73102 /* add certificates */
74103 for (i = 0 ; i < 2 ; i ++ ) {
75104 static const char * esteid_cert_names [2 ] = {"Isikutuvastus" , "Allkirjastamine" };
76- static const char * esteid_cert_paths [2 ] = {"3f00:adf1:3401" , "3f00:adf2:341f" };
105+ static const char * cert_paths [2 ][2 ] = {
106+ {"3f00:adf1:3401" , "3f00:adf2:341f" },
107+ {"3f00:adf1:3402" , "3f00:adf2:341e" }
108+ };
77109 static const u8 esteid_cert_ids [2 ] = {1 , 2 };
78110
79111 struct sc_pkcs15_cert_info cert_info = {
@@ -82,7 +114,7 @@ static int sc_pkcs15emu_esteid2018_init(sc_pkcs15_card_t *p15card) {
82114 struct sc_pkcs15_object cert_obj = {0 };
83115
84116 strlcpy (cert_obj .label , esteid_cert_names [i ], sizeof (cert_obj .label ));
85- sc_format_path (esteid_cert_paths [i ], & cert_info .path );
117+ sc_format_path (cert_paths [ cert_slot ] [i ], & cert_info .path );
86118 r = sc_pkcs15emu_add_x509_cert (p15card , & cert_obj , & cert_info );
87119 LOG_TEST_GOTO_ERR (card -> ctx , r , "Could not add cert oebjct" );
88120
0 commit comments