2 *****************************************************************************
4 * File: fko_encryption.c
6 * Author: Damien S. Stuart
8 * Purpose: Set/Get the spa encryption type.
10 * Copyright 2009-2010 Damien Stuart (dstuart@dstuart.org)
12 * License (GNU Public License):
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
29 *****************************************************************************
31 #include "fko_common.h"
33 #include "cipher_funcs.h"
37 #include "gpgme_funcs.h"
43 /* Prep and encrypt using Rijndael
46 _rijndael_encrypt(fko_ctx_t ctx, const char *enc_key)
50 unsigned char *cipher;
53 /* Make a bucket big enough to hold the enc msg + digest (plaintext)
54 * and populate it appropriately.
56 plain = malloc(strlen(ctx->encoded_msg) + strlen(ctx->digest) + 2);
58 return(FKO_ERROR_MEMORY_ALLOCATION);
60 sprintf(plain, "%s:%s", ctx->encoded_msg, ctx->digest);
62 /* Make a bucket for the encrypted version and populate it.
64 cipher = malloc(strlen(plain) + 32); /* Plus padding for salt and Block */
66 return(FKO_ERROR_MEMORY_ALLOCATION);
68 cipher_len = rij_encrypt(
69 (unsigned char*)plain, strlen(plain), (char*)enc_key, cipher
72 /* Now make a bucket for the base64-encoded version and populate it.
74 b64cipher = malloc(((cipher_len / 3) * 4) + 8);
76 return(FKO_ERROR_MEMORY_ALLOCATION);
78 b64_encode(cipher, b64cipher, cipher_len);
79 strip_b64_eq(b64cipher);
81 ctx->encrypted_msg = strdup(b64cipher);
89 if(ctx->encrypted_msg == NULL)
90 return(FKO_ERROR_MEMORY_ALLOCATION);
95 /* Decode, decrypt, and parse SPA data into the context.
98 _rijndael_decrypt(fko_ctx_t ctx, const char *dec_key)
102 unsigned char *cipher;
103 int cipher_len, pt_len, i, err = 0;
105 int b64_len = strlen(ctx->encrypted_msg);
107 /* Now see if we need to add the "Salted__" string to the front of the
110 if(strncmp(ctx->encrypted_msg, B64_RIJNDAEL_SALT, strlen(B64_RIJNDAEL_SALT)))
112 /* We need to realloc space for the salt.
114 tbuf = realloc(ctx->encrypted_msg, b64_len + 12);
116 return(FKO_ERROR_MEMORY_ALLOCATION);
118 memmove(tbuf+strlen(B64_RIJNDAEL_SALT), tbuf, b64_len);
120 ctx->encrypted_msg = memcpy(tbuf, B64_RIJNDAEL_SALT, strlen(B64_RIJNDAEL_SALT));
122 /* Adjust b64_len for added SALT value and Make sure we are still
123 * a properly NULL-terminated string (Ubuntu was one system for
124 * which this was an issue).
126 b64_len += strlen(B64_RIJNDAEL_SALT);
127 tbuf[b64_len] = '\0';
130 /* Create a bucket for the (base64) decoded encrypted data and get the
133 cipher = malloc(strlen(ctx->encrypted_msg));
135 return(FKO_ERROR_MEMORY_ALLOCATION);
137 cipher_len = b64_decode(ctx->encrypted_msg, cipher);
139 /* Create a bucket for the plaintext data and decrypt the message
142 ctx->encoded_msg = malloc(cipher_len);
143 if(ctx->encoded_msg == NULL)
144 return(FKO_ERROR_MEMORY_ALLOCATION);
146 pt_len = rij_decrypt(cipher, cipher_len, dec_key, (unsigned char*)ctx->encoded_msg);
148 /* Done with cipher...
152 /* The length of the decrypted data should be within 32 bytes of the
153 * length of the encrypted version.
155 if(pt_len < (cipher_len - 32))
156 return(FKO_ERROR_DECRYPTION_SIZE);
158 /* At this point we can check the data to see if we have a good
159 * decryption by ensuring the first field (16-digit random decimal
160 * value) is valid and is followed by a colon. Additional checks
161 * are made in fko_decode_spa_data().
163 ndx = (unsigned char *)ctx->encoded_msg;
164 for(i=0; i<FKO_RAND_VAL_SIZE; i++)
165 if(!isdigit(*(ndx++)))
168 if(err > 0 || *ndx != ':')
169 return(FKO_ERROR_DECRYPTION_FAILURE);
171 /* Call fko_decode and return the results.
173 return(fko_decode_spa_data(ctx));
179 /* Prep and encrypt using gpgme
182 gpg_encrypt(fko_ctx_t ctx, const char *enc_key)
187 unsigned char *cipher = NULL;
190 /* First make sure we have a recipient key set.
192 if(ctx->gpg_recipient == NULL)
193 return(FKO_ERROR_MISSING_GPG_KEY_DATA);
195 /* Make a bucket big enough to hold the enc msg + digest (plaintext)
196 * and populate it appropriately.
198 plain = malloc(strlen(ctx->encoded_msg) + strlen(ctx->digest) + 2);
200 return(FKO_ERROR_MEMORY_ALLOCATION);
202 sprintf(plain, "%s:%s", ctx->encoded_msg, ctx->digest);
204 res = gpgme_encrypt(ctx,
205 (unsigned char*)plain, strlen(plain),
206 enc_key, &cipher, &cipher_len
209 /* --DSS XXX: Better parsing of what went wrong would be nice :)
211 if(res != FKO_SUCCESS)
221 /* Now make a bucket for the base64-encoded version and populate it.
223 b64cipher = malloc(((cipher_len / 3) * 4) + 8);
224 if(b64cipher == NULL)
225 return(FKO_ERROR_MEMORY_ALLOCATION);
227 b64_encode(cipher, b64cipher, cipher_len);
228 strip_b64_eq(b64cipher);
230 ctx->encrypted_msg = strdup(b64cipher);
238 if(ctx->encrypted_msg == NULL)
239 return(FKO_ERROR_MEMORY_ALLOCATION);
244 /* Prep and decrypt using gpgme
247 gpg_decrypt(fko_ctx_t ctx, const char *dec_key)
250 unsigned char *cipher;
254 int b64_len = strlen(ctx->encrypted_msg);
256 /* Now see if we need to add the "hQ" string to the front of the
257 * base64-encoded-GPG-encrypted data.
259 if(strncmp(ctx->encrypted_msg, B64_GPG_PREFIX, strlen(B64_GPG_PREFIX)))
261 /* We need to realloc space for the GPG prefix of hQ.
263 tbuf = realloc(ctx->encrypted_msg, b64_len + 12);
265 return(FKO_ERROR_MEMORY_ALLOCATION);
267 memmove(tbuf+strlen(B64_GPG_PREFIX), tbuf, b64_len);
269 ctx->encrypted_msg = memcpy(tbuf, B64_GPG_PREFIX, strlen(B64_GPG_PREFIX));
271 /* Adjust b64_len for added SALT value and Make sure we are still
272 * a properly NULL-terminated string (Ubuntu was one system for
273 * which this was an issue).
275 b64_len += strlen(B64_GPG_PREFIX);
276 tbuf[b64_len] = '\0';
279 /* Create a bucket for the (base64) decoded encrypted data and get the
282 cipher = malloc(strlen(ctx->encrypted_msg));
284 return(FKO_ERROR_MEMORY_ALLOCATION);
286 cipher_len = b64_decode(ctx->encrypted_msg, cipher);
288 /* Create a bucket for the plaintext data and decrypt the message
291 /* --DSS Actually, the needed memory will be malloced in the gpgme_decrypt
292 // function. Just leaving this here for reference (for now).
293 //ctx->encoded_msg = malloc(cipher_len);
294 //if(ctx->encoded_msg == NULL)
295 // return(FKO_ERROR_MEMORY_ALLOCATION);
298 res = gpgme_decrypt(ctx, cipher, cipher_len,
299 dec_key, (unsigned char**)&ctx->encoded_msg, &cipher_len
302 /* Done with cipher...
306 if(res != FKO_SUCCESS)
309 /* XXX: We could put some kind of sanity check of the decrypted
313 /* Call fko_decode and return the results.
315 return(fko_decode_spa_data(ctx));
318 #endif /* HAVE_LIBGPGME */
320 /* Set the SPA encryption type.
323 fko_set_spa_encryption_type(fko_ctx_t ctx, const short encrypt_type)
325 /* Must be initialized
327 if(!CTX_INITIALIZED(ctx))
328 return(FKO_ERROR_CTX_NOT_INITIALIZED);
330 if(encrypt_type < 0 || encrypt_type >= FKO_LAST_ENCRYPTION_TYPE)
331 return(FKO_ERROR_INVALID_DATA);
333 ctx->encryption_type = encrypt_type;
335 ctx->state |= FKO_ENCRYPT_TYPE_MODIFIED;
340 /* Return the SPA encryption type.
343 fko_get_spa_encryption_type(fko_ctx_t ctx, short *enc_type)
345 /* Must be initialized
347 if(!CTX_INITIALIZED(ctx))
348 return(FKO_ERROR_CTX_NOT_INITIALIZED);
350 *enc_type = ctx->encryption_type;
355 /* Encrypt the encoded SPA data.
358 fko_encrypt_spa_data(fko_ctx_t ctx, const char *enc_key)
362 /* Must be initialized
364 if(!CTX_INITIALIZED(ctx))
366 return(FKO_ERROR_CTX_NOT_INITIALIZED);
369 /* If there is no encoded data or the SPA data has been modified,
370 * go ahead and re-encode here.
372 if(ctx->encoded_msg == NULL || FKO_IS_SPA_DATA_MODIFIED(ctx))
373 res = fko_encode_spa_data(ctx);
378 /* Croak on invalid encoded message as well. At present this is a
379 * check for a somewhat arbitrary minimum length for the encoded
382 if(strlen(ctx->encoded_msg) < MIN_SPA_ENCODED_MSG_SIZE)
384 return(FKO_ERROR_MISSING_ENCODED_DATA);
387 /* Encrypt according to type and return...
389 if(ctx->encryption_type == FKO_ENCRYPTION_RIJNDAEL)
390 res = _rijndael_encrypt(ctx, enc_key);
391 else if(ctx->encryption_type == FKO_ENCRYPTION_GPG)
393 res = gpg_encrypt(ctx, enc_key);
395 res = FKO_ERROR_UNSUPPORTED_FEATURE;
398 res = FKO_ERROR_INVALID_ENCRYPTION_TYPE;
403 /* Decode, decrypt, and parse SPA data into the context.
406 fko_decrypt_spa_data(fko_ctx_t ctx, const char *dec_key)
410 /* Get the (assumed) type of encryption used. This will also provide
411 * some data validation.
413 enc_type = fko_encryption_type(ctx->encrypted_msg);
415 //strlen(ctx->encrypted_msg) < MIN_SPA_ENCODED_MSG_SIZE)
417 if(enc_type == FKO_ENCRYPTION_GPG)
419 ctx->encryption_type = FKO_ENCRYPTION_GPG;
421 res = gpg_decrypt(ctx, dec_key);
423 res = FKO_ERROR_UNSUPPORTED_FEATURE;
426 else if(enc_type == FKO_ENCRYPTION_RIJNDAEL)
428 ctx->encryption_type = FKO_ENCRYPTION_RIJNDAEL;
429 res = _rijndael_decrypt(ctx, dec_key);
432 return(FKO_ERROR_INVALID_DATA);
437 /* Return the assumed encryption type based on the raw encrypted data.
440 fko_encryption_type(const char *enc_data)
444 /* Sanity check the data.
447 return(FKO_ENCRYPTION_INVALID_DATA);
449 /* Determine type of encryption used. For now, we are using the
450 * size of the message.
452 * XXX: We will want to come up with a more reliable method of
453 * identifying the encryption type.
455 enc_data_len = strlen(enc_data);
457 if(enc_data_len >= MIN_GNUPG_MSG_SIZE)
458 return(FKO_ENCRYPTION_GPG);
460 else if(enc_data_len < MIN_GNUPG_MSG_SIZE
461 && enc_data_len >= MIN_SPA_ENCODED_MSG_SIZE)
462 return(FKO_ENCRYPTION_RIJNDAEL);
465 return(FKO_ENCRYPTION_UNKNOWN);
468 /* Set the GPG recipient key name.
471 fko_set_gpg_recipient(fko_ctx_t ctx, const char *recip)
475 gpgme_key_t key = NULL;
477 /* Must be initialized
479 if(!CTX_INITIALIZED(ctx))
480 return(FKO_ERROR_CTX_NOT_INITIALIZED);
482 if(ctx->encryption_type != FKO_ENCRYPTION_GPG)
483 return(FKO_ERROR_WRONG_ENCRYPTION_TYPE);
485 ctx->gpg_recipient = strdup(recip);
486 if(ctx->gpg_recipient == NULL)
487 return(FKO_ERROR_MEMORY_ALLOCATION);
491 res = get_gpg_key(ctx, &key, 0);
492 if(res != FKO_SUCCESS)
494 free(ctx->gpg_recipient);
495 ctx->gpg_recipient = NULL;
499 ctx->recipient_key = key;
501 ctx->state |= FKO_DATA_MODIFIED;
505 return(FKO_ERROR_UNSUPPORTED_FEATURE);
506 #endif /* HAVE_LIBGPGME */
509 /* Set the GPG home dir.
512 fko_set_gpg_exe(fko_ctx_t ctx, const char *gpg_exe)
517 /* Must be initialized
519 if(!CTX_INITIALIZED(ctx))
520 return(FKO_ERROR_CTX_NOT_INITIALIZED);
522 /* If we are unable to stat the given path/file and determine if it
523 * is a regular file or symbolic link, then return with error.
525 if(stat(gpg_exe, &st) != 0)
526 return(FKO_ERROR_GPGME_BAD_GPG_EXE);
528 if(!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode))
529 return(FKO_ERROR_GPGME_BAD_GPG_EXE);
531 ctx->gpg_exe = strdup(gpg_exe);
532 if(ctx->gpg_exe == NULL)
533 return(FKO_ERROR_MEMORY_ALLOCATION);
537 return(FKO_ERROR_UNSUPPORTED_FEATURE);
538 #endif /* HAVE_LIBGPGME */
541 /* Get the GPG home dir.
544 fko_get_gpg_exe(fko_ctx_t ctx, char **gpg_exe)
547 /* Must be initialized
549 if(!CTX_INITIALIZED(ctx))
550 return(FKO_ERROR_CTX_NOT_INITIALIZED);
552 *gpg_exe = ctx->gpg_exe;
556 return(FKO_ERROR_UNSUPPORTED_FEATURE);
557 #endif /* HAVE_LIBGPGME */
560 /* Get the GPG recipient key name.
563 fko_get_gpg_recipient(fko_ctx_t ctx, char **recipient)
566 /* Must be initialized
568 if(!CTX_INITIALIZED(ctx))
569 return(FKO_ERROR_CTX_NOT_INITIALIZED);
571 *recipient = ctx->gpg_recipient;
575 return(FKO_ERROR_UNSUPPORTED_FEATURE);
576 #endif /* HAVE_LIBGPGME */
579 /* Set the GPG signer key name.
582 fko_set_gpg_signer(fko_ctx_t ctx, const char *signer)
586 gpgme_key_t key = NULL;
588 /* Must be initialized
590 if(!CTX_INITIALIZED(ctx))
591 return(FKO_ERROR_CTX_NOT_INITIALIZED);
593 if(ctx->encryption_type != FKO_ENCRYPTION_GPG)
594 return(FKO_ERROR_WRONG_ENCRYPTION_TYPE);
596 ctx->gpg_signer = strdup(signer);
597 if(ctx->gpg_signer == NULL)
598 return(FKO_ERROR_MEMORY_ALLOCATION);
602 res = get_gpg_key(ctx, &key, 1);
603 if(res != FKO_SUCCESS)
605 free(ctx->gpg_signer);
606 ctx->gpg_signer = NULL;
610 ctx->signer_key = key;
612 ctx->state |= FKO_DATA_MODIFIED;
616 return(FKO_ERROR_UNSUPPORTED_FEATURE);
617 #endif /* HAVE_LIBGPGME */
620 /* Get the GPG signer key name.
623 fko_get_gpg_signer(fko_ctx_t ctx, char **signer)
626 /* Must be initialized
628 if(!CTX_INITIALIZED(ctx))
629 return(FKO_ERROR_CTX_NOT_INITIALIZED);
631 *signer = ctx->gpg_signer;
635 return(FKO_ERROR_UNSUPPORTED_FEATURE);
636 #endif /* HAVE_LIBGPGME */
639 /* Set the GPG home dir.
642 fko_set_gpg_home_dir(fko_ctx_t ctx, const char *gpg_home_dir)
647 /* Must be initialized
649 if(!CTX_INITIALIZED(ctx))
650 return(FKO_ERROR_CTX_NOT_INITIALIZED);
652 /* If we are unable to stat the given dir, then return with error.
654 if(stat(gpg_home_dir, &st) != 0)
655 return(FKO_ERROR_GPGME_BAD_HOME_DIR);
657 if(!S_ISDIR(st.st_mode))
658 return(FKO_ERROR_GPGME_BAD_HOME_DIR);
660 ctx->gpg_home_dir = strdup(gpg_home_dir);
661 if(ctx->gpg_home_dir == NULL)
662 return(FKO_ERROR_MEMORY_ALLOCATION);
666 return(FKO_ERROR_UNSUPPORTED_FEATURE);
667 #endif /* HAVE_LIBGPGME */
670 /* Get the GPG home dir.
673 fko_get_gpg_home_dir(fko_ctx_t ctx, char **home_dir)
676 /* Must be initialized
678 if(!CTX_INITIALIZED(ctx))
679 return(FKO_ERROR_CTX_NOT_INITIALIZED);
681 *home_dir = ctx->gpg_home_dir;
685 return(FKO_ERROR_UNSUPPORTED_FEATURE);
686 #endif /* HAVE_LIBGPGME */
690 fko_set_gpg_signature_verify(fko_ctx_t ctx, const unsigned char val)
693 /* Must be initialized
695 if(!CTX_INITIALIZED(ctx))
696 return(FKO_ERROR_CTX_NOT_INITIALIZED);
698 ctx->verify_gpg_sigs = (val != 0) ? 1 : 0;
702 return(FKO_ERROR_UNSUPPORTED_FEATURE);
703 #endif /* HAVE_LIBGPGME */
707 fko_get_gpg_signature_verify(fko_ctx_t ctx, unsigned char *val)
710 /* Must be initialized
712 if(!CTX_INITIALIZED(ctx))
713 return(FKO_ERROR_CTX_NOT_INITIALIZED);
715 *val = ctx->verify_gpg_sigs;
719 return(FKO_ERROR_UNSUPPORTED_FEATURE);
720 #endif /* HAVE_LIBGPGME */
724 fko_set_gpg_ignore_verify_error(fko_ctx_t ctx, const unsigned char val)
727 /* Must be initialized
729 if(!CTX_INITIALIZED(ctx))
730 return(FKO_ERROR_CTX_NOT_INITIALIZED);
732 ctx->ignore_gpg_sig_error = (val != 0) ? 1 : 0;
736 return(FKO_ERROR_UNSUPPORTED_FEATURE);
737 #endif /* HAVE_LIBGPGME */
741 fko_get_gpg_ignore_verify_error(fko_ctx_t ctx, unsigned char *val)
744 /* Must be initialized
746 if(!CTX_INITIALIZED(ctx))
747 return(FKO_ERROR_CTX_NOT_INITIALIZED);
749 *val = ctx->ignore_gpg_sig_error;
753 return(FKO_ERROR_UNSUPPORTED_FEATURE);
754 #endif /* HAVE_LIBGPGME */
759 fko_get_gpg_signature_fpr(fko_ctx_t ctx, char **fpr)
762 /* Must be initialized
764 if(!CTX_INITIALIZED(ctx))
765 return(FKO_ERROR_CTX_NOT_INITIALIZED);
767 /* Must be using GPG encryption.
769 if(ctx->encryption_type != FKO_ENCRYPTION_GPG)
770 return(FKO_ERROR_WRONG_ENCRYPTION_TYPE);
772 /* Make sure we are supposed to verify signatures.
774 if(ctx->verify_gpg_sigs == 0)
775 return(FKO_ERROR_GPGME_SIGNATURE_VERIFY_DISABLED);
777 /* Make sure we have a signature to work with.
779 if(ctx->gpg_sigs == NULL)
780 return(FKO_ERROR_GPGME_NO_SIGNATURE);
782 *fpr = ctx->gpg_sigs->fpr;
786 return(FKO_ERROR_UNSUPPORTED_FEATURE);
787 #endif /* HAVE_LIBGPGME */
791 fko_get_gpg_signature_id(fko_ctx_t ctx, char **id)
794 /* Must be initialized
796 if(!CTX_INITIALIZED(ctx))
797 return(FKO_ERROR_CTX_NOT_INITIALIZED);
799 /* Must be using GPG encryption.
801 if(ctx->encryption_type != FKO_ENCRYPTION_GPG)
802 return(FKO_ERROR_WRONG_ENCRYPTION_TYPE);
804 /* Make sure we are supposed to verify signatures.
806 if(ctx->verify_gpg_sigs == 0)
807 return(FKO_ERROR_GPGME_SIGNATURE_VERIFY_DISABLED);
809 /* Make sure we have a signature to work with.
811 if(ctx->gpg_sigs == NULL)
812 return(FKO_ERROR_GPGME_NO_SIGNATURE);
814 *id = ctx->gpg_sigs->fpr + strlen(ctx->gpg_sigs->fpr) - 8;
818 return(FKO_ERROR_UNSUPPORTED_FEATURE);
819 #endif /* HAVE_LIBGPGME */
823 fko_get_gpg_signature_summary(fko_ctx_t ctx, int *sigsum)
826 /* Must be initialized
828 if(!CTX_INITIALIZED(ctx))
829 return(FKO_ERROR_CTX_NOT_INITIALIZED);
831 /* Must be using GPG encryption.
833 if(ctx->encryption_type != FKO_ENCRYPTION_GPG)
834 return(FKO_ERROR_WRONG_ENCRYPTION_TYPE);
836 /* Make sure we are supposed to verify signatures.
838 if(ctx->verify_gpg_sigs == 0)
839 return(FKO_ERROR_GPGME_SIGNATURE_VERIFY_DISABLED);
841 /* Make sure we have a signature to work with.
843 if(ctx->gpg_sigs == NULL)
844 return(FKO_ERROR_GPGME_NO_SIGNATURE);
846 *sigsum = ctx->gpg_sigs->summary;
850 return(FKO_ERROR_UNSUPPORTED_FEATURE);
851 #endif /* HAVE_LIBGPGME */
855 fko_get_gpg_signature_status(fko_ctx_t ctx, int *sigstat)
858 /* Must be initialized
860 if(!CTX_INITIALIZED(ctx))
861 return(FKO_ERROR_CTX_NOT_INITIALIZED);
863 /* Must be using GPG encryption.
865 if(ctx->encryption_type != FKO_ENCRYPTION_GPG)
866 return(FKO_ERROR_WRONG_ENCRYPTION_TYPE);
868 /* Make sure we are supposed to verify signatures.
870 if(ctx->verify_gpg_sigs == 0)
871 return(FKO_ERROR_GPGME_SIGNATURE_VERIFY_DISABLED);
873 /* Make sure we have a signature to work with.
875 if(ctx->gpg_sigs == NULL)
876 return(FKO_ERROR_GPGME_NO_SIGNATURE);
878 *sigstat = ctx->gpg_sigs->status;
882 return(FKO_ERROR_UNSUPPORTED_FEATURE);
883 #endif /* HAVE_LIBGPGME */
887 fko_gpg_signature_id_match(fko_ctx_t ctx, const char *id, unsigned char *result)
892 /* Must be initialized
894 if(!CTX_INITIALIZED(ctx))
895 return(FKO_ERROR_CTX_NOT_INITIALIZED);
897 /* Must be using GPG encryption.
899 if(ctx->encryption_type != FKO_ENCRYPTION_GPG)
900 return(FKO_ERROR_WRONG_ENCRYPTION_TYPE);
902 /* Make sure we are supposed to verify signatures.
904 if(ctx->verify_gpg_sigs == 0)
905 return(FKO_ERROR_GPGME_SIGNATURE_VERIFY_DISABLED);
907 /* Make sure we have a signature to work with.
909 if(ctx->gpg_sigs == NULL)
910 return(FKO_ERROR_GPGME_NO_SIGNATURE);
912 fko_get_gpg_signature_id(ctx, &curr_id);
914 *result = strcmp(id, curr_id) == 0 ? 1 : 0;
918 return(FKO_ERROR_UNSUPPORTED_FEATURE);
919 #endif /* HAVE_LIBGPGME */
923 fko_gpg_signature_fpr_match(fko_ctx_t ctx, const char *id, unsigned char *result)
926 /* Must be initialized
928 if(!CTX_INITIALIZED(ctx))
929 return(FKO_ERROR_CTX_NOT_INITIALIZED);
931 /* Must be using GPG encryption.
933 if(ctx->encryption_type != FKO_ENCRYPTION_GPG)
934 return(FKO_ERROR_WRONG_ENCRYPTION_TYPE);
936 /* Make sure we are supposed to verify signatures.
938 if(ctx->verify_gpg_sigs == 0)
939 return(FKO_ERROR_GPGME_SIGNATURE_VERIFY_DISABLED);
941 /* Make sure we have a signature to work with.
943 if(ctx->gpg_sigs == NULL)
944 return(FKO_ERROR_GPGME_NO_SIGNATURE);
946 *result = strcmp(id, ctx->gpg_sigs->fpr) == 0 ? 1 : 0;
950 return(FKO_ERROR_UNSUPPORTED_FEATURE);
951 #endif /* HAVE_LIBGPGME */