Coverage Report

Created: 2026-01-09 06:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/opensc/src/libopensc/pkcs15-esinit.c
Line
Count
Source
1
/*
2
 * This library is free software; you can redistribute it and/or
3
 * modify it under the terms of the GNU Lesser General Public
4
 * License as published by the Free Software Foundation; either
5
 * version 2.1 of the License, or (at your option) any later version.
6
 *
7
 * This library is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10
 * Lesser General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU Lesser General Public
13
 * License along with this library; if not, write to the Free Software
14
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
 */
16
/* Initially written by Weitao Sun (weitao@ftsafe.com) 2008*/
17
18
#ifdef HAVE_CONFIG_H
19
#include "config.h"
20
#endif
21
22
#include <stdlib.h>
23
#include <string.h>
24
#include <stdio.h>
25
26
#include "internal.h"
27
#include "pkcs15.h"
28
#include "cardctl.h"
29
30
3
#define MANU_ID   "entersafe"
31
32
static int entersafe_detect_card( sc_pkcs15_card_t *p15card)
33
10.8k
{
34
10.8k
  sc_card_t *card = p15card->card;
35
36
10.8k
  SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
37
38
  /* check if we have the correct card OS */
39
10.8k
  if (strcmp(card->name, "entersafe"))
40
10.6k
    return SC_ERROR_WRONG_CARD;
41
42
156
    return SC_SUCCESS;
43
10.8k
}
44
45
static int sc_pkcs15emu_entersafe_init( sc_pkcs15_card_t *p15card)
46
156
{
47
156
  int    r;
48
156
  char   buf[256];
49
156
  sc_card_t *card = p15card->card;
50
156
  sc_serial_number_t serial;
51
52
156
  SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
53
54
  /* get serial number */
55
156
  r = sc_card_ctl(card, SC_CARDCTL_GET_SERIALNR, &serial);
56
156
  if (r != SC_SUCCESS)
57
153
    return SC_ERROR_INTERNAL;
58
3
  r = sc_bin_to_hex(serial.value, serial.len, buf, sizeof(buf), 0);
59
3
  if (r != SC_SUCCESS)
60
0
    return SC_ERROR_INTERNAL;
61
62
3
  set_string(&p15card->tokeninfo->serial_number, buf);
63
3
  if (!p15card->tokeninfo->serial_number)
64
0
    return SC_ERROR_INTERNAL;
65
66
  /* the manufacturer ID, in this case Giesecke & Devrient GmbH */
67
3
  set_string(&p15card->tokeninfo->manufacturer_id, MANU_ID);
68
3
  if (!p15card->tokeninfo->manufacturer_id) {
69
0
    free(p15card->tokeninfo->serial_number);
70
0
    p15card->tokeninfo->serial_number = NULL;
71
0
    return SC_ERROR_INTERNAL;
72
0
  }
73
74
3
  return SC_SUCCESS;
75
3
}
76
77
int sc_pkcs15emu_entersafe_init_ex(sc_pkcs15_card_t *p15card,
78
           struct sc_aid *aid)
79
10.8k
{
80
10.8k
  SC_FUNC_CALLED(p15card->card->ctx, SC_LOG_DEBUG_VERBOSE);
81
82
10.8k
  if (entersafe_detect_card(p15card))
83
10.6k
    return SC_ERROR_WRONG_CARD;
84
156
  return sc_pkcs15emu_entersafe_init(p15card);
85
10.8k
}