1 /* test-stubs.c - The GnuPG signature verify utility
2  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005, 2006,
3  *               2008, 2009, 2012 Free Software Foundation, Inc.
4  *
5  * This file is part of GnuPG.
6  *
7  * GnuPG is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * GnuPG is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, see <https://www.gnu.org/licenses/>.
19  */
20 
21 #include <config.h>
22 #include <errno.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <ctype.h>
27 #include <unistd.h>
28 
29 #define INCLUDED_BY_MAIN_MODULE 1
30 #include "gpg.h"
31 #include "../common/util.h"
32 #include "packet.h"
33 #include "../common/iobuf.h"
34 #include "main.h"
35 #include "options.h"
36 #include "keydb.h"
37 #include "trustdb.h"
38 #include "filter.h"
39 #include "../common/ttyio.h"
40 #include "../common/i18n.h"
41 #include "../common/sysutils.h"
42 #include "../common/status.h"
43 #include "call-agent.h"
44 
45 int g10_errors_seen;
46 
47 
48 void
g10_exit(int rc)49 g10_exit( int rc )
50 {
51   rc = rc? rc : log_get_errorcount(0)? 2 : g10_errors_seen? 1 : 0;
52   exit(rc );
53 }
54 
55 
56 /* Stub:
57  * We have to override the trustcheck from pkclist.c because
58  * this utility assumes that all keys in the keyring are trustworthy
59  */
60 gpg_error_t
check_signatures_trust(ctrl_t ctrl,kbnode_t kblock,PKT_public_key * pk,PKT_signature * sig)61 check_signatures_trust (ctrl_t ctrl, kbnode_t kblock,
62                         PKT_public_key *pk, PKT_signature *sig)
63 {
64   (void)ctrl;
65   (void)kblock;
66   (void)pk;
67   (void)sig;
68   return 0;
69 }
70 
71 void
read_trust_options(ctrl_t ctrl,byte * trust_model,ulong * created,ulong * nextcheck,byte * marginals,byte * completes,byte * cert_depth,byte * min_cert_level)72 read_trust_options (ctrl_t ctrl,
73                     byte *trust_model, ulong *created, ulong *nextcheck,
74                     byte *marginals, byte *completes, byte *cert_depth,
75                     byte *min_cert_level)
76 {
77   (void)ctrl;
78   (void)trust_model;
79   (void)created;
80   (void)nextcheck;
81   (void)marginals;
82   (void)completes;
83   (void)cert_depth;
84   (void)min_cert_level;
85 }
86 
87 /* Stub:
88  * We don't have the trustdb , so we have to provide some stub functions
89  * instead
90  */
91 
92 int
cache_disabled_value(ctrl_t ctrl,PKT_public_key * pk)93 cache_disabled_value (ctrl_t ctrl, PKT_public_key *pk)
94 {
95   (void)ctrl;
96   (void)pk;
97   return 0;
98 }
99 
100 void
check_trustdb_stale(ctrl_t ctrl)101 check_trustdb_stale (ctrl_t ctrl)
102 {
103   (void)ctrl;
104 }
105 
106 int
get_validity_info(ctrl_t ctrl,kbnode_t kb,PKT_public_key * pk,PKT_user_id * uid)107 get_validity_info (ctrl_t ctrl, kbnode_t kb, PKT_public_key *pk,
108                    PKT_user_id *uid)
109 {
110   (void)ctrl;
111   (void)kb;
112   (void)pk;
113   (void)uid;
114   return '?';
115 }
116 
117 unsigned int
get_validity(ctrl_t ctrl,kbnode_t kb,PKT_public_key * pk,PKT_user_id * uid,PKT_signature * sig,int may_ask)118 get_validity (ctrl_t ctrl, kbnode_t kb, PKT_public_key *pk, PKT_user_id *uid,
119               PKT_signature *sig, int may_ask)
120 {
121   (void)ctrl;
122   (void)kb;
123   (void)pk;
124   (void)uid;
125   (void)sig;
126   (void)may_ask;
127   return 0;
128 }
129 
130 const char *
trust_value_to_string(unsigned int value)131 trust_value_to_string (unsigned int value)
132 {
133   (void)value;
134   return "err";
135 }
136 
137 const char *
uid_trust_string_fixed(ctrl_t ctrl,PKT_public_key * key,PKT_user_id * uid)138 uid_trust_string_fixed (ctrl_t ctrl, PKT_public_key *key, PKT_user_id *uid)
139 {
140   (void)ctrl;
141   (void)key;
142   (void)uid;
143   return "err";
144 }
145 
146 int
get_ownertrust_info(ctrl_t ctrl,PKT_public_key * pk,int no_create)147 get_ownertrust_info (ctrl_t ctrl, PKT_public_key *pk, int no_create)
148 {
149   (void)ctrl;
150   (void)pk;
151   (void)no_create;
152   return '?';
153 }
154 
155 unsigned int
get_ownertrust(ctrl_t ctrl,PKT_public_key * pk)156 get_ownertrust (ctrl_t ctrl, PKT_public_key *pk)
157 {
158   (void)ctrl;
159   (void)pk;
160   return TRUST_UNKNOWN;
161 }
162 
163 
164 /* Stubs:
165  * Because we only work with trusted keys, it does not make sense to
166  * get them from a keyserver
167  */
168 
169 struct keyserver_spec *
keyserver_match(struct keyserver_spec * spec)170 keyserver_match (struct keyserver_spec *spec)
171 {
172   (void)spec;
173   return NULL;
174 }
175 
176 int
keyserver_any_configured(ctrl_t ctrl)177 keyserver_any_configured (ctrl_t ctrl)
178 {
179   (void)ctrl;
180   return 0;
181 }
182 
183 int
keyserver_import_keyid(u32 * keyid,void * dummy,unsigned int flags)184 keyserver_import_keyid (u32 *keyid, void *dummy, unsigned int flags)
185 {
186   (void)keyid;
187   (void)dummy;
188   (void)flags;
189   return -1;
190 }
191 
192 int
keyserver_import_fprint(ctrl_t ctrl,const byte * fprint,size_t fprint_len,struct keyserver_spec * keyserver,unsigned int flags)193 keyserver_import_fprint (ctrl_t ctrl, const byte *fprint,size_t fprint_len,
194 			 struct keyserver_spec *keyserver, unsigned int flags)
195 {
196   (void)ctrl;
197   (void)fprint;
198   (void)fprint_len;
199   (void)keyserver;
200   (void)flags;
201   return -1;
202 }
203 
204 int
keyserver_import_fprint_ntds(ctrl_t ctrl,const byte * fprint,size_t fprint_len)205 keyserver_import_fprint_ntds (ctrl_t ctrl,
206                               const byte *fprint, size_t fprint_len)
207 {
208   (void)ctrl;
209   (void)fprint;
210   (void)fprint_len;
211   return -1;
212 }
213 
214 int
keyserver_import_cert(const char * name)215 keyserver_import_cert (const char *name)
216 {
217   (void)name;
218   return -1;
219 }
220 
221 gpg_error_t
keyserver_import_wkd(ctrl_t ctrl,const char * name,unsigned int flags,unsigned char ** fpr,size_t * fpr_len)222 keyserver_import_wkd (ctrl_t ctrl, const char *name, unsigned int flags,
223                       unsigned char **fpr, size_t *fpr_len)
224 {
225   (void)ctrl;
226   (void)name;
227   (void)flags;
228   (void)fpr;
229   (void)fpr_len;
230   return GPG_ERR_BUG;
231 }
232 
233 int
keyserver_import_mbox(const char * name,struct keyserver_spec * spec)234 keyserver_import_mbox (const char *name,struct keyserver_spec *spec)
235 {
236   (void)name;
237   (void)spec;
238   return -1;
239 }
240 
241 int
keyserver_import_ntds(ctrl_t ctrl,const char * mbox,unsigned char ** fpr,size_t * fprlen)242 keyserver_import_ntds (ctrl_t ctrl, const char *mbox,
243                        unsigned char **fpr, size_t *fprlen)
244 {
245   (void)ctrl;
246   (void)mbox;
247   (void)fpr;
248   (void)fprlen;
249   return -1;
250 }
251 
252 int
keyserver_import_ldap(const char * name)253 keyserver_import_ldap (const char *name)
254 {
255   (void)name;
256   return -1;
257 }
258 
259 gpg_error_t
read_key_from_file_or_buffer(ctrl_t ctrl,const char * fname,const void * buffer,size_t buflen,kbnode_t * r_keyblock)260 read_key_from_file_or_buffer (ctrl_t ctrl, const char *fname,
261                               const void *buffer, size_t buflen,
262                               kbnode_t *r_keyblock)
263 {
264   (void)ctrl;
265   (void)fname;
266   (void)buffer;
267   (void)buflen;
268   (void)r_keyblock;
269   return -1;
270 }
271 
272 gpg_error_t
import_included_key_block(ctrl_t ctrl,kbnode_t keyblock)273 import_included_key_block (ctrl_t ctrl, kbnode_t keyblock)
274 {
275   (void)ctrl;
276   (void)keyblock;
277   return -1;
278 }
279 
280 
281 /* Stub:
282  * No encryption here but mainproc links to these functions.
283  */
284 gpg_error_t
get_session_key(ctrl_t ctrl,struct pubkey_enc_list * k,DEK * dek)285 get_session_key (ctrl_t ctrl, struct pubkey_enc_list *k, DEK *dek)
286 {
287   (void)ctrl;
288   (void)k;
289   (void)dek;
290   return GPG_ERR_GENERAL;
291 }
292 
293 /* Stub: */
294 gpg_error_t
get_override_session_key(DEK * dek,const char * string)295 get_override_session_key (DEK *dek, const char *string)
296 {
297   (void)dek;
298   (void)string;
299   return GPG_ERR_GENERAL;
300 }
301 
302 /* Stub: */
303 int
decrypt_data(ctrl_t ctrl,void * procctx,PKT_encrypted * ed,DEK * dek)304 decrypt_data (ctrl_t ctrl, void *procctx, PKT_encrypted *ed, DEK *dek)
305 {
306   (void)ctrl;
307   (void)procctx;
308   (void)ed;
309   (void)dek;
310   return GPG_ERR_GENERAL;
311 }
312 
313 
314 /* Stub:
315  * No interactive commands, so we don't need the helptexts
316  */
317 void
display_online_help(const char * keyword)318 display_online_help (const char *keyword)
319 {
320   (void)keyword;
321 }
322 
323 /* Stub:
324  * We don't use secret keys, but getkey.c links to this
325  */
326 int
check_secret_key(PKT_public_key * pk,int n)327 check_secret_key (PKT_public_key *pk, int n)
328 {
329   (void)pk;
330   (void)n;
331   return GPG_ERR_GENERAL;
332 }
333 
334 /* Stub:
335  * No secret key, so no passphrase needed
336  */
337 DEK *
passphrase_to_dek(int cipher_algo,STRING2KEY * s2k,int create,int nocache,const char * tmp,unsigned int flags,int * canceled)338 passphrase_to_dek (int cipher_algo, STRING2KEY *s2k, int create, int nocache,
339                    const char *tmp, unsigned int flags, int *canceled)
340 {
341   (void)cipher_algo;
342   (void)s2k;
343   (void)create;
344   (void)nocache;
345   (void)tmp;
346   (void)flags;
347 
348   if (canceled)
349     *canceled = 0;
350   return NULL;
351 }
352 
353 void
passphrase_clear_cache(const char * cacheid)354 passphrase_clear_cache (const char *cacheid)
355 {
356   (void)cacheid;
357 }
358 
359 struct keyserver_spec *
parse_preferred_keyserver(PKT_signature * sig)360 parse_preferred_keyserver(PKT_signature *sig)
361 {
362   (void)sig;
363   return NULL;
364 }
365 
366 struct keyserver_spec *
parse_keyserver_uri(const char * uri,int require_scheme,const char * configname,unsigned int configlineno)367 parse_keyserver_uri (const char *uri, int require_scheme,
368                      const char *configname, unsigned int configlineno)
369 {
370   (void)uri;
371   (void)require_scheme;
372   (void)configname;
373   (void)configlineno;
374   return NULL;
375 }
376 
377 void
free_keyserver_spec(struct keyserver_spec * keyserver)378 free_keyserver_spec (struct keyserver_spec *keyserver)
379 {
380   (void)keyserver;
381 }
382 
383 /* Stubs to avoid linking to photoid.c */
384 void
show_photos(const struct user_attribute * attrs,int count,PKT_public_key * pk)385 show_photos (const struct user_attribute *attrs, int count, PKT_public_key *pk)
386 {
387   (void)attrs;
388   (void)count;
389   (void)pk;
390 }
391 
392 int
parse_image_header(const struct user_attribute * attr,byte * type,u32 * len)393 parse_image_header (const struct user_attribute *attr, byte *type, u32 *len)
394 {
395   (void)attr;
396   (void)type;
397   (void)len;
398   return 0;
399 }
400 
401 char *
image_type_to_string(byte type,int string)402 image_type_to_string (byte type, int string)
403 {
404   (void)type;
405   (void)string;
406   return NULL;
407 }
408 
409 #ifdef ENABLE_CARD_SUPPORT
410 int
agent_scd_getattr(const char * name,struct agent_card_info_s * info)411 agent_scd_getattr (const char *name, struct agent_card_info_s *info)
412 {
413   (void)name;
414   (void)info;
415   return 0;
416 }
417 #endif /* ENABLE_CARD_SUPPORT */
418 
419 /* We do not do any locking, so use these stubs here */
420 void
dotlock_disable(void)421 dotlock_disable (void)
422 {
423 }
424 
425 dotlock_t
dotlock_create(const char * file_to_lock,unsigned int flags)426 dotlock_create (const char *file_to_lock, unsigned int flags)
427 {
428   (void)file_to_lock;
429   (void)flags;
430   return NULL;
431 }
432 
433 void
dotlock_destroy(dotlock_t h)434 dotlock_destroy (dotlock_t h)
435 {
436   (void)h;
437 }
438 
439 int
dotlock_take(dotlock_t h,long timeout)440 dotlock_take (dotlock_t h, long timeout)
441 {
442   (void)h;
443   (void)timeout;
444   return 0;
445 }
446 
447 int
dotlock_release(dotlock_t h)448 dotlock_release (dotlock_t h)
449 {
450   (void)h;
451   return 0;
452 }
453 
454 void
dotlock_remove_lockfiles(void)455 dotlock_remove_lockfiles (void)
456 {
457 }
458 
459 int
agent_probe_secret_key(ctrl_t ctrl,PKT_public_key * pk)460 agent_probe_secret_key (ctrl_t ctrl, PKT_public_key *pk)
461 {
462   (void)ctrl;
463   (void)pk;
464   return 0;
465 }
466 
467 gpg_error_t
agent_probe_any_secret_key(ctrl_t ctrl,kbnode_t keyblock)468 agent_probe_any_secret_key (ctrl_t ctrl, kbnode_t keyblock)
469 {
470   (void)ctrl;
471   (void)keyblock;
472   return gpg_error (GPG_ERR_NO_SECKEY);
473 }
474 
475 gpg_error_t
agent_get_keyinfo(ctrl_t ctrl,const char * hexkeygrip,char ** r_serialno,int * r_cleartext)476 agent_get_keyinfo (ctrl_t ctrl, const char *hexkeygrip,
477                    char **r_serialno, int *r_cleartext)
478 {
479   (void)ctrl;
480   (void)hexkeygrip;
481   (void)r_cleartext;
482   *r_serialno = NULL;
483   return gpg_error (GPG_ERR_NO_SECKEY);
484 }
485 
486 gpg_error_t
export_pubkey_buffer(ctrl_t ctrl,const char * keyspec,unsigned int options,const void * prefix,size_t prefixlen,export_stats_t stats,kbnode_t * r_keyblock,void ** r_data,size_t * r_datalen)487 export_pubkey_buffer (ctrl_t ctrl, const char *keyspec, unsigned int options,
488                       const void *prefix, size_t prefixlen,
489                       export_stats_t stats,
490                       kbnode_t *r_keyblock, void **r_data, size_t *r_datalen)
491 {
492   (void)ctrl;
493   (void)keyspec;
494   (void)options;
495   (void)prefix;
496   (void)prefixlen;
497   (void)stats;
498 
499   *r_keyblock = NULL;
500   *r_data = NULL;
501   *r_datalen = 0;
502   return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
503 }
504 
505 gpg_error_t
tofu_write_tfs_record(ctrl_t ctrl,estream_t fp,PKT_public_key * pk,const char * user_id)506 tofu_write_tfs_record (ctrl_t ctrl, estream_t fp,
507                        PKT_public_key *pk, const char *user_id)
508 {
509   (void)ctrl;
510   (void)fp;
511   (void)pk;
512   (void)user_id;
513   return gpg_error (GPG_ERR_GENERAL);
514 }
515 
516 gpg_error_t
tofu_get_policy(ctrl_t ctrl,PKT_public_key * pk,PKT_user_id * user_id,enum tofu_policy * policy)517 tofu_get_policy (ctrl_t ctrl, PKT_public_key *pk, PKT_user_id *user_id,
518 		 enum tofu_policy *policy)
519 {
520   (void)ctrl;
521   (void)pk;
522   (void)user_id;
523   (void)policy;
524   return gpg_error (GPG_ERR_GENERAL);
525 }
526 
527 const char *
tofu_policy_str(enum tofu_policy policy)528 tofu_policy_str (enum tofu_policy policy)
529 {
530   (void)policy;
531 
532   return "unknown";
533 }
534 
535 void
tofu_begin_batch_update(ctrl_t ctrl)536 tofu_begin_batch_update (ctrl_t ctrl)
537 {
538   (void)ctrl;
539 }
540 
541 void
tofu_end_batch_update(ctrl_t ctrl)542 tofu_end_batch_update (ctrl_t ctrl)
543 {
544   (void)ctrl;
545 }
546 
547 gpg_error_t
tofu_notice_key_changed(ctrl_t ctrl,kbnode_t kb)548 tofu_notice_key_changed (ctrl_t ctrl, kbnode_t kb)
549 {
550   (void) ctrl;
551   (void) kb;
552 
553   return 0;
554 }
555 
556 int
get_revocation_reason(PKT_signature * sig,char ** r_reason,char ** r_comment,size_t * r_commentlen)557 get_revocation_reason (PKT_signature *sig, char **r_reason,
558                        char **r_comment, size_t *r_commentlen)
559 {
560   (void)sig;
561   (void)r_commentlen;
562 
563   if (r_reason)
564     *r_reason = NULL;
565   if (r_comment)
566     *r_comment = NULL;
567   return 0;
568 }
569