| 1 | /* scd.h - Interface to Scdaemon |
| 2 | Copyright (C) 2007, 2008, 2009 g10code GmbH. |
| 3 | |
| 4 | This file is part of Poldi. |
| 5 | |
| 6 | Poldi is free software; you can redistribute it and/or modify it |
| 7 | under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation; either version 3 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | Poldi is distributed in the hope that it will be useful, but |
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program; if not, see |
| 18 | <http://www.gnu.org/licenses/>. */ |
| 19 | |
| 20 | #ifndef POLDI_SCD_H |
| 21 | #define POLDI_SCD_H |
| 22 | |
| 23 | #include <poldi.h> |
| 24 | |
| 25 | #include "util/simplelog.h" |
| 26 | |
| 27 | struct scd_context; |
| 28 | |
| 29 | typedef struct scd_context *scd_context_t; |
| 30 | |
| 31 | struct scd_cardinfo |
| 32 | { |
| 33 | char *serialno; /* malloced hex string. */ |
| 34 | char *disp_name; /* malloced. */ |
| 35 | char *pubkey_url; /* malloced. */ |
| 36 | char *login_data; /* malloced. */ |
| 37 | char *disp_lang; /* malloced. */ |
| 38 | char fpr1valid; |
| 39 | char fpr2valid; |
| 40 | char fpr3valid; |
| 41 | char fpr1[20]; |
| 42 | char fpr2[20]; |
| 43 | char fpr3[20]; |
| 44 | }; |
| 45 | |
| 46 | typedef struct scd_cardinfo scd_cardinfo_t; |
| 47 | |
| 48 | #define SCD_FLAG_VERBOSE (1 << 0) |
| 49 | |
| 50 | /* Fork it off and work by pipes. Returns proper error code or zero |
| 51 | on success. */ |
| 52 | gpg_error_t scd_connect (scd_context_t *scd_ctx, int use_agent, |
| 53 | const char *scd_path, const char *scd_options, |
| 54 | log_handle_t loghandle); |
| 55 | |
| 56 | /* Disconnect from SCDaemon; destroy the context SCD_CTX. */ |
| 57 | void scd_disconnect (scd_context_t scd_ctx); |
| 58 | |
| 59 | typedef int (*scd_pincb_t) (void *data, const char *, char *, size_t); |
| 60 | |
| 61 | void scd_set_pincb (scd_context_t scd_ctx, |
| 62 | scd_pincb_t pincb, void *cookie); |
| 63 | |
| 64 | /* Return the serial number of the card or an appropriate error. The |
| 65 | serial number is returned as a hexstring. */ |
| 66 | gpg_error_t scd_serialno (scd_context_t ctx, char **r_serialno); |
| 67 | |
| 68 | /* Read information from card and fill the cardinfo structure |
| 69 | CARDINFO. Returns proper error code, zero on success. */ |
| 70 | int scd_learn (scd_context_t ctx, |
| 71 | struct scd_cardinfo *cardinfo); |
| 72 | |
| 73 | /* Simply release the cardinfo structure INFO. INFO being NULL is |
| 74 | okay. */ |
| 75 | void scd_release_cardinfo (struct scd_cardinfo cardinfo); |
| 76 | |
| 77 | /* Create a signature using the current card. CTX is the handle for |
| 78 | the scd subsystem. KEYID identifies the key on the card to use for |
| 79 | signing. INDATA/INDATALEN is the input for the signature function. |
| 80 | The signature created is written into newly allocated memory in |
| 81 | *R_BUF, *R_BUFLEN will hold the length of the signature. */ |
| 82 | gpg_error_t scd_pksign (scd_context_t ctx, |
| 83 | const char *keyid, |
| 84 | const unsigned char *indata, size_t indatalen, |
| 85 | unsigned char **r_buf, size_t *r_buflen); |
| 86 | |
| 87 | /* Read a key with ID and return it in an allocate buffer pointed to |
| 88 | by r_BUF as a valid S-expression. */ |
| 89 | int scd_readkey (scd_context_t ctx, |
| 90 | const char *id, gcry_sexp_t *key); |
| 91 | |
| 92 | /* Sends a GETINFO command for WHAT to the scdaemon through CTX. The |
| 93 | newly allocated result is stored in *RESULT. Returns proper error |
| 94 | code, zero on success. */ |
| 95 | int scd_getinfo (scd_context_t ctx, const char *what, char **result); |
| 96 | |
| 97 | /* Initializer objet for struct scd_cardinfo instances. */ |
| 98 | extern struct scd_cardinfo scd_cardinfo_null; |
| 99 | |
| 100 | #endif |