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
|
|
|
|
|
|
|
|
|
|
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-01-15 08:03:26 +00:00
|
|
|
|
// definitions for signing
|
2001-12-24 00:09:24 +00:00
|
|
|
|
#ifndef GPGMEPLUG_SIGN_MAKE_MIME_OBJECT
|
|
|
|
|
#define GPGMEPLUG_SIGN_INCLUDE_CLEARTEXT true
|
|
|
|
|
#define GPGMEPLUG_SIGN_MAKE_MIME_OBJECT true
|
|
|
|
|
#define GPGMEPLUG_SIGN_MAKE_MULTI_MIME true
|
2002-01-15 08:03:26 +00:00
|
|
|
|
#define GPGMEPLUG_SIGN_CTYPE_MAIN "multipart/signed;protocol=application/pgp-signature;micalg=pgp-sha1"
|
2001-12-24 00:09:24 +00:00
|
|
|
|
#define GPGMEPLUG_SIGN_CDISP_MAIN ""
|
|
|
|
|
#define GPGMEPLUG_SIGN_CTENC_MAIN ""
|
|
|
|
|
#define GPGMEPLUG_SIGN_CTYPE_VERSION ""
|
|
|
|
|
#define GPGMEPLUG_SIGN_CDISP_VERSION ""
|
|
|
|
|
#define GPGMEPLUG_SIGN_CTENC_VERSION ""
|
|
|
|
|
#define GPGMEPLUG_SIGN_BTEXT_VERSION ""
|
|
|
|
|
#define GPGMEPLUG_SIGN_CTYPE_CODE "application/pgp-signature"
|
|
|
|
|
#define GPGMEPLUG_SIGN_CDISP_CODE ""
|
|
|
|
|
#define GPGMEPLUG_SIGN_CTENC_CODE ""
|
|
|
|
|
#define GPGMEPLUG_SIGN_FLAT_PREFIX ""
|
|
|
|
|
#define GPGMEPLUG_SIGN_FLAT_SEPARATOR ""
|
|
|
|
|
#define GPGMEPLUG_SIGN_FLAT_POSTFIX ""
|
|
|
|
|
#endif
|
2002-01-15 08:03:26 +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 ""
|
|
|
|
|
#endif
|
|
|
|
|
// 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.
|
|
|
|
|
#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"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
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;
|
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
|
|
|
|
|
|
|
|
|
bool initialize()
|
|
|
|
|
{
|
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;
|
|
|
|
|
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;
|
|
|
|
|
|
2001-11-21 09:42:08 +00:00
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 )
|
|
|
|
|
{
|
|
|
|
|
switch ( flag ) {
|
|
|
|
|
case CryptPlugFeat_SignMessages: return true;
|
|
|
|
|
case CryptPlugFeat_VerifySignatures: return true;
|
|
|
|
|
case CryptPlugFeat_EncryptMessages: return true;
|
|
|
|
|
case CryptPlugFeat_DecryptMessages: return true;
|
|
|
|
|
// undefined or not yet implemented:
|
|
|
|
|
case CryptPlugFeat_undef: return false;
|
|
|
|
|
default: return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
bool isEmailInCertificate( const char* email, const char* certificate )
|
|
|
|
|
{
|
|
|
|
|
/* PENDING(g10) this function should return true if the email
|
|
|
|
|
address passed as the first parameter is contained in the
|
|
|
|
|
certificate passed as the second parameter, and false
|
|
|
|
|
otherwise. This is used to alert the user if his own email
|
|
|
|
|
address is not contained in the certificate he uses for
|
|
|
|
|
signing.
|
|
|
|
|
Note that the parameter email can be anything that is allowed
|
|
|
|
|
in a From: line.
|
2002-03-01 16:55:50 +00:00
|
|
|
|
Another note: OK, OK, we'll handle that in the MUA. You can
|
|
|
|
|
assume that you only get the email address.
|
2002-02-28 12:09:45 +00:00
|
|
|
|
*/
|
|
|
|
|
return false; // dummy
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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 )
|
|
|
|
|
{
|
|
|
|
|
/* PENDING(g10)
|
|
|
|
|
Please return the number of days that are left until the
|
|
|
|
|
certificate specified in the parameter certificate expires.
|
|
|
|
|
*/
|
|
|
|
|
return 10; // dummy that triggers a warning in the MUA
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
return 10; // dummy that triggers a warning in the MUA
|
|
|
|
|
}
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
return 10; // dummy that triggers a warning in the MUA
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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 )
|
|
|
|
|
{
|
|
|
|
|
/* PENDING(g10)
|
|
|
|
|
Please return the number of days that are left until the
|
|
|
|
|
certificate specified in the parameter certificate expires.
|
|
|
|
|
*/
|
|
|
|
|
return 10; // dummy that triggers a warning in the MUA
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
return 10; // dummy that triggers a warning in the MUA
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
return 10; // dummy that triggers a warning in the MUA
|
|
|
|
|
}
|
|
|
|
|
|
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 );
|
|
|
|
|
*dest = malloc( sLen + 1 );
|
2002-01-15 08:03:26 +00:00
|
|
|
|
strcpy( *dest, src );
|
|
|
|
|
(*dest)[sLen] = '\0';
|
2001-12-24 00:09:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-21 09:42:08 +00:00
|
|
|
|
bool signMessage( const char* cleartext,
|
|
|
|
|
const char** ciphertext,
|
2001-12-24 00:09:24 +00:00
|
|
|
|
const char* certificate,
|
|
|
|
|
struct StructuringInfo* structuring )
|
2001-11-21 09:42:08 +00:00
|
|
|
|
{
|
|
|
|
|
GpgmeCtx ctx;
|
2001-11-23 02:08:53 +00:00
|
|
|
|
GpgmeError err;
|
2001-11-22 09:36:53 +00:00
|
|
|
|
GpgmeData data, sig;
|
2001-11-29 12:29:55 +00:00
|
|
|
|
size_t rSLen = 0;
|
|
|
|
|
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
|
|
|
|
|
2001-11-21 09:42:08 +00:00
|
|
|
|
gpgme_set_armor (ctx, 1);
|
|
|
|
|
gpgme_set_textmode (ctx, 1);
|
|
|
|
|
|
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-02-28 07:49:13 +00:00
|
|
|
|
// PENDING(g10) Implement this
|
|
|
|
|
//gpgme_set_signature_algorithm( ctx, config.signatureAlgorithm );
|
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 );
|
2001-11-29 12:29:55 +00:00
|
|
|
|
err = gpgme_op_sign (ctx, data, sig, GPGME_SIG_MODE_DETACH );
|
|
|
|
|
|
|
|
|
|
if (!err) {
|
|
|
|
|
rSig = gpgme_data_release_and_get_mem( sig, &rSLen );
|
|
|
|
|
*ciphertext = malloc( rSLen + 1 );
|
|
|
|
|
if( *ciphertext ) {
|
|
|
|
|
if( rSLen ) {
|
|
|
|
|
bOk = true;
|
|
|
|
|
strncpy((char*)*ciphertext, rSig, rSLen );
|
|
|
|
|
}
|
|
|
|
|
((char*)(*ciphertext))[rSLen] = '\0';
|
2001-11-25 03:37:13 +00:00
|
|
|
|
}
|
2001-11-29 12:29:55 +00:00
|
|
|
|
free( rSig );
|
2001-11-21 09:42:08 +00:00
|
|
|
|
}
|
2001-11-29 12:29:55 +00:00
|
|
|
|
else {
|
|
|
|
|
gpgme_data_release( sig );
|
|
|
|
|
*ciphertext = 0;
|
|
|
|
|
// hier fehlt eine Fehlerbehandlung, falls das
|
|
|
|
|
// Signieren schiefging
|
|
|
|
|
}
|
|
|
|
|
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 ) {
|
|
|
|
|
structuring->includeCleartext = GPGMEPLUG_SIGN_INCLUDE_CLEARTEXT;
|
|
|
|
|
structuring->makeMimeObject = GPGMEPLUG_SIGN_MAKE_MIME_OBJECT;
|
|
|
|
|
if( structuring->makeMimeObject ) {
|
|
|
|
|
structuring->makeMultiMime = GPGMEPLUG_SIGN_MAKE_MULTI_MIME;
|
|
|
|
|
storeNewCharPtr( &structuring->contentTypeMain,
|
|
|
|
|
GPGMEPLUG_SIGN_CTYPE_MAIN );
|
|
|
|
|
storeNewCharPtr( &structuring->contentDispMain,
|
|
|
|
|
GPGMEPLUG_SIGN_CDISP_MAIN );
|
|
|
|
|
storeNewCharPtr( &structuring->contentTEncMain,
|
|
|
|
|
GPGMEPLUG_SIGN_CTENC_MAIN );
|
|
|
|
|
if( structuring->makeMultiMime ) {
|
|
|
|
|
storeNewCharPtr( &structuring->contentTypeVersion,
|
|
|
|
|
GPGMEPLUG_SIGN_CTYPE_VERSION );
|
|
|
|
|
storeNewCharPtr( &structuring->contentDispVersion,
|
|
|
|
|
GPGMEPLUG_SIGN_CDISP_VERSION );
|
|
|
|
|
storeNewCharPtr( &structuring->contentTEncVersion,
|
|
|
|
|
GPGMEPLUG_SIGN_CTENC_VERSION );
|
|
|
|
|
storeNewCharPtr( &structuring->bodyTextVersion,
|
|
|
|
|
GPGMEPLUG_SIGN_BTEXT_VERSION );
|
|
|
|
|
storeNewCharPtr( &structuring->contentTypeCode,
|
|
|
|
|
GPGMEPLUG_SIGN_CTYPE_CODE );
|
|
|
|
|
storeNewCharPtr( &structuring->contentDispCode,
|
|
|
|
|
GPGMEPLUG_SIGN_CDISP_CODE );
|
|
|
|
|
storeNewCharPtr( &structuring->contentTEncCode,
|
|
|
|
|
GPGMEPLUG_SIGN_CTENC_CODE );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
storeNewCharPtr( &structuring->flatTextPrefix,
|
|
|
|
|
GPGMEPLUG_SIGN_FLAT_PREFIX );
|
|
|
|
|
storeNewCharPtr( &structuring->flatTextSeparator,
|
|
|
|
|
GPGMEPLUG_SIGN_FLAT_SEPARATOR );
|
|
|
|
|
storeNewCharPtr( &structuring->flatTextPostfix,
|
|
|
|
|
GPGMEPLUG_SIGN_FLAT_POSTFIX );
|
|
|
|
|
}
|
|
|
|
|
}
|
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-25 21:53:39 +00:00
|
|
|
|
static const char*
|
|
|
|
|
sig_status_to_string( GpgmeSigStat status )
|
|
|
|
|
{
|
2001-12-24 00:09:24 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2001-11-25 21:53:39 +00:00
|
|
|
|
|
2001-12-24 00:09:24 +00:00
|
|
|
|
return result;
|
2001-11-25 21:53:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-26 15:54:12 +00:00
|
|
|
|
bool checkMessageSignature( const char* ciphertext,
|
2001-11-25 15:23:21 +00:00
|
|
|
|
const char* signaturetext,
|
2002-03-05 21:23:58 +00:00
|
|
|
|
bool signatureIsBinary,
|
|
|
|
|
int signatureLen,
|
2001-11-25 15:23:21 +00:00
|
|
|
|
struct SignatureMetaData* sigmeta )
|
2001-11-26 15:54:12 +00:00
|
|
|
|
{
|
2001-12-24 00:09:24 +00:00
|
|
|
|
GpgmeCtx ctx;
|
|
|
|
|
GpgmeSigStat status;
|
|
|
|
|
GpgmeData datapart, sigpart;
|
|
|
|
|
GpgmeError err;
|
|
|
|
|
GpgmeKey key;
|
|
|
|
|
time_t created;
|
|
|
|
|
int sig_idx = 0;
|
|
|
|
|
const char* statusStr;
|
|
|
|
|
const char* fpr;
|
|
|
|
|
|
|
|
|
|
gpgme_new( &ctx );
|
|
|
|
|
gpgme_set_protocol (ctx, GPGMEPLUG_PROTOCOL);
|
2002-03-05 21:23:58 +00:00
|
|
|
|
gpgme_set_armor (ctx, signatureIsBinary ? 0 : 1);
|
|
|
|
|
// gpgme_set_textmode (ctx, signatureIsBinary ? 0 : 1);
|
|
|
|
|
|
2001-12-24 00:09:24 +00:00
|
|
|
|
gpgme_data_new_from_mem( &datapart, ciphertext,
|
2002-03-06 17:23:17 +00:00
|
|
|
|
strlen( ciphertext ), 1 );
|
2002-03-05 21:23:58 +00:00
|
|
|
|
|
|
|
|
|
gpgme_data_new_from_mem( &sigpart,
|
|
|
|
|
signaturetext,
|
|
|
|
|
signatureIsBinary
|
|
|
|
|
? signatureLen
|
2002-03-06 17:23:17 +00:00
|
|
|
|
: strlen( signaturetext ),
|
2002-03-05 21:23:58 +00:00
|
|
|
|
1 );
|
2001-12-24 00:09:24 +00:00
|
|
|
|
|
|
|
|
|
gpgme_op_verify( ctx, sigpart, datapart, &status );
|
|
|
|
|
gpgme_data_release( datapart );
|
|
|
|
|
gpgme_data_release( sigpart );
|
|
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
|
fpr = gpgme_get_sig_status( ctx, sig_idx, &status, &created );
|
|
|
|
|
sigmeta->extended_info = 0;
|
|
|
|
|
while( fpr != NULL ) {
|
|
|
|
|
struct tm* ctime_val;
|
|
|
|
|
const char* sig_status;
|
|
|
|
|
|
|
|
|
|
void* realloc_return = realloc( sigmeta->extended_info,
|
|
|
|
|
sizeof( struct SignatureMetaDataExtendedInfo ) * ( sig_idx + 1 ) );
|
|
|
|
|
if( realloc_return ) {
|
|
|
|
|
sigmeta->extended_info = realloc_return;
|
|
|
|
|
// 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 ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = gpgme_get_sig_key (ctx, sig_idx, &key);
|
|
|
|
|
sig_status = sig_status_to_string( status );
|
|
|
|
|
sigmeta->extended_info[sig_idx].status_text = malloc( strlen( sig_status ) + 1 );
|
|
|
|
|
if( sigmeta->extended_info[sig_idx].status_text ) {
|
|
|
|
|
strcpy( sigmeta->extended_info[sig_idx].status_text,
|
|
|
|
|
sig_status );
|
|
|
|
|
sigmeta->extended_info[sig_idx].status_text[strlen( sig_status )] = '\0';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sigmeta->extended_info[sig_idx].fingerprint = malloc( strlen( fpr ) + 1 );
|
|
|
|
|
if( sigmeta->extended_info[sig_idx].fingerprint ) {
|
|
|
|
|
strcpy( sigmeta->extended_info[sig_idx].fingerprint, fpr );
|
|
|
|
|
sigmeta->extended_info[sig_idx].fingerprint[strlen( fpr )] = '\0';
|
|
|
|
|
}
|
2001-12-06 16:59:09 +00:00
|
|
|
|
} else
|
2001-12-24 00:09:24 +00:00
|
|
|
|
break; // if allocation fails once, it isn't likely to
|
|
|
|
|
// succeed the next time either
|
|
|
|
|
|
|
|
|
|
fpr = gpgme_get_sig_status (ctx, ++sig_idx, &status, &created);
|
|
|
|
|
}
|
|
|
|
|
sigmeta->extended_info_count = sig_idx;
|
|
|
|
|
sigmeta->nota_xml = gpgme_get_notation( ctx );
|
|
|
|
|
sigmeta->status_code = status;
|
2001-11-26 15:54:12 +00:00
|
|
|
|
|
2001-12-24 00:09:24 +00:00
|
|
|
|
gpgme_release( ctx );
|
|
|
|
|
return ( status == GPGME_SIG_STAT_GOOD );
|
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-07 14:10:07 +00:00
|
|
|
|
/* returns the next address in a comma-separated list
|
|
|
|
|
or NULL if the list is empty. The function honors double quotes
|
|
|
|
|
and '(' ')' comments.
|
|
|
|
|
A non-NULL return value should be deleted with free().
|
|
|
|
|
*/
|
|
|
|
|
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 ) {
|
|
|
|
|
|
|
|
|
|
switch( **address ) {
|
|
|
|
|
case '\\': /* escaped character */
|
|
|
|
|
++(*address);
|
|
|
|
|
break;
|
|
|
|
|
case '"':
|
|
|
|
|
if( comment == 0 ) {
|
|
|
|
|
if( quote > 0 ) --quote;
|
|
|
|
|
else ++quote;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case '(': /* comment start */
|
|
|
|
|
if( quote == 0 ) ++comment;
|
|
|
|
|
break;
|
|
|
|
|
case ')': /* comment end */
|
|
|
|
|
if( quote == 0 ) --comment;
|
|
|
|
|
break;
|
|
|
|
|
case '\0':
|
|
|
|
|
case ',': /* delimiter */
|
|
|
|
|
if( quote == 0 && comment == 0 ) {
|
|
|
|
|
found = 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
++(*address);
|
|
|
|
|
if( found ) break;
|
|
|
|
|
}
|
|
|
|
|
if( found || **address == 0 ) {
|
|
|
|
|
size_t len;
|
|
|
|
|
while( isspace( *start ) ) ++start;
|
|
|
|
|
len = *address - start;
|
|
|
|
|
if( len > 0 ) {
|
|
|
|
|
if( **address != 0 ) --len;
|
|
|
|
|
result = malloc( len*sizeof(char)+1 );
|
|
|
|
|
strncpy( result, start, len );
|
|
|
|
|
result[len] = '\0';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-21 09:42:08 +00:00
|
|
|
|
bool encryptMessage( const char* cleartext,
|
2001-11-25 03:37:13 +00:00
|
|
|
|
const char** ciphertext,
|
2001-12-24 00:09:24 +00:00
|
|
|
|
const char* addressee,
|
|
|
|
|
struct StructuringInfo* structuring )
|
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;
|
2001-11-29 12:29:55 +00:00
|
|
|
|
size_t rCLen = 0;
|
2001-11-25 05:07:44 +00:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
gpgme_set_armor (ctx, 1);
|
|
|
|
|
gpgme_set_textmode (ctx, 1);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
2001-12-18 21:11:03 +00:00
|
|
|
|
if( GPGMEPLUG_PROTOCOL == GPGME_PROTOCOL_CMS )
|
|
|
|
|
{
|
2001-12-24 00:09:24 +00:00
|
|
|
|
gpgme_recipients_add_name_with_validity (rset,
|
2001-12-18 21:11:03 +00:00
|
|
|
|
"/CN=test cert 1,OU=Aegypten Project,O=g10 Code GmbH,L=Düsseldorf,C=DE",
|
|
|
|
|
GPGME_VALIDITY_FULL );
|
|
|
|
|
fputs( "\nGPGSMPLUG encryptMessage() using test key of Aegypten Project\n", stderr );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2002-03-07 14:10:07 +00:00
|
|
|
|
const char* p = addressee;
|
|
|
|
|
char* tok;
|
|
|
|
|
while( (tok = nextAddress( &p ) ) != 0 ) {
|
|
|
|
|
gpgme_recipients_add_name (rset, tok);
|
|
|
|
|
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-07 21:18:27 +00:00
|
|
|
|
// PENDING(g10) Implement this
|
|
|
|
|
// Possible values: RSA = 1, SHA1 = 2, TripleDES = 3
|
|
|
|
|
//gpgme_set_encryption_algorithm( ctx, config.encryptionAlgorithm );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// PENDING(g10) Implement this
|
|
|
|
|
// gpgme_set_encryption_check_certificate_path(
|
|
|
|
|
// config.checkCertificatePath )
|
|
|
|
|
|
|
|
|
|
// PENDING(g10) Implement this
|
|
|
|
|
// gpgme_set_encryption_check_certificate_path_to_root(
|
|
|
|
|
// config.checkEncryptionCertificatePathToRoot )
|
|
|
|
|
|
2001-11-25 05:07:44 +00:00
|
|
|
|
|
2001-11-29 12:29:55 +00:00
|
|
|
|
err = gpgme_op_encrypt (ctx, rset, gPlaintext, gCiphertext );
|
2001-12-18 21:11:03 +00:00
|
|
|
|
if( err )
|
|
|
|
|
fprintf( stderr, "gpgme_op_encrypt() returned this error code: %i\n\n", err );
|
|
|
|
|
|
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
|
|
|
|
|
2001-11-29 12:29:55 +00:00
|
|
|
|
if( !err ) {
|
|
|
|
|
rCiph = gpgme_data_release_and_get_mem( gCiphertext, &rCLen );
|
|
|
|
|
*ciphertext = malloc( rCLen + 1 );
|
|
|
|
|
if( *ciphertext ) {
|
|
|
|
|
if( rCLen ) {
|
|
|
|
|
bOk = true;
|
|
|
|
|
strncpy((char*)*ciphertext, rCiph, rCLen );
|
|
|
|
|
}
|
|
|
|
|
((char*)(*ciphertext))[rCLen] = 0;
|
2001-11-25 05:07:44 +00:00
|
|
|
|
}
|
2001-11-29 12:29:55 +00:00
|
|
|
|
free( rCiph );
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
gpgme_data_release ( gCiphertext );
|
|
|
|
|
*ciphertext = 0;
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
|
|
// implementation of this function is still missing
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2001-12-06 17:19:07 +00:00
|
|
|
|
bool decryptMessage( const char* ciphertext,
|
|
|
|
|
const char** cleartext,
|
|
|
|
|
const char* certificate )
|
|
|
|
|
{
|
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);
|
|
|
|
|
|
|
|
|
|
gpgme_data_new_from_mem( &gCiphertext, ciphertext,
|
|
|
|
|
1+strlen( ciphertext ), 1 );
|
|
|
|
|
gpgme_data_new( &gPlaintext );
|
2001-12-06 17:19:07 +00:00
|
|
|
|
|
2001-12-13 15:13:09 +00:00
|
|
|
|
gpgme_op_decrypt( ctx, gCiphertext, gPlaintext );
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
bool decryptAndCheckMessage( const char* ciphertext,
|
|
|
|
|
const char** cleartext, const char* certificate,
|
|
|
|
|
struct SignatureMetaData* sigmeta ){ return true; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char* requestCertificateDialog(){ return 0; }
|
|
|
|
|
|
|
|
|
|
bool requestDecentralCertificate( const char* name, const char*
|
|
|
|
|
email, const char* organization, const char* department,
|
|
|
|
|
const char* ca_address ){ return true; }
|
|
|
|
|
|
|
|
|
|
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(){}
|