2001-11-21 09:42:08 +00:00
|
|
|
|
/* -*- Mode: C -*-
|
|
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
|
|
|
|
|
|
GPGMEPLUG - an GPGME based cryptography plug-in following
|
|
|
|
|
the common CRYPTPLUG specification.
|
|
|
|
|
|
|
|
|
|
Copyright (C) 2001 by Klar<EFBFBD>lvdalens Datakonsult AB
|
2002-07-01 13:01:51 +00:00
|
|
|
|
Copyright (C) 2002 g10 Code GmbH
|
2001-11-21 09:42:08 +00:00
|
|
|
|
|
|
|
|
|
GPGMEPLUG is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; version 2 of the License.
|
|
|
|
|
|
|
|
|
|
GPGMEPLUG is distributed in the hope that it will be useful,
|
|
|
|
|
it under the terms of GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; version 2 of the License
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*! \file gpgmeplug.c
|
|
|
|
|
\brief GPGME implementation of CRYPTPLUG following the
|
|
|
|
|
specification located in common API header cryptplug.h.
|
|
|
|
|
|
|
|
|
|
CRYPTPLUG is an independent cryptography plug-in API
|
|
|
|
|
developed for Sphinx-enabeling KMail and Mutt.
|
|
|
|
|
|
|
|
|
|
CRYPTPLUG was designed for the Aegypten project, but it may
|
|
|
|
|
be used by 3rd party developers as well to design pluggable
|
|
|
|
|
crypto backends for the above mentioned MUAs.
|
|
|
|
|
|
|
|
|
|
\note All string parameters appearing in this API are to be
|
|
|
|
|
interpreted as UTF-8 encoded.
|
|
|
|
|
|
|
|
|
|
\see cryptplug.h
|
|
|
|
|
*/
|
|
|
|
|
|
2001-11-21 21:08:02 +00:00
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2001-11-21 09:42:08 +00:00
|
|
|
|
#include <config.h>
|
2001-11-21 21:08:02 +00:00
|
|
|
|
#endif
|
2001-11-21 09:42:08 +00:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <errno.h>
|
2001-11-25 21:53:39 +00:00
|
|
|
|
#include <time.h>
|
2002-03-07 14:10:07 +00:00
|
|
|
|
#include <ctype.h>
|
2001-11-21 09:42:08 +00:00
|
|
|
|
|
2002-01-14 20:33:50 +00:00
|
|
|
|
#ifndef BUG_URL
|
|
|
|
|
#define BUG_URL "http:://www.gnupg.org/aegypten/"
|
|
|
|
|
#endif
|
|
|
|
|
|
2001-11-21 23:34:51 +00:00
|
|
|
|
#include "gpgme.h"
|
2001-11-22 18:48:53 +00:00
|
|
|
|
#ifndef GPGMEPLUG_PROTOCOL
|
|
|
|
|
#define GPGMEPLUG_PROTOCOL GPGME_PROTOCOL_OpenPGP
|
|
|
|
|
#endif
|
2001-11-21 09:42:08 +00:00
|
|
|
|
|
2002-03-23 11:35:31 +00:00
|
|
|
|
/* definitions for signing */
|
2002-07-01 13:01:51 +00:00
|
|
|
|
/* 1. opaque signatures (only used for S/MIME). */
|
2002-06-12 11:05:42 +00:00
|
|
|
|
#ifndef GPGMEPLUG_OPA_SIGN_MAKE_MIME_OBJECT
|
|
|
|
|
#define GPGMEPLUG_OPA_SIGN_INCLUDE_CLEARTEXT false
|
|
|
|
|
#define GPGMEPLUG_OPA_SIGN_MAKE_MIME_OBJECT false
|
|
|
|
|
#define GPGMEPLUG_OPA_SIGN_MAKE_MULTI_MIME false
|
|
|
|
|
#define GPGMEPLUG_OPA_SIGN_CTYPE_MAIN ""
|
|
|
|
|
#define GPGMEPLUG_OPA_SIGN_CDISP_MAIN ""
|
|
|
|
|
#define GPGMEPLUG_OPA_SIGN_CTENC_MAIN ""
|
|
|
|
|
#define GPGMEPLUG_OPA_SIGN_CTYPE_VERSION ""
|
|
|
|
|
#define GPGMEPLUG_OPA_SIGN_CDISP_VERSION ""
|
|
|
|
|
#define GPGMEPLUG_OPA_SIGN_CTENC_VERSION ""
|
|
|
|
|
#define GPGMEPLUG_OPA_SIGN_BTEXT_VERSION ""
|
|
|
|
|
#define GPGMEPLUG_OPA_SIGN_CTYPE_CODE ""
|
|
|
|
|
#define GPGMEPLUG_OPA_SIGN_CDISP_CODE ""
|
|
|
|
|
#define GPGMEPLUG_OPA_SIGN_CTENC_CODE ""
|
|
|
|
|
#define GPGMEPLUG_OPA_SIGN_FLAT_PREFIX ""
|
|
|
|
|
#define GPGMEPLUG_OPA_SIGN_FLAT_SEPARATOR ""
|
|
|
|
|
#define GPGMEPLUG_OPA_SIGN_FLAT_POSTFIX ""
|
|
|
|
|
#endif
|
2002-07-01 13:01:51 +00:00
|
|
|
|
/* 2. detached signatures (used for S/MIME and for OpenPGP) */
|
2002-06-12 11:05:42 +00:00
|
|
|
|
#ifndef GPGMEPLUG_DET_SIGN_MAKE_MIME_OBJECT
|
|
|
|
|
#define GPGMEPLUG_DET_SIGN_INCLUDE_CLEARTEXT true
|
|
|
|
|
#define GPGMEPLUG_DET_SIGN_MAKE_MIME_OBJECT true
|
|
|
|
|
#define GPGMEPLUG_DET_SIGN_MAKE_MULTI_MIME true
|
|
|
|
|
#define GPGMEPLUG_DET_SIGN_CTYPE_MAIN "multipart/signed;protocol=application/pgp-signature;micalg=pgp-sha1"
|
|
|
|
|
#define GPGMEPLUG_DET_SIGN_CDISP_MAIN ""
|
|
|
|
|
#define GPGMEPLUG_DET_SIGN_CTENC_MAIN ""
|
|
|
|
|
#define GPGMEPLUG_DET_SIGN_CTYPE_VERSION ""
|
|
|
|
|
#define GPGMEPLUG_DET_SIGN_CDISP_VERSION ""
|
|
|
|
|
#define GPGMEPLUG_DET_SIGN_CTENC_VERSION ""
|
|
|
|
|
#define GPGMEPLUG_DET_SIGN_BTEXT_VERSION ""
|
|
|
|
|
#define GPGMEPLUG_DET_SIGN_CTYPE_CODE "application/pgp-signature"
|
|
|
|
|
#define GPGMEPLUG_DET_SIGN_CDISP_CODE ""
|
|
|
|
|
#define GPGMEPLUG_DET_SIGN_CTENC_CODE ""
|
|
|
|
|
#define GPGMEPLUG_DET_SIGN_FLAT_PREFIX ""
|
|
|
|
|
#define GPGMEPLUG_DET_SIGN_FLAT_SEPARATOR ""
|
|
|
|
|
#define GPGMEPLUG_DET_SIGN_FLAT_POSTFIX ""
|
|
|
|
|
#endif
|
2002-07-01 13:01:51 +00:00
|
|
|
|
/* 3. common definitions for opaque and detached signing */
|
2002-06-12 11:05:42 +00:00
|
|
|
|
#ifndef __GPGMEPLUG_SIGNATURE_CODE_IS_BINARY
|
2002-03-22 10:40:24 +00:00
|
|
|
|
#define __GPGMEPLUG_SIGNATURE_CODE_IS_BINARY false
|
2001-12-24 00:09:24 +00:00
|
|
|
|
#endif
|
2002-06-12 11:05:42 +00:00
|
|
|
|
|
2002-04-27 05:32:39 +00:00
|
|
|
|
#define __GPGMEPLUG_ERROR_CLEARTEXT_IS_ZERO "Error: Cannot run checkMessageSignature() with cleartext == 0"
|
2002-06-12 11:05:42 +00:00
|
|
|
|
|
2002-03-23 11:35:31 +00:00
|
|
|
|
/* definitions for encoding */
|
2001-12-24 00:09:24 +00:00
|
|
|
|
#ifndef GPGMEPLUG_ENC_MAKE_MIME_OBJECT
|
|
|
|
|
#define GPGMEPLUG_ENC_INCLUDE_CLEARTEXT false
|
|
|
|
|
#define GPGMEPLUG_ENC_MAKE_MIME_OBJECT true
|
|
|
|
|
#define GPGMEPLUG_ENC_MAKE_MULTI_MIME true
|
|
|
|
|
#define GPGMEPLUG_ENC_CTYPE_MAIN "multipart/encrypted; protocol=application/pgp-encrypted"
|
|
|
|
|
#define GPGMEPLUG_ENC_CDISP_MAIN ""
|
|
|
|
|
#define GPGMEPLUG_ENC_CTENC_MAIN ""
|
|
|
|
|
#define GPGMEPLUG_ENC_CTYPE_VERSION "application/pgp-encrypted"
|
|
|
|
|
#define GPGMEPLUG_ENC_CDISP_VERSION "attachment"
|
|
|
|
|
#define GPGMEPLUG_ENC_CTENC_VERSION ""
|
|
|
|
|
#define GPGMEPLUG_ENC_BTEXT_VERSION "Version: 1"
|
|
|
|
|
#define GPGMEPLUG_ENC_CTYPE_CODE "application/octet-stream"
|
|
|
|
|
#define GPGMEPLUG_ENC_CDISP_CODE "inline; filename=\"msg.asc\""
|
|
|
|
|
#define GPGMEPLUG_ENC_CTENC_CODE ""
|
|
|
|
|
#define GPGMEPLUG_ENC_FLAT_PREFIX ""
|
|
|
|
|
#define GPGMEPLUG_ENC_FLAT_SEPARATOR ""
|
|
|
|
|
#define GPGMEPLUG_ENC_FLAT_POSTFIX ""
|
2002-03-22 10:40:24 +00:00
|
|
|
|
#define __GPGMEPLUG_ENCRYPTED_CODE_IS_BINARY false
|
2001-12-24 00:09:24 +00:00
|
|
|
|
#endif
|
2002-03-23 11:35:31 +00:00
|
|
|
|
/* Note: The following specification will result in
|
|
|
|
|
function encryptAndSignMessage() producing
|
|
|
|
|
_empty_ mails.
|
|
|
|
|
This must be changed as soon as our plugin
|
|
|
|
|
is supporting the encryptAndSignMessage() function. */
|
2001-12-24 00:09:24 +00:00
|
|
|
|
#ifndef GPGMEPLUG_ENCSIGN_MAKE_MIME_OBJECT
|
|
|
|
|
#define GPGMEPLUG_ENCSIGN_INCLUDE_CLEARTEXT false
|
|
|
|
|
#define GPGMEPLUG_ENCSIGN_MAKE_MIME_OBJECT false
|
|
|
|
|
#define GPGMEPLUG_ENCSIGN_MAKE_MULTI_MIME false
|
|
|
|
|
#define GPGMEPLUG_ENCSIGN_CTYPE_MAIN ""
|
|
|
|
|
#define GPGMEPLUG_ENCSIGN_CDISP_MAIN ""
|
|
|
|
|
#define GPGMEPLUG_ENCSIGN_CTENC_MAIN ""
|
|
|
|
|
#define GPGMEPLUG_ENCSIGN_CTYPE_VERSION ""
|
|
|
|
|
#define GPGMEPLUG_ENCSIGN_CDISP_VERSION ""
|
|
|
|
|
#define GPGMEPLUG_ENCSIGN_CTENC_VERSION ""
|
|
|
|
|
#define GPGMEPLUG_ENCSIGN_BTEXT_VERSION ""
|
|
|
|
|
#define GPGMEPLUG_ENCSIGN_CTYPE_CODE ""
|
|
|
|
|
#define GPGMEPLUG_ENCSIGN_CDISP_CODE ""
|
|
|
|
|
#define GPGMEPLUG_ENCSIGN_CTENC_CODE ""
|
|
|
|
|
#define GPGMEPLUG_ENCSIGN_FLAT_PREFIX ""
|
|
|
|
|
#define GPGMEPLUG_ENCSIGN_FLAT_SEPARATOR ""
|
|
|
|
|
#define GPGMEPLUG_ENCSIGN_FLAT_POSTFIX ""
|
|
|
|
|
#endif
|
|
|
|
|
|
2001-11-21 09:42:08 +00:00
|
|
|
|
#include "cryptplug.h"
|
|
|
|
|
|
|
|
|
|
|
2002-06-28 14:51:12 +00:00
|
|
|
|
#define days_from_seconds(x) ((x)/86400)
|
|
|
|
|
|
|
|
|
|
|
2001-11-21 09:42:08 +00:00
|
|
|
|
typedef struct {
|
2002-01-14 20:33:50 +00:00
|
|
|
|
const char* bugURL;
|
2001-11-21 09:42:08 +00:00
|
|
|
|
const char* signatureKeyCertificate;
|
|
|
|
|
SignatureAlgorithm signatureAlgorithm;
|
2002-06-12 11:05:42 +00:00
|
|
|
|
SignatureCompoundMode signatureCompoundMode;
|
2001-11-21 09:42:08 +00:00
|
|
|
|
SendCertificates sendCertificates;
|
|
|
|
|
SignEmail signEmail;
|
|
|
|
|
bool saveSentSignatures;
|
|
|
|
|
bool warnNoCertificate;
|
|
|
|
|
PinRequests numPINRequests;
|
|
|
|
|
bool checkSignatureCertificatePathToRoot;
|
|
|
|
|
bool signatureUseCRLs;
|
|
|
|
|
EncryptionAlgorithm encryptionAlgorithm;
|
|
|
|
|
EncryptEmail encryptEmail;
|
|
|
|
|
bool saveMessagesEncrypted;
|
|
|
|
|
bool checkEncryptionCertificatePathToRoot;
|
|
|
|
|
bool encryptionUseCRLs;
|
|
|
|
|
bool encryptionCRLExpiryNearWarning;
|
|
|
|
|
int encryptionCRLNearExpiryInterval;
|
|
|
|
|
struct DirectoryServer *directoryServers;
|
|
|
|
|
unsigned int numDirectoryServers;
|
|
|
|
|
CertificateSource certificateSource;
|
|
|
|
|
CertificateSource cRLSource;
|
2001-11-21 10:55:02 +00:00
|
|
|
|
bool warnSendUnsigned;
|
|
|
|
|
int numPINRequestsInterval;
|
|
|
|
|
bool signatureCertificateExpiryNearWarning;
|
|
|
|
|
int signatureCertificateExpiryNearInterval;
|
|
|
|
|
bool cACertificateExpiryNearWarning;
|
|
|
|
|
int cACertificateExpiryNearInterval;
|
|
|
|
|
bool rootCertificateExpiryNearWarning;
|
|
|
|
|
int rootCertificateExpiryNearInterval;
|
|
|
|
|
bool warnSendUnencrypted;
|
|
|
|
|
bool checkCertificatePath;
|
|
|
|
|
bool receiverCertificateExpiryNearWarning;
|
|
|
|
|
int receiverCertificateExpiryNearWarningInterval;
|
|
|
|
|
bool certificateInChainExpiryNearWarning;
|
|
|
|
|
int certificateInChainExpiryNearWarningInterval;
|
|
|
|
|
bool receiverEmailAddressNotInCertificateWarning;
|
2002-07-01 13:01:51 +00:00
|
|
|
|
const char* libVersion; /* a statically allocated string with the GPGME Version used */
|
2001-11-21 09:42:08 +00:00
|
|
|
|
} Config;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Config config;
|
|
|
|
|
|
2001-11-21 10:55:02 +00:00
|
|
|
|
#define NEAR_EXPIRY 14
|
2001-11-21 09:42:08 +00:00
|
|
|
|
|
2002-07-01 13:01:51 +00:00
|
|
|
|
/* Max number of parts in a DN */
|
|
|
|
|
#define MAX_GPGME_IDX 20
|
|
|
|
|
|
|
|
|
|
/* some macros to replace ctype ones and avoid locale problems */
|
|
|
|
|
#define spacep(p) (*(p) == ' ' || *(p) == '\t')
|
|
|
|
|
#define digitp(p) (*(p) >= '0' && *(p) <= '9')
|
|
|
|
|
#define hexdigitp(a) (digitp (a) \
|
|
|
|
|
|| (*(a) >= 'A' && *(a) <= 'F') \
|
|
|
|
|
|| (*(a) >= 'a' && *(a) <= 'f'))
|
|
|
|
|
/* the atoi macros assume that the buffer has only valid digits */
|
|
|
|
|
#define atoi_1(p) (*(p) - '0' )
|
|
|
|
|
#define atoi_2(p) ((atoi_1(p) * 10) + atoi_1((p)+1))
|
|
|
|
|
#define atoi_4(p) ((atoi_2(p) * 100) + atoi_2((p)+2))
|
|
|
|
|
#define xtoi_1(p) (*(p) <= '9'? (*(p)- '0'): \
|
|
|
|
|
*(p) <= 'F'? (*(p)-'A'+10):(*(p)-'a'+10))
|
|
|
|
|
#define xtoi_2(p) ((xtoi_1(p) * 16) + xtoi_1((p)+1))
|
|
|
|
|
|
|
|
|
|
static void *
|
|
|
|
|
xmalloc (size_t n)
|
|
|
|
|
{
|
|
|
|
|
char *p = malloc (n);
|
|
|
|
|
if (!p)
|
|
|
|
|
{
|
|
|
|
|
fputs ("\nfatal: out of core\n", stderr);
|
|
|
|
|
exit (4);
|
|
|
|
|
}
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Please: Don't call an allocation function xfoo when it may return NULL. */
|
|
|
|
|
/* Wrong: #define xstrdup( x ) (x)?strdup(x):0 */
|
|
|
|
|
/* Right: */
|
|
|
|
|
static char *
|
|
|
|
|
xstrdup (const char *string)
|
|
|
|
|
{
|
2002-07-01 13:09:18 +00:00
|
|
|
|
char *p = xmalloc (strlen (string)+1);
|
2002-07-01 13:01:51 +00:00
|
|
|
|
strcpy (p, string);
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-11-21 09:42:08 +00:00
|
|
|
|
bool initialize()
|
|
|
|
|
{
|
2002-10-31 13:14:41 +00:00
|
|
|
|
int engineCheckVersion = gpgme_engine_check_version (GPGMEPLUG_PROTOCOL);
|
2002-01-14 20:33:50 +00:00
|
|
|
|
config.bugURL = malloc( strlen( BUG_URL ) + 1 );
|
|
|
|
|
strcpy( (char* )config.bugURL, BUG_URL );
|
|
|
|
|
config.signatureKeyCertificate = malloc( 1 );
|
|
|
|
|
strcpy( (char* )config.signatureKeyCertificate, "" );
|
2001-11-21 09:42:08 +00:00
|
|
|
|
config.signatureAlgorithm = SignAlg_SHA1;
|
2002-06-12 11:05:42 +00:00
|
|
|
|
if( GPGMEPLUG_PROTOCOL == GPGME_PROTOCOL_CMS )
|
|
|
|
|
config.signatureCompoundMode = SignatureCompoundMode_Opaque;
|
|
|
|
|
else
|
|
|
|
|
config.signatureCompoundMode = SignatureCompoundMode_Detached;
|
2001-11-21 09:42:08 +00:00
|
|
|
|
config.sendCertificates = SendCert_SendChainWithRoot;
|
|
|
|
|
config.signEmail = SignEmail_SignAll;
|
|
|
|
|
config.saveSentSignatures = true;
|
|
|
|
|
config.warnNoCertificate = true;
|
|
|
|
|
config.numPINRequests = PinRequest_Always;
|
|
|
|
|
config.checkSignatureCertificatePathToRoot = true;
|
|
|
|
|
config.signatureUseCRLs = true;
|
|
|
|
|
config.encryptionAlgorithm = EncryptAlg_RSA;
|
|
|
|
|
config.encryptEmail = EncryptEmail_Ask;
|
|
|
|
|
config.saveMessagesEncrypted = true;
|
|
|
|
|
config.checkEncryptionCertificatePathToRoot = true;
|
|
|
|
|
config.encryptionUseCRLs = true;
|
|
|
|
|
config.encryptionCRLExpiryNearWarning = true;
|
|
|
|
|
config.encryptionCRLNearExpiryInterval = NEAR_EXPIRY;
|
|
|
|
|
config.directoryServers = NULL;
|
|
|
|
|
config.numDirectoryServers = 0;
|
|
|
|
|
config.certificateSource = CertSrc_Server;
|
|
|
|
|
config.cRLSource = CertSrc_Server;
|
2001-11-21 10:55:02 +00:00
|
|
|
|
config.warnSendUnsigned = true;
|
|
|
|
|
config.numPINRequestsInterval = NEAR_EXPIRY;
|
|
|
|
|
config.signatureCertificateExpiryNearWarning = true;
|
|
|
|
|
config.signatureCertificateExpiryNearInterval = NEAR_EXPIRY;
|
|
|
|
|
config.cACertificateExpiryNearWarning = true;
|
|
|
|
|
config.cACertificateExpiryNearInterval = NEAR_EXPIRY;
|
|
|
|
|
config.rootCertificateExpiryNearWarning = true;
|
|
|
|
|
config.rootCertificateExpiryNearInterval = NEAR_EXPIRY;
|
|
|
|
|
config.warnSendUnencrypted = false;
|
|
|
|
|
config.checkCertificatePath = true;
|
|
|
|
|
config.receiverCertificateExpiryNearWarning = true;
|
|
|
|
|
config.receiverCertificateExpiryNearWarningInterval = NEAR_EXPIRY;
|
|
|
|
|
config.certificateInChainExpiryNearWarning = true;
|
|
|
|
|
config.certificateInChainExpiryNearWarningInterval = NEAR_EXPIRY;
|
|
|
|
|
config.receiverEmailAddressNotInCertificateWarning = true;
|
2002-06-19 12:56:43 +00:00
|
|
|
|
config.libVersion = gpgme_check_version (NULL);
|
2002-10-31 13:14:41 +00:00
|
|
|
|
if( engineCheckVersion != GPGME_No_Error )
|
|
|
|
|
fprintf( stderr, "gpgmeplug initialize() returned %i\n", engineCheckVersion );
|
|
|
|
|
return (engineCheckVersion == GPGME_No_Error);
|
2001-11-21 09:42:08 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void deinitialize()
|
|
|
|
|
{
|
2001-11-21 16:57:54 +00:00
|
|
|
|
unsigned int i;
|
|
|
|
|
for( i = 0; i < config.numDirectoryServers; ++i ) {
|
2001-11-21 21:08:02 +00:00
|
|
|
|
free( (char *)config.directoryServers[i].servername );
|
|
|
|
|
free( (char *)config.directoryServers[i].description );
|
2001-11-21 16:57:54 +00:00
|
|
|
|
}
|
2001-11-21 21:08:02 +00:00
|
|
|
|
free( config.directoryServers );
|
2001-11-21 09:42:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool hasFeature( Feature flag )
|
|
|
|
|
{
|
2002-03-23 11:35:31 +00:00
|
|
|
|
/* our own plugins are supposed to support everything */
|
2001-11-21 09:42:08 +00:00
|
|
|
|
switch ( flag ) {
|
2002-03-21 13:14:20 +00:00
|
|
|
|
case Feature_SignMessages: return true;
|
|
|
|
|
case Feature_VerifySignatures: return true;
|
|
|
|
|
case Feature_EncryptMessages: return true;
|
|
|
|
|
case Feature_DecryptMessages: return true;
|
|
|
|
|
case Feature_SendCertificates: return true;
|
|
|
|
|
case Feature_WarnSignCertificateExpiry: return true;
|
|
|
|
|
case Feature_WarnSignEmailNotInCertificate: return true;
|
|
|
|
|
case Feature_PinEntrySettings: return true;
|
|
|
|
|
case Feature_StoreMessagesWithSigs: return true;
|
|
|
|
|
case Feature_EncryptionCRLs: return true;
|
|
|
|
|
case Feature_WarnEncryptCertificateExpiry: return true;
|
|
|
|
|
case Feature_WarnEncryptEmailNotInCertificate: return true;
|
|
|
|
|
case Feature_StoreMessagesEncrypted: return true;
|
|
|
|
|
case Feature_CheckCertificatePath: return true;
|
2002-06-26 15:16:32 +00:00
|
|
|
|
case Feature_CertificateDirectoryService: return false;
|
|
|
|
|
case Feature_CRLDirectoryService: return false;
|
2002-03-23 11:35:31 +00:00
|
|
|
|
/* undefined or not yet implemented: */
|
2002-03-21 13:14:20 +00:00
|
|
|
|
case Feature_undef: return false;
|
|
|
|
|
default: return false;
|
2001-11-21 09:42:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-06-19 12:56:43 +00:00
|
|
|
|
const char* libVersion(){ return config.libVersion; }
|
|
|
|
|
|
|
|
|
|
|
2002-01-14 20:33:50 +00:00
|
|
|
|
const char* bugURL(){ return config.bugURL; }
|
|
|
|
|
|
|
|
|
|
|
2001-11-21 09:42:08 +00:00
|
|
|
|
void unsafeStationery( void** pixmap, const char** menutext, char* accel,
|
|
|
|
|
const char** tooltip, const char** statusbartext ){}
|
|
|
|
|
|
|
|
|
|
void signedStationery( void** pixmap, const char** menutext, char* accel,
|
|
|
|
|
const char** tooltip, const char** statusbartext ){}
|
|
|
|
|
|
|
|
|
|
void encryptedStationery( void** pixmap, const char**
|
|
|
|
|
menutext, char* accel,
|
|
|
|
|
const char** tooltip, const char** statusbartext ){}
|
|
|
|
|
|
|
|
|
|
void signedEncryptedStationery( void** pixmap, const char**
|
|
|
|
|
menutext, char* accel,
|
|
|
|
|
const char** tooltip, const char** statusbartext ){}
|
|
|
|
|
|
|
|
|
|
const char* signatureConfigurationDialog(){ return 0; }
|
|
|
|
|
|
|
|
|
|
const char* signatureKeySelectionDialog(){ return 0; }
|
|
|
|
|
|
|
|
|
|
const char* signatureAlgorithmDialog(){ return 0; }
|
|
|
|
|
|
|
|
|
|
const char* signatureHandlingDialog(){ return 0; }
|
|
|
|
|
|
|
|
|
|
void setSignatureKeyCertificate( const char* certificate )
|
|
|
|
|
{
|
|
|
|
|
config.signatureKeyCertificate = certificate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char* signatureKeyCertificate()
|
|
|
|
|
{
|
|
|
|
|
return config.signatureKeyCertificate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setSignatureAlgorithm( SignatureAlgorithm sigAlg )
|
|
|
|
|
{
|
|
|
|
|
config.signatureAlgorithm = sigAlg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SignatureAlgorithm signatureAlgorithm()
|
|
|
|
|
{
|
|
|
|
|
return config.signatureAlgorithm;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-12 11:05:42 +00:00
|
|
|
|
void setSignatureCompoundMode( SignatureCompoundMode signComp )
|
|
|
|
|
{
|
|
|
|
|
config.signatureCompoundMode = signComp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SignatureCompoundMode signatureCompoundMode()
|
|
|
|
|
{
|
|
|
|
|
return config.signatureCompoundMode;
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-21 09:42:08 +00:00
|
|
|
|
void setSendCertificates( SendCertificates sendCert )
|
|
|
|
|
{
|
|
|
|
|
config.sendCertificates = sendCert;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendCertificates sendCertificates()
|
|
|
|
|
{
|
|
|
|
|
return config.sendCertificates;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setSignEmail( SignEmail signMail )
|
|
|
|
|
{
|
|
|
|
|
config.signEmail = signMail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SignEmail signEmail()
|
|
|
|
|
{
|
|
|
|
|
return config.signEmail;
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-21 10:55:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setWarnSendUnsigned( bool flag )
|
2001-11-21 09:42:08 +00:00
|
|
|
|
{
|
2001-11-21 10:55:02 +00:00
|
|
|
|
config.warnSendUnsigned = flag;
|
2001-11-21 09:42:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-21 10:55:02 +00:00
|
|
|
|
bool warnSendUnsigned()
|
2001-11-21 09:42:08 +00:00
|
|
|
|
{
|
2001-11-21 10:55:02 +00:00
|
|
|
|
return config.warnSendUnsigned;
|
2001-11-21 09:42:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-21 10:55:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setSaveSentSignatures( bool flag )
|
2001-11-21 09:42:08 +00:00
|
|
|
|
{
|
2001-11-21 10:55:02 +00:00
|
|
|
|
config.saveSentSignatures = flag;
|
2001-11-21 09:42:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-21 10:55:02 +00:00
|
|
|
|
bool saveSentSignatures()
|
2001-11-21 09:42:08 +00:00
|
|
|
|
{
|
2001-11-21 10:55:02 +00:00
|
|
|
|
return config.saveSentSignatures;
|
2001-11-21 09:42:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setWarnNoCertificate( bool flag )
|
|
|
|
|
{
|
|
|
|
|
config.warnNoCertificate = flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool warnNoCertificate()
|
|
|
|
|
{
|
|
|
|
|
return config.warnNoCertificate;
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-28 12:09:45 +00:00
|
|
|
|
|
2002-10-31 13:14:41 +00:00
|
|
|
|
bool isEmailInCertificate( const char* email, const char* fingerprint )
|
2002-02-28 12:09:45 +00:00
|
|
|
|
{
|
2002-10-31 13:14:41 +00:00
|
|
|
|
GpgmeCtx ctx;
|
|
|
|
|
GpgmeError err;
|
|
|
|
|
GpgmeKey rKey;
|
|
|
|
|
int UID_idx;
|
|
|
|
|
const char* attr_string;
|
|
|
|
|
int emailCount = 0;
|
|
|
|
|
bool bOk = false;
|
2002-10-31 13:59:38 +00:00
|
|
|
|
int fprLen = strlen( fingerprint );
|
2002-10-31 13:14:41 +00:00
|
|
|
|
|
2002-10-31 13:59:38 +00:00
|
|
|
|
fprintf( stderr, "gpgmeplug isEmailInCertificate looking for fingerprint %s\n", fingerprint );
|
|
|
|
|
|
2002-10-31 13:14:41 +00:00
|
|
|
|
gpgme_new( &ctx );
|
|
|
|
|
gpgme_set_protocol( ctx, GPGMEPLUG_PROTOCOL );
|
|
|
|
|
|
|
|
|
|
err = gpgme_op_keylist_start( ctx, fingerprint, 0 );
|
|
|
|
|
if ( GPGME_No_Error == err ) {
|
|
|
|
|
err = gpgme_op_keylist_next( ctx, &rKey );
|
|
|
|
|
gpgme_op_keylist_end( ctx );
|
|
|
|
|
if ( GPGME_No_Error == err ) {
|
|
|
|
|
/* extract email(s) */
|
|
|
|
|
for( UID_idx = 0;
|
|
|
|
|
(attr_string = gpgme_key_get_string_attr(
|
|
|
|
|
rKey, GPGME_ATTR_EMAIL, 0, UID_idx ) );
|
|
|
|
|
++UID_idx ){
|
2002-10-31 13:59:38 +00:00
|
|
|
|
if (attr_string && *attr_string) {
|
2002-10-31 13:14:41 +00:00
|
|
|
|
++emailCount;
|
|
|
|
|
fprintf( stderr, "gpgmeplug isEmailInCertificate found email: %s\n", attr_string );
|
|
|
|
|
if( 0 == strcasecmp(attr_string, email) ){
|
|
|
|
|
bOk = true;
|
|
|
|
|
break;
|
2002-10-31 13:59:38 +00:00
|
|
|
|
}else{
|
|
|
|
|
attr_string = gpgme_key_get_string_attr(
|
|
|
|
|
rKey, GPGME_ATTR_USERID, 0, UID_idx );
|
|
|
|
|
if (attr_string && *attr_string == '<'){
|
|
|
|
|
++attr_string;
|
|
|
|
|
if( 0 == strncasecmp(attr_string, email, fprLen) ){
|
|
|
|
|
bOk = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-10-31 13:14:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if( !emailCount )
|
|
|
|
|
fprintf( stderr, "gpgmeplug isEmailInCertificate found NO EMAIL\n" );
|
|
|
|
|
else if( !bOk )
|
|
|
|
|
fprintf( stderr, "gpgmeplug isEmailInCertificate found NO MATCHING email\n" );
|
|
|
|
|
gpgme_key_release( rKey );
|
|
|
|
|
}else{
|
|
|
|
|
fprintf( stderr, "gpgmeplug isEmailInCertificate found NO CERTIFICATE for fingerprint %s\n", fingerprint );
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
fprintf( stderr, "gpgmeplug isEmailInCertificate could NOT open KEYLIST for fingerprint %s\n", fingerprint );
|
|
|
|
|
}
|
|
|
|
|
gpgme_release( ctx );
|
|
|
|
|
|
|
|
|
|
return bOk;
|
2002-02-28 12:09:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-21 09:42:08 +00:00
|
|
|
|
void setNumPINRequests( PinRequests reqMode )
|
|
|
|
|
{
|
|
|
|
|
config.numPINRequests = reqMode;
|
2002-03-01 16:55:50 +00:00
|
|
|
|
|
|
|
|
|
/* PENDING(g10) Put this value into gpg and make it ask for the pin
|
|
|
|
|
according to this. Note that there is also
|
|
|
|
|
setNumPINRequestsInterval() which is only used if reqMode ==
|
|
|
|
|
PinRequest_AfterMinutes.
|
|
|
|
|
*/
|
2001-11-21 09:42:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PinRequests numPINRequests()
|
|
|
|
|
{
|
|
|
|
|
return config.numPINRequests;
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-21 10:55:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setNumPINRequestsInterval( int interval )
|
|
|
|
|
{
|
|
|
|
|
config.numPINRequestsInterval = interval;
|
2002-03-01 16:55:50 +00:00
|
|
|
|
|
|
|
|
|
/* PENDING(g10) Put this value into gpg and make it ask for the pin
|
|
|
|
|
according to this. Note that this should only be used if
|
|
|
|
|
config.numPINRequests (set with setNumPINRequests()) has the
|
|
|
|
|
value PinRequest_AfterMinutes.
|
|
|
|
|
*/
|
2001-11-21 10:55:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int numPINRequestsInterval()
|
|
|
|
|
{
|
|
|
|
|
return config.numPINRequestsInterval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-11-21 09:42:08 +00:00
|
|
|
|
void setCheckSignatureCertificatePathToRoot( bool flag )
|
|
|
|
|
{
|
|
|
|
|
config.checkSignatureCertificatePathToRoot = flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool checkSignatureCertificatePathToRoot()
|
|
|
|
|
{
|
|
|
|
|
return config.checkSignatureCertificatePathToRoot;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setSignatureUseCRLs( bool flag )
|
|
|
|
|
{
|
|
|
|
|
config.signatureUseCRLs = flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool signatureUseCRLs()
|
|
|
|
|
{
|
|
|
|
|
return config.signatureUseCRLs;
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-21 10:55:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setSignatureCertificateExpiryNearWarning( bool flag )
|
|
|
|
|
{
|
|
|
|
|
config.signatureCertificateExpiryNearWarning = flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool signatureCertificateExpiryNearWarning( void )
|
|
|
|
|
{
|
|
|
|
|
return config.signatureCertificateExpiryNearWarning;
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-28 09:14:39 +00:00
|
|
|
|
|
|
|
|
|
int signatureCertificateDaysLeftToExpiry( const char* certificate )
|
|
|
|
|
{
|
2002-05-08 12:05:17 +00:00
|
|
|
|
GpgmeCtx ctx;
|
|
|
|
|
GpgmeError err;
|
|
|
|
|
GpgmeKey rKey;
|
2002-09-03 16:21:34 +00:00
|
|
|
|
int daysLeft = CRYPTPLUG_CERT_DOES_NEVER_EXPIRE;
|
2002-05-08 12:05:17 +00:00
|
|
|
|
|
|
|
|
|
gpgme_new( &ctx );
|
|
|
|
|
gpgme_set_protocol( ctx, GPGMEPLUG_PROTOCOL );
|
|
|
|
|
|
|
|
|
|
err = gpgme_op_keylist_start( ctx, certificate, 0 );
|
|
|
|
|
if ( GPGME_No_Error == err ) {
|
|
|
|
|
err = gpgme_op_keylist_next( ctx, &rKey );
|
|
|
|
|
gpgme_op_keylist_end( ctx );
|
|
|
|
|
if ( GPGME_No_Error == err ) {
|
|
|
|
|
time_t expire_time = gpgme_key_get_ulong_attr(
|
2002-09-03 16:21:34 +00:00
|
|
|
|
rKey, GPGME_ATTR_EXPIRE, NULL, 0 );
|
2002-09-29 21:14:16 +00:00
|
|
|
|
if ( 0 != expire_time ) {
|
|
|
|
|
time_t cur_time = time (NULL);
|
|
|
|
|
if( cur_time > expire_time ) {
|
|
|
|
|
daysLeft = days_from_seconds(cur_time - expire_time);
|
|
|
|
|
daysLeft *= -1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
daysLeft = days_from_seconds(expire_time - cur_time);
|
2002-09-03 16:21:34 +00:00
|
|
|
|
}
|
2002-05-08 12:05:17 +00:00
|
|
|
|
gpgme_key_release( rKey );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
gpgme_release( ctx );
|
2002-06-26 08:04:43 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
fprintf( stderr, "gpgmeplug signatureCertificateDaysLeftToExpiry returned %d\n", daysLeft );
|
|
|
|
|
*/
|
2002-05-08 12:05:17 +00:00
|
|
|
|
|
|
|
|
|
return daysLeft;
|
2002-02-28 09:14:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-21 10:55:02 +00:00
|
|
|
|
void setSignatureCertificateExpiryNearInterval( int interval )
|
2001-11-21 09:42:08 +00:00
|
|
|
|
{
|
2001-11-21 10:55:02 +00:00
|
|
|
|
config.signatureCertificateExpiryNearInterval = interval;
|
2001-11-21 09:42:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-21 10:55:02 +00:00
|
|
|
|
int signatureCertificateExpiryNearInterval( void )
|
2001-11-21 09:42:08 +00:00
|
|
|
|
{
|
2001-11-21 10:55:02 +00:00
|
|
|
|
return config.signatureCertificateExpiryNearInterval;
|
2001-11-21 09:42:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-21 10:55:02 +00:00
|
|
|
|
void setCACertificateExpiryNearWarning( bool flag )
|
2001-11-21 09:42:08 +00:00
|
|
|
|
{
|
2001-11-21 10:55:02 +00:00
|
|
|
|
config.cACertificateExpiryNearWarning = flag;
|
2001-11-21 09:42:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-21 10:55:02 +00:00
|
|
|
|
bool caCertificateExpiryNearWarning( void )
|
2001-11-21 09:42:08 +00:00
|
|
|
|
{
|
2001-11-21 10:55:02 +00:00
|
|
|
|
return config.cACertificateExpiryNearWarning;
|
2001-11-21 09:42:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-02-28 09:14:39 +00:00
|
|
|
|
int caCertificateDaysLeftToExpiry( const char* certificate )
|
|
|
|
|
{
|
|
|
|
|
/* PENDING(g10)
|
|
|
|
|
Please return the number of days that are left until the
|
|
|
|
|
CA certificate for the certificate specified in the parameter
|
|
|
|
|
certificate expires.
|
|
|
|
|
*/
|
2002-06-26 08:04:43 +00:00
|
|
|
|
/*
|
|
|
|
|
GpgmeCtx ctx;
|
|
|
|
|
GpgmeError err;
|
|
|
|
|
GpgmeKey rKey;
|
|
|
|
|
time_t daysLeft = 0;
|
|
|
|
|
|
|
|
|
|
gpgme_new( &ctx );
|
|
|
|
|
gpgme_set_protocol( ctx, GPGMEPLUG_PROTOCOL );
|
|
|
|
|
|
|
|
|
|
err = gpgme_op_keylist_start( ctx, certificate, 0 );
|
|
|
|
|
if ( GPGME_No_Error == err ) {
|
|
|
|
|
err = gpgme_op_keylist_next( ctx, &rKey );
|
|
|
|
|
gpgme_op_keylist_end( ctx );
|
|
|
|
|
if ( GPGME_No_Error == err ) {
|
|
|
|
|
time_t expire_time = gpgme_key_get_ulong_attr(
|
|
|
|
|
rKey,
|
|
|
|
|
|
|
|
|
|
??????????????????????? GPGME_ATTR_EXPIRE, ???????????????????????
|
|
|
|
|
|
|
|
|
|
NULL, 0 );
|
|
|
|
|
time_t cur_time = time (NULL);
|
2002-06-28 14:51:12 +00:00
|
|
|
|
daysLeft = days_from_seconds(expire_time - cur_time);
|
2002-06-26 08:04:43 +00:00
|
|
|
|
gpgme_key_release( rKey );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
gpgme_release( ctx );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// fprintf( stderr, "gpgmeplug caCertificateDaysLeftToExpiry returned %d\n", daysLeft );
|
|
|
|
|
return daysLeft;
|
|
|
|
|
*/
|
|
|
|
|
|
2002-03-23 11:35:31 +00:00
|
|
|
|
return 10; /* dummy that triggers a warning in the MUA */
|
2002-02-28 09:14:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-21 10:55:02 +00:00
|
|
|
|
void setCACertificateExpiryNearInterval( int interval )
|
|
|
|
|
{
|
|
|
|
|
config.cACertificateExpiryNearInterval = interval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int caCertificateExpiryNearInterval( void )
|
|
|
|
|
{
|
|
|
|
|
return config.cACertificateExpiryNearInterval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setRootCertificateExpiryNearWarning( bool flag )
|
|
|
|
|
{
|
|
|
|
|
config.rootCertificateExpiryNearWarning = flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool rootCertificateExpiryNearWarning( void )
|
|
|
|
|
{
|
|
|
|
|
return config.rootCertificateExpiryNearWarning;
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-28 09:14:39 +00:00
|
|
|
|
int rootCertificateDaysLeftToExpiry( const char* certificate )
|
|
|
|
|
{
|
|
|
|
|
/* PENDING(g10)
|
|
|
|
|
Please return the number of days that are left until the
|
|
|
|
|
root certificate for the certificate specified in the parameter
|
|
|
|
|
certificate expires.
|
|
|
|
|
*/
|
2002-06-26 08:04:43 +00:00
|
|
|
|
/*
|
|
|
|
|
GpgmeCtx ctx;
|
|
|
|
|
GpgmeError err;
|
|
|
|
|
GpgmeKey rKey;
|
|
|
|
|
time_t daysLeft = 0;
|
|
|
|
|
|
|
|
|
|
gpgme_new( &ctx );
|
|
|
|
|
gpgme_set_protocol( ctx, GPGMEPLUG_PROTOCOL );
|
|
|
|
|
|
|
|
|
|
err = gpgme_op_keylist_start( ctx, certificate, 0 );
|
|
|
|
|
if ( GPGME_No_Error == err ) {
|
|
|
|
|
err = gpgme_op_keylist_next( ctx, &rKey );
|
|
|
|
|
gpgme_op_keylist_end( ctx );
|
|
|
|
|
if ( GPGME_No_Error == err ) {
|
|
|
|
|
time_t expire_time = gpgme_key_get_ulong_attr(
|
|
|
|
|
rKey,
|
|
|
|
|
|
|
|
|
|
??????????????????????? GPGME_ATTR_EXPIRE, ???????????????????????
|
|
|
|
|
|
|
|
|
|
NULL, 0 );
|
|
|
|
|
time_t cur_time = time (NULL);
|
2002-06-28 14:51:12 +00:00
|
|
|
|
daysLeft = days_from_seconds(expire_time - cur_time);
|
2002-06-26 08:04:43 +00:00
|
|
|
|
gpgme_key_release( rKey );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
gpgme_release( ctx );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// fprintf( stderr, "gpgmeplug rootCertificateDaysLeftToExpiry returned %d\n", daysLeft );
|
|
|
|
|
return daysLeft;
|
|
|
|
|
*/
|
|
|
|
|
|
2002-03-23 11:35:31 +00:00
|
|
|
|
return 10; /* dummy that triggers a warning in the MUA */
|
2002-02-28 09:14:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-21 10:55:02 +00:00
|
|
|
|
void setRootCertificateExpiryNearInterval( int interval )
|
|
|
|
|
{
|
|
|
|
|
config.rootCertificateExpiryNearInterval = interval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int rootCertificateExpiryNearInterval( void )
|
|
|
|
|
{
|
|
|
|
|
return config.rootCertificateExpiryNearInterval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-11-21 09:42:08 +00:00
|
|
|
|
|
|
|
|
|
const char* encryptionConfigurationDialog(){ return 0; }
|
|
|
|
|
|
|
|
|
|
const char* encryptionAlgorithmDialog(){ return 0; }
|
|
|
|
|
|
|
|
|
|
const char* encryptionHandlingDialog(){ return 0; }
|
|
|
|
|
|
|
|
|
|
const char* encryptionReceiverDialog(){ return 0; }
|
|
|
|
|
|
|
|
|
|
void setEncryptionAlgorithm( EncryptionAlgorithm cryptAlg )
|
|
|
|
|
{
|
|
|
|
|
config.encryptionAlgorithm = cryptAlg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EncryptionAlgorithm encryptionAlgorithm()
|
|
|
|
|
{
|
|
|
|
|
return config.encryptionAlgorithm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setEncryptEmail( EncryptEmail cryptMode )
|
|
|
|
|
{
|
|
|
|
|
config.encryptEmail = cryptMode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EncryptEmail encryptEmail()
|
|
|
|
|
{
|
|
|
|
|
return config.encryptEmail;
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-21 10:55:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setWarnSendUnencrypted( bool flag )
|
|
|
|
|
{
|
|
|
|
|
config.warnSendUnencrypted = flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool warnSendUnencrypted()
|
|
|
|
|
{
|
|
|
|
|
return config.warnSendUnencrypted;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-11-21 09:42:08 +00:00
|
|
|
|
void setSaveMessagesEncrypted( bool flag )
|
|
|
|
|
{
|
|
|
|
|
config.saveMessagesEncrypted = flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool saveMessagesEncrypted()
|
|
|
|
|
{
|
|
|
|
|
return config.saveMessagesEncrypted;
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-21 10:55:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setCheckCertificatePath( bool flag )
|
|
|
|
|
{
|
|
|
|
|
config.checkCertificatePath = flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool checkCertificatePath()
|
|
|
|
|
{
|
|
|
|
|
return config.checkCertificatePath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-11-21 09:42:08 +00:00
|
|
|
|
void setCheckEncryptionCertificatePathToRoot( bool flag )
|
|
|
|
|
{
|
|
|
|
|
config.checkEncryptionCertificatePathToRoot = flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool checkEncryptionCertificatePathToRoot()
|
|
|
|
|
{
|
|
|
|
|
return config.checkEncryptionCertificatePathToRoot;
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-21 10:55:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setReceiverCertificateExpiryNearWarning( bool flag )
|
|
|
|
|
{
|
|
|
|
|
config.receiverCertificateExpiryNearWarning = flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool receiverCertificateExpiryNearWarning()
|
|
|
|
|
{
|
|
|
|
|
return config.receiverCertificateExpiryNearWarning;
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-07 21:18:27 +00:00
|
|
|
|
|
|
|
|
|
int receiverCertificateDaysLeftToExpiry( const char* certificate )
|
|
|
|
|
{
|
2002-06-26 15:16:32 +00:00
|
|
|
|
GpgmeCtx ctx;
|
|
|
|
|
GpgmeError err;
|
|
|
|
|
GpgmeKey rKey;
|
2002-09-03 16:21:34 +00:00
|
|
|
|
int daysLeft = CRYPTPLUG_CERT_DOES_NEVER_EXPIRE;
|
2002-06-26 15:16:32 +00:00
|
|
|
|
|
|
|
|
|
gpgme_new( &ctx );
|
|
|
|
|
gpgme_set_protocol( ctx, GPGMEPLUG_PROTOCOL );
|
|
|
|
|
|
|
|
|
|
err = gpgme_op_keylist_start( ctx, certificate, 0 );
|
|
|
|
|
if ( GPGME_No_Error == err ) {
|
|
|
|
|
err = gpgme_op_keylist_next( ctx, &rKey );
|
|
|
|
|
gpgme_op_keylist_end( ctx );
|
|
|
|
|
if ( GPGME_No_Error == err ) {
|
|
|
|
|
time_t expire_time = gpgme_key_get_ulong_attr(
|
|
|
|
|
rKey,GPGME_ATTR_EXPIRE, NULL, 0 );
|
2002-09-29 21:14:16 +00:00
|
|
|
|
if ( 0 != expire_time ) {
|
|
|
|
|
time_t cur_time = time (NULL);
|
|
|
|
|
if( cur_time > expire_time ) {
|
|
|
|
|
daysLeft = days_from_seconds(cur_time - expire_time);
|
|
|
|
|
daysLeft *= -1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
daysLeft = days_from_seconds(expire_time - cur_time);
|
2002-09-03 16:21:34 +00:00
|
|
|
|
}
|
2002-06-26 15:16:32 +00:00
|
|
|
|
gpgme_key_release( rKey );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
gpgme_release( ctx );
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
fprintf( stderr, "gpgmeplug receiverCertificateDaysLeftToExpiry returned %d\n", daysLeft );
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
return daysLeft;
|
2002-03-07 21:18:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-21 10:55:02 +00:00
|
|
|
|
void setReceiverCertificateExpiryNearWarningInterval( int interval )
|
|
|
|
|
{
|
|
|
|
|
config.receiverCertificateExpiryNearWarningInterval = interval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int receiverCertificateExpiryNearWarningInterval()
|
|
|
|
|
{
|
|
|
|
|
return config.receiverCertificateExpiryNearWarningInterval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setCertificateInChainExpiryNearWarning( bool flag )
|
|
|
|
|
{
|
|
|
|
|
config.certificateInChainExpiryNearWarning = flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool certificateInChainExpiryNearWarning()
|
|
|
|
|
{
|
|
|
|
|
return config.certificateInChainExpiryNearWarning;
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-07 21:18:27 +00:00
|
|
|
|
|
|
|
|
|
int certificateInChainDaysLeftToExpiry( const char* certificate )
|
|
|
|
|
{
|
|
|
|
|
/* PENDING(g10)
|
|
|
|
|
Please return the number of days that are left until the
|
|
|
|
|
the first certificate in the chain of the specified certificate
|
|
|
|
|
expires.
|
|
|
|
|
*/
|
2002-03-23 11:35:31 +00:00
|
|
|
|
return 10; /* dummy that triggers a warning in the MUA */
|
2002-03-07 21:18:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-21 10:55:02 +00:00
|
|
|
|
void setCertificateInChainExpiryNearWarningInterval( int interval )
|
|
|
|
|
{
|
|
|
|
|
config.certificateInChainExpiryNearWarningInterval = interval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int certificateInChainExpiryNearWarningInterval()
|
|
|
|
|
{
|
|
|
|
|
return config.certificateInChainExpiryNearWarningInterval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setReceiverEmailAddressNotInCertificateWarning( bool flag )
|
|
|
|
|
{
|
|
|
|
|
config.receiverEmailAddressNotInCertificateWarning = flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool receiverEmailAddressNotInCertificateWarning()
|
|
|
|
|
{
|
|
|
|
|
return config.receiverEmailAddressNotInCertificateWarning;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-11-21 09:42:08 +00:00
|
|
|
|
void setEncryptionUseCRLs( bool flag )
|
|
|
|
|
{
|
|
|
|
|
config.encryptionUseCRLs = flag;
|
2002-03-01 17:54:26 +00:00
|
|
|
|
|
|
|
|
|
/* PENDING(g10) Store this setting in gpgme and use it. If true,
|
|
|
|
|
every certificate used for encryption should be checked against
|
|
|
|
|
applicable CRLs.
|
|
|
|
|
*/
|
2001-11-21 09:42:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool encryptionUseCRLs()
|
|
|
|
|
{
|
|
|
|
|
return config.encryptionUseCRLs;
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-01 17:54:26 +00:00
|
|
|
|
|
|
|
|
|
int encryptionCRLsDaysLeftToExpiry()
|
|
|
|
|
{
|
|
|
|
|
/* PENDING(g10)
|
|
|
|
|
Please return the number of days that are left until the
|
|
|
|
|
CRL used for encryption expires.
|
|
|
|
|
*/
|
2002-03-23 11:35:31 +00:00
|
|
|
|
return 10; /* dummy that triggers a warning in the MUA */
|
2002-03-01 17:54:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-21 09:42:08 +00:00
|
|
|
|
void setEncryptionCRLExpiryNearWarning( bool flag )
|
|
|
|
|
{
|
|
|
|
|
config.encryptionCRLExpiryNearWarning = flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool encryptionCRLExpiryNearWarning()
|
|
|
|
|
{
|
|
|
|
|
return config.encryptionCRLExpiryNearWarning;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setEncryptionCRLNearExpiryInterval( int interval )
|
|
|
|
|
{
|
|
|
|
|
config.encryptionCRLNearExpiryInterval = interval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int encryptionCRLNearExpiryInterval()
|
|
|
|
|
{
|
|
|
|
|
return config.encryptionCRLNearExpiryInterval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char* directoryServiceConfigurationDialog(){ return 0; }
|
|
|
|
|
|
2001-11-21 16:57:54 +00:00
|
|
|
|
void appendDirectoryServer( const char* servername,
|
|
|
|
|
int port,
|
2001-11-21 09:42:08 +00:00
|
|
|
|
const char* description )
|
|
|
|
|
{
|
2001-11-21 16:57:54 +00:00
|
|
|
|
struct DirectoryServer *newServers = NULL;
|
2001-11-21 21:08:02 +00:00
|
|
|
|
newServers = realloc( config.directoryServers,
|
|
|
|
|
(1+config.numDirectoryServers) * sizeof *newServers );
|
2001-11-21 16:57:54 +00:00
|
|
|
|
if( newServers ) {
|
|
|
|
|
config.directoryServers = newServers;
|
|
|
|
|
newServers[ config.numDirectoryServers ].servername =
|
2001-11-22 17:32:21 +00:00
|
|
|
|
malloc( 1+strlen( servername ) );
|
2001-11-21 16:57:54 +00:00
|
|
|
|
if( newServers[ config.numDirectoryServers ].servername ) {
|
|
|
|
|
strcpy( (char *)newServers[ config.numDirectoryServers ].servername,
|
|
|
|
|
servername );
|
|
|
|
|
newServers[ config.numDirectoryServers ].description =
|
2001-11-22 17:32:21 +00:00
|
|
|
|
malloc( 1+strlen( description ) );
|
2001-11-21 16:57:54 +00:00
|
|
|
|
if( newServers[ config.numDirectoryServers ].description ) {
|
|
|
|
|
strcpy( (char *)newServers[ config.numDirectoryServers ].description,
|
|
|
|
|
description );
|
|
|
|
|
newServers[ config.numDirectoryServers ].port = port;
|
|
|
|
|
config.numDirectoryServers += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-11-21 09:42:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setDirectoryServers( struct DirectoryServer server[], unsigned int size )
|
|
|
|
|
{
|
2001-11-21 16:57:54 +00:00
|
|
|
|
unsigned int i;
|
|
|
|
|
int oldSize = config.numDirectoryServers;
|
|
|
|
|
struct DirectoryServer *newServers = NULL;
|
2001-11-21 21:08:02 +00:00
|
|
|
|
newServers = calloc ( size, sizeof *newServers );
|
2001-11-21 16:57:54 +00:00
|
|
|
|
if( newServers ) {
|
|
|
|
|
for( i=0; i < oldSize; ++i ) {
|
2001-11-21 21:08:02 +00:00
|
|
|
|
free( (char *)config.directoryServers[i].servername );
|
|
|
|
|
free( (char *)config.directoryServers[i].description );
|
2001-11-21 16:57:54 +00:00
|
|
|
|
}
|
2001-11-21 21:08:02 +00:00
|
|
|
|
free( config.directoryServers );
|
2001-11-21 16:57:54 +00:00
|
|
|
|
for( i=0; i < size; ++i ) {
|
2001-11-22 17:32:21 +00:00
|
|
|
|
newServers[ i ].servername = malloc( 1+strlen( server[i].servername ) );
|
2001-11-21 16:57:54 +00:00
|
|
|
|
if( newServers[ i ].servername ) {
|
|
|
|
|
strcpy( (char *)newServers[ i ].servername, server[i].servername );
|
2001-11-22 17:32:21 +00:00
|
|
|
|
newServers[ i ].description = malloc( 1+strlen( server[i].description ) );
|
2001-11-21 16:57:54 +00:00
|
|
|
|
if( newServers[ i ].description ) {
|
|
|
|
|
strcpy( (char *)newServers[ i ].description, server[i].description );
|
|
|
|
|
newServers[ i ].port = server[i].port;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
config.directoryServers = newServers;
|
2001-11-21 09:42:08 +00:00
|
|
|
|
config.numDirectoryServers = size;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct DirectoryServer * directoryServers( int* numServers )
|
|
|
|
|
{
|
|
|
|
|
if( numServers )
|
|
|
|
|
*numServers = config.numDirectoryServers;
|
|
|
|
|
return config.directoryServers;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void setCertificateSource( CertificateSource source )
|
|
|
|
|
{
|
|
|
|
|
config.certificateSource = source;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CertificateSource certificateSource()
|
|
|
|
|
{
|
|
|
|
|
return config.certificateSource;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setCRLSource( CertificateSource source )
|
|
|
|
|
{
|
|
|
|
|
config.cRLSource = source;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CertificateSource crlSource()
|
|
|
|
|
{
|
|
|
|
|
return config.cRLSource;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool certificateValidity( const char* certificate,
|
|
|
|
|
int* level ){ return true; }
|
|
|
|
|
|
|
|
|
|
|
2001-12-24 00:09:24 +00:00
|
|
|
|
void storeNewCharPtr( char** dest, const char* src )
|
|
|
|
|
{
|
2002-01-14 20:33:50 +00:00
|
|
|
|
int sLen = strlen( src );
|
2002-07-01 13:01:51 +00:00
|
|
|
|
*dest = xmalloc( sLen + 1 );
|
2002-01-15 08:03:26 +00:00
|
|
|
|
strcpy( *dest, src );
|
2001-12-24 00:09:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-21 09:42:08 +00:00
|
|
|
|
bool signMessage( const char* cleartext,
|
2002-04-17 15:00:53 +00:00
|
|
|
|
char** ciphertext,
|
2002-03-22 10:40:24 +00:00
|
|
|
|
const size_t* cipherLen,
|
2001-12-24 00:09:24 +00:00
|
|
|
|
const char* certificate,
|
2002-04-17 15:00:53 +00:00
|
|
|
|
struct StructuringInfo* structuring,
|
|
|
|
|
int* errId,
|
|
|
|
|
char** errTxt )
|
2001-11-21 09:42:08 +00:00
|
|
|
|
{
|
2002-06-12 11:05:42 +00:00
|
|
|
|
bool bIsOpaque;
|
2001-11-21 09:42:08 +00:00
|
|
|
|
GpgmeCtx ctx;
|
2001-11-23 02:08:53 +00:00
|
|
|
|
GpgmeError err;
|
2002-05-31 09:28:58 +00:00
|
|
|
|
GpgmeKey rKey;
|
2001-11-22 09:36:53 +00:00
|
|
|
|
GpgmeData data, sig;
|
2002-03-22 10:40:24 +00:00
|
|
|
|
char* rSig = 0;
|
|
|
|
|
bool bOk = false;
|
2002-02-26 23:19:19 +00:00
|
|
|
|
int sendCerts = 1;
|
2001-11-21 14:18:52 +00:00
|
|
|
|
|
2001-12-24 00:09:24 +00:00
|
|
|
|
init_StructuringInfo( structuring );
|
|
|
|
|
|
2001-11-22 09:36:53 +00:00
|
|
|
|
if( !ciphertext )
|
|
|
|
|
return false;
|
2001-11-21 23:23:24 +00:00
|
|
|
|
|
2001-11-23 02:08:53 +00:00
|
|
|
|
err = gpgme_new (&ctx);
|
2001-11-22 18:48:53 +00:00
|
|
|
|
gpgme_set_protocol (ctx, GPGMEPLUG_PROTOCOL);
|
2001-11-22 17:32:21 +00:00
|
|
|
|
|
2002-03-22 10:40:24 +00:00
|
|
|
|
gpgme_set_armor (ctx, __GPGMEPLUG_SIGNATURE_CODE_IS_BINARY ? 0 : 1);
|
2002-03-23 11:35:31 +00:00
|
|
|
|
/* gpgme_set_textmode (ctx, 1); */
|
2001-11-21 09:42:08 +00:00
|
|
|
|
|
2002-02-26 23:19:19 +00:00
|
|
|
|
switch ( config.sendCertificates ) {
|
2002-02-26 01:01:28 +00:00
|
|
|
|
case SendCert_undef:
|
|
|
|
|
break;
|
|
|
|
|
case SendCert_DontSend:
|
|
|
|
|
sendCerts = 0;
|
|
|
|
|
break;
|
|
|
|
|
case SendCert_SendOwn:
|
|
|
|
|
sendCerts = 1;
|
|
|
|
|
break;
|
|
|
|
|
case SendCert_SendChainWithoutRoot:
|
|
|
|
|
sendCerts = -2;
|
|
|
|
|
break;
|
|
|
|
|
case SendCert_SendChainWithRoot:
|
|
|
|
|
sendCerts = -1;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
sendCerts = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
gpgme_set_include_certs (ctx, sendCerts);
|
2002-03-05 21:23:58 +00:00
|
|
|
|
|
2002-05-31 09:28:58 +00:00
|
|
|
|
/* select the signer's key if provided */
|
|
|
|
|
if (certificate != 0) {
|
|
|
|
|
err = gpgme_op_keylist_start(ctx, certificate, 0);
|
2002-07-02 16:32:29 +00:00
|
|
|
|
while (err == GPGME_No_Error) {
|
|
|
|
|
err = gpgme_op_keylist_next(ctx, &rKey);
|
|
|
|
|
if (err == GPGME_No_Error) {
|
|
|
|
|
unsigned long u;
|
|
|
|
|
u = gpgme_key_get_ulong_attr(rKey, GPGME_ATTR_CAN_SIGN, 0, 0);
|
|
|
|
|
if( u ) {
|
|
|
|
|
|
|
|
|
|
// const char* s;
|
|
|
|
|
// s = gpgme_key_get_string_attr(rKey, GPGME_ATTR_FPR, 0, 0);
|
|
|
|
|
// fprintf( stderr, "gpgmeplug signMessage signing with key: %s\n", s );
|
|
|
|
|
|
|
|
|
|
/* clear existing signers */
|
|
|
|
|
gpgme_signers_clear(ctx);
|
|
|
|
|
/* set the signing key */
|
|
|
|
|
gpgme_signers_add(ctx, rKey);
|
|
|
|
|
/* we only support one signer for now */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-05-31 09:28:58 +00:00
|
|
|
|
}
|
2002-07-02 16:32:29 +00:00
|
|
|
|
gpgme_op_keylist_end(ctx);
|
2002-05-31 09:28:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-04-17 15:00:53 +00:00
|
|
|
|
/* PENDING(g10) Implement this
|
2002-03-23 11:35:31 +00:00
|
|
|
|
|
|
|
|
|
gpgme_set_signature_algorithm( ctx, config.signatureAlgorithm )
|
|
|
|
|
--> This does not make sense. The algorithm is a property of
|
|
|
|
|
the certificate used [wk 2002-03-23] */
|
2002-02-26 01:01:28 +00:00
|
|
|
|
|
2001-11-21 14:18:52 +00:00
|
|
|
|
gpgme_data_new_from_mem (&data, cleartext,
|
2002-03-06 17:23:17 +00:00
|
|
|
|
strlen( cleartext ), 1 );
|
2001-11-21 09:42:08 +00:00
|
|
|
|
gpgme_data_new ( &sig );
|
2002-06-12 11:05:42 +00:00
|
|
|
|
|
2002-07-01 13:01:51 +00:00
|
|
|
|
/* NOTE: Currently we support Opaque signed messages only for S/MIME,
|
|
|
|
|
but not for OpenPGP mode! */
|
2002-06-12 11:05:42 +00:00
|
|
|
|
if( GPGMEPLUG_PROTOCOL == GPGME_PROTOCOL_CMS )
|
|
|
|
|
bIsOpaque = (SignatureCompoundMode_Opaque == signatureCompoundMode());
|
|
|
|
|
else
|
|
|
|
|
bIsOpaque = false;
|
|
|
|
|
|
|
|
|
|
err = gpgme_op_sign ( ctx,
|
|
|
|
|
data,
|
|
|
|
|
sig,
|
|
|
|
|
bIsOpaque
|
|
|
|
|
? GPGME_SIG_MODE_NORMAL
|
|
|
|
|
: GPGME_SIG_MODE_DETACH );
|
2001-11-29 12:29:55 +00:00
|
|
|
|
|
2002-05-31 09:28:58 +00:00
|
|
|
|
if ( err == GPGME_No_Error ) {
|
2002-03-22 17:06:43 +00:00
|
|
|
|
if( __GPGMEPLUG_SIGNATURE_CODE_IS_BINARY ) {
|
2002-03-22 10:40:24 +00:00
|
|
|
|
*ciphertext = gpgme_data_release_and_get_mem( sig, (size_t*)cipherLen );
|
2002-03-22 17:06:43 +00:00
|
|
|
|
bOk = true;
|
|
|
|
|
}
|
2002-03-22 10:40:24 +00:00
|
|
|
|
else {
|
|
|
|
|
rSig = gpgme_data_release_and_get_mem( sig, (size_t*)cipherLen );
|
|
|
|
|
*ciphertext = malloc( *cipherLen + 1 );
|
|
|
|
|
if( *ciphertext ) {
|
|
|
|
|
if( *cipherLen ) {
|
|
|
|
|
bOk = true;
|
|
|
|
|
strncpy((char*)*ciphertext, rSig, *cipherLen );
|
|
|
|
|
}
|
2002-04-17 15:00:53 +00:00
|
|
|
|
(*ciphertext)[*cipherLen] = '\0';
|
2001-11-29 12:29:55 +00:00
|
|
|
|
}
|
2002-03-22 10:40:24 +00:00
|
|
|
|
free( rSig );
|
2001-11-25 03:37:13 +00:00
|
|
|
|
}
|
2001-11-21 09:42:08 +00:00
|
|
|
|
}
|
2001-11-29 12:29:55 +00:00
|
|
|
|
else {
|
|
|
|
|
gpgme_data_release( sig );
|
2002-05-31 09:28:58 +00:00
|
|
|
|
/*
|
|
|
|
|
*ciphertext = malloc( 70 );
|
|
|
|
|
strcpy((char*)*ciphertext, "xyz\nsig-dummy\nzyx" );
|
|
|
|
|
(*ciphertext)[17] = '\0';
|
|
|
|
|
err = 0;
|
|
|
|
|
{
|
|
|
|
|
*/
|
2001-11-29 12:29:55 +00:00
|
|
|
|
*ciphertext = 0;
|
2002-05-31 09:28:58 +00:00
|
|
|
|
fprintf( stderr, "\n\n gpgme_op_sign() returned this error code: %i\n\n", err );
|
2002-04-17 15:00:53 +00:00
|
|
|
|
if( errId )
|
|
|
|
|
*errId = err;
|
|
|
|
|
if( errTxt ) {
|
|
|
|
|
const char* _errTxt = gpgme_strerror( err );
|
|
|
|
|
*errTxt = malloc( strlen( _errTxt ) + 1 );
|
|
|
|
|
if( *errTxt )
|
|
|
|
|
strcpy(*errTxt, _errTxt );
|
|
|
|
|
}
|
2002-05-31 09:28:58 +00:00
|
|
|
|
/*
|
|
|
|
|
}
|
|
|
|
|
*/
|
2001-11-29 12:29:55 +00:00
|
|
|
|
}
|
|
|
|
|
gpgme_data_release( data );
|
2001-11-21 09:42:08 +00:00
|
|
|
|
gpgme_release (ctx);
|
2001-11-21 14:18:52 +00:00
|
|
|
|
|
2001-12-24 00:09:24 +00:00
|
|
|
|
if( bOk && structuring ) {
|
2002-06-12 11:05:42 +00:00
|
|
|
|
if( bIsOpaque ) {
|
|
|
|
|
structuring->includeCleartext = GPGMEPLUG_OPA_SIGN_INCLUDE_CLEARTEXT;
|
|
|
|
|
structuring->makeMimeObject = GPGMEPLUG_OPA_SIGN_MAKE_MIME_OBJECT;
|
|
|
|
|
if( structuring->makeMimeObject ) {
|
|
|
|
|
structuring->makeMultiMime = GPGMEPLUG_OPA_SIGN_MAKE_MULTI_MIME;
|
|
|
|
|
storeNewCharPtr( &structuring->contentTypeMain,
|
|
|
|
|
GPGMEPLUG_OPA_SIGN_CTYPE_MAIN );
|
|
|
|
|
storeNewCharPtr( &structuring->contentDispMain,
|
|
|
|
|
GPGMEPLUG_OPA_SIGN_CDISP_MAIN );
|
|
|
|
|
storeNewCharPtr( &structuring->contentTEncMain,
|
|
|
|
|
GPGMEPLUG_OPA_SIGN_CTENC_MAIN );
|
|
|
|
|
if( structuring->makeMultiMime ) {
|
|
|
|
|
storeNewCharPtr( &structuring->contentTypeVersion,
|
|
|
|
|
GPGMEPLUG_OPA_SIGN_CTYPE_VERSION );
|
|
|
|
|
storeNewCharPtr( &structuring->contentDispVersion,
|
|
|
|
|
GPGMEPLUG_OPA_SIGN_CDISP_VERSION );
|
|
|
|
|
storeNewCharPtr( &structuring->contentTEncVersion,
|
|
|
|
|
GPGMEPLUG_OPA_SIGN_CTENC_VERSION );
|
|
|
|
|
storeNewCharPtr( &structuring->bodyTextVersion,
|
|
|
|
|
GPGMEPLUG_OPA_SIGN_BTEXT_VERSION );
|
|
|
|
|
storeNewCharPtr( &structuring->contentTypeCode,
|
|
|
|
|
GPGMEPLUG_OPA_SIGN_CTYPE_CODE );
|
|
|
|
|
storeNewCharPtr( &structuring->contentDispCode,
|
|
|
|
|
GPGMEPLUG_OPA_SIGN_CDISP_CODE );
|
|
|
|
|
storeNewCharPtr( &structuring->contentTEncCode,
|
|
|
|
|
GPGMEPLUG_OPA_SIGN_CTENC_CODE );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
storeNewCharPtr( &structuring->flatTextPrefix,
|
|
|
|
|
GPGMEPLUG_OPA_SIGN_FLAT_PREFIX );
|
|
|
|
|
storeNewCharPtr( &structuring->flatTextSeparator,
|
|
|
|
|
GPGMEPLUG_OPA_SIGN_FLAT_SEPARATOR );
|
|
|
|
|
storeNewCharPtr( &structuring->flatTextPostfix,
|
|
|
|
|
GPGMEPLUG_OPA_SIGN_FLAT_POSTFIX );
|
2001-12-24 00:09:24 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2002-06-12 11:05:42 +00:00
|
|
|
|
structuring->includeCleartext = GPGMEPLUG_DET_SIGN_INCLUDE_CLEARTEXT;
|
|
|
|
|
structuring->makeMimeObject = GPGMEPLUG_DET_SIGN_MAKE_MIME_OBJECT;
|
|
|
|
|
if( structuring->makeMimeObject ) {
|
|
|
|
|
structuring->makeMultiMime = GPGMEPLUG_DET_SIGN_MAKE_MULTI_MIME;
|
|
|
|
|
storeNewCharPtr( &structuring->contentTypeMain,
|
|
|
|
|
GPGMEPLUG_DET_SIGN_CTYPE_MAIN );
|
|
|
|
|
storeNewCharPtr( &structuring->contentDispMain,
|
|
|
|
|
GPGMEPLUG_DET_SIGN_CDISP_MAIN );
|
|
|
|
|
storeNewCharPtr( &structuring->contentTEncMain,
|
|
|
|
|
GPGMEPLUG_DET_SIGN_CTENC_MAIN );
|
|
|
|
|
if( structuring->makeMultiMime ) {
|
|
|
|
|
storeNewCharPtr( &structuring->contentTypeVersion,
|
|
|
|
|
GPGMEPLUG_DET_SIGN_CTYPE_VERSION );
|
|
|
|
|
storeNewCharPtr( &structuring->contentDispVersion,
|
|
|
|
|
GPGMEPLUG_DET_SIGN_CDISP_VERSION );
|
|
|
|
|
storeNewCharPtr( &structuring->contentTEncVersion,
|
|
|
|
|
GPGMEPLUG_DET_SIGN_CTENC_VERSION );
|
|
|
|
|
storeNewCharPtr( &structuring->bodyTextVersion,
|
|
|
|
|
GPGMEPLUG_DET_SIGN_BTEXT_VERSION );
|
|
|
|
|
storeNewCharPtr( &structuring->contentTypeCode,
|
|
|
|
|
GPGMEPLUG_DET_SIGN_CTYPE_CODE );
|
|
|
|
|
storeNewCharPtr( &structuring->contentDispCode,
|
|
|
|
|
GPGMEPLUG_DET_SIGN_CDISP_CODE );
|
|
|
|
|
storeNewCharPtr( &structuring->contentTEncCode,
|
|
|
|
|
GPGMEPLUG_DET_SIGN_CTENC_CODE );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
storeNewCharPtr( &structuring->flatTextPrefix,
|
|
|
|
|
GPGMEPLUG_DET_SIGN_FLAT_PREFIX );
|
|
|
|
|
storeNewCharPtr( &structuring->flatTextSeparator,
|
|
|
|
|
GPGMEPLUG_DET_SIGN_FLAT_SEPARATOR );
|
|
|
|
|
storeNewCharPtr( &structuring->flatTextPostfix,
|
|
|
|
|
GPGMEPLUG_DET_SIGN_FLAT_POSTFIX );
|
|
|
|
|
}
|
2001-12-24 00:09:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-11-25 03:37:13 +00:00
|
|
|
|
return bOk;
|
2001-11-21 09:42:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-25 15:23:21 +00:00
|
|
|
|
|
2001-11-21 09:42:08 +00:00
|
|
|
|
|
|
|
|
|
bool storeCertificatesFromMessage(
|
|
|
|
|
const char* ciphertext ){ return true; }
|
|
|
|
|
|
|
|
|
|
|
2002-03-08 15:44:09 +00:00
|
|
|
|
/* returns address if address doesn't contain a <xxx> part
|
|
|
|
|
* else it returns a new string xxx and frees address
|
2002-03-08 00:51:25 +00:00
|
|
|
|
*/
|
|
|
|
|
static char* parseAddress( char* address )
|
|
|
|
|
{
|
|
|
|
|
char* result = address;
|
|
|
|
|
char* i;
|
|
|
|
|
char* j;
|
|
|
|
|
if( !result ) return result;
|
|
|
|
|
i = index( address, '<' );
|
|
|
|
|
if( i ) {
|
|
|
|
|
j = index( i+1, '>' );
|
|
|
|
|
if( j == NULL ) j = address+strlen(address);
|
2002-07-01 13:01:51 +00:00
|
|
|
|
result = xmalloc( j-i );
|
2002-03-08 00:51:25 +00:00
|
|
|
|
strncpy( result, i+1, j-i-1 );
|
|
|
|
|
result[j-i-1] = '\0';
|
|
|
|
|
free( address );
|
|
|
|
|
} else {
|
|
|
|
|
i = address;
|
|
|
|
|
j = i+strlen(address);
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
/* remove surrounding whitespace */
|
|
|
|
|
char* k = result+(j-i-1);
|
|
|
|
|
char* l = result;
|
|
|
|
|
while( isspace( *l ) ) ++l;
|
|
|
|
|
while( isspace( *k ) ) --k;
|
|
|
|
|
if( l != result || k != result+(j-i-1) ) {
|
2002-07-01 13:01:51 +00:00
|
|
|
|
char* result2 = xmalloc( k-l+2 );
|
2002-03-08 00:51:25 +00:00
|
|
|
|
strncpy( result2, l, k-l+1 );
|
|
|
|
|
result2[k-l+1] = '\0';
|
|
|
|
|
free(result);
|
|
|
|
|
result = result2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-07 14:10:07 +00:00
|
|
|
|
static char* nextAddress( const char** address )
|
|
|
|
|
{
|
|
|
|
|
const char *start = *address;
|
|
|
|
|
char* result = NULL;
|
|
|
|
|
int quote = 0;
|
|
|
|
|
int comment = 0;
|
|
|
|
|
int found = 0;
|
|
|
|
|
if( *address == NULL ) return NULL;
|
|
|
|
|
while( **address ) {
|
2002-03-08 15:44:09 +00:00
|
|
|
|
|
2002-03-07 14:10:07 +00:00
|
|
|
|
switch( **address ) {
|
|
|
|
|
case '\\': /* escaped character */
|
|
|
|
|
++(*address);
|
|
|
|
|
break;
|
|
|
|
|
case '"':
|
|
|
|
|
if( comment == 0 ) {
|
2002-03-08 15:44:09 +00:00
|
|
|
|
if( quote > 0 ) --quote;
|
|
|
|
|
else ++quote;
|
2002-03-07 14:10:07 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case '(': /* comment start */
|
|
|
|
|
if( quote == 0 ) ++comment;
|
|
|
|
|
break;
|
|
|
|
|
case ')': /* comment end */
|
|
|
|
|
if( quote == 0 ) --comment;
|
2002-03-08 15:44:09 +00:00
|
|
|
|
break;
|
2002-03-07 14:10:07 +00:00
|
|
|
|
case '\0':
|
2002-03-08 15:44:09 +00:00
|
|
|
|
case '\1': /* delimiter */
|
2002-03-07 14:10:07 +00:00
|
|
|
|
if( quote == 0 && comment == 0 ) {
|
2002-03-08 15:44:09 +00:00
|
|
|
|
found = 1;
|
2002-03-07 14:10:07 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
++(*address);
|
|
|
|
|
if( found ) break;
|
|
|
|
|
}
|
|
|
|
|
if( found || **address == 0 ) {
|
|
|
|
|
size_t len;
|
|
|
|
|
len = *address - start;
|
|
|
|
|
if( len > 0 ) {
|
|
|
|
|
if( **address != 0 ) --len;
|
2002-07-01 13:01:51 +00:00
|
|
|
|
result = xmalloc( len*sizeof(char)+1 );
|
2002-03-07 14:10:07 +00:00
|
|
|
|
strncpy( result, start, len );
|
|
|
|
|
result[len] = '\0';
|
2002-03-08 15:44:09 +00:00
|
|
|
|
}
|
2002-03-07 14:10:07 +00:00
|
|
|
|
}
|
2002-03-08 00:51:25 +00:00
|
|
|
|
return parseAddress(result);
|
2002-03-07 14:10:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-03-08 15:44:09 +00:00
|
|
|
|
bool encryptMessage( const char* cleartext,
|
2001-11-25 03:37:13 +00:00
|
|
|
|
const char** ciphertext,
|
2002-03-22 10:40:24 +00:00
|
|
|
|
const size_t* cipherLen,
|
2002-03-08 15:44:09 +00:00
|
|
|
|
const char* certificate,
|
2002-04-17 15:00:53 +00:00
|
|
|
|
struct StructuringInfo* structuring,
|
|
|
|
|
int* errId,
|
|
|
|
|
char** errTxt )
|
2001-11-25 03:37:13 +00:00
|
|
|
|
{
|
2001-11-25 05:07:44 +00:00
|
|
|
|
GpgmeCtx ctx;
|
|
|
|
|
GpgmeError err;
|
|
|
|
|
GpgmeData gCiphertext, gPlaintext;
|
|
|
|
|
GpgmeRecipients rset;
|
|
|
|
|
char* rCiph = 0;
|
|
|
|
|
bool bOk = false;
|
|
|
|
|
|
2001-12-24 00:09:24 +00:00
|
|
|
|
init_StructuringInfo( structuring );
|
|
|
|
|
|
2001-11-25 05:07:44 +00:00
|
|
|
|
gpgme_new (&ctx);
|
|
|
|
|
gpgme_set_protocol (ctx, GPGMEPLUG_PROTOCOL);
|
|
|
|
|
|
2002-03-22 10:40:24 +00:00
|
|
|
|
gpgme_set_armor (ctx, __GPGMEPLUG_ENCRYPTED_CODE_IS_BINARY ? 0 : 1);
|
2002-03-23 11:35:31 +00:00
|
|
|
|
/* gpgme_set_textmode (ctx, 1); */
|
2001-11-25 05:07:44 +00:00
|
|
|
|
|
|
|
|
|
gpgme_data_new_from_mem (&gPlaintext, cleartext,
|
|
|
|
|
1+strlen( cleartext ), 1 );
|
|
|
|
|
err = gpgme_data_new ( &gCiphertext );
|
|
|
|
|
|
|
|
|
|
gpgme_recipients_new (&rset);
|
2001-12-18 20:13:08 +00:00
|
|
|
|
|
2002-03-08 15:44:09 +00:00
|
|
|
|
/*
|
2001-12-18 21:11:03 +00:00
|
|
|
|
if( GPGMEPLUG_PROTOCOL == GPGME_PROTOCOL_CMS )
|
|
|
|
|
{
|
2002-04-02 11:52:55 +00:00
|
|
|
|
gpgme_recipients_add_name (rset,
|
2002-06-25 15:05:59 +00:00
|
|
|
|
"/CN=test cert 1,OU=Aegypten Project,O=g10 Code GmbH,L=D<>?sseldorf,C=DE" );
|
2002-04-02 11:52:55 +00:00
|
|
|
|
|
2001-12-18 21:11:03 +00:00
|
|
|
|
fputs( "\nGPGSMPLUG encryptMessage() using test key of Aegypten Project\n", stderr );
|
|
|
|
|
}
|
|
|
|
|
else
|
2002-03-08 15:44:09 +00:00
|
|
|
|
*/
|
2001-12-18 21:11:03 +00:00
|
|
|
|
{
|
2002-03-08 15:44:09 +00:00
|
|
|
|
const char* p = certificate;
|
2002-03-07 14:10:07 +00:00
|
|
|
|
char* tok;
|
2002-03-08 15:44:09 +00:00
|
|
|
|
while( (tok = nextAddress( &p ) ) != 0 ) {
|
2002-04-02 11:52:55 +00:00
|
|
|
|
gpgme_recipients_add_name (rset, tok );
|
2002-03-07 14:10:07 +00:00
|
|
|
|
fprintf( stderr, "\nGPGMEPLUG encryptMessage() using addressee %s\n", tok );
|
|
|
|
|
free(tok);
|
|
|
|
|
}
|
2001-12-18 21:11:03 +00:00
|
|
|
|
}
|
2001-12-18 20:13:08 +00:00
|
|
|
|
|
2002-03-23 11:35:31 +00:00
|
|
|
|
/* PENDING(g10) Implement this
|
|
|
|
|
Possible values: RSA = 1, SHA1 = 2, TripleDES = 3
|
|
|
|
|
gpgme_set_encryption_algorithm( ctx, config.encryptionAlgorithm );
|
|
|
|
|
|
|
|
|
|
-> Your are mixing public key and symmetric algorithms. The
|
|
|
|
|
latter may be configured but the sphix specifications do opnly
|
|
|
|
|
allow 3-DES so this is not nothing we need to do. The proper way
|
|
|
|
|
to select the symmetric algorithm is anyway by looking at the
|
|
|
|
|
capabilities of the certificate because this is the only way to
|
|
|
|
|
know what the recipient can accept. [wk 2002-03-23]
|
|
|
|
|
|
|
|
|
|
PENDING(g10) Implement this
|
|
|
|
|
gpgme_set_encryption_check_certificate_path(
|
|
|
|
|
config.checkCertificatePath )
|
2002-03-07 21:18:27 +00:00
|
|
|
|
|
2002-03-23 11:35:31 +00:00
|
|
|
|
PENDING(g10) Implement this
|
|
|
|
|
gpgme_set_encryption_check_certificate_path_to_root(
|
|
|
|
|
config.checkEncryptionCertificatePathToRoot )
|
2002-03-07 21:18:27 +00:00
|
|
|
|
|
2002-03-23 11:35:31 +00:00
|
|
|
|
-> Not checking a certificate up to the ROOT CA is dangerous and
|
|
|
|
|
stupid. There is no need for those options. [wk 2002-03-23] */
|
2002-03-07 21:18:27 +00:00
|
|
|
|
|
|
|
|
|
|
2001-11-25 05:07:44 +00:00
|
|
|
|
|
2001-11-29 12:29:55 +00:00
|
|
|
|
err = gpgme_op_encrypt (ctx, rset, gPlaintext, gCiphertext );
|
2002-04-17 15:00:53 +00:00
|
|
|
|
if( err ) {
|
2002-07-03 15:43:41 +00:00
|
|
|
|
fprintf( stderr, "\ngpgme_op_encrypt() returned this error code: %i\n", err );
|
2002-04-17 15:00:53 +00:00
|
|
|
|
if( errId )
|
|
|
|
|
*errId = err;
|
|
|
|
|
if( errTxt ) {
|
|
|
|
|
const char* _errTxt = gpgme_strerror( err );
|
2002-07-03 15:43:41 +00:00
|
|
|
|
*errTxt = malloc( strlen( _errTxt ) + 100 ); // leave room for reason string
|
|
|
|
|
if( *errTxt ) {
|
|
|
|
|
char* opInfo;
|
2002-04-17 15:00:53 +00:00
|
|
|
|
strcpy(*errTxt, _errTxt );
|
2002-07-03 15:43:41 +00:00
|
|
|
|
opInfo = gpgme_get_op_info(ctx, 0);
|
|
|
|
|
if( NULL != opInfo && *opInfo ){
|
|
|
|
|
const int opLen = strlen( opInfo );
|
|
|
|
|
const int reasonLen = 8;
|
|
|
|
|
char reason[ 1+reasonLen ];
|
|
|
|
|
char* pos1;
|
|
|
|
|
strcpy( reason, "<reason>" );
|
|
|
|
|
pos1 = strstr( opInfo, reason );
|
|
|
|
|
if( NULL != pos1 &&
|
|
|
|
|
opLen > reasonLen + (pos1 - opInfo) ){
|
|
|
|
|
char* pos2;
|
|
|
|
|
pos1 += reasonLen;
|
|
|
|
|
pos2 = strchr( pos1, '<' );
|
|
|
|
|
if( NULL != pos2 &&
|
|
|
|
|
pos1 < pos2 ){
|
|
|
|
|
long int reasonId;
|
|
|
|
|
strcat( *errTxt, " - " );
|
|
|
|
|
*pos2 = '\0';
|
|
|
|
|
fprintf( stderr, " and this reason code: %s\n\n", pos1 );
|
|
|
|
|
reasonId = strtol( pos1, NULL, 10 );
|
|
|
|
|
switch( reasonId ) {
|
|
|
|
|
case 0: strcat( *errTxt, "No specific reason given" );
|
|
|
|
|
break;
|
|
|
|
|
case 1: strcat( *errTxt, "Not Found" );
|
|
|
|
|
break;
|
|
|
|
|
case 2: strcat( *errTxt, "Ambigious specification" );
|
|
|
|
|
break;
|
|
|
|
|
case 3: strcat( *errTxt, "Key can't be used for operation" );
|
|
|
|
|
break;
|
|
|
|
|
case 4: strcat( *errTxt, "Key has been revoked" );
|
|
|
|
|
break;
|
|
|
|
|
case 5: strcat( *errTxt, "Key has expired" );
|
|
|
|
|
break;
|
|
|
|
|
case 6: strcat( *errTxt, "No CRL known for certificate" );
|
|
|
|
|
break;
|
|
|
|
|
case 7: strcat( *errTxt, "No current CRL available" );
|
|
|
|
|
break;
|
|
|
|
|
case 8: strcat( *errTxt, "Contraints not matched" );
|
|
|
|
|
break;
|
|
|
|
|
default: {
|
|
|
|
|
strcat( *errTxt, "Extended error Id: #" );
|
|
|
|
|
strcat( *errTxt, pos1 );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*pos2 = '<';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
free( opInfo );
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-04-17 15:00:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-12-18 21:11:03 +00:00
|
|
|
|
|
2001-11-25 05:07:44 +00:00
|
|
|
|
gpgme_recipients_release (rset);
|
2001-11-29 12:29:55 +00:00
|
|
|
|
gpgme_data_release (gPlaintext);
|
2001-11-25 05:07:44 +00:00
|
|
|
|
|
2002-05-31 09:28:58 +00:00
|
|
|
|
if( err == GPGME_No_Error ) {
|
2002-03-22 17:06:43 +00:00
|
|
|
|
if( __GPGMEPLUG_ENCRYPTED_CODE_IS_BINARY ) {
|
2002-03-22 10:40:24 +00:00
|
|
|
|
*ciphertext = gpgme_data_release_and_get_mem( gCiphertext, (size_t*)cipherLen );
|
2002-03-22 17:06:43 +00:00
|
|
|
|
bOk = true;
|
|
|
|
|
}
|
2002-03-22 10:40:24 +00:00
|
|
|
|
else {
|
|
|
|
|
rCiph = gpgme_data_release_and_get_mem( gCiphertext, (size_t*)cipherLen );
|
|
|
|
|
*ciphertext = malloc( *cipherLen + 1 );
|
|
|
|
|
if( *ciphertext ) {
|
|
|
|
|
if( *cipherLen ) {
|
|
|
|
|
bOk = true;
|
|
|
|
|
strncpy((char*)*ciphertext, rCiph, *cipherLen );
|
|
|
|
|
}
|
|
|
|
|
((char*)(*ciphertext))[*cipherLen] = 0;
|
2001-11-29 12:29:55 +00:00
|
|
|
|
}
|
2002-03-22 10:40:24 +00:00
|
|
|
|
free( rCiph );
|
2001-11-25 05:07:44 +00:00
|
|
|
|
}
|
2001-11-29 12:29:55 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
gpgme_data_release ( gCiphertext );
|
|
|
|
|
*ciphertext = 0;
|
2002-03-23 11:35:31 +00:00
|
|
|
|
/* error handling is missing: if only one untrusted key was found
|
|
|
|
|
(or none at all), gpg won't sign the message. (hier fehlt eine
|
|
|
|
|
Fehlerbehandlung: fuer einen Recipient nur ein untrusted key
|
|
|
|
|
(oder gar keiner) gefunden wurde, verweigert gpg das signieren.)
|
|
|
|
|
*/
|
2001-11-25 05:07:44 +00:00
|
|
|
|
}
|
2001-12-13 15:13:09 +00:00
|
|
|
|
|
2001-11-25 05:07:44 +00:00
|
|
|
|
gpgme_release (ctx);
|
|
|
|
|
|
2001-12-18 21:11:03 +00:00
|
|
|
|
fflush( stderr );
|
|
|
|
|
|
2001-12-24 00:09:24 +00:00
|
|
|
|
if( bOk && structuring ) {
|
|
|
|
|
structuring->includeCleartext = GPGMEPLUG_ENC_INCLUDE_CLEARTEXT;
|
|
|
|
|
structuring->makeMimeObject = GPGMEPLUG_ENC_MAKE_MIME_OBJECT;
|
|
|
|
|
if( structuring->makeMimeObject ) {
|
|
|
|
|
structuring->makeMultiMime = GPGMEPLUG_ENC_MAKE_MULTI_MIME;
|
|
|
|
|
storeNewCharPtr( &structuring->contentTypeMain,
|
|
|
|
|
GPGMEPLUG_ENC_CTYPE_MAIN );
|
|
|
|
|
storeNewCharPtr( &structuring->contentDispMain,
|
|
|
|
|
GPGMEPLUG_ENC_CDISP_MAIN );
|
|
|
|
|
storeNewCharPtr( &structuring->contentTEncMain,
|
|
|
|
|
GPGMEPLUG_ENC_CTENC_MAIN );
|
|
|
|
|
if( structuring->makeMultiMime ) {
|
|
|
|
|
storeNewCharPtr( &structuring->contentTypeVersion,
|
|
|
|
|
GPGMEPLUG_ENC_CTYPE_VERSION );
|
|
|
|
|
storeNewCharPtr( &structuring->contentDispVersion,
|
|
|
|
|
GPGMEPLUG_ENC_CDISP_VERSION );
|
|
|
|
|
storeNewCharPtr( &structuring->contentTEncVersion,
|
|
|
|
|
GPGMEPLUG_ENC_CTENC_VERSION );
|
|
|
|
|
storeNewCharPtr( &structuring->bodyTextVersion,
|
|
|
|
|
GPGMEPLUG_ENC_BTEXT_VERSION );
|
|
|
|
|
storeNewCharPtr( &structuring->contentTypeCode,
|
|
|
|
|
GPGMEPLUG_ENC_CTYPE_CODE );
|
|
|
|
|
storeNewCharPtr( &structuring->contentDispCode,
|
|
|
|
|
GPGMEPLUG_ENC_CDISP_CODE );
|
|
|
|
|
storeNewCharPtr( &structuring->contentTEncCode,
|
|
|
|
|
GPGMEPLUG_ENC_CTENC_CODE );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
storeNewCharPtr( &structuring->flatTextPrefix,
|
|
|
|
|
GPGMEPLUG_ENC_FLAT_PREFIX );
|
|
|
|
|
storeNewCharPtr( &structuring->flatTextSeparator,
|
|
|
|
|
GPGMEPLUG_ENC_FLAT_SEPARATOR );
|
|
|
|
|
storeNewCharPtr( &structuring->flatTextPostfix,
|
|
|
|
|
GPGMEPLUG_ENC_FLAT_POSTFIX );
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-11-25 05:07:44 +00:00
|
|
|
|
return bOk;
|
2001-11-25 03:37:13 +00:00
|
|
|
|
}
|
2001-11-21 09:42:08 +00:00
|
|
|
|
|
2001-11-25 05:07:44 +00:00
|
|
|
|
|
2001-11-21 09:42:08 +00:00
|
|
|
|
bool encryptAndSignMessage( const char* cleartext,
|
2001-12-24 00:09:24 +00:00
|
|
|
|
const char** ciphertext,
|
|
|
|
|
const char* certificate,
|
|
|
|
|
struct StructuringInfo* structuring )
|
|
|
|
|
{
|
|
|
|
|
bool bOk;
|
|
|
|
|
|
|
|
|
|
init_StructuringInfo( structuring );
|
|
|
|
|
|
|
|
|
|
bOk = false;
|
|
|
|
|
|
2002-03-23 11:35:31 +00:00
|
|
|
|
/* implementation of this function is still missing */
|
2001-12-24 00:09:24 +00:00
|
|
|
|
|
|
|
|
|
if( bOk && structuring ) {
|
|
|
|
|
structuring->includeCleartext = GPGMEPLUG_ENCSIGN_INCLUDE_CLEARTEXT;
|
|
|
|
|
structuring->makeMimeObject = GPGMEPLUG_ENCSIGN_MAKE_MIME_OBJECT;
|
|
|
|
|
if( structuring->makeMimeObject ) {
|
|
|
|
|
structuring->makeMultiMime = GPGMEPLUG_ENCSIGN_MAKE_MULTI_MIME;
|
|
|
|
|
storeNewCharPtr( &structuring->contentTypeMain,
|
|
|
|
|
GPGMEPLUG_ENCSIGN_CTYPE_MAIN );
|
|
|
|
|
storeNewCharPtr( &structuring->contentDispMain,
|
|
|
|
|
GPGMEPLUG_ENCSIGN_CDISP_MAIN );
|
|
|
|
|
storeNewCharPtr( &structuring->contentTEncMain,
|
|
|
|
|
GPGMEPLUG_ENCSIGN_CTENC_MAIN );
|
|
|
|
|
if( structuring->makeMultiMime ) {
|
|
|
|
|
storeNewCharPtr( &structuring->contentTypeVersion,
|
|
|
|
|
GPGMEPLUG_ENCSIGN_CTYPE_VERSION );
|
|
|
|
|
storeNewCharPtr( &structuring->contentDispVersion,
|
|
|
|
|
GPGMEPLUG_ENCSIGN_CDISP_VERSION );
|
|
|
|
|
storeNewCharPtr( &structuring->contentTEncVersion,
|
|
|
|
|
GPGMEPLUG_ENCSIGN_CTENC_VERSION );
|
|
|
|
|
storeNewCharPtr( &structuring->bodyTextVersion,
|
|
|
|
|
GPGMEPLUG_ENCSIGN_BTEXT_VERSION );
|
|
|
|
|
storeNewCharPtr( &structuring->contentTypeCode,
|
|
|
|
|
GPGMEPLUG_ENCSIGN_CTYPE_CODE );
|
|
|
|
|
storeNewCharPtr( &structuring->contentDispCode,
|
|
|
|
|
GPGMEPLUG_ENCSIGN_CDISP_CODE );
|
|
|
|
|
storeNewCharPtr( &structuring->contentTEncCode,
|
|
|
|
|
GPGMEPLUG_ENCSIGN_CTENC_CODE );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
storeNewCharPtr( &structuring->flatTextPrefix,
|
|
|
|
|
GPGMEPLUG_ENCSIGN_FLAT_PREFIX );
|
|
|
|
|
storeNewCharPtr( &structuring->flatTextSeparator,
|
|
|
|
|
GPGMEPLUG_ENCSIGN_FLAT_SEPARATOR );
|
|
|
|
|
storeNewCharPtr( &structuring->flatTextPostfix,
|
|
|
|
|
GPGMEPLUG_ENCSIGN_FLAT_POSTFIX );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return bOk;
|
|
|
|
|
}
|
2001-11-21 09:42:08 +00:00
|
|
|
|
|
2002-03-21 21:48:33 +00:00
|
|
|
|
|
2001-12-06 17:19:07 +00:00
|
|
|
|
bool decryptMessage( const char* ciphertext,
|
2002-03-21 21:48:33 +00:00
|
|
|
|
bool cipherIsBinary,
|
|
|
|
|
int cipherLen,
|
2001-12-06 17:19:07 +00:00
|
|
|
|
const char** cleartext,
|
2002-06-27 08:21:58 +00:00
|
|
|
|
const char* certificate,
|
|
|
|
|
int* errId,
|
|
|
|
|
char** errTxt )
|
2001-12-06 17:19:07 +00:00
|
|
|
|
{
|
2001-12-13 15:13:09 +00:00
|
|
|
|
GpgmeCtx ctx;
|
|
|
|
|
GpgmeError err;
|
|
|
|
|
GpgmeData gCiphertext, gPlaintext;
|
|
|
|
|
size_t rCLen = 0;
|
|
|
|
|
char* rCiph = 0;
|
|
|
|
|
bool bOk = false;
|
2001-12-06 17:19:07 +00:00
|
|
|
|
|
2001-12-13 15:13:09 +00:00
|
|
|
|
if( !ciphertext )
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
err = gpgme_new (&ctx);
|
|
|
|
|
gpgme_set_protocol (ctx, GPGMEPLUG_PROTOCOL);
|
2002-03-21 21:48:33 +00:00
|
|
|
|
|
|
|
|
|
gpgme_set_armor (ctx, cipherIsBinary ? 0 : 1);
|
2002-03-23 11:35:31 +00:00
|
|
|
|
/* gpgme_set_textmode (ctx, cipherIsBinary ? 0 : 1); */
|
2001-12-13 15:13:09 +00:00
|
|
|
|
|
2002-03-21 21:48:33 +00:00
|
|
|
|
/*
|
2001-12-13 15:13:09 +00:00
|
|
|
|
gpgme_data_new_from_mem( &gCiphertext, ciphertext,
|
2002-03-23 11:35:31 +00:00
|
|
|
|
1+strlen( ciphertext ), 1 ); */
|
2002-03-21 21:48:33 +00:00
|
|
|
|
gpgme_data_new_from_mem( &gCiphertext,
|
|
|
|
|
ciphertext,
|
|
|
|
|
cipherIsBinary
|
|
|
|
|
? cipherLen
|
|
|
|
|
: strlen( ciphertext ),
|
|
|
|
|
1 );
|
|
|
|
|
|
2001-12-13 15:13:09 +00:00
|
|
|
|
gpgme_data_new( &gPlaintext );
|
2001-12-06 17:19:07 +00:00
|
|
|
|
|
2002-06-27 08:21:58 +00:00
|
|
|
|
err = err = gpgme_op_decrypt( ctx, gCiphertext, gPlaintext );
|
|
|
|
|
if( err ) {
|
|
|
|
|
fprintf( stderr, "\ngpgme_op_decrypt() returned this error code: %i\n\n", err );
|
|
|
|
|
if( errId )
|
|
|
|
|
*errId = err;
|
|
|
|
|
if( errTxt ) {
|
|
|
|
|
const char* _errTxt = gpgme_strerror( err );
|
|
|
|
|
*errTxt = malloc( strlen( _errTxt ) + 1 );
|
|
|
|
|
if( *errTxt )
|
|
|
|
|
strcpy(*errTxt, _errTxt );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-12-13 15:13:09 +00:00
|
|
|
|
gpgme_data_release( gCiphertext );
|
2001-12-06 17:19:07 +00:00
|
|
|
|
|
2001-12-13 15:13:09 +00:00
|
|
|
|
rCiph = gpgme_data_release_and_get_mem( gPlaintext, &rCLen );
|
2001-12-06 17:19:07 +00:00
|
|
|
|
|
2001-12-13 15:13:09 +00:00
|
|
|
|
*cleartext = malloc( rCLen + 1 );
|
|
|
|
|
if( *cleartext ) {
|
|
|
|
|
if( rCLen ) {
|
|
|
|
|
bOk = true;
|
|
|
|
|
strncpy((char*)*cleartext, rCiph, rCLen );
|
|
|
|
|
}
|
|
|
|
|
((char*)(*cleartext))[rCLen] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free( rCiph );
|
|
|
|
|
gpgme_release( ctx );
|
|
|
|
|
return bOk;
|
2001-12-06 17:19:07 +00:00
|
|
|
|
}
|
2001-11-21 09:42:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char* requestCertificateDialog(){ return 0; }
|
|
|
|
|
|
2002-07-01 13:01:51 +00:00
|
|
|
|
|
|
|
|
|
/* The buffer generatedKey contains the LEN bytes you want.
|
|
|
|
|
Caller is responsible for freeing. */
|
2002-04-18 07:38:15 +00:00
|
|
|
|
bool requestDecentralCertificate( const char* certparms,
|
|
|
|
|
char** generatedKey, int* length )
|
2002-04-17 14:16:53 +00:00
|
|
|
|
{
|
2002-04-18 07:38:15 +00:00
|
|
|
|
GpgmeError err;
|
2002-04-17 14:16:53 +00:00
|
|
|
|
GpgmeCtx ctx;
|
2002-04-18 19:26:03 +00:00
|
|
|
|
GpgmeData pub;
|
2002-04-18 07:38:15 +00:00
|
|
|
|
int len;
|
|
|
|
|
|
|
|
|
|
err = gpgme_data_new (&pub);
|
2002-04-18 19:26:03 +00:00
|
|
|
|
fprintf( stderr, "1: gpgme returned %d\n", err );
|
2002-04-17 14:16:53 +00:00
|
|
|
|
if( err != GPGME_No_Error )
|
|
|
|
|
return false;
|
|
|
|
|
|
2002-04-18 07:38:15 +00:00
|
|
|
|
err = gpgme_new (&ctx);
|
2002-04-18 19:26:03 +00:00
|
|
|
|
fprintf( stderr, "2: gpgme returned %d\n", err );
|
2002-04-18 07:38:15 +00:00
|
|
|
|
if( err != GPGME_No_Error ) {
|
|
|
|
|
gpgme_data_release( pub );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2002-04-17 14:16:53 +00:00
|
|
|
|
|
2002-04-18 07:38:15 +00:00
|
|
|
|
gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS);
|
2002-05-31 15:34:39 +00:00
|
|
|
|
/* Don't ASCII-armor, the MUA will use base64 encoding */
|
|
|
|
|
/* gpgme_set_armor (ctx, 1); */
|
2002-04-18 07:38:15 +00:00
|
|
|
|
err = gpgme_op_genkey (ctx, certparms, pub, NULL );
|
2002-04-18 19:26:03 +00:00
|
|
|
|
fprintf( stderr, "3: gpgme returned %d\n", err );
|
2002-04-18 07:38:15 +00:00
|
|
|
|
if( err != GPGME_No_Error ) {
|
|
|
|
|
gpgme_data_release( pub );
|
|
|
|
|
gpgme_release( ctx );
|
2002-04-17 14:16:53 +00:00
|
|
|
|
return false;
|
2002-04-18 07:38:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gpgme_release (ctx);
|
|
|
|
|
*generatedKey = gpgme_data_release_and_get_mem (pub, &len);
|
|
|
|
|
*length = len;
|
2002-04-17 14:16:53 +00:00
|
|
|
|
|
2002-04-18 19:26:03 +00:00
|
|
|
|
return true;
|
2002-04-17 14:16:53 +00:00
|
|
|
|
}
|
2001-11-21 09:42:08 +00:00
|
|
|
|
|
|
|
|
|
bool requestCentralCertificateAndPSE( const char* name,
|
|
|
|
|
const char* email, const char* organization, const char* department,
|
|
|
|
|
const char* ca_address ){ return true; }
|
|
|
|
|
|
|
|
|
|
bool createPSE(){ return true; }
|
|
|
|
|
|
|
|
|
|
bool registerCertificate( const char* certificate ){ return true; }
|
|
|
|
|
|
|
|
|
|
bool requestCertificateProlongation( const char* certificate,
|
|
|
|
|
const char* ca_address ){ return true; }
|
|
|
|
|
|
|
|
|
|
const char* certificateChain(){ return 0; }
|
|
|
|
|
|
|
|
|
|
bool deleteCertificate( const char* certificate ){ return true; }
|
|
|
|
|
|
|
|
|
|
bool archiveCertificate( const char* certificate ){ return true; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char* displayCRL(){ return 0; }
|
|
|
|
|
|
|
|
|
|
void updateCRL(){}
|
2002-05-31 15:34:39 +00:00
|
|
|
|
|
2002-06-28 18:30:23 +00:00
|
|
|
|
|
2002-06-24 20:25:19 +00:00
|
|
|
|
char *
|
|
|
|
|
trim_trailing_spaces( char *string )
|
|
|
|
|
{
|
|
|
|
|
char *p, *mark;
|
|
|
|
|
|
|
|
|
|
for( mark = NULL, p = string; *p; p++ ) {
|
|
|
|
|
if( isspace( *p ) ) {
|
|
|
|
|
if( !mark )
|
|
|
|
|
mark = p;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
mark = NULL;
|
|
|
|
|
}
|
|
|
|
|
if( mark )
|
|
|
|
|
*mark = '\0' ;
|
|
|
|
|
|
|
|
|
|
return string ;
|
|
|
|
|
}
|
2002-05-31 15:34:39 +00:00
|
|
|
|
|
|
|
|
|
/* Parse a DN and return an array-ized one. This is not a validating
|
|
|
|
|
parser and it does not support any old-stylish syntax; gpgme is
|
|
|
|
|
expected to return only rfc2253 compatible strings. */
|
|
|
|
|
static const unsigned char *
|
|
|
|
|
parse_dn_part (struct DnPair *array, const unsigned char *string)
|
|
|
|
|
{
|
|
|
|
|
const unsigned char *s, *s1;
|
|
|
|
|
size_t n;
|
|
|
|
|
unsigned char *p;
|
|
|
|
|
|
|
|
|
|
/* parse attributeType */
|
|
|
|
|
for (s = string+1; *s && *s != '='; s++)
|
|
|
|
|
;
|
|
|
|
|
if (!*s)
|
|
|
|
|
return NULL; /* error */
|
|
|
|
|
n = s - string;
|
|
|
|
|
if (!n)
|
|
|
|
|
return NULL; /* empty key */
|
2002-06-28 18:30:23 +00:00
|
|
|
|
array->key = p = xmalloc (n+1);
|
2002-06-24 20:25:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
memcpy (p, string, n);
|
2002-05-31 15:34:39 +00:00
|
|
|
|
p[n] = 0;
|
2002-06-24 20:25:19 +00:00
|
|
|
|
trim_trailing_spaces (p);
|
|
|
|
|
if ( !strcmp (p, "1.2.840.113549.1.9.1") )
|
|
|
|
|
strcpy (p, "EMail");
|
2002-05-31 15:34:39 +00:00
|
|
|
|
string = s + 1;
|
|
|
|
|
|
|
|
|
|
if (*string == '#')
|
|
|
|
|
{ /* hexstring */
|
|
|
|
|
string++;
|
|
|
|
|
for (s=string; hexdigitp (s); s++)
|
|
|
|
|
s++;
|
|
|
|
|
n = s - string;
|
|
|
|
|
if (!n || (n & 1))
|
|
|
|
|
return NULL; /* empty or odd number of digits */
|
|
|
|
|
n /= 2;
|
2002-06-28 18:30:23 +00:00
|
|
|
|
array->value = p = xmalloc (n+1);
|
2002-06-24 20:25:19 +00:00
|
|
|
|
|
|
|
|
|
|
2002-05-31 15:34:39 +00:00
|
|
|
|
for (s1=string; n; s1 += 2, n--)
|
|
|
|
|
*p++ = xtoi_2 (s1);
|
|
|
|
|
*p = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{ /* regular v3 quoted string */
|
|
|
|
|
for (n=0, s=string; *s; s++)
|
|
|
|
|
{
|
|
|
|
|
if (*s == '\\')
|
|
|
|
|
{ /* pair */
|
|
|
|
|
s++;
|
|
|
|
|
if (*s == ',' || *s == '=' || *s == '+'
|
|
|
|
|
|| *s == '<' || *s == '>' || *s == '#' || *s == ';'
|
|
|
|
|
|| *s == '\\' || *s == '\"' || *s == ' ')
|
|
|
|
|
n++;
|
|
|
|
|
else if (hexdigitp (s) && hexdigitp (s+1))
|
|
|
|
|
{
|
|
|
|
|
s++;
|
|
|
|
|
n++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return NULL; /* invalid escape sequence */
|
|
|
|
|
}
|
|
|
|
|
else if (*s == '\"')
|
|
|
|
|
return NULL; /* invalid encoding */
|
|
|
|
|
else if (*s == ',' || *s == '=' || *s == '+'
|
|
|
|
|
|| *s == '<' || *s == '>' || *s == '#' || *s == ';' )
|
|
|
|
|
break;
|
|
|
|
|
else
|
|
|
|
|
n++;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-28 18:30:23 +00:00
|
|
|
|
array->value = p = xmalloc (n+1);
|
2002-06-24 20:25:19 +00:00
|
|
|
|
|
|
|
|
|
|
2002-05-31 15:34:39 +00:00
|
|
|
|
for (s=string; n; s++, n--)
|
|
|
|
|
{
|
|
|
|
|
if (*s == '\\')
|
|
|
|
|
{
|
|
|
|
|
s++;
|
|
|
|
|
if (hexdigitp (s))
|
|
|
|
|
{
|
|
|
|
|
*p++ = xtoi_2 (s);
|
|
|
|
|
s++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
*p++ = *s;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
*p++ = *s;
|
|
|
|
|
}
|
|
|
|
|
*p = 0;
|
|
|
|
|
}
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Parse a DN and return an array-ized one. This is not a validating
|
|
|
|
|
parser and it does not support any old-stylish syntax; gpgme is
|
|
|
|
|
expected to return only rfc2253 compatible strings. */
|
|
|
|
|
static struct DnPair *
|
|
|
|
|
parse_dn (const unsigned char *string)
|
|
|
|
|
{
|
|
|
|
|
struct DnPair *array;
|
|
|
|
|
size_t arrayidx, arraysize;
|
|
|
|
|
int i;
|
|
|
|
|
|
2002-06-26 04:44:58 +00:00
|
|
|
|
if( !string )
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2002-05-31 15:34:39 +00:00
|
|
|
|
arraysize = 7; /* C,ST,L,O,OU,CN,email */
|
|
|
|
|
arrayidx = 0;
|
2002-06-28 18:30:23 +00:00
|
|
|
|
array = xmalloc ((arraysize+1) * sizeof *array);
|
2002-06-24 20:25:19 +00:00
|
|
|
|
|
|
|
|
|
|
2002-05-31 15:34:39 +00:00
|
|
|
|
while (*string)
|
|
|
|
|
{
|
|
|
|
|
while (*string == ' ')
|
|
|
|
|
string++;
|
|
|
|
|
if (!*string)
|
|
|
|
|
break; /* ready */
|
|
|
|
|
if (arrayidx >= arraysize)
|
|
|
|
|
{ /* mutt lacks a real safe_realoc - so we need to copy */
|
|
|
|
|
struct DnPair *a2;
|
|
|
|
|
|
|
|
|
|
arraysize += 5;
|
2002-06-28 18:30:23 +00:00
|
|
|
|
a2 = xmalloc ((arraysize+1) * sizeof *array);
|
2002-05-31 15:34:39 +00:00
|
|
|
|
for (i=0; i < arrayidx; i++)
|
|
|
|
|
{
|
|
|
|
|
a2[i].key = array[i].key;
|
|
|
|
|
a2[i].value = array[i].value;
|
|
|
|
|
}
|
2002-07-01 13:01:51 +00:00
|
|
|
|
free (array);
|
2002-05-31 15:34:39 +00:00
|
|
|
|
array = a2;
|
|
|
|
|
}
|
|
|
|
|
array[arrayidx].key = NULL;
|
|
|
|
|
array[arrayidx].value = NULL;
|
|
|
|
|
string = parse_dn_part (array+arrayidx, string);
|
|
|
|
|
arrayidx++;
|
|
|
|
|
if (!string)
|
|
|
|
|
goto failure;
|
|
|
|
|
while (*string == ' ')
|
|
|
|
|
string++;
|
|
|
|
|
if (*string && *string != ',' && *string != ';' && *string != '+')
|
|
|
|
|
goto failure; /* invalid delimiter */
|
|
|
|
|
if (*string)
|
|
|
|
|
string++;
|
|
|
|
|
}
|
|
|
|
|
array[arrayidx].key = NULL;
|
|
|
|
|
array[arrayidx].value = NULL;
|
|
|
|
|
return array;
|
|
|
|
|
|
|
|
|
|
failure:
|
|
|
|
|
for (i=0; i < arrayidx; i++)
|
|
|
|
|
{
|
2002-07-01 13:01:51 +00:00
|
|
|
|
free (array[i].key);
|
|
|
|
|
free (array[i].value);
|
2002-05-31 15:34:39 +00:00
|
|
|
|
}
|
2002-07-01 13:01:51 +00:00
|
|
|
|
free (array);
|
2002-05-31 15:34:39 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-25 17:42:21 +00:00
|
|
|
|
static int
|
|
|
|
|
add_dn_part( char* result, struct DnPair* dn, const char* part )
|
2002-06-10 11:24:39 +00:00
|
|
|
|
{
|
|
|
|
|
int any = 0;
|
2002-05-31 15:34:39 +00:00
|
|
|
|
|
2002-06-26 04:44:58 +00:00
|
|
|
|
if( dn ) {
|
|
|
|
|
for(; dn->key; ++dn ) {
|
|
|
|
|
if( !strcmp( dn->key, part ) ) {
|
|
|
|
|
if( any ) strcat( result, "+" );
|
|
|
|
|
/* email hack */
|
|
|
|
|
if( !strcmp( part, "1.2.840.113549.1.9.1" ) ) strcat( result, "EMail" );
|
|
|
|
|
else strcat( result, part );
|
|
|
|
|
strcat( result, "=" );
|
|
|
|
|
strcat( result, dn->value );
|
|
|
|
|
any = 1;
|
|
|
|
|
}
|
2002-06-10 11:24:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return any;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-25 17:42:21 +00:00
|
|
|
|
static char*
|
|
|
|
|
reorder_dn( struct DnPair *dn )
|
2002-06-10 11:24:39 +00:00
|
|
|
|
{
|
2002-07-01 13:01:51 +00:00
|
|
|
|
/* note: The must parts are: CN, L, OU, O, C */
|
2002-06-20 05:05:43 +00:00
|
|
|
|
const char* stdpart[] = {
|
|
|
|
|
"CN", "S", "SN", "GN", "T", "UID",
|
|
|
|
|
"MAIL", "EMAIL", "MOBILE", "TEL", "FAX", "STREET",
|
|
|
|
|
"L", "PC", "SP", "ST",
|
|
|
|
|
"OU",
|
|
|
|
|
"O",
|
2002-06-20 16:48:37 +00:00
|
|
|
|
"C",
|
|
|
|
|
NULL
|
2002-06-20 05:05:43 +00:00
|
|
|
|
};
|
2002-06-10 11:24:39 +00:00
|
|
|
|
int any=0, any2=0, len=0, i;
|
|
|
|
|
char* result;
|
2002-06-26 04:44:58 +00:00
|
|
|
|
if( dn ) {
|
|
|
|
|
for( i = 0; dn[i].key; ++i ) {
|
|
|
|
|
len += strlen( dn[i].key );
|
|
|
|
|
len += strlen( dn[i].value );
|
|
|
|
|
len += 4; /* ',' and '=', and possibly "(" and ")" */
|
|
|
|
|
}
|
2002-06-10 11:24:39 +00:00
|
|
|
|
}
|
2002-06-28 18:30:23 +00:00
|
|
|
|
result = xmalloc( (len+1)*sizeof(char) );
|
2002-06-10 11:24:39 +00:00
|
|
|
|
*result = 0;
|
|
|
|
|
|
|
|
|
|
/* add standard parts */
|
|
|
|
|
for( i = 0; stdpart[i]; ++i ) {
|
|
|
|
|
if( any ) {
|
|
|
|
|
strcat( result, "," );
|
|
|
|
|
}
|
|
|
|
|
any = add_dn_part( result, dn, stdpart[i] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* add remaining parts in no particular order */
|
2002-06-26 04:44:58 +00:00
|
|
|
|
if( dn ) {
|
|
|
|
|
for(; dn->key; ++dn ) {
|
|
|
|
|
for( i = 0; stdpart[i]; ++i ) {
|
|
|
|
|
if( !strcmp( dn->key, stdpart[i] ) ) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if( !stdpart[i] ) {
|
|
|
|
|
if( any ) strcat( result, "," );
|
|
|
|
|
if( !any2 ) strcat( result, "(");
|
|
|
|
|
any = add_dn_part( result, dn, dn->key );
|
|
|
|
|
any2 = 1;
|
2002-06-10 11:24:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if( any2 ) strcat( result, ")");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2002-05-31 15:34:39 +00:00
|
|
|
|
|
|
|
|
|
struct CertIterator {
|
|
|
|
|
GpgmeCtx ctx;
|
|
|
|
|
struct CertificateInfo info;
|
|
|
|
|
};
|
|
|
|
|
|
2002-06-25 17:42:21 +00:00
|
|
|
|
struct CertIterator*
|
|
|
|
|
startListCertificates( const char* pattern, int remote )
|
2002-05-31 15:34:39 +00:00
|
|
|
|
{
|
|
|
|
|
GpgmeError err;
|
|
|
|
|
struct CertIterator* it;
|
2002-06-27 16:26:15 +00:00
|
|
|
|
const char* patterns[] = { pattern, NULL };
|
2002-07-01 12:52:29 +00:00
|
|
|
|
fprintf( stderr, "startListCertificates( \"%s\", %d )\n", pattern, remote );
|
2002-05-31 15:34:39 +00:00
|
|
|
|
|
2002-06-28 18:30:23 +00:00
|
|
|
|
it = xmalloc( sizeof( struct CertIterator ) );
|
2002-05-31 15:34:39 +00:00
|
|
|
|
|
|
|
|
|
err = gpgme_new (&(it->ctx));
|
|
|
|
|
/*fprintf( stderr, "2: gpgme returned %d\n", err );*/
|
|
|
|
|
if( err != GPGME_No_Error ) {
|
|
|
|
|
free( it );
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gpgme_set_protocol (it->ctx, GPGME_PROTOCOL_CMS);
|
2002-06-10 18:37:11 +00:00
|
|
|
|
if( remote ) gpgme_set_keylist_mode ( it->ctx, GPGME_KEYLIST_MODE_EXTERN );
|
|
|
|
|
else gpgme_set_keylist_mode ( it->ctx, GPGME_KEYLIST_MODE_LOCAL );
|
2002-06-27 16:26:15 +00:00
|
|
|
|
err = gpgme_op_keylist_ext_start ( it->ctx, patterns, 0, 0);
|
2002-05-31 15:34:39 +00:00
|
|
|
|
if( err != GPGME_No_Error ) {
|
2002-07-01 12:52:29 +00:00
|
|
|
|
fprintf( stderr, "gpgme_op_keylist_ext_start returned %d", err );
|
2002-05-31 15:34:39 +00:00
|
|
|
|
endListCertificates( it );
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
memset( &(it->info), 0, sizeof( struct CertificateInfo ) );
|
|
|
|
|
return it;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-13 01:56:31 +00:00
|
|
|
|
/* free() each string in a char*[] and the array itself */
|
2002-06-25 17:42:21 +00:00
|
|
|
|
static void
|
|
|
|
|
freeStringArray( char** c )
|
2002-05-31 15:34:39 +00:00
|
|
|
|
{
|
|
|
|
|
char** _c = c;
|
2002-07-01 13:01:51 +00:00
|
|
|
|
|
2002-05-31 15:34:39 +00:00
|
|
|
|
while( c && *c ) {
|
|
|
|
|
/*fprintf( stderr, "freeing \"%s\"\n", *c );*/
|
2002-07-01 13:01:51 +00:00
|
|
|
|
free( *c );
|
2002-05-31 15:34:39 +00:00
|
|
|
|
++c;
|
|
|
|
|
}
|
2002-07-01 13:01:51 +00:00
|
|
|
|
free( _c );
|
2002-05-31 15:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-06-13 01:56:31 +00:00
|
|
|
|
/* free all malloc'ed data in a struct CertificateInfo */
|
2002-06-25 17:42:21 +00:00
|
|
|
|
static void
|
|
|
|
|
freeInfo( struct CertificateInfo* info )
|
2002-05-31 15:34:39 +00:00
|
|
|
|
{
|
|
|
|
|
struct DnPair* a = info->dnarray;
|
|
|
|
|
assert( info );
|
2002-07-01 13:01:51 +00:00
|
|
|
|
freeStringArray( info->userid );
|
|
|
|
|
free( info->serial);
|
|
|
|
|
free( info->fingerprint );
|
|
|
|
|
free( info->issuer );
|
|
|
|
|
free( info->chainid );
|
|
|
|
|
free( info->caps );
|
2002-05-31 15:34:39 +00:00
|
|
|
|
while( a && a->key && a->value ) {
|
2002-07-01 13:01:51 +00:00
|
|
|
|
free (a->key);
|
|
|
|
|
free (a->value);
|
2002-05-31 15:34:39 +00:00
|
|
|
|
++a;
|
|
|
|
|
}
|
2002-07-01 13:01:51 +00:00
|
|
|
|
free (info->dnarray);
|
2002-05-31 15:34:39 +00:00
|
|
|
|
memset( info, 0, sizeof( *info ) );
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-13 01:56:31 +00:00
|
|
|
|
/* Format the fingerprint nicely. The caller should
|
2002-07-01 13:01:51 +00:00
|
|
|
|
free the returned value using free() */
|
2002-06-10 11:24:39 +00:00
|
|
|
|
static char* make_fingerprint( const char* fpr )
|
|
|
|
|
{
|
|
|
|
|
int len = strlen(fpr);
|
|
|
|
|
int i = 0;
|
2002-06-28 18:30:23 +00:00
|
|
|
|
char* result = xmalloc( (len + len/2 + 1)*sizeof(char) );
|
2002-07-01 13:01:51 +00:00
|
|
|
|
|
2002-06-10 11:24:39 +00:00
|
|
|
|
for(; *fpr; ++fpr, ++i ) {
|
|
|
|
|
if( i%3 == 2) {
|
|
|
|
|
result[i] = ':'; ++i;
|
|
|
|
|
}
|
|
|
|
|
result[i] = *fpr;
|
|
|
|
|
}
|
|
|
|
|
result[i] = 0;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2002-05-31 15:34:39 +00:00
|
|
|
|
|
2002-06-25 17:42:21 +00:00
|
|
|
|
int
|
|
|
|
|
nextCertificate( struct CertIterator* it, struct CertificateInfo** result )
|
2002-05-31 15:34:39 +00:00
|
|
|
|
{
|
|
|
|
|
GpgmeError err;
|
|
|
|
|
GpgmeKey key;
|
2002-06-13 01:56:31 +00:00
|
|
|
|
int retval = GPGME_No_Error;
|
2002-05-31 15:34:39 +00:00
|
|
|
|
assert( it );
|
2002-07-01 12:52:29 +00:00
|
|
|
|
fprintf( stderr, "nextCertificates( %p, %p )\n", it, result );
|
2002-05-31 15:34:39 +00:00
|
|
|
|
err = gpgme_op_keylist_next ( it->ctx, &key);
|
|
|
|
|
if( err != GPGME_EOF ) {
|
|
|
|
|
int idx;
|
|
|
|
|
const char* s;
|
|
|
|
|
unsigned long u;
|
|
|
|
|
char* names[MAX_GPGME_IDX+1];
|
2002-06-10 17:53:04 +00:00
|
|
|
|
struct DnPair *issuer_dn, *tmp_dn;
|
2002-06-13 01:56:31 +00:00
|
|
|
|
retval = err;
|
2002-05-31 15:34:39 +00:00
|
|
|
|
memset( names, 0, sizeof( names ) );
|
|
|
|
|
freeInfo( &(it->info) );
|
|
|
|
|
|
|
|
|
|
for( idx = 0; (s = gpgme_key_get_string_attr (key, GPGME_ATTR_USERID, 0, idx)) && idx < MAX_GPGME_IDX;
|
|
|
|
|
++idx ) {
|
|
|
|
|
names[idx] = xstrdup( s );
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-28 18:30:23 +00:00
|
|
|
|
it->info.userid = xmalloc( sizeof( char* ) * (idx+1) );
|
2002-05-31 15:34:39 +00:00
|
|
|
|
memset( it->info.userid, 0, sizeof( char* ) * (idx+1) );
|
|
|
|
|
it->info.dnarray = 0;
|
|
|
|
|
for( idx = 0; names[idx] != 0; ++idx ) {
|
|
|
|
|
struct DnPair* a = parse_dn( names[idx] );
|
2002-06-10 11:24:39 +00:00
|
|
|
|
if( idx == 0 ) {
|
|
|
|
|
it->info.userid[idx] = reorder_dn( a );
|
2002-06-13 01:56:31 +00:00
|
|
|
|
it->info.dnarray = a;
|
2002-07-01 13:01:51 +00:00
|
|
|
|
free (names[idx]);
|
|
|
|
|
names[idx] = NULL;
|
2002-06-10 11:24:39 +00:00
|
|
|
|
} else {
|
|
|
|
|
it->info.userid[idx] = names[idx];
|
|
|
|
|
}
|
2002-05-31 15:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
it->info.userid[idx] = 0;
|
|
|
|
|
|
|
|
|
|
s = gpgme_key_get_string_attr (key, GPGME_ATTR_SERIAL, 0, 0);
|
2002-06-28 18:30:23 +00:00
|
|
|
|
it->info.serial = s? xstrdup(s) : NULL;
|
2002-05-31 15:34:39 +00:00
|
|
|
|
|
|
|
|
|
s = gpgme_key_get_string_attr (key, GPGME_ATTR_FPR, 0, 0);
|
2002-06-10 11:24:39 +00:00
|
|
|
|
it->info.fingerprint = make_fingerprint( s );
|
2002-05-31 15:34:39 +00:00
|
|
|
|
|
|
|
|
|
s = gpgme_key_get_string_attr (key, GPGME_ATTR_ISSUER, 0, 0);
|
2002-06-10 17:53:04 +00:00
|
|
|
|
if( s ) {
|
|
|
|
|
issuer_dn = tmp_dn = parse_dn( s );
|
|
|
|
|
/*it->info.issuer = xstrdup(s);*/
|
|
|
|
|
it->info.issuer = reorder_dn( issuer_dn );
|
2002-09-20 11:47:55 +00:00
|
|
|
|
while( tmp_dn && tmp_dn->key ) {
|
2002-07-03 11:04:54 +00:00
|
|
|
|
free( tmp_dn->key );
|
|
|
|
|
free( tmp_dn->value );
|
2002-06-10 17:53:04 +00:00
|
|
|
|
++tmp_dn;
|
|
|
|
|
}
|
2002-07-01 13:01:51 +00:00
|
|
|
|
free( issuer_dn );
|
|
|
|
|
issuer_dn = tmp_dn = NULL;
|
2002-06-10 17:53:04 +00:00
|
|
|
|
} else {
|
|
|
|
|
it->info.issuer = NULL;
|
|
|
|
|
}
|
2002-05-31 15:34:39 +00:00
|
|
|
|
s = gpgme_key_get_string_attr (key, GPGME_ATTR_CHAINID, 0, 0);
|
2002-06-28 18:30:23 +00:00
|
|
|
|
it->info.chainid = s? xstrdup(s): NULL;
|
2002-05-31 15:34:39 +00:00
|
|
|
|
|
|
|
|
|
s = gpgme_key_get_string_attr (key, GPGME_ATTR_KEY_CAPS, 0, 0);
|
2002-06-28 18:30:23 +00:00
|
|
|
|
it->info.caps = s? xstrdup(s) : NULL;
|
2002-05-31 15:34:39 +00:00
|
|
|
|
|
|
|
|
|
u = gpgme_key_get_ulong_attr (key, GPGME_ATTR_CREATED, 0, 0);
|
|
|
|
|
it->info.created = u;
|
|
|
|
|
|
|
|
|
|
u = gpgme_key_get_ulong_attr (key, GPGME_ATTR_EXPIRE, 0, 0);
|
|
|
|
|
it->info.expire = u;
|
|
|
|
|
|
|
|
|
|
u = gpgme_key_get_ulong_attr (key, GPGME_ATTR_IS_SECRET, 0, 0);
|
|
|
|
|
it->info.secret = u;
|
|
|
|
|
|
|
|
|
|
u = gpgme_key_get_ulong_attr (key, GPGME_ATTR_UID_INVALID, 0, 0);
|
|
|
|
|
it->info.invalid = u;
|
|
|
|
|
|
|
|
|
|
u = gpgme_key_get_ulong_attr (key, GPGME_ATTR_KEY_EXPIRED, 0, 0);
|
|
|
|
|
it->info.expired = u;
|
|
|
|
|
|
|
|
|
|
u = gpgme_key_get_ulong_attr (key, GPGME_ATTR_KEY_DISABLED, 0, 0);
|
|
|
|
|
it->info.disabled = u;
|
|
|
|
|
|
|
|
|
|
gpgme_key_release (key);
|
2002-06-13 01:56:31 +00:00
|
|
|
|
/*return &(it->info);*/
|
|
|
|
|
*result = &(it->info);
|
2002-06-27 13:15:02 +00:00
|
|
|
|
} else {
|
|
|
|
|
*result = NULL;
|
|
|
|
|
}
|
2002-06-13 01:56:31 +00:00
|
|
|
|
return retval;
|
2002-05-31 15:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-06-27 13:15:02 +00:00
|
|
|
|
int
|
2002-06-25 17:42:21 +00:00
|
|
|
|
endListCertificates( struct CertIterator* it )
|
2002-05-31 15:34:39 +00:00
|
|
|
|
{
|
2002-06-27 13:15:02 +00:00
|
|
|
|
char *s = gpgme_get_op_info (it->ctx, 0);
|
|
|
|
|
int truncated = s && strstr (s, "<truncated/>");
|
2002-07-01 12:52:29 +00:00
|
|
|
|
fprintf( stderr, "endListCertificates( %p )\n", it );
|
2002-06-27 13:15:02 +00:00
|
|
|
|
if( s ) free( s );
|
2002-05-31 15:34:39 +00:00
|
|
|
|
assert(it);
|
|
|
|
|
freeInfo( &(it->info) );
|
|
|
|
|
gpgme_op_keylist_end(it->ctx);
|
|
|
|
|
gpgme_release (it->ctx);
|
|
|
|
|
free( it );
|
2002-06-27 13:15:02 +00:00
|
|
|
|
return truncated;
|
2002-05-31 15:34:39 +00:00
|
|
|
|
}
|
2002-06-24 20:25:19 +00:00
|
|
|
|
|
2002-06-25 17:42:21 +00:00
|
|
|
|
int
|
2002-07-31 12:37:34 +00:00
|
|
|
|
importCertificateWithFPR( const char* fingerprint, char** additional_info )
|
2002-06-25 17:42:21 +00:00
|
|
|
|
{
|
|
|
|
|
GpgmeError err;
|
|
|
|
|
GpgmeCtx ctx;
|
|
|
|
|
GpgmeData keydata;
|
|
|
|
|
GpgmeRecipients recips;
|
|
|
|
|
char* buf;
|
2002-06-25 20:24:29 +00:00
|
|
|
|
const char* tmp1;
|
2002-06-25 17:42:21 +00:00
|
|
|
|
char* tmp2;
|
2002-08-20 23:37:43 +00:00
|
|
|
|
int count = 0;
|
2002-06-25 20:24:29 +00:00
|
|
|
|
|
2002-06-25 17:42:21 +00:00
|
|
|
|
err = gpgme_new( &ctx );
|
|
|
|
|
/*fprintf( stderr, "2: gpgme returned %d\n", err );*/
|
|
|
|
|
if( err != GPGME_No_Error ) {
|
|
|
|
|
return err;
|
|
|
|
|
}
|
2002-06-25 20:24:29 +00:00
|
|
|
|
gpgme_set_protocol( ctx, GPGME_PROTOCOL_CMS );
|
|
|
|
|
gpgme_set_keylist_mode( ctx, GPGME_KEYLIST_MODE_LOCAL );
|
2002-06-25 17:42:21 +00:00
|
|
|
|
|
|
|
|
|
err = gpgme_data_new( &keydata );
|
|
|
|
|
if( err ) {
|
|
|
|
|
fprintf( stderr, "gpgme_data_new returned %d\n", err );
|
|
|
|
|
gpgme_release( ctx );
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = gpgme_recipients_new( &recips );
|
|
|
|
|
if( err ) {
|
|
|
|
|
fprintf( stderr, "gpgme_recipients_new returned %d\n", err );
|
|
|
|
|
gpgme_data_release( keydata );
|
|
|
|
|
gpgme_release( ctx );
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-28 18:30:23 +00:00
|
|
|
|
buf = malloc( sizeof(char)*( strlen( fingerprint ) + 1 ) );
|
2002-06-25 17:42:21 +00:00
|
|
|
|
if( !buf ) {
|
|
|
|
|
gpgme_recipients_release( recips );
|
|
|
|
|
gpgme_data_release( keydata );
|
|
|
|
|
gpgme_release( ctx );
|
|
|
|
|
return GPGME_Out_Of_Core;
|
|
|
|
|
}
|
|
|
|
|
tmp1 = fingerprint;
|
|
|
|
|
tmp2 = buf;
|
|
|
|
|
while( *tmp1 ) {
|
|
|
|
|
if( *tmp1 != ':' ) *tmp2++ = *tmp1;
|
|
|
|
|
tmp1++;
|
|
|
|
|
}
|
|
|
|
|
*tmp2 = 0;
|
|
|
|
|
fprintf( stderr, "calling gpgme_recipients_add_name( %s )\n", buf );
|
2002-06-25 20:24:29 +00:00
|
|
|
|
err = gpgme_recipients_add_name( recips, buf );
|
2002-06-25 17:42:21 +00:00
|
|
|
|
if( err ) {
|
|
|
|
|
fprintf( stderr, "gpgme_recipients_add_name returned %d\n", err );
|
2002-07-01 13:01:51 +00:00
|
|
|
|
free (buf);
|
2002-06-25 17:42:21 +00:00
|
|
|
|
gpgme_recipients_release( recips );
|
|
|
|
|
gpgme_data_release( keydata );
|
|
|
|
|
gpgme_release( ctx );
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = gpgme_op_export( ctx, recips, keydata );
|
|
|
|
|
if( err ) {
|
|
|
|
|
fprintf( stderr, "gpgme_op_export returned %d\n", err );
|
2002-07-01 13:01:51 +00:00
|
|
|
|
free (buf);
|
2002-07-31 12:37:34 +00:00
|
|
|
|
*additional_info = gpgme_get_op_info( ctx, 0 );
|
2002-06-25 17:42:21 +00:00
|
|
|
|
gpgme_recipients_release( recips );
|
|
|
|
|
gpgme_data_release( keydata );
|
|
|
|
|
gpgme_release( ctx );
|
|
|
|
|
return err;
|
|
|
|
|
}
|
2002-07-01 13:01:51 +00:00
|
|
|
|
free (buf);
|
|
|
|
|
buf = NULL;
|
2002-06-25 17:42:21 +00:00
|
|
|
|
|
2002-08-20 23:37:43 +00:00
|
|
|
|
err = gpgme_op_import_ext( ctx, keydata, &count );
|
2002-07-31 12:37:34 +00:00
|
|
|
|
*additional_info = gpgme_get_op_info( ctx, 0 );
|
2002-06-25 17:42:21 +00:00
|
|
|
|
if( err ) {
|
2002-08-20 23:37:43 +00:00
|
|
|
|
fprintf( stderr, "gpgme_op_import_ext returned %d\n", err );
|
2002-06-25 17:42:21 +00:00
|
|
|
|
gpgme_recipients_release( recips );
|
2002-07-31 12:37:34 +00:00
|
|
|
|
gpgme_data_release( keydata );
|
2002-06-25 17:42:21 +00:00
|
|
|
|
gpgme_release( ctx );
|
|
|
|
|
return err;
|
|
|
|
|
}
|
2002-08-20 23:37:43 +00:00
|
|
|
|
if( count < 1 ) {
|
|
|
|
|
/* we didn't import anything?!? */
|
|
|
|
|
fprintf( stderr, "gpgme_op_import_ext did not import any certificates\n" );
|
|
|
|
|
gpgme_recipients_release( recips );
|
|
|
|
|
gpgme_data_release( keydata );
|
|
|
|
|
gpgme_release( ctx );
|
|
|
|
|
return -1; /* FIXME */
|
|
|
|
|
}
|
2002-06-25 17:42:21 +00:00
|
|
|
|
|
|
|
|
|
gpgme_recipients_release( recips );
|
|
|
|
|
gpgme_data_release( keydata );
|
|
|
|
|
gpgme_release( ctx );
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2002-07-31 12:37:34 +00:00
|
|
|
|
int
|
|
|
|
|
importCertificateFromMem( const char* data, size_t length , char** additional_info )
|
|
|
|
|
{
|
|
|
|
|
GpgmeError err;
|
|
|
|
|
GpgmeCtx ctx;
|
|
|
|
|
GpgmeData keydata;
|
2002-08-20 23:37:43 +00:00
|
|
|
|
int count = 0;
|
2002-07-31 12:37:34 +00:00
|
|
|
|
|
|
|
|
|
err = gpgme_new( &ctx );
|
|
|
|
|
/*fprintf( stderr, "2: gpgme returned %d\n", err );*/
|
|
|
|
|
if( err != GPGME_No_Error ) {
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
gpgme_set_protocol( ctx, GPGME_PROTOCOL_CMS );
|
|
|
|
|
gpgme_set_keylist_mode( ctx, GPGME_KEYLIST_MODE_LOCAL );
|
|
|
|
|
|
|
|
|
|
err = gpgme_data_new_from_mem( &keydata, data, length, 0 );
|
|
|
|
|
if( err ) {
|
|
|
|
|
fprintf( stderr, "gpgme_data_new returned %d\n", err );
|
|
|
|
|
gpgme_release( ctx );
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-20 23:37:43 +00:00
|
|
|
|
err = gpgme_op_import_ext( ctx, keydata, &count );
|
2002-07-31 12:37:34 +00:00
|
|
|
|
*additional_info = gpgme_get_op_info( ctx, 0 );
|
2002-08-20 23:37:43 +00:00
|
|
|
|
if( err) {
|
|
|
|
|
fprintf( stderr, "gpgme_op_import_ext returned %d\n", err );
|
2002-07-31 12:37:34 +00:00
|
|
|
|
gpgme_data_release( keydata );
|
|
|
|
|
gpgme_release( ctx );
|
|
|
|
|
return err;
|
|
|
|
|
}
|
2002-08-20 23:37:43 +00:00
|
|
|
|
if( count < 1 ) {
|
|
|
|
|
/* we didn't import anything?!? */
|
2002-09-03 16:21:34 +00:00
|
|
|
|
fprintf( stderr, "gpgme_op_import_ext did not import any certificate\n" );
|
2002-08-20 23:37:43 +00:00
|
|
|
|
gpgme_data_release( keydata );
|
|
|
|
|
gpgme_release( ctx );
|
|
|
|
|
return -1; /* FIXME */
|
|
|
|
|
}
|
2002-07-31 12:37:34 +00:00
|
|
|
|
|
|
|
|
|
gpgme_data_release( keydata );
|
|
|
|
|
gpgme_release( ctx );
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2002-06-24 20:25:19 +00:00
|
|
|
|
|
2002-06-28 19:50:31 +00:00
|
|
|
|
/* == == == == == == == == == == == == == == == == == == == == == == == == ==
|
|
|
|
|
== ==
|
|
|
|
|
== Continuation of CryptPlug code ==
|
|
|
|
|
== ==
|
|
|
|
|
== == == == == == == == == == == == == == == == == == == == == == == == == */
|
2002-06-24 20:25:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Find all certificate for a given addressee and return them in a
|
|
|
|
|
'\1' separated list.
|
2002-06-26 00:05:30 +00:00
|
|
|
|
NOTE: The certificate parameter must point to a not-yet allocated
|
|
|
|
|
char*. The function will allocate the memory needed and
|
|
|
|
|
return the size in newSize.
|
2002-06-25 15:05:59 +00:00
|
|
|
|
If secretOnly is true, only secret keys are returned.
|
2002-06-24 20:25:19 +00:00
|
|
|
|
*/
|
2002-06-26 00:05:30 +00:00
|
|
|
|
bool findCertificates( const char* addressee,
|
|
|
|
|
char** certificates,
|
2002-06-26 04:44:58 +00:00
|
|
|
|
int* newSize,
|
2002-06-26 00:05:30 +00:00
|
|
|
|
bool secretOnly )
|
2002-06-24 20:25:19 +00:00
|
|
|
|
{
|
2002-06-28 19:40:13 +00:00
|
|
|
|
#define MAXCERTS 1024
|
2002-06-28 19:37:06 +00:00
|
|
|
|
/* use const char declarations since all of them are needed twice */
|
2002-06-26 04:44:58 +00:00
|
|
|
|
const char* delimiter = "\1";
|
|
|
|
|
const char* openBracket = " (";
|
|
|
|
|
const char* closeBracket = ")";
|
|
|
|
|
|
2002-06-24 20:25:19 +00:00
|
|
|
|
GpgmeCtx ctx;
|
|
|
|
|
GpgmeError err;
|
|
|
|
|
GpgmeKey rKey;
|
|
|
|
|
const char *s;
|
|
|
|
|
const char *s2;
|
|
|
|
|
char* dn;
|
|
|
|
|
struct DnPair* a;
|
|
|
|
|
int nFound = 0;
|
2002-06-26 04:44:58 +00:00
|
|
|
|
int iFound = 0;
|
|
|
|
|
int siz = 0;
|
2002-06-28 18:30:23 +00:00
|
|
|
|
char* DNs[MAXCERTS];
|
|
|
|
|
char* FPRs[MAXCERTS];
|
2002-06-26 04:44:58 +00:00
|
|
|
|
|
|
|
|
|
if( ! certificates ){
|
|
|
|
|
fprintf( stderr, "gpgme: findCertificates called with invalid *certificates pointer\n" );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-26 00:05:30 +00:00
|
|
|
|
if( ! newSize ){
|
2002-06-26 04:44:58 +00:00
|
|
|
|
fprintf( stderr, "gpgme: findCertificates called with invalid newSize pointer\n" );
|
2002-06-26 00:05:30 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2002-06-24 20:25:19 +00:00
|
|
|
|
|
2002-06-26 04:44:58 +00:00
|
|
|
|
*certificates = 0;
|
|
|
|
|
*newSize = 0;
|
|
|
|
|
|
2002-06-28 18:30:23 +00:00
|
|
|
|
/* calculate length of buffer needed for certs plus fingerprints */
|
2002-06-24 20:25:19 +00:00
|
|
|
|
gpgme_new (&ctx);
|
|
|
|
|
gpgme_set_protocol (ctx, GPGMEPLUG_PROTOCOL);
|
2002-06-26 00:05:30 +00:00
|
|
|
|
err = gpgme_op_keylist_start(ctx, addressee, secretOnly ? 1 : 0);
|
|
|
|
|
while( GPGME_No_Error == err ) {
|
|
|
|
|
err = gpgme_op_keylist_next(ctx, &rKey);
|
|
|
|
|
if( GPGME_No_Error == err ) {
|
|
|
|
|
s = gpgme_key_get_string_attr (rKey, GPGME_ATTR_USERID, NULL, 0);
|
|
|
|
|
if( s ) {
|
2002-06-26 04:44:58 +00:00
|
|
|
|
dn = xstrdup( s );
|
2002-06-26 00:05:30 +00:00
|
|
|
|
s2 = gpgme_key_get_string_attr (rKey, GPGME_ATTR_FPR, NULL, 0);
|
|
|
|
|
if( s2 ) {
|
|
|
|
|
if( nFound )
|
2002-06-26 04:44:58 +00:00
|
|
|
|
siz += strlen( delimiter );
|
|
|
|
|
a = parse_dn( dn );
|
|
|
|
|
free( dn );
|
2002-06-26 00:05:30 +00:00
|
|
|
|
dn = reorder_dn( a );
|
2002-06-26 04:44:58 +00:00
|
|
|
|
siz += strlen( dn );
|
|
|
|
|
siz += strlen( openBracket );
|
|
|
|
|
siz += strlen( s2 );
|
|
|
|
|
siz += strlen( closeBracket );
|
2002-06-28 14:12:18 +00:00
|
|
|
|
DNs[ nFound ] = dn;
|
2002-07-01 13:01:51 +00:00
|
|
|
|
dn = NULL; /* prevent it from being free'ed below. */
|
2002-06-26 04:44:58 +00:00
|
|
|
|
FPRs[nFound ] = xstrdup( s2 );
|
2002-06-26 00:05:30 +00:00
|
|
|
|
++nFound;
|
2002-06-28 19:40:13 +00:00
|
|
|
|
if( nFound >= MAXCERTS ) {
|
2002-06-26 04:44:58 +00:00
|
|
|
|
fprintf( stderr,
|
|
|
|
|
"gpgme: findCertificates found too many certificates (%d)\n",
|
2002-06-28 18:30:23 +00:00
|
|
|
|
MAXCERTS );
|
2002-06-26 04:44:58 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2002-06-26 00:05:30 +00:00
|
|
|
|
}
|
2002-07-01 11:36:48 +00:00
|
|
|
|
free (dn);
|
2002-06-26 00:05:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
gpgme_op_keylist_end( ctx );
|
2002-06-26 04:44:58 +00:00
|
|
|
|
gpgme_release (ctx);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( 0 < siz ) {
|
2002-06-28 18:30:23 +00:00
|
|
|
|
/* add one for trailing ZERO char */
|
2002-06-26 04:44:58 +00:00
|
|
|
|
++siz;
|
|
|
|
|
*newSize = siz;
|
2002-06-28 18:30:23 +00:00
|
|
|
|
/* allocate the buffer */
|
2002-07-01 12:08:24 +00:00
|
|
|
|
*certificates = xmalloc( sizeof(char) * siz );
|
2002-06-26 04:44:58 +00:00
|
|
|
|
memset( *certificates, 0, sizeof(char) * siz );
|
2002-06-28 18:30:23 +00:00
|
|
|
|
/* fill the buffer */
|
2002-07-01 11:36:48 +00:00
|
|
|
|
for (iFound=0; iFound < nFound; iFound++) {
|
2002-06-26 04:44:58 +00:00
|
|
|
|
if( !iFound )
|
|
|
|
|
strcpy(*certificates, DNs[iFound] );
|
|
|
|
|
else {
|
|
|
|
|
strcat(*certificates, delimiter );
|
|
|
|
|
strcat(*certificates, DNs[iFound] );
|
2002-06-24 20:25:19 +00:00
|
|
|
|
}
|
2002-06-26 04:44:58 +00:00
|
|
|
|
strcat( *certificates, openBracket );
|
|
|
|
|
strcat( *certificates, FPRs[iFound] );
|
|
|
|
|
strcat( *certificates, closeBracket );
|
|
|
|
|
free( DNs[ iFound ] );
|
|
|
|
|
free( FPRs[iFound ] );
|
2002-06-24 20:25:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-06-26 04:44:58 +00:00
|
|
|
|
|
2002-06-24 20:25:19 +00:00
|
|
|
|
return ( 0 < nFound );
|
|
|
|
|
}
|
2002-06-28 14:12:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const char*
|
|
|
|
|
sig_status_to_string( GpgmeSigStat status )
|
|
|
|
|
{
|
|
|
|
|
const char *result;
|
|
|
|
|
|
|
|
|
|
switch (status) {
|
|
|
|
|
case GPGME_SIG_STAT_NONE:
|
|
|
|
|
result = "Oops: Signature not verified";
|
|
|
|
|
break;
|
|
|
|
|
case GPGME_SIG_STAT_NOSIG:
|
|
|
|
|
result = "No signature found";
|
|
|
|
|
break;
|
|
|
|
|
case GPGME_SIG_STAT_GOOD:
|
|
|
|
|
result = "Good signature";
|
|
|
|
|
break;
|
|
|
|
|
case GPGME_SIG_STAT_BAD:
|
|
|
|
|
result = "BAD signature";
|
|
|
|
|
break;
|
|
|
|
|
case GPGME_SIG_STAT_NOKEY:
|
|
|
|
|
result = "No public key to verify the signature";
|
|
|
|
|
break;
|
|
|
|
|
case GPGME_SIG_STAT_ERROR:
|
|
|
|
|
result = "Error verifying the signature";
|
|
|
|
|
break;
|
|
|
|
|
case GPGME_SIG_STAT_DIFF:
|
|
|
|
|
result = "Different results for signatures";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
result = "Error: Unknown status";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-09-12 11:02:02 +00:00
|
|
|
|
void obtain_signature_information( GpgmeCtx * ctx,
|
|
|
|
|
GpgmeSigStat status,
|
|
|
|
|
struct SignatureMetaData* sigmeta )
|
2002-06-28 14:12:18 +00:00
|
|
|
|
{
|
|
|
|
|
GpgmeError err;
|
|
|
|
|
GpgmeKey key;
|
2002-09-12 11:02:02 +00:00
|
|
|
|
const char* statusStr;
|
|
|
|
|
const char* fpr;
|
|
|
|
|
unsigned long sumGPGME;
|
|
|
|
|
SigStatusFlags sumPlug;
|
2002-06-28 14:12:18 +00:00
|
|
|
|
time_t created;
|
|
|
|
|
struct DnPair* a;
|
|
|
|
|
int sig_idx=0;
|
|
|
|
|
int UID_idx=0;
|
|
|
|
|
|
|
|
|
|
/* Provide information in the sigmeta struct */
|
|
|
|
|
/* the status string */
|
|
|
|
|
statusStr = sig_status_to_string( status );
|
|
|
|
|
sigmeta->status = malloc( strlen( statusStr ) + 1 );
|
|
|
|
|
if( sigmeta->status ) {
|
|
|
|
|
strcpy( sigmeta->status, statusStr );
|
|
|
|
|
sigmeta->status[strlen( statusStr )] = '\0';
|
|
|
|
|
} else
|
|
|
|
|
; /* nothing to do, is already 0 */
|
|
|
|
|
|
|
|
|
|
/* Extended information for any number of signatures. */
|
2002-09-12 11:02:02 +00:00
|
|
|
|
fpr = gpgme_get_sig_status( *ctx, sig_idx, &status, &created );
|
2002-06-28 14:12:18 +00:00
|
|
|
|
sigmeta->extended_info = 0;
|
|
|
|
|
while( fpr != NULL ) {
|
|
|
|
|
struct tm* ctime_val;
|
|
|
|
|
const char* sig_status;
|
|
|
|
|
|
|
|
|
|
void* alloc_return = realloc( sigmeta->extended_info,
|
|
|
|
|
sizeof( struct SignatureMetaDataExtendedInfo )
|
|
|
|
|
* ( sig_idx + 1 ) );
|
|
|
|
|
if( alloc_return ) {
|
|
|
|
|
sigmeta->extended_info = alloc_return;
|
|
|
|
|
|
|
|
|
|
/* clear the data area */
|
|
|
|
|
memset( &sigmeta->extended_info[sig_idx],
|
|
|
|
|
0,
|
|
|
|
|
sizeof (struct SignatureMetaDataExtendedInfo) );
|
|
|
|
|
|
|
|
|
|
/* the creation time */
|
|
|
|
|
sigmeta->extended_info[sig_idx].creation_time = malloc( sizeof( struct tm ) );
|
|
|
|
|
if( sigmeta->extended_info[sig_idx].creation_time ) {
|
|
|
|
|
ctime_val = localtime( &created );
|
|
|
|
|
memcpy( sigmeta->extended_info[sig_idx].creation_time,
|
|
|
|
|
ctime_val, sizeof( struct tm ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* the extended signature verification status */
|
2002-09-12 11:02:02 +00:00
|
|
|
|
sumGPGME = gpgme_get_sig_ulong_attr( *ctx,
|
2002-06-28 14:12:18 +00:00
|
|
|
|
sig_idx,
|
|
|
|
|
GPGME_ATTR_SIG_SUMMARY,
|
|
|
|
|
0 );
|
|
|
|
|
fprintf( stderr, "gpgmeplug checkMessageSignature status flags: %lX\n", sumGPGME );
|
2002-07-01 13:01:51 +00:00
|
|
|
|
/* translate GPGME status flags to common CryptPlug status flags */
|
2002-06-28 14:12:18 +00:00
|
|
|
|
sumPlug = 0;
|
|
|
|
|
if( sumGPGME & GPGME_SIGSUM_VALID ) sumPlug |= SigStat_VALID ;
|
|
|
|
|
if( sumGPGME & GPGME_SIGSUM_GREEN ) sumPlug |= SigStat_GREEN ;
|
|
|
|
|
if( sumGPGME & GPGME_SIGSUM_RED ) sumPlug |= SigStat_RED ;
|
|
|
|
|
if( sumGPGME & GPGME_SIGSUM_KEY_REVOKED ) sumPlug |= SigStat_KEY_REVOKED;
|
|
|
|
|
if( sumGPGME & GPGME_SIGSUM_KEY_EXPIRED ) sumPlug |= SigStat_KEY_EXPIRED;
|
|
|
|
|
if( sumGPGME & GPGME_SIGSUM_SIG_EXPIRED ) sumPlug |= SigStat_SIG_EXPIRED;
|
|
|
|
|
if( sumGPGME & GPGME_SIGSUM_KEY_MISSING ) sumPlug |= SigStat_KEY_MISSING;
|
|
|
|
|
if( sumGPGME & GPGME_SIGSUM_CRL_MISSING ) sumPlug |= SigStat_CRL_MISSING;
|
|
|
|
|
if( sumGPGME & GPGME_SIGSUM_CRL_TOO_OLD ) sumPlug |= SigStat_CRL_TOO_OLD;
|
|
|
|
|
if( sumGPGME & GPGME_SIGSUM_BAD_POLICY ) sumPlug |= SigStat_BAD_POLICY ;
|
|
|
|
|
if( sumGPGME & GPGME_SIGSUM_SYS_ERROR ) sumPlug |= SigStat_SYS_ERROR ;
|
|
|
|
|
if( !sumPlug )
|
|
|
|
|
sumPlug = SigStat_NUMERICAL_CODE | sumGPGME;
|
|
|
|
|
sigmeta->extended_info[sig_idx].sigStatusFlags = sumPlug;
|
|
|
|
|
|
|
|
|
|
sigmeta->extended_info[sig_idx].validity = GPGME_VALIDITY_UNKNOWN;
|
|
|
|
|
|
2002-09-12 11:02:02 +00:00
|
|
|
|
err = gpgme_get_sig_key (*ctx, sig_idx, &key);
|
2002-06-28 14:12:18 +00:00
|
|
|
|
|
|
|
|
|
if ( err == GPGME_No_Error) {
|
|
|
|
|
const char* attr_string;
|
|
|
|
|
unsigned long attr_ulong;
|
|
|
|
|
|
|
|
|
|
/* extract key identidy */
|
|
|
|
|
attr_string = gpgme_key_get_string_attr(key, GPGME_ATTR_KEYID, 0, 0);
|
|
|
|
|
if (attr_string != 0)
|
|
|
|
|
storeNewCharPtr( &sigmeta->extended_info[sig_idx].keyid, attr_string );
|
|
|
|
|
|
|
|
|
|
/* extract finger print */
|
|
|
|
|
attr_string = gpgme_key_get_string_attr(key, GPGME_ATTR_FPR, 0, 0);
|
|
|
|
|
if (attr_string != 0)
|
|
|
|
|
storeNewCharPtr( &sigmeta->extended_info[sig_idx].fingerprint,
|
|
|
|
|
attr_string );
|
|
|
|
|
|
|
|
|
|
/* algorithms useable with this key */
|
|
|
|
|
attr_string = gpgme_key_get_string_attr(key, GPGME_ATTR_ALGO, 0, 0);
|
|
|
|
|
if (attr_string != 0)
|
|
|
|
|
storeNewCharPtr( &sigmeta->extended_info[sig_idx].algo,
|
|
|
|
|
attr_string );
|
|
|
|
|
attr_ulong = gpgme_key_get_ulong_attr(key, GPGME_ATTR_ALGO, 0, 0);
|
|
|
|
|
sigmeta->extended_info[sig_idx].algo_num = attr_ulong;
|
|
|
|
|
|
|
|
|
|
/* extract key validity */
|
|
|
|
|
attr_ulong = gpgme_key_get_ulong_attr(key, GPGME_ATTR_VALIDITY, 0, 0);
|
|
|
|
|
sigmeta->extended_info[sig_idx].validity = attr_ulong;
|
|
|
|
|
|
|
|
|
|
/* extract user id, according to the documentation it's representable
|
|
|
|
|
* as a number, but it seems that it also has a string representation
|
|
|
|
|
*/
|
|
|
|
|
attr_string = gpgme_key_get_string_attr(key, GPGME_ATTR_USERID, 0, 0);
|
|
|
|
|
if (attr_string != 0) {
|
|
|
|
|
a = parse_dn( attr_string );
|
2002-07-01 12:08:24 +00:00
|
|
|
|
sigmeta->extended_info[sig_idx].userid = reorder_dn( a );
|
2002-06-28 14:12:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
attr_ulong = gpgme_key_get_ulong_attr(key, GPGME_ATTR_USERID, 0, 0);
|
|
|
|
|
sigmeta->extended_info[sig_idx].userid_num = attr_ulong;
|
|
|
|
|
|
|
|
|
|
/* extract the length */
|
2002-07-02 16:32:29 +00:00
|
|
|
|
sigmeta->extended_info[sig_idx].keylen = attr_ulong;
|
2002-06-28 14:12:18 +00:00
|
|
|
|
|
|
|
|
|
/* extract the creation time of the key */
|
|
|
|
|
attr_ulong = gpgme_key_get_ulong_attr(key, GPGME_ATTR_CREATED, 0, 0);
|
|
|
|
|
sigmeta->extended_info[sig_idx].key_created = attr_ulong;
|
|
|
|
|
|
|
|
|
|
/* extract the expiration time of the key */
|
|
|
|
|
attr_ulong = gpgme_key_get_ulong_attr(key, GPGME_ATTR_EXPIRE, 0, 0);
|
|
|
|
|
sigmeta->extended_info[sig_idx].key_expires = attr_ulong;
|
|
|
|
|
|
|
|
|
|
/* extract user name */
|
|
|
|
|
attr_string = gpgme_key_get_string_attr(key, GPGME_ATTR_NAME, 0, 0);
|
|
|
|
|
if (attr_string != 0) {
|
|
|
|
|
a = parse_dn( attr_string );
|
2002-07-01 12:08:24 +00:00
|
|
|
|
sigmeta->extended_info[sig_idx].name = reorder_dn( a );
|
2002-06-28 14:12:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* extract email(s) */
|
|
|
|
|
sigmeta->extended_info[sig_idx].emailCount = 0;
|
|
|
|
|
sigmeta->extended_info[sig_idx].emailList = 0;
|
|
|
|
|
for( UID_idx=0;
|
|
|
|
|
(attr_string = gpgme_key_get_string_attr(key,
|
|
|
|
|
GPGME_ATTR_EMAIL, 0, UID_idx));
|
|
|
|
|
++UID_idx ){
|
|
|
|
|
if (*attr_string) {
|
|
|
|
|
fprintf( stderr, "gpgmeplug checkMessageSignature found email: %s\n", attr_string );
|
2002-07-04 00:02:19 +00:00
|
|
|
|
if( !sigmeta->extended_info[sig_idx].emailCount )
|
2002-06-28 14:12:18 +00:00
|
|
|
|
alloc_return =
|
|
|
|
|
malloc( sizeof( char*) );
|
|
|
|
|
else
|
|
|
|
|
alloc_return =
|
|
|
|
|
realloc( sigmeta->extended_info[sig_idx].emailList,
|
|
|
|
|
sizeof( char*)
|
|
|
|
|
* (sigmeta->extended_info[sig_idx].emailCount + 1) );
|
|
|
|
|
if( alloc_return ) {
|
|
|
|
|
sigmeta->extended_info[sig_idx].emailList = alloc_return;
|
|
|
|
|
storeNewCharPtr(
|
|
|
|
|
&( sigmeta->extended_info[sig_idx].emailList[
|
|
|
|
|
sigmeta->extended_info[sig_idx].emailCount ] ),
|
|
|
|
|
attr_string );
|
|
|
|
|
++sigmeta->extended_info[sig_idx].emailCount;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if( !sigmeta->extended_info[sig_idx].emailCount )
|
|
|
|
|
fprintf( stderr, "gpgmeplug checkMessageSignature found NO EMAIL\n" );
|
|
|
|
|
|
|
|
|
|
/* extract the comment */
|
|
|
|
|
attr_string = gpgme_key_get_string_attr(key, GPGME_ATTR_COMMENT, 0, 0);
|
|
|
|
|
if (attr_string != 0)
|
|
|
|
|
storeNewCharPtr( &sigmeta->extended_info[sig_idx].comment,
|
|
|
|
|
attr_string );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
storeNewCharPtr( &sigmeta->extended_info[sig_idx].fingerprint, fpr );
|
|
|
|
|
|
|
|
|
|
sig_status = sig_status_to_string( status );
|
|
|
|
|
storeNewCharPtr( &sigmeta->extended_info[sig_idx].status_text,
|
|
|
|
|
sig_status );
|
|
|
|
|
|
|
|
|
|
} else
|
|
|
|
|
break; /* if allocation fails once, it isn't likely to
|
|
|
|
|
succeed the next time either */
|
|
|
|
|
|
2002-09-12 11:02:02 +00:00
|
|
|
|
fpr = gpgme_get_sig_status (*ctx, ++sig_idx, &status, &created);
|
2002-06-28 14:12:18 +00:00
|
|
|
|
}
|
|
|
|
|
sigmeta->extended_info_count = sig_idx;
|
2002-09-12 11:02:02 +00:00
|
|
|
|
sigmeta->nota_xml = gpgme_get_notation( *ctx );
|
2002-06-28 14:12:18 +00:00
|
|
|
|
sigmeta->status_code = status;
|
2002-09-12 11:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool checkMessageSignature( char** cleartext,
|
|
|
|
|
const char* signaturetext,
|
|
|
|
|
bool signatureIsBinary,
|
|
|
|
|
int signatureLen,
|
|
|
|
|
struct SignatureMetaData* sigmeta )
|
|
|
|
|
{
|
|
|
|
|
GpgmeCtx ctx;
|
|
|
|
|
GpgmeSigStat status;
|
|
|
|
|
GpgmeData datapart, sigpart;
|
|
|
|
|
char* rClear = 0;
|
|
|
|
|
size_t clearLen;
|
|
|
|
|
bool isOpaqueSigned;
|
|
|
|
|
|
|
|
|
|
if( !cleartext ) {
|
|
|
|
|
if( sigmeta )
|
|
|
|
|
storeNewCharPtr( &sigmeta->status,
|
|
|
|
|
__GPGMEPLUG_ERROR_CLEARTEXT_IS_ZERO );
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2002-06-28 14:12:18 +00:00
|
|
|
|
|
2002-09-12 11:02:02 +00:00
|
|
|
|
isOpaqueSigned = !*cleartext;
|
|
|
|
|
|
|
|
|
|
gpgme_new( &ctx );
|
|
|
|
|
gpgme_set_protocol (ctx, GPGMEPLUG_PROTOCOL);
|
|
|
|
|
gpgme_set_armor (ctx, signatureIsBinary ? 0 : 1);
|
|
|
|
|
/* gpgme_set_textmode (ctx, signatureIsBinary ? 0 : 1); */
|
|
|
|
|
|
|
|
|
|
if( isOpaqueSigned )
|
|
|
|
|
gpgme_data_new( &datapart );
|
|
|
|
|
else
|
|
|
|
|
gpgme_data_new_from_mem( &datapart, *cleartext,
|
|
|
|
|
strlen( *cleartext ), 1 );
|
|
|
|
|
|
|
|
|
|
gpgme_data_new_from_mem( &sigpart,
|
|
|
|
|
signaturetext,
|
|
|
|
|
signatureIsBinary
|
|
|
|
|
? signatureLen
|
|
|
|
|
: strlen( signaturetext ),
|
|
|
|
|
1 );
|
|
|
|
|
|
2002-10-12 14:32:01 +00:00
|
|
|
|
gpgme_op_verify( ctx, sigpart, isOpaqueSigned ? NULL : datapart,
|
|
|
|
|
isOpaqueSigned ? datapart : NULL, &status );
|
2002-09-12 11:02:02 +00:00
|
|
|
|
|
|
|
|
|
if( isOpaqueSigned ) {
|
|
|
|
|
rClear = gpgme_data_release_and_get_mem( datapart, &clearLen );
|
|
|
|
|
*cleartext = malloc( clearLen + 1 );
|
|
|
|
|
if( *cleartext ) {
|
|
|
|
|
if( clearLen )
|
|
|
|
|
strncpy(*cleartext, rClear, clearLen );
|
|
|
|
|
(*cleartext)[clearLen] = '\0';
|
|
|
|
|
}
|
|
|
|
|
free( rClear );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
gpgme_data_release( datapart );
|
|
|
|
|
|
|
|
|
|
gpgme_data_release( sigpart );
|
|
|
|
|
|
|
|
|
|
obtain_signature_information( &ctx, status, sigmeta );
|
|
|
|
|
|
2002-06-28 14:12:18 +00:00
|
|
|
|
gpgme_release( ctx );
|
|
|
|
|
return ( status == GPGME_SIG_STAT_GOOD );
|
|
|
|
|
}
|
|
|
|
|
|
2002-09-12 11:02:02 +00:00
|
|
|
|
|
|
|
|
|
bool decryptAndCheckMessage( const char* ciphertext,
|
|
|
|
|
bool cipherIsBinary,
|
|
|
|
|
int cipherLen,
|
|
|
|
|
const char** cleartext,
|
|
|
|
|
const char* certificate,
|
|
|
|
|
bool* signatureFound,
|
|
|
|
|
struct SignatureMetaData* sigmeta,
|
|
|
|
|
int* errId,
|
|
|
|
|
char** errTxt )
|
|
|
|
|
{
|
|
|
|
|
GpgmeCtx ctx;
|
|
|
|
|
GpgmeError err;
|
|
|
|
|
GpgmeSigStat sigstatus;
|
|
|
|
|
GpgmeData gCiphertext, gPlaintext;
|
|
|
|
|
size_t rCLen = 0;
|
|
|
|
|
char* rCiph = 0;
|
|
|
|
|
bool bOk = false;
|
|
|
|
|
|
|
|
|
|
if( !ciphertext )
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
err = gpgme_new (&ctx);
|
|
|
|
|
gpgme_set_protocol (ctx, GPGMEPLUG_PROTOCOL);
|
|
|
|
|
|
|
|
|
|
gpgme_set_armor (ctx, cipherIsBinary ? 0 : 1);
|
|
|
|
|
/* gpgme_set_textmode (ctx, cipherIsBinary ? 0 : 1); */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
gpgme_data_new_from_mem( &gCiphertext, ciphertext,
|
|
|
|
|
1+strlen( ciphertext ), 1 ); */
|
|
|
|
|
gpgme_data_new_from_mem( &gCiphertext,
|
|
|
|
|
ciphertext,
|
|
|
|
|
cipherIsBinary
|
|
|
|
|
? cipherLen
|
|
|
|
|
: strlen( ciphertext ),
|
|
|
|
|
1 );
|
|
|
|
|
|
|
|
|
|
gpgme_data_new( &gPlaintext );
|
|
|
|
|
|
|
|
|
|
err = gpgme_op_decrypt_verify( ctx, gCiphertext, gPlaintext, &sigstatus );
|
|
|
|
|
gpgme_data_release( gCiphertext );
|
|
|
|
|
if( err ) {
|
|
|
|
|
fprintf( stderr, "\ngpgme_op_decrypt_verify() returned this error code: %i\n\n", err );
|
|
|
|
|
if( errId )
|
|
|
|
|
*errId = err;
|
|
|
|
|
if( errTxt ) {
|
|
|
|
|
const char* _errTxt = gpgme_strerror( err );
|
|
|
|
|
*errTxt = malloc( strlen( _errTxt ) + 1 );
|
|
|
|
|
if( *errTxt )
|
|
|
|
|
strcpy(*errTxt, _errTxt );
|
|
|
|
|
}
|
|
|
|
|
gpgme_data_release( gPlaintext );
|
|
|
|
|
gpgme_release( ctx );
|
|
|
|
|
return bOk;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rCiph = gpgme_data_release_and_get_mem( gPlaintext, &rCLen );
|
|
|
|
|
|
|
|
|
|
*cleartext = malloc( rCLen + 1 );
|
|
|
|
|
if( *cleartext ) {
|
|
|
|
|
if( rCLen ) {
|
|
|
|
|
bOk = true;
|
|
|
|
|
strncpy((char*)*cleartext, rCiph, rCLen );
|
|
|
|
|
}
|
|
|
|
|
((char*)(*cleartext))[rCLen] = 0;
|
|
|
|
|
}
|
|
|
|
|
free( rCiph );
|
|
|
|
|
|
|
|
|
|
if( signatureFound )
|
|
|
|
|
*signatureFound = sigstatus != GPGME_SIG_STAT_NONE;
|
|
|
|
|
if( sigmeta && sigstatus != GPGME_SIG_STAT_NONE )
|
|
|
|
|
obtain_signature_information( &ctx, sigstatus, sigmeta );
|
|
|
|
|
|
|
|
|
|
gpgme_release( ctx );
|
|
|
|
|
return bOk;
|
|
|
|
|
}
|