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 snprintf(plain, strlen(ctx->encoded_msg) + strlen(ctx->digest) + 2,
61 "%s:%s", ctx->encoded_msg, ctx->digest);
63 /* Make a bucket for the encrypted version and populate it.
65 cipher = malloc(strlen(plain) + 32); /* Plus padding for salt and Block */
67 return(FKO_ERROR_MEMORY_ALLOCATION);
69 cipher_len = rij_encrypt(
70 (unsigned char*)plain, strlen(plain), (char*)enc_key, cipher
73 /* Now make a bucket for the base64-encoded version and populate it.
75 b64cipher = malloc(((cipher_len / 3) * 4) + 8);
77 return(FKO_ERROR_MEMORY_ALLOCATION);
79 b64_encode(cipher, b64cipher, cipher_len);
80 strip_b64_eq(b64cipher);
82 ctx->encrypted_msg = strdup(b64cipher);
90 if(ctx->encrypted_msg == NULL)
91 return(FKO_ERROR_MEMORY_ALLOCATION);
96 /* Decode, decrypt, and parse SPA data into the context.
99 _rijndael_decrypt(fko_ctx_t ctx, const char *dec_key)
103 unsigned char *cipher;
104 int cipher_len, pt_len, i, err = 0;
106 int b64_len = strlen(ctx->encrypted_msg);
108 /* Now see if we need to add the "Salted__" string to the front of the
111 if(strncmp(ctx->encrypted_msg, B64_RIJNDAEL_SALT, strlen(B64_RIJNDAEL_SALT)))
113 /* We need to realloc space for the salt.
115 tbuf = realloc(ctx->encrypted_msg, b64_len + 12);
117 return(FKO_ERROR_MEMORY_ALLOCATION);
119 memmove(tbuf+strlen(B64_RIJNDAEL_SALT), tbuf, b64_len);
121 ctx->encrypted_msg = memcpy(tbuf, B64_RIJNDAEL_SALT, strlen(B64_RIJNDAEL_SALT));
123 /* Adjust b64_len for added SALT value and Make sure we are still
124 * a properly NULL-terminated string (Ubuntu was one system for
125 * which this was an issue).
127 b64_len += strlen(B64_RIJNDAEL_SALT);
128 tbuf[b64_len] = '\0';
131 /* Create a bucket for the (base64) decoded encrypted data and get the
134 cipher = malloc(strlen(ctx->encrypted_msg));
136 return(FKO_ERROR_MEMORY_ALLOCATION);
138 cipher_len = b64_decode(ctx->encrypted_msg, cipher);
140 /* Create a bucket for the plaintext data and decrypt the message
143 ctx->encoded_msg = malloc(cipher_len);
144 if(ctx->encoded_msg == NULL)
145 return(FKO_ERROR_MEMORY_ALLOCATION);
147 pt_len = rij_decrypt(cipher, cipher_len, dec_key, (unsigned char*)ctx->encoded_msg);
149 /* Done with cipher...
153 /* The length of the decrypted data should be within 32 bytes of the
154 * length of the encrypted version.
156 if(pt_len < (cipher_len - 32))
157 return(FKO_ERROR_DECRYPTION_SIZE);
159 /* At this point we can check the data to see if we have a good
160 * decryption by ensuring the first field (16-digit random decimal
161 * value) is valid and is followed by a colon. Additional checks
162 * are made in fko_decode_spa_data().
164 ndx = (unsigned char *)ctx->encoded_msg;
165 for(i=0; i<FKO_RAND_VAL_SIZE; i++)
166 if(!isdigit(*(ndx++)))
169 if(err > 0 || *ndx != ':')
170 return(FKO_ERROR_DECRYPTION_FAILURE);
172 /* Call fko_decode and return the results.
174 return(fko_decode_spa_data(ctx));
180 /* Prep and encrypt using gpgme
183 gpg_encrypt(fko_ctx_t ctx, const char *enc_key)
188 unsigned char *cipher = NULL;
191 /* First make sure we have a recipient key set.
193 if(ctx->gpg_recipient == NULL)
194 return(FKO_ERROR_MISSING_GPG_KEY_DATA);
196 /* Make a bucket big enough to hold the enc msg + digest (plaintext)
197 * and populate it appropriately.
199 plain = malloc(strlen(ctx->encoded_msg) + strlen(ctx->digest) + 2);
201 return(FKO_ERROR_MEMORY_ALLOCATION);
203 snprintf(plain, strlen(ctx->encoded_msg) + strlen(ctx->digest) + 2,
204 "%s:%s", ctx->encoded_msg, ctx->digest);
206 res = gpgme_encrypt(ctx,
207 (unsigned char*)plain, strlen(plain),
208 enc_key, &cipher, &cipher_len
211 /* --DSS XXX: Better parsing of what went wrong would be nice :)
213 if(res != FKO_SUCCESS)
223 /* Now make a bucket for the base64-encoded version and populate it.
225 b64cipher = malloc(((cipher_len / 3) * 4) + 8);
226 if(b64cipher == NULL)
227 return(FKO_ERROR_MEMORY_ALLOCATION);
229 b64_encode(cipher, b64cipher, cipher_len);
230 strip_b64_eq(b64cipher);
232 ctx->encrypted_msg = strdup(b64cipher);
240 if(ctx->encrypted_msg == NULL)
241 return(FKO_ERROR_MEMORY_ALLOCATION);
246 /* Prep and decrypt using gpgme
249 gpg_decrypt(fko_ctx_t ctx, const char *dec_key)
252 unsigned char *cipher;
256 int b64_len = strlen(ctx->encrypted_msg);
258 /* Now see if we need to add the "hQ" string to the front of the
259 * base64-encoded-GPG-encrypted data.
261 if(strncmp(ctx->encrypted_msg, B64_GPG_PREFIX, strlen(B64_GPG_PREFIX)))
263 /* We need to realloc space for the GPG prefix of hQ.
265 tbuf = realloc(ctx->encrypted_msg, b64_len + 12);
267 return(FKO_ERROR_MEMORY_ALLOCATION);
269 memmove(tbuf+strlen(B64_GPG_PREFIX), tbuf, b64_len);
271 ctx->encrypted_msg = memcpy(tbuf, B64_GPG_PREFIX, strlen(B64_GPG_PREFIX));
273 /* Adjust b64_len for added SALT value and Make sure we are still
274 * a properly NULL-terminated string (Ubuntu was one system for
275 * which this was an issue).
277 b64_len += strlen(B64_GPG_PREFIX);
278 tbuf[b64_len] = '\0';
281 /* Create a bucket for the (base64) decoded encrypted data and get the
284 cipher = malloc(strlen(ctx->encrypted_msg));
286 return(FKO_ERROR_MEMORY_ALLOCATION);
288 cipher_len = b64_decode(ctx->encrypted_msg, cipher);
290 /* Create a bucket for the plaintext data and decrypt the message
293 /* --DSS Actually, the needed memory will be malloced in the gpgme_decrypt
294 // function. Just leaving this here for reference (for now).
295 //ctx->encoded_msg = malloc(cipher_len);
296 //if(ctx->encoded_msg == NULL)
297 // return(FKO_ERROR_MEMORY_ALLOCATION);
300 res = gpgme_decrypt(ctx, cipher, cipher_len,
301 dec_key, (unsigned char**)&ctx->encoded_msg, &cipher_len
304 /* Done with cipher...
308 if(res != FKO_SUCCESS)
311 /* XXX: We could put some kind of sanity check of the decrypted
315 /* Call fko_decode and return the results.
317 return(fko_decode_spa_data(ctx));
320 #endif /* HAVE_LIBGPGME */
322 /* Set the SPA encryption type.
325 fko_set_spa_encryption_type(fko_ctx_t ctx, const short encrypt_type)
327 /* Must be initialized
329 if(!CTX_INITIALIZED(ctx))
330 return(FKO_ERROR_CTX_NOT_INITIALIZED);
332 if(encrypt_type < 0 || encrypt_type >= FKO_LAST_ENCRYPTION_TYPE)
333 return(FKO_ERROR_INVALID_DATA);
335 ctx->encryption_type = encrypt_type;
337 ctx->state |= FKO_ENCRYPT_TYPE_MODIFIED;
342 /* Return the SPA encryption type.
345 fko_get_spa_encryption_type(fko_ctx_t ctx, short *enc_type)
347 /* Must be initialized
349 if(!CTX_INITIALIZED(ctx))
350 return(FKO_ERROR_CTX_NOT_INITIALIZED);
352 *enc_type = ctx->encryption_type;
357 /* Encrypt the encoded SPA data.
360 fko_encrypt_spa_data(fko_ctx_t ctx, const char *enc_key)
364 /* Must be initialized
366 if(!CTX_INITIALIZED(ctx))
368 return(FKO_ERROR_CTX_NOT_INITIALIZED);
371 /* If there is no encoded data or the SPA data has been modified,
372 * go ahead and re-encode here.
374 if(ctx->encoded_msg == NULL || FKO_IS_SPA_DATA_MODIFIED(ctx))
375 res = fko_encode_spa_data(ctx);
380 /* Croak on invalid encoded message as well. At present this is a
381 * check for a somewhat arbitrary minimum length for the encoded
384 if(strlen(ctx->encoded_msg) < MIN_SPA_ENCODED_MSG_SIZE)
386 return(FKO_ERROR_MISSING_ENCODED_DATA);
389 /* Encrypt according to type and return...
391 if(ctx->encryption_type == FKO_ENCRYPTION_RIJNDAEL)
392 res = _rijndael_encrypt(ctx, enc_key);
393 else if(ctx->encryption_type == FKO_ENCRYPTION_GPG)
395 res = gpg_encrypt(ctx, enc_key);
397 res = FKO_ERROR_UNSUPPORTED_FEATURE;
400 res = FKO_ERROR_INVALID_ENCRYPTION_TYPE;
405 /* Decode, decrypt, and parse SPA data into the context.
408 fko_decrypt_spa_data(fko_ctx_t ctx, const char *dec_key)
412 /* Get the (assumed) type of encryption used. This will also provide
413 * some data validation.
415 enc_type = fko_encryption_type(ctx->encrypted_msg);
417 //strlen(ctx->encrypted_msg) < MIN_SPA_ENCODED_MSG_SIZE)
419 if(enc_type == FKO_ENCRYPTION_GPG)
421 ctx->encryption_type = FKO_ENCRYPTION_GPG;
423 res = gpg_decrypt(ctx, dec_key);
425 res = FKO_ERROR_UNSUPPORTED_FEATURE;
428 else if(enc_type == FKO_ENCRYPTION_RIJNDAEL)
430 ctx->encryption_type = FKO_ENCRYPTION_RIJNDAEL;
431 res = _rijndael_decrypt(ctx, dec_key);
434 return(FKO_ERROR_INVALID_DATA);
439 /* Return the assumed encryption type based on the raw encrypted data.
442 fko_encryption_type(const char *enc_data)
446 /* Sanity check the data.
449 return(FKO_ENCRYPTION_INVALID_DATA);
451 /* Determine type of encryption used. For now, we are using the
452 * size of the message.
454 * XXX: We will want to come up with a more reliable method of
455 * identifying the encryption type.
457 enc_data_len = strlen(enc_data);
459 if(enc_data_len >= MIN_GNUPG_MSG_SIZE)
460 return(FKO_ENCRYPTION_GPG);
462 else if(enc_data_len < MIN_GNUPG_MSG_SIZE
463 && enc_data_len >= MIN_SPA_ENCODED_MSG_SIZE)
464 return(FKO_ENCRYPTION_RIJNDAEL);
467 return(FKO_ENCRYPTION_UNKNOWN);
470 /* Set the GPG recipient key name.
473 fko_set_gpg_recipient(fko_ctx_t ctx, const char *recip)
477 gpgme_key_t key = NULL;
479 /* Must be initialized
481 if(!CTX_INITIALIZED(ctx))
482 return(FKO_ERROR_CTX_NOT_INITIALIZED);
484 if(ctx->encryption_type != FKO_ENCRYPTION_GPG)
485 return(FKO_ERROR_WRONG_ENCRYPTION_TYPE);
487 ctx->gpg_recipient = strdup(recip);
488 if(ctx->gpg_recipient == NULL)
489 return(FKO_ERROR_MEMORY_ALLOCATION);
493 res = get_gpg_key(ctx, &key, 0);
494 if(res != FKO_SUCCESS)
496 free(ctx->gpg_recipient);
497 ctx->gpg_recipient = NULL;
501 ctx->recipient_key = key;
503 ctx->state |= FKO_DATA_MODIFIED;
507 return(FKO_ERROR_UNSUPPORTED_FEATURE);
508 #endif /* HAVE_LIBGPGME */
511 /* Set the GPG home dir.
514 fko_set_gpg_exe(fko_ctx_t ctx, const char *gpg_exe)
519 /* Must be initialized
521 if(!CTX_INITIALIZED(ctx))
522 return(FKO_ERROR_CTX_NOT_INITIALIZED);
524 /* If we are unable to stat the given path/file and determine if it
525 * is a regular file or symbolic link, then return with error.
527 if(stat(gpg_exe, &st) != 0)
528 return(FKO_ERROR_GPGME_BAD_GPG_EXE);
530 if(!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode))
531 return(FKO_ERROR_GPGME_BAD_GPG_EXE);
533 ctx->gpg_exe = strdup(gpg_exe);
534 if(ctx->gpg_exe == NULL)
535 return(FKO_ERROR_MEMORY_ALLOCATION);
539 return(FKO_ERROR_UNSUPPORTED_FEATURE);
540 #endif /* HAVE_LIBGPGME */
543 /* Get the GPG home dir.
546 fko_get_gpg_exe(fko_ctx_t ctx, char **gpg_exe)
549 /* Must be initialized
551 if(!CTX_INITIALIZED(ctx))
552 return(FKO_ERROR_CTX_NOT_INITIALIZED);
554 *gpg_exe = ctx->gpg_exe;
558 return(FKO_ERROR_UNSUPPORTED_FEATURE);
559 #endif /* HAVE_LIBGPGME */
562 /* Get the GPG recipient key name.
565 fko_get_gpg_recipient(fko_ctx_t ctx, char **recipient)
568 /* Must be initialized
570 if(!CTX_INITIALIZED(ctx))
571 return(FKO_ERROR_CTX_NOT_INITIALIZED);
573 *recipient = ctx->gpg_recipient;
577 return(FKO_ERROR_UNSUPPORTED_FEATURE);
578 #endif /* HAVE_LIBGPGME */
581 /* Set the GPG signer key name.
584 fko_set_gpg_signer(fko_ctx_t ctx, const char *signer)
588 gpgme_key_t key = NULL;
590 /* Must be initialized
592 if(!CTX_INITIALIZED(ctx))
593 return(FKO_ERROR_CTX_NOT_INITIALIZED);
595 if(ctx->encryption_type != FKO_ENCRYPTION_GPG)
596 return(FKO_ERROR_WRONG_ENCRYPTION_TYPE);
598 ctx->gpg_signer = strdup(signer);
599 if(ctx->gpg_signer == NULL)
600 return(FKO_ERROR_MEMORY_ALLOCATION);
604 res = get_gpg_key(ctx, &key, 1);
605 if(res != FKO_SUCCESS)
607 free(ctx->gpg_signer);
608 ctx->gpg_signer = NULL;
612 ctx->signer_key = key;
614 ctx->state |= FKO_DATA_MODIFIED;
618 return(FKO_ERROR_UNSUPPORTED_FEATURE);
619 #endif /* HAVE_LIBGPGME */
622 /* Get the GPG signer key name.
625 fko_get_gpg_signer(fko_ctx_t ctx, char **signer)
628 /* Must be initialized
630 if(!CTX_INITIALIZED(ctx))
631 return(FKO_ERROR_CTX_NOT_INITIALIZED);
633 *signer = ctx->gpg_signer;
637 return(FKO_ERROR_UNSUPPORTED_FEATURE);
638 #endif /* HAVE_LIBGPGME */
641 /* Set the GPG home dir.
644 fko_set_gpg_home_dir(fko_ctx_t ctx, const char *gpg_home_dir)
649 /* Must be initialized
651 if(!CTX_INITIALIZED(ctx))
652 return(FKO_ERROR_CTX_NOT_INITIALIZED);
654 /* If we are unable to stat the given dir, then return with error.
656 if(stat(gpg_home_dir, &st) != 0)
657 return(FKO_ERROR_GPGME_BAD_HOME_DIR);
659 if(!S_ISDIR(st.st_mode))
660 return(FKO_ERROR_GPGME_BAD_HOME_DIR);
662 ctx->gpg_home_dir = strdup(gpg_home_dir);
663 if(ctx->gpg_home_dir == NULL)
664 return(FKO_ERROR_MEMORY_ALLOCATION);
668 return(FKO_ERROR_UNSUPPORTED_FEATURE);
669 #endif /* HAVE_LIBGPGME */
672 /* Get the GPG home dir.
675 fko_get_gpg_home_dir(fko_ctx_t ctx, char **home_dir)
678 /* Must be initialized
680 if(!CTX_INITIALIZED(ctx))
681 return(FKO_ERROR_CTX_NOT_INITIALIZED);
683 *home_dir = ctx->gpg_home_dir;
687 return(FKO_ERROR_UNSUPPORTED_FEATURE);
688 #endif /* HAVE_LIBGPGME */
692 fko_set_gpg_signature_verify(fko_ctx_t ctx, const unsigned char val)
695 /* Must be initialized
697 if(!CTX_INITIALIZED(ctx))
698 return(FKO_ERROR_CTX_NOT_INITIALIZED);
700 ctx->verify_gpg_sigs = (val != 0) ? 1 : 0;
704 return(FKO_ERROR_UNSUPPORTED_FEATURE);
705 #endif /* HAVE_LIBGPGME */
709 fko_get_gpg_signature_verify(fko_ctx_t ctx, unsigned char *val)
712 /* Must be initialized
714 if(!CTX_INITIALIZED(ctx))
715 return(FKO_ERROR_CTX_NOT_INITIALIZED);
717 *val = ctx->verify_gpg_sigs;
721 return(FKO_ERROR_UNSUPPORTED_FEATURE);
722 #endif /* HAVE_LIBGPGME */
726 fko_set_gpg_ignore_verify_error(fko_ctx_t ctx, const unsigned char val)
729 /* Must be initialized
731 if(!CTX_INITIALIZED(ctx))
732 return(FKO_ERROR_CTX_NOT_INITIALIZED);
734 ctx->ignore_gpg_sig_error = (val != 0) ? 1 : 0;
738 return(FKO_ERROR_UNSUPPORTED_FEATURE);
739 #endif /* HAVE_LIBGPGME */
743 fko_get_gpg_ignore_verify_error(fko_ctx_t ctx, unsigned char *val)
746 /* Must be initialized
748 if(!CTX_INITIALIZED(ctx))
749 return(FKO_ERROR_CTX_NOT_INITIALIZED);
751 *val = ctx->ignore_gpg_sig_error;
755 return(FKO_ERROR_UNSUPPORTED_FEATURE);
756 #endif /* HAVE_LIBGPGME */
761 fko_get_gpg_signature_fpr(fko_ctx_t ctx, char **fpr)
764 /* Must be initialized
766 if(!CTX_INITIALIZED(ctx))
767 return(FKO_ERROR_CTX_NOT_INITIALIZED);
769 /* Must be using GPG encryption.
771 if(ctx->encryption_type != FKO_ENCRYPTION_GPG)
772 return(FKO_ERROR_WRONG_ENCRYPTION_TYPE);
774 /* Make sure we are supposed to verify signatures.
776 if(ctx->verify_gpg_sigs == 0)
777 return(FKO_ERROR_GPGME_SIGNATURE_VERIFY_DISABLED);
779 /* Make sure we have a signature to work with.
781 if(ctx->gpg_sigs == NULL)
782 return(FKO_ERROR_GPGME_NO_SIGNATURE);
784 *fpr = ctx->gpg_sigs->fpr;
788 return(FKO_ERROR_UNSUPPORTED_FEATURE);
789 #endif /* HAVE_LIBGPGME */
793 fko_get_gpg_signature_id(fko_ctx_t ctx, char **id)
796 /* Must be initialized
798 if(!CTX_INITIALIZED(ctx))
799 return(FKO_ERROR_CTX_NOT_INITIALIZED);
801 /* Must be using GPG encryption.
803 if(ctx->encryption_type != FKO_ENCRYPTION_GPG)
804 return(FKO_ERROR_WRONG_ENCRYPTION_TYPE);
806 /* Make sure we are supposed to verify signatures.
808 if(ctx->verify_gpg_sigs == 0)
809 return(FKO_ERROR_GPGME_SIGNATURE_VERIFY_DISABLED);
811 /* Make sure we have a signature to work with.
813 if(ctx->gpg_sigs == NULL)
814 return(FKO_ERROR_GPGME_NO_SIGNATURE);
816 *id = ctx->gpg_sigs->fpr + strlen(ctx->gpg_sigs->fpr) - 8;
820 return(FKO_ERROR_UNSUPPORTED_FEATURE);
821 #endif /* HAVE_LIBGPGME */
825 fko_get_gpg_signature_summary(fko_ctx_t ctx, int *sigsum)
828 /* Must be initialized
830 if(!CTX_INITIALIZED(ctx))
831 return(FKO_ERROR_CTX_NOT_INITIALIZED);
833 /* Must be using GPG encryption.
835 if(ctx->encryption_type != FKO_ENCRYPTION_GPG)
836 return(FKO_ERROR_WRONG_ENCRYPTION_TYPE);
838 /* Make sure we are supposed to verify signatures.
840 if(ctx->verify_gpg_sigs == 0)
841 return(FKO_ERROR_GPGME_SIGNATURE_VERIFY_DISABLED);
843 /* Make sure we have a signature to work with.
845 if(ctx->gpg_sigs == NULL)
846 return(FKO_ERROR_GPGME_NO_SIGNATURE);
848 *sigsum = ctx->gpg_sigs->summary;
852 return(FKO_ERROR_UNSUPPORTED_FEATURE);
853 #endif /* HAVE_LIBGPGME */
857 fko_get_gpg_signature_status(fko_ctx_t ctx, int *sigstat)
860 /* Must be initialized
862 if(!CTX_INITIALIZED(ctx))
863 return(FKO_ERROR_CTX_NOT_INITIALIZED);
865 /* Must be using GPG encryption.
867 if(ctx->encryption_type != FKO_ENCRYPTION_GPG)
868 return(FKO_ERROR_WRONG_ENCRYPTION_TYPE);
870 /* Make sure we are supposed to verify signatures.
872 if(ctx->verify_gpg_sigs == 0)
873 return(FKO_ERROR_GPGME_SIGNATURE_VERIFY_DISABLED);
875 /* Make sure we have a signature to work with.
877 if(ctx->gpg_sigs == NULL)
878 return(FKO_ERROR_GPGME_NO_SIGNATURE);
880 *sigstat = ctx->gpg_sigs->status;
884 return(FKO_ERROR_UNSUPPORTED_FEATURE);
885 #endif /* HAVE_LIBGPGME */
889 fko_gpg_signature_id_match(fko_ctx_t ctx, const char *id, unsigned char *result)
894 /* Must be initialized
896 if(!CTX_INITIALIZED(ctx))
897 return(FKO_ERROR_CTX_NOT_INITIALIZED);
899 /* Must be using GPG encryption.
901 if(ctx->encryption_type != FKO_ENCRYPTION_GPG)
902 return(FKO_ERROR_WRONG_ENCRYPTION_TYPE);
904 /* Make sure we are supposed to verify signatures.
906 if(ctx->verify_gpg_sigs == 0)
907 return(FKO_ERROR_GPGME_SIGNATURE_VERIFY_DISABLED);
909 /* Make sure we have a signature to work with.
911 if(ctx->gpg_sigs == NULL)
912 return(FKO_ERROR_GPGME_NO_SIGNATURE);
914 fko_get_gpg_signature_id(ctx, &curr_id);
916 *result = strcmp(id, curr_id) == 0 ? 1 : 0;
920 return(FKO_ERROR_UNSUPPORTED_FEATURE);
921 #endif /* HAVE_LIBGPGME */
925 fko_gpg_signature_fpr_match(fko_ctx_t ctx, const char *id, unsigned char *result)
928 /* Must be initialized
930 if(!CTX_INITIALIZED(ctx))
931 return(FKO_ERROR_CTX_NOT_INITIALIZED);
933 /* Must be using GPG encryption.
935 if(ctx->encryption_type != FKO_ENCRYPTION_GPG)
936 return(FKO_ERROR_WRONG_ENCRYPTION_TYPE);
938 /* Make sure we are supposed to verify signatures.
940 if(ctx->verify_gpg_sigs == 0)
941 return(FKO_ERROR_GPGME_SIGNATURE_VERIFY_DISABLED);
943 /* Make sure we have a signature to work with.
945 if(ctx->gpg_sigs == NULL)
946 return(FKO_ERROR_GPGME_NO_SIGNATURE);
948 *result = strcmp(id, ctx->gpg_sigs->fpr) == 0 ? 1 : 0;
952 return(FKO_ERROR_UNSUPPORTED_FEATURE);
953 #endif /* HAVE_LIBGPGME */