2019-02-25 09:28:22 +01:00
|
|
|
/* gpg-card.h - Common definitions for the gpg-card-tool
|
2020-02-11 14:58:17 +01:00
|
|
|
* Copyright (C) 2019, 2020 g10 Code GmbH
|
2019-01-27 20:12:00 +01:00
|
|
|
*
|
|
|
|
* This file is part of GnuPG.
|
|
|
|
*
|
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, see <https://gnu.org/licenses/>.
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*/
|
|
|
|
|
2019-02-25 09:28:22 +01:00
|
|
|
#ifndef GNUPG_GPG_CARD_H
|
|
|
|
#define GNUPG_GPG_CARD_H
|
2019-01-27 20:12:00 +01:00
|
|
|
|
|
|
|
#include "../common/session-env.h"
|
2020-09-08 08:34:42 +02:00
|
|
|
#include "../common/strlist.h"
|
2019-01-27 20:12:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* We keep all global options in the structure OPT. */
|
2020-02-10 16:37:34 +01:00
|
|
|
EXTERN_UNLESS_MAIN_MODULE
|
2019-01-27 20:12:00 +01:00
|
|
|
struct
|
|
|
|
{
|
2019-01-31 18:57:16 +01:00
|
|
|
int interactive;
|
2019-01-27 20:12:00 +01:00
|
|
|
int verbose;
|
|
|
|
unsigned int debug;
|
|
|
|
int quiet;
|
|
|
|
int with_colons;
|
2024-05-16 09:33:24 +02:00
|
|
|
const char *gpg_program;
|
|
|
|
const char *gpgsm_program;
|
|
|
|
const char *agent_program;
|
2019-01-27 20:12:00 +01:00
|
|
|
int autostart;
|
|
|
|
|
2020-02-12 11:16:41 +01:00
|
|
|
int no_key_lookup; /* Assume --no-key-lookup for "list". */
|
|
|
|
|
2020-07-02 15:47:57 +02:00
|
|
|
int no_history; /* Do not use the command line history. */
|
|
|
|
|
2019-01-27 20:12:00 +01:00
|
|
|
/* Options passed to the gpg-agent: */
|
|
|
|
session_env_t session_env;
|
|
|
|
char *lc_ctype;
|
|
|
|
char *lc_messages;
|
|
|
|
|
|
|
|
} opt;
|
|
|
|
|
|
|
|
/* Debug values and macros. */
|
|
|
|
#define DBG_IPC_VALUE 1024 /* Debug assuan communication. */
|
|
|
|
#define DBG_EXTPROG_VALUE 16384 /* Debug external program calls */
|
|
|
|
|
|
|
|
#define DBG_IPC (opt.debug & DBG_IPC_VALUE)
|
|
|
|
#define DBG_EXTPROG (opt.debug & DBG_EXTPROG_VALUE)
|
|
|
|
|
2019-01-30 15:01:34 +01:00
|
|
|
/* The maximum length of a binary fingerprint. */
|
|
|
|
#define MAX_FINGERPRINT_LEN 32
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Data structures to store keyblocks (aka certificates).
|
|
|
|
*/
|
|
|
|
struct pubkey_s
|
|
|
|
{
|
|
|
|
struct pubkey_s *next; /* The next key. */
|
|
|
|
unsigned char grip[KEYGRIP_LEN];
|
|
|
|
unsigned char fpr[MAX_FINGERPRINT_LEN];
|
|
|
|
unsigned char fprlen; /* The used length of a FPR. */
|
2020-02-12 12:50:38 +01:00
|
|
|
time_t created; /* The creation date of the key. */
|
2019-01-30 15:01:34 +01:00
|
|
|
unsigned int grip_valid:1;/* The grip is valid. */
|
|
|
|
unsigned int requested: 1;/* This is the requested grip. */
|
|
|
|
};
|
|
|
|
typedef struct pubkey_s *pubkey_t;
|
|
|
|
|
|
|
|
struct userid_s
|
|
|
|
{
|
|
|
|
struct userid_s *next;
|
|
|
|
char *value; /* Malloced. */
|
|
|
|
};
|
|
|
|
typedef struct userid_s *userid_t;
|
|
|
|
|
|
|
|
struct keyblock_s
|
|
|
|
{
|
|
|
|
struct keyblock_s *next; /* Allow to link several keyblocks. */
|
|
|
|
int protocol; /* GPGME_PROTOCOL_OPENPGP or _CMS. */
|
|
|
|
pubkey_t keys; /* The key. For OpenPGP primary + list of subkeys. */
|
|
|
|
userid_t uids; /* The list of user ids. */
|
|
|
|
};
|
|
|
|
typedef struct keyblock_s *keyblock_t;
|
|
|
|
|
|
|
|
|
2019-01-27 20:12:00 +01:00
|
|
|
|
|
|
|
/* Enumeration of the known card application types. */
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
APP_TYPE_NONE, /* Not yet known or for direct APDU sending. */
|
|
|
|
APP_TYPE_OPENPGP,
|
|
|
|
APP_TYPE_NKS,
|
|
|
|
APP_TYPE_DINSIG,
|
|
|
|
APP_TYPE_P15,
|
|
|
|
APP_TYPE_GELDKARTE,
|
|
|
|
APP_TYPE_SC_HSM,
|
|
|
|
APP_TYPE_PIV,
|
|
|
|
APP_TYPE_UNKNOWN /* Unknown by this tool. */
|
|
|
|
} app_type_t;
|
|
|
|
|
|
|
|
|
2019-01-30 15:01:34 +01:00
|
|
|
/* An object to store information pertaining to a key pair as stored
|
|
|
|
* on a card. This is commonly used as a linked list with all keys
|
|
|
|
* known for the current card. */
|
2019-01-29 08:48:53 +01:00
|
|
|
struct key_info_s
|
|
|
|
{
|
|
|
|
struct key_info_s *next;
|
|
|
|
|
|
|
|
unsigned char grip[20];/* The keygrip. */
|
|
|
|
|
|
|
|
unsigned char xflag; /* Temporary flag to help processing a list. */
|
|
|
|
|
2020-02-10 14:12:36 +01:00
|
|
|
/* OpenPGP card and possible other cards keyalgo string (an atom)
|
|
|
|
* and the id of the algorithm. */
|
|
|
|
const char *keyalgo;
|
|
|
|
enum gcry_pk_algos keyalgo_id;
|
|
|
|
|
2021-03-30 17:28:45 +02:00
|
|
|
/* An optional malloced label for the key. */
|
|
|
|
char *label;
|
|
|
|
|
2019-01-29 08:48:53 +01:00
|
|
|
/* The three next items are mostly useful for OpenPGP cards. */
|
|
|
|
unsigned char fprlen; /* Use length of the next item. */
|
|
|
|
unsigned char fpr[32]; /* The binary fingerprint of length FPRLEN. */
|
|
|
|
u32 created; /* The time the key was created. */
|
2019-02-21 12:43:07 +01:00
|
|
|
unsigned int usage; /* Usage flags. (GCRY_PK_USAGE_*) */
|
2019-01-29 08:48:53 +01:00
|
|
|
char keyref[1]; /* String with the keyref (e.g. OPENPGP.1). */
|
|
|
|
};
|
|
|
|
typedef struct key_info_s *key_info_t;
|
|
|
|
|
2019-01-27 20:12:00 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The object used to store information about a card.
|
|
|
|
*/
|
|
|
|
struct card_info_s
|
|
|
|
{
|
2019-01-31 18:57:16 +01:00
|
|
|
int initialized; /* True if a learn command was successful. */
|
2020-05-27 11:27:32 +02:00
|
|
|
int need_sn_cmd; /* The SERIALNO command needs to be issued. */
|
2020-06-30 14:36:44 +02:00
|
|
|
int card_removed; /* Helper flag set by some listing functions. */
|
2019-01-27 20:12:00 +01:00
|
|
|
int error; /* private. */
|
|
|
|
char *reader; /* Reader information. */
|
2019-01-29 13:28:10 +01:00
|
|
|
char *cardtype; /* NULL or type of the card. */
|
2019-03-05 17:40:08 +01:00
|
|
|
unsigned int cardversion; /* Firmware version of the card. */
|
2019-01-27 20:12:00 +01:00
|
|
|
char *apptypestr; /* Malloced application type string. */
|
|
|
|
app_type_t apptype;/* Translated from APPTYPESTR. */
|
2019-03-05 17:40:08 +01:00
|
|
|
unsigned int appversion; /* Version of the application. */
|
2020-04-03 10:00:57 +02:00
|
|
|
unsigned int manufacturer_id;
|
|
|
|
char *manufacturer_name; /* malloced. */
|
2019-01-27 20:12:00 +01:00
|
|
|
char *serialno; /* malloced hex string. */
|
|
|
|
char *dispserialno;/* malloced string. */
|
|
|
|
char *disp_name; /* malloced. */
|
|
|
|
char *disp_lang; /* malloced. */
|
|
|
|
int disp_sex; /* 0 = unspecified, 1 = male, 2 = female */
|
|
|
|
char *pubkey_url; /* malloced. */
|
|
|
|
char *login_data; /* malloced. */
|
|
|
|
char *private_do[4]; /* malloced. */
|
|
|
|
char cafpr1len; /* Length of the CA-fingerprint or 0 if invalid. */
|
|
|
|
char cafpr2len;
|
|
|
|
char cafpr3len;
|
|
|
|
char cafpr1[20];
|
|
|
|
char cafpr2[20];
|
|
|
|
char cafpr3[20];
|
2019-01-29 08:48:53 +01:00
|
|
|
key_info_t kinfo; /* Linked list with all keypair related data. */
|
2019-01-27 20:12:00 +01:00
|
|
|
unsigned long sig_counter;
|
2019-01-29 09:30:15 +01:00
|
|
|
int chv1_cached; /* For openpgp this is true if a PIN is not
|
|
|
|
required for each signing. Note that the
|
|
|
|
gpg-agent might cache it anyway. */
|
|
|
|
int is_v2; /* True if this is a v2 openpgp card. */
|
2021-03-18 11:29:31 +01:00
|
|
|
byte nchvmaxlen; /* Number of valid items in CHVMAXLEN. */
|
2020-05-07 19:47:07 +02:00
|
|
|
int chvmaxlen[4]; /* Maximum allowed length of a CHV. */
|
2021-03-18 11:29:31 +01:00
|
|
|
byte nchvinfo; /* Number of valid items in CHVINFO. */
|
2020-05-07 19:47:07 +02:00
|
|
|
int chvinfo[4]; /* Allowed retries for the CHV; 0 = blocked. */
|
2021-03-18 11:29:31 +01:00
|
|
|
char *chvlabels; /* Malloced String with CHV labels. */
|
2019-01-29 13:28:10 +01:00
|
|
|
unsigned char chvusage[2]; /* Data object 5F2F */
|
2019-01-27 20:12:00 +01:00
|
|
|
struct {
|
|
|
|
unsigned int ki:1; /* Key import available. */
|
|
|
|
unsigned int aac:1; /* Algorithm attributes are changeable. */
|
|
|
|
unsigned int kdf:1; /* KDF object to support PIN hashing available. */
|
2020-05-26 16:16:24 +02:00
|
|
|
unsigned int bt:1; /* Button for confirmation available. */
|
|
|
|
unsigned int sm:1; /* Secure messaging available. */
|
|
|
|
unsigned int smalgo:15;/* Secure messaging cipher algorithm. */
|
|
|
|
unsigned int private_dos:1;/* Support fpr private use DOs. */
|
|
|
|
unsigned int mcl3:16; /* Max. length for a OpenPGP card cert.3 */
|
2019-01-27 20:12:00 +01:00
|
|
|
} extcap;
|
|
|
|
unsigned int status_indicator;
|
|
|
|
int kdf_do_enabled; /* True if card has a KDF object. */
|
2020-05-26 16:16:24 +02:00
|
|
|
int uif[3]; /* True if User Interaction Flag is on. */
|
|
|
|
/* 1 = on, 2 = permanent on. */
|
2020-09-08 08:34:42 +02:00
|
|
|
strlist_t supported_keyalgo[3];
|
2019-01-27 20:12:00 +01:00
|
|
|
};
|
|
|
|
typedef struct card_info_s *card_info_t;
|
|
|
|
|
|
|
|
|
2019-02-25 09:28:22 +01:00
|
|
|
/*-- card-keys.c --*/
|
2019-01-30 15:01:34 +01:00
|
|
|
void release_keyblock (keyblock_t keyblock);
|
2019-01-30 17:48:41 +01:00
|
|
|
void flush_keyblock_cache (void);
|
2019-01-30 15:01:34 +01:00
|
|
|
gpg_error_t get_matching_keys (const unsigned char *keygrip, int protocol,
|
|
|
|
keyblock_t *r_keyblock);
|
|
|
|
gpg_error_t test_get_matching_keys (const char *hexgrip);
|
2020-06-03 16:24:44 +02:00
|
|
|
gpg_error_t get_minimal_openpgp_key (estream_t *r_key, const char *fingerprint);
|
2019-01-30 15:01:34 +01:00
|
|
|
|
|
|
|
|
2019-02-25 09:28:22 +01:00
|
|
|
/*-- card-misc.c --*/
|
2019-01-29 08:48:53 +01:00
|
|
|
key_info_t find_kinfo (card_info_t info, const char *keyref);
|
2019-01-31 16:06:47 +01:00
|
|
|
void *hex_to_buffer (const char *string, size_t *r_length);
|
2019-02-13 09:46:36 +01:00
|
|
|
gpg_error_t send_apdu (const char *hexapdu, const char *desc,
|
|
|
|
unsigned int ignore,
|
|
|
|
unsigned char **r_data, size_t *r_datalen);
|
2019-01-29 08:48:53 +01:00
|
|
|
|
2019-01-27 20:12:00 +01:00
|
|
|
/*-- card-call-scd.c --*/
|
|
|
|
void release_card_info (card_info_t info);
|
|
|
|
const char *app_type_string (app_type_t app_type);
|
|
|
|
|
2020-05-28 13:00:27 +02:00
|
|
|
gpg_error_t scd_apdu (const char *hexapdu, const char *options,
|
|
|
|
unsigned int *r_sw,
|
2019-02-13 09:46:36 +01:00
|
|
|
unsigned char **r_data, size_t *r_datalen);
|
2020-01-16 21:28:45 +01:00
|
|
|
|
|
|
|
gpg_error_t scd_switchcard (const char *serialno);
|
|
|
|
gpg_error_t scd_switchapp (const char *appname);
|
|
|
|
|
2021-04-01 10:34:06 +02:00
|
|
|
gpg_error_t scd_learn (card_info_t info, int reread);
|
2019-01-27 20:12:00 +01:00
|
|
|
gpg_error_t scd_getattr (const char *name, struct card_info_s *info);
|
|
|
|
gpg_error_t scd_setattr (const char *name,
|
|
|
|
const unsigned char *value, size_t valuelen);
|
|
|
|
gpg_error_t scd_writecert (const char *certidstr,
|
|
|
|
const unsigned char *certdata, size_t certdatalen);
|
2019-03-05 15:49:20 +01:00
|
|
|
gpg_error_t scd_writekey (const char *keyref, int force, const char *keygrip);
|
2019-02-08 11:58:27 +01:00
|
|
|
gpg_error_t scd_genkey (const char *keyref, int force, const char *algo,
|
|
|
|
u32 *createtime);
|
2019-01-27 20:12:00 +01:00
|
|
|
gpg_error_t scd_serialno (char **r_serialno, const char *demand);
|
2020-01-16 21:28:45 +01:00
|
|
|
|
2019-01-27 20:12:00 +01:00
|
|
|
gpg_error_t scd_readcert (const char *certidstr,
|
|
|
|
void **r_buf, size_t *r_buflen);
|
2021-04-21 21:03:57 +02:00
|
|
|
gpg_error_t scd_readkey (const char *keyrefstr, int create_shadow,
|
|
|
|
gcry_sexp_t *r_result);
|
2019-01-27 20:12:00 +01:00
|
|
|
gpg_error_t scd_cardlist (strlist_t *result);
|
2020-01-16 21:28:45 +01:00
|
|
|
gpg_error_t scd_applist (strlist_t *result, int all);
|
2020-06-30 14:36:44 +02:00
|
|
|
gpg_error_t scd_change_pin (const char *pinref, int reset_mode, int nullpin);
|
2019-01-27 20:12:00 +01:00
|
|
|
gpg_error_t scd_checkpin (const char *serialno);
|
2024-01-16 18:05:46 +01:00
|
|
|
gpg_error_t scd_havekey_info (const unsigned char *grip, char **r_result);
|
|
|
|
gpg_error_t scd_delete_key (const unsigned char *grip, int force);
|
2019-01-27 20:12:00 +01:00
|
|
|
|
|
|
|
unsigned long agent_get_s2k_count (void);
|
|
|
|
|
2020-11-27 11:28:16 +01:00
|
|
|
char *scd_apdu_strerror (unsigned int sw);
|
|
|
|
|
|
|
|
|
2019-02-25 09:28:22 +01:00
|
|
|
/*-- card-yubikey.c --*/
|
2019-03-28 10:56:28 +01:00
|
|
|
gpg_error_t yubikey_commands (card_info_t info,
|
common,agent,dirmngr,g10,tools: Fix split_fields API.
* common/stringhelp.h (split_fields): Use const * for the strings in
the ARRAY.
(split_fields_colon): Likewise.
* common/stringhelp.c (split_fields, split_fields_colon): Fix
the implementation.
* agent/call-scd.c, agent/command.c: Follow the change.
* common/t-stringhelp.c, dirmngr/loadswdb.c: Likewise.
* g10/call-agent.c, tools/card-call-scd.c: Likewise.
* tools/card-yubikey.c, tools/gpg-card.c: Likewise.
* tools/gpg-card.h, tools/gpg-wks-client.c: Likewise.
* tools/gpgconf-comp.c, tools/gpgconf.c: Likewise.
* tools/wks-util.c: Likewise.
--
The strings in the ARRAY don't need to be released by caller, as those
are references. It's easier to follow the code when it's explicitly
const *.
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2020-09-18 03:20:23 +02:00
|
|
|
estream_t fp, int argc, const char *argv[]);
|
2019-01-27 20:12:00 +01:00
|
|
|
|
|
|
|
|
2019-02-25 09:28:22 +01:00
|
|
|
#endif /*GNUPG_GPG_CARD_H*/
|