@@ -43,8 +43,8 @@ is_latvian_eid(sc_pkcs15_card_t *p15card)
4343static int sc_pkcs15emu_esteid2018_init (sc_pkcs15_card_t * p15card ) {
4444 sc_card_t * card = p15card -> card ;
4545 u8 buff [11 ];
46- int r , i ;
47- size_t field_length = 0 , taglen ;
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,45 @@ 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+ u8 * buf ;
75+ const u8 * ptr ;
76+ sc_pkcs15_object_t obj = {0 };
77+ sc_pkcs15_cert_info_t * cert_info = NULL ;
78+
79+ if (!p15card -> file_app ) {
80+ p15card -> file_app = sc_file_new ();
81+ }
82+ if (!p15card -> file_app ) {
83+ LOG_FUNC_RETURN (card -> ctx , SC_ERROR_OUT_OF_MEMORY );
84+ }
85+
86+ sc_format_path ("3F00adf1" , & p15card -> file_app -> path );
87+ sc_format_path ("3F00adf17005" , & tmppath );
88+ r = sc_pkcs15_read_file (p15card , & tmppath , & buf , & buflen , 0 );
89+ LOG_TEST_GOTO_ERR (card -> ctx , r , "Reading EF.CDF file failed" );
90+ ptr = buf ;
91+ r = sc_pkcs15_decode_cdf_entry (p15card , & obj , & ptr , & buflen );
92+ LOG_TEST_GOTO_ERR (card -> ctx , r , "Decoding EF.CDF file failed" );
93+
94+ cert_info = (struct sc_pkcs15_cert_info * )obj .data ;
95+ if (cert_info && cert_info -> path .len > 0 ) {
96+ cert_slot = cert_info -> path .value [cert_info -> path .len - 1 ] - 1 ;
97+ }
98+
99+ sc_pkcs15_free_cert_info (cert_info );
100+ sc_file_free (p15card -> file_app );
101+ p15card -> file_app = NULL ;
102+ free (buf );
103+ }
104+
73105 /* add certificates */
74106 for (i = 0 ; i < 2 ; i ++ ) {
75107 static const char * esteid_cert_names [2 ] = {"Isikutuvastus" , "Allkirjastamine" };
76- static const char * esteid_cert_paths [2 ] = {"3f00:adf1:3401" , "3f00:adf2:341f" };
108+ static const char * cert_paths [2 ][2 ] = {
109+ {"3f00:adf1:3401" , "3f00:adf2:341f" },
110+ {"3f00:adf1:3402" , "3f00:adf2:341e" }
111+ };
77112 static const u8 esteid_cert_ids [2 ] = {1 , 2 };
78113
79114 struct sc_pkcs15_cert_info cert_info = {
@@ -82,7 +117,7 @@ static int sc_pkcs15emu_esteid2018_init(sc_pkcs15_card_t *p15card) {
82117 struct sc_pkcs15_object cert_obj = {0 };
83118
84119 strlcpy (cert_obj .label , esteid_cert_names [i ], sizeof (cert_obj .label ));
85- sc_format_path (esteid_cert_paths [i ], & cert_info .path );
120+ sc_format_path (cert_paths [ cert_slot ] [i ], & cert_info .path );
86121 r = sc_pkcs15emu_add_x509_cert (p15card , & cert_obj , & cert_info );
87122 LOG_TEST_GOTO_ERR (card -> ctx , r , "Could not add cert oebjct" );
88123
0 commit comments