2000-11-07 13:32:38 +00:00
|
|
|
/* encrypt.c - encrypt functions
|
|
|
|
* Copyright (C) 2000 Werner Koch (dd9jn)
|
2002-02-06 01:41:15 +00:00
|
|
|
* Copyright (C) 2001, 2002 g10 Code GmbH
|
2000-11-07 13:32:38 +00:00
|
|
|
*
|
|
|
|
* This file is part of GPGME.
|
|
|
|
*
|
|
|
|
* GPGME is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* GPGME is distributed in the hope that it will be useful,
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
#include "context.h"
|
|
|
|
#include "ops.h"
|
|
|
|
|
2001-09-03 18:41:53 +00:00
|
|
|
#define SKIP_TOKEN_OR_RETURN(a) do { \
|
|
|
|
while (*(a) && *(a) != ' ') (a)++; \
|
|
|
|
while (*(a) == ' ') (a)++; \
|
|
|
|
if (!*(a)) \
|
|
|
|
return; /* oops */ \
|
|
|
|
} while (0)
|
|
|
|
|
2001-11-15 21:32:09 +00:00
|
|
|
struct encrypt_result_s
|
|
|
|
{
|
2002-02-26 23:39:58 +00:00
|
|
|
int no_valid_recipients;
|
|
|
|
int invalid_recipients;
|
2001-11-15 21:32:09 +00:00
|
|
|
GpgmeData xmlinfo;
|
2001-09-03 18:41:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2001-11-15 21:32:09 +00:00
|
|
|
_gpgme_release_encrypt_result (EncryptResult result)
|
2001-09-03 18:41:53 +00:00
|
|
|
{
|
2001-11-15 21:32:09 +00:00
|
|
|
if (!result)
|
|
|
|
return;
|
|
|
|
gpgme_data_release (result->xmlinfo);
|
|
|
|
xfree (result);
|
2001-09-03 18:41:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse the args and save the information
|
|
|
|
* in an XML structure.
|
|
|
|
* With args of NULL the xml structure is closed.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
append_xml_encinfo (GpgmeData *rdh, char *args)
|
|
|
|
{
|
2002-01-30 21:52:32 +00:00
|
|
|
GpgmeData dh;
|
|
|
|
char helpbuf[100];
|
2001-09-03 18:41:53 +00:00
|
|
|
|
2002-01-30 21:52:32 +00:00
|
|
|
if (!*rdh)
|
|
|
|
{
|
|
|
|
if (gpgme_data_new (rdh))
|
|
|
|
return; /* FIXME: We are ignoring out-of-core. */
|
|
|
|
dh = *rdh;
|
|
|
|
_gpgme_data_append_string (dh, "<GnupgOperationInfo>\n");
|
2001-09-03 18:41:53 +00:00
|
|
|
}
|
2002-01-30 21:52:32 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
dh = *rdh;
|
|
|
|
_gpgme_data_append_string (dh, " </encryption>\n");
|
2001-09-03 18:41:53 +00:00
|
|
|
}
|
|
|
|
|
2002-01-30 21:52:32 +00:00
|
|
|
if (!args)
|
|
|
|
{
|
|
|
|
/* Just close the XML containter. */
|
|
|
|
_gpgme_data_append_string (dh, "</GnupgOperationInfo>\n");
|
|
|
|
return;
|
2001-09-03 18:41:53 +00:00
|
|
|
}
|
|
|
|
|
2002-01-30 21:52:32 +00:00
|
|
|
_gpgme_data_append_string (dh, " <encryption>\n"
|
|
|
|
" <error>\n"
|
|
|
|
" <invalidRecipient/>\n");
|
2001-09-03 18:41:53 +00:00
|
|
|
|
2002-01-30 21:52:32 +00:00
|
|
|
sprintf (helpbuf, " <reason>%d</reason>\n", atoi (args));
|
|
|
|
_gpgme_data_append_string (dh, helpbuf);
|
|
|
|
SKIP_TOKEN_OR_RETURN (args);
|
|
|
|
|
|
|
|
_gpgme_data_append_string (dh, " <name>");
|
|
|
|
_gpgme_data_append_percentstring_for_xml (dh, args);
|
|
|
|
_gpgme_data_append_string (dh, "</name>\n"
|
|
|
|
" </error>\n");
|
2001-09-03 18:41:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-26 00:08:09 +00:00
|
|
|
void
|
|
|
|
_gpgme_encrypt_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args)
|
2000-11-07 13:32:38 +00:00
|
|
|
{
|
2002-02-02 Marcus Brinkmann <marcus@g10code.de>
This patch has gotten a bit large... mmh. The main thing that
happens here is that error values are now not determined in the
operation function after gpgme_wait completed, but in the status
handler when EOF is received. It should always be the case that
either an error is flagged or EOF is received, so that after a
gpgme_wait you should never have the situation that no error is
flagged and EOF is not received. One problem is that the engine
status handlers don't have access to the context, a horrible
kludge works around this for now. All errors that happen during a
pending operation should be catched and reported in ctx->error,
including out-of-core and cancellation. This rounds up neatly a
couple of loose ends, and makes it possible to pass up any errors
in the communication with the backend as well. As a bonus, there
will be a function to access gpgme->wait, so that the operations
can truly be implemented with their _start function.
* engine-gpgsm.c (gpgsm_status_handler): Horrible kludge to report
error back to the context.
* rungpg.c (gpg_status_handler): Same horrible kludge applied here.
* engine-gpgsm.c (gpgsm_assuan_simple_command): Add error checking.
* wait.c (_gpgme_wait_on_condition): If canceled, set CTX->error
to a value indication that.
* verify.c (add_notation): Set error, not out_of_core.
(finish_sig): Likewise.
(gpgme_op_verify_start): Don't clear out_of_core.
(_gpgme_verify_status_handler): At EOF, clean up the notation data.
(gpgme_op_verify): And don't do it here.
* trustlist.c (trustlist_status_handler): Check error, not out_of_core.
(gpgme_op_trustlist_start): Don't clear out_of_core.
(gpgme_op_trustlist_next): Check error, not out_of_core.
(gpgme_op_trustlist_end): Likewise.
* ops.h (test_and_allocate_result): New macro.
(_gpgme_passphrase_result): Remove prototype.
* delete.c (gpgme_op_delete): Return error from context.
(delete_status_handler): Use macro test_and_allocate_result.
Perform error checking at EOF.
(gpgme_op_delete_start): Release result.
* passphrase.c (_gpgme_passphrase_status_handler): Use macro
test_and_allocate_result, and perform error checking here.
(_gpgme_passphrase_result): Function removed.
* sign.c (gpgme_op_sign_start): Do not set out_of_core to zero.
(gpgme_op_sign): Just return the error value from the context.
(sign_status_handler): Only progress if no error is set yet. If
we process an EOF, set the resulting error value (if any).
* decrypt.c (_gpgme_decrypt_result): Function removed.
(create_result_struct): Function removed.
(_gpgme_decrypt_status_handler): Use macro test_and_allocate_result,
caclulate error on EOF, do not progress with errors.
(_gpgme_decrypt_start): Do not set out_of_core to zero.
(gpgme_op_decrypt): Just return the error value from the context.
* encrypt.c (encrypt_status_handler): Perform the error checking
here.
(gpgme_op_encrypt_start): Do not clear out_of_core.
* export.c (export_status_handler): Return if error is set in context.
(gpgme_op_export_start): Release result.
(gpgme_op_export): Return error from context.
* decrypt-verify.c (gpgme_op_decrypt_verify): Return the error in
the context.
* genkey.c (genkey_status_handler): Use macro
test_and_allocate_result. Perform error checking at EOF.
(gpgme_op_genkey): Just return the error from context.
* import.c (gpgme_op_import): Return the error from context.
(import_status_handler): Use macro test_and_allocate_result.
* keylist.c (gpgme_op_keylist_start): Do not clear out_of_core.
(gpgme_op_keylist_next): Return error of context.
(keylist_colon_handler): Set error instead out_of_code.
(finish_key): Likewise.
* context.h: Remove member out_of_core, add member error.
* gpgme.c (_gpgme_release_result): Clear error flag.
* engine.h (_gpgme_engine_get_error): New prototype.
* engine.c (_gpgme_engine_get_error): New function.
* engine-gpgsm.c (_gpgme_gpgsm_get_error): New function.
* engine-gpgsm.c (map_assuan_error): New function.
(gpgsm_assuan_simple_command): Change return type to GpgmeError,
use the new function to map error values.
(gpgsm_set_fd): Change return type tp GpgmeError.
(_gpgme_gpgsm_op_decrypt): Change type of ERR to GpgmeError.
(gpgsm_set_recipients): Likewise. Change type of return value
equivalently. Adjust error values.
(_gpgme_gpgsm_op_import): Likewise.
(_gpgme_gpgsm_op_sign): Likewise.
(struct gpgsm_object_s): New member error.
(gpgsm_status_handler): Set error if error occurs. Determine
error number from ERR line received. If assuan_read_line fails,
terminate the connection.
2002-02-02 03:52:59 +00:00
|
|
|
if (ctx->error)
|
2002-01-30 21:52:32 +00:00
|
|
|
return;
|
2002-02-02 Marcus Brinkmann <marcus@g10code.de>
This patch has gotten a bit large... mmh. The main thing that
happens here is that error values are now not determined in the
operation function after gpgme_wait completed, but in the status
handler when EOF is received. It should always be the case that
either an error is flagged or EOF is received, so that after a
gpgme_wait you should never have the situation that no error is
flagged and EOF is not received. One problem is that the engine
status handlers don't have access to the context, a horrible
kludge works around this for now. All errors that happen during a
pending operation should be catched and reported in ctx->error,
including out-of-core and cancellation. This rounds up neatly a
couple of loose ends, and makes it possible to pass up any errors
in the communication with the backend as well. As a bonus, there
will be a function to access gpgme->wait, so that the operations
can truly be implemented with their _start function.
* engine-gpgsm.c (gpgsm_status_handler): Horrible kludge to report
error back to the context.
* rungpg.c (gpg_status_handler): Same horrible kludge applied here.
* engine-gpgsm.c (gpgsm_assuan_simple_command): Add error checking.
* wait.c (_gpgme_wait_on_condition): If canceled, set CTX->error
to a value indication that.
* verify.c (add_notation): Set error, not out_of_core.
(finish_sig): Likewise.
(gpgme_op_verify_start): Don't clear out_of_core.
(_gpgme_verify_status_handler): At EOF, clean up the notation data.
(gpgme_op_verify): And don't do it here.
* trustlist.c (trustlist_status_handler): Check error, not out_of_core.
(gpgme_op_trustlist_start): Don't clear out_of_core.
(gpgme_op_trustlist_next): Check error, not out_of_core.
(gpgme_op_trustlist_end): Likewise.
* ops.h (test_and_allocate_result): New macro.
(_gpgme_passphrase_result): Remove prototype.
* delete.c (gpgme_op_delete): Return error from context.
(delete_status_handler): Use macro test_and_allocate_result.
Perform error checking at EOF.
(gpgme_op_delete_start): Release result.
* passphrase.c (_gpgme_passphrase_status_handler): Use macro
test_and_allocate_result, and perform error checking here.
(_gpgme_passphrase_result): Function removed.
* sign.c (gpgme_op_sign_start): Do not set out_of_core to zero.
(gpgme_op_sign): Just return the error value from the context.
(sign_status_handler): Only progress if no error is set yet. If
we process an EOF, set the resulting error value (if any).
* decrypt.c (_gpgme_decrypt_result): Function removed.
(create_result_struct): Function removed.
(_gpgme_decrypt_status_handler): Use macro test_and_allocate_result,
caclulate error on EOF, do not progress with errors.
(_gpgme_decrypt_start): Do not set out_of_core to zero.
(gpgme_op_decrypt): Just return the error value from the context.
* encrypt.c (encrypt_status_handler): Perform the error checking
here.
(gpgme_op_encrypt_start): Do not clear out_of_core.
* export.c (export_status_handler): Return if error is set in context.
(gpgme_op_export_start): Release result.
(gpgme_op_export): Return error from context.
* decrypt-verify.c (gpgme_op_decrypt_verify): Return the error in
the context.
* genkey.c (genkey_status_handler): Use macro
test_and_allocate_result. Perform error checking at EOF.
(gpgme_op_genkey): Just return the error from context.
* import.c (gpgme_op_import): Return the error from context.
(import_status_handler): Use macro test_and_allocate_result.
* keylist.c (gpgme_op_keylist_start): Do not clear out_of_core.
(gpgme_op_keylist_next): Return error of context.
(keylist_colon_handler): Set error instead out_of_code.
(finish_key): Likewise.
* context.h: Remove member out_of_core, add member error.
* gpgme.c (_gpgme_release_result): Clear error flag.
* engine.h (_gpgme_engine_get_error): New prototype.
* engine.c (_gpgme_engine_get_error): New function.
* engine-gpgsm.c (_gpgme_gpgsm_get_error): New function.
* engine-gpgsm.c (map_assuan_error): New function.
(gpgsm_assuan_simple_command): Change return type to GpgmeError,
use the new function to map error values.
(gpgsm_set_fd): Change return type tp GpgmeError.
(_gpgme_gpgsm_op_decrypt): Change type of ERR to GpgmeError.
(gpgsm_set_recipients): Likewise. Change type of return value
equivalently. Adjust error values.
(_gpgme_gpgsm_op_import): Likewise.
(_gpgme_gpgsm_op_sign): Likewise.
(struct gpgsm_object_s): New member error.
(gpgsm_status_handler): Set error if error occurs. Determine
error number from ERR line received. If assuan_read_line fails,
terminate the connection.
2002-02-02 03:52:59 +00:00
|
|
|
test_and_allocate_result (ctx, encrypt);
|
2002-01-30 21:52:32 +00:00
|
|
|
|
|
|
|
switch (code)
|
|
|
|
{
|
|
|
|
case STATUS_EOF:
|
|
|
|
if (ctx->result.encrypt->xmlinfo)
|
|
|
|
{
|
|
|
|
append_xml_encinfo (&ctx->result.encrypt->xmlinfo, NULL);
|
|
|
|
_gpgme_set_op_info (ctx, ctx->result.encrypt->xmlinfo);
|
|
|
|
ctx->result.encrypt->xmlinfo = NULL;
|
2001-09-03 18:41:53 +00:00
|
|
|
}
|
2002-02-26 23:39:58 +00:00
|
|
|
if (ctx->result.encrypt->no_valid_recipients)
|
2002-02-02 Marcus Brinkmann <marcus@g10code.de>
This patch has gotten a bit large... mmh. The main thing that
happens here is that error values are now not determined in the
operation function after gpgme_wait completed, but in the status
handler when EOF is received. It should always be the case that
either an error is flagged or EOF is received, so that after a
gpgme_wait you should never have the situation that no error is
flagged and EOF is not received. One problem is that the engine
status handlers don't have access to the context, a horrible
kludge works around this for now. All errors that happen during a
pending operation should be catched and reported in ctx->error,
including out-of-core and cancellation. This rounds up neatly a
couple of loose ends, and makes it possible to pass up any errors
in the communication with the backend as well. As a bonus, there
will be a function to access gpgme->wait, so that the operations
can truly be implemented with their _start function.
* engine-gpgsm.c (gpgsm_status_handler): Horrible kludge to report
error back to the context.
* rungpg.c (gpg_status_handler): Same horrible kludge applied here.
* engine-gpgsm.c (gpgsm_assuan_simple_command): Add error checking.
* wait.c (_gpgme_wait_on_condition): If canceled, set CTX->error
to a value indication that.
* verify.c (add_notation): Set error, not out_of_core.
(finish_sig): Likewise.
(gpgme_op_verify_start): Don't clear out_of_core.
(_gpgme_verify_status_handler): At EOF, clean up the notation data.
(gpgme_op_verify): And don't do it here.
* trustlist.c (trustlist_status_handler): Check error, not out_of_core.
(gpgme_op_trustlist_start): Don't clear out_of_core.
(gpgme_op_trustlist_next): Check error, not out_of_core.
(gpgme_op_trustlist_end): Likewise.
* ops.h (test_and_allocate_result): New macro.
(_gpgme_passphrase_result): Remove prototype.
* delete.c (gpgme_op_delete): Return error from context.
(delete_status_handler): Use macro test_and_allocate_result.
Perform error checking at EOF.
(gpgme_op_delete_start): Release result.
* passphrase.c (_gpgme_passphrase_status_handler): Use macro
test_and_allocate_result, and perform error checking here.
(_gpgme_passphrase_result): Function removed.
* sign.c (gpgme_op_sign_start): Do not set out_of_core to zero.
(gpgme_op_sign): Just return the error value from the context.
(sign_status_handler): Only progress if no error is set yet. If
we process an EOF, set the resulting error value (if any).
* decrypt.c (_gpgme_decrypt_result): Function removed.
(create_result_struct): Function removed.
(_gpgme_decrypt_status_handler): Use macro test_and_allocate_result,
caclulate error on EOF, do not progress with errors.
(_gpgme_decrypt_start): Do not set out_of_core to zero.
(gpgme_op_decrypt): Just return the error value from the context.
* encrypt.c (encrypt_status_handler): Perform the error checking
here.
(gpgme_op_encrypt_start): Do not clear out_of_core.
* export.c (export_status_handler): Return if error is set in context.
(gpgme_op_export_start): Release result.
(gpgme_op_export): Return error from context.
* decrypt-verify.c (gpgme_op_decrypt_verify): Return the error in
the context.
* genkey.c (genkey_status_handler): Use macro
test_and_allocate_result. Perform error checking at EOF.
(gpgme_op_genkey): Just return the error from context.
* import.c (gpgme_op_import): Return the error from context.
(import_status_handler): Use macro test_and_allocate_result.
* keylist.c (gpgme_op_keylist_start): Do not clear out_of_core.
(gpgme_op_keylist_next): Return error of context.
(keylist_colon_handler): Set error instead out_of_code.
(finish_key): Likewise.
* context.h: Remove member out_of_core, add member error.
* gpgme.c (_gpgme_release_result): Clear error flag.
* engine.h (_gpgme_engine_get_error): New prototype.
* engine.c (_gpgme_engine_get_error): New function.
* engine-gpgsm.c (_gpgme_gpgsm_get_error): New function.
* engine-gpgsm.c (map_assuan_error): New function.
(gpgsm_assuan_simple_command): Change return type to GpgmeError,
use the new function to map error values.
(gpgsm_set_fd): Change return type tp GpgmeError.
(_gpgme_gpgsm_op_decrypt): Change type of ERR to GpgmeError.
(gpgsm_set_recipients): Likewise. Change type of return value
equivalently. Adjust error values.
(_gpgme_gpgsm_op_import): Likewise.
(_gpgme_gpgsm_op_sign): Likewise.
(struct gpgsm_object_s): New member error.
(gpgsm_status_handler): Set error if error occurs. Determine
error number from ERR line received. If assuan_read_line fails,
terminate the connection.
2002-02-02 03:52:59 +00:00
|
|
|
ctx->error = mk_error (No_Recipients);
|
2002-02-26 23:39:58 +00:00
|
|
|
else if (ctx->result.encrypt->invalid_recipients)
|
|
|
|
ctx->error = mk_error (Invalid_Recipients);
|
2002-01-30 21:52:32 +00:00
|
|
|
break;
|
2001-09-03 18:41:53 +00:00
|
|
|
|
2002-01-30 21:52:32 +00:00
|
|
|
case STATUS_INV_RECP:
|
2002-02-26 23:39:58 +00:00
|
|
|
ctx->result.encrypt->invalid_recipients++;
|
2002-01-30 21:52:32 +00:00
|
|
|
append_xml_encinfo (&ctx->result.encrypt->xmlinfo, args);
|
|
|
|
break;
|
2001-09-03 18:41:53 +00:00
|
|
|
|
2002-01-30 21:52:32 +00:00
|
|
|
case STATUS_NO_RECP:
|
2002-02-26 23:39:58 +00:00
|
|
|
ctx->result.encrypt->no_valid_recipients = 1;
|
2002-01-30 21:52:32 +00:00
|
|
|
break;
|
2001-09-07 12:47:33 +00:00
|
|
|
|
2002-01-30 21:52:32 +00:00
|
|
|
default:
|
|
|
|
break;
|
2001-09-03 18:41:53 +00:00
|
|
|
}
|
2000-11-07 13:32:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GpgmeError
|
2001-11-21 03:40:17 +00:00
|
|
|
gpgme_op_encrypt_start (GpgmeCtx ctx, GpgmeRecipients recp, GpgmeData plain,
|
|
|
|
GpgmeData ciph)
|
2000-11-07 13:32:38 +00:00
|
|
|
{
|
2001-11-21 03:40:17 +00:00
|
|
|
int err = 0;
|
2000-11-07 13:32:38 +00:00
|
|
|
|
2001-11-21 03:40:17 +00:00
|
|
|
fail_on_pending_request (ctx);
|
|
|
|
ctx->pending = 1;
|
2000-11-07 13:32:38 +00:00
|
|
|
|
2001-11-21 03:40:17 +00:00
|
|
|
_gpgme_release_result (ctx);
|
2001-09-03 18:41:53 +00:00
|
|
|
|
2001-11-21 03:40:17 +00:00
|
|
|
/* Do some checks. */
|
|
|
|
if (!gpgme_recipients_count (recp))
|
|
|
|
{
|
|
|
|
/* Fixme: In this case we should do symmentric encryption. */
|
|
|
|
err = mk_error (No_Recipients);
|
|
|
|
goto leave;
|
2000-11-07 13:32:38 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 03:40:17 +00:00
|
|
|
/* Create an engine object. */
|
|
|
|
_gpgme_engine_release (ctx->engine);
|
|
|
|
ctx->engine = NULL;
|
|
|
|
err = _gpgme_engine_new (ctx->use_cms ? GPGME_PROTOCOL_CMS
|
|
|
|
: GPGME_PROTOCOL_OpenPGP, &ctx->engine);
|
|
|
|
if (err)
|
|
|
|
goto leave;
|
|
|
|
|
2002-02-26 00:08:09 +00:00
|
|
|
_gpgme_engine_set_status_handler (ctx->engine, _gpgme_encrypt_status_handler,
|
|
|
|
ctx);
|
2001-11-21 03:40:17 +00:00
|
|
|
_gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity);
|
|
|
|
|
|
|
|
/* Check the supplied data */
|
|
|
|
if (gpgme_data_get_type (plain) == GPGME_DATA_TYPE_NONE)
|
|
|
|
{
|
|
|
|
err = mk_error (No_Data);
|
|
|
|
goto leave;
|
2000-11-07 13:32:38 +00:00
|
|
|
}
|
2001-11-21 03:40:17 +00:00
|
|
|
_gpgme_data_set_mode (plain, GPGME_DATA_MODE_OUT);
|
|
|
|
if (!ciph || gpgme_data_get_type (ciph) != GPGME_DATA_TYPE_NONE)
|
|
|
|
{
|
|
|
|
err = mk_error (Invalid_Value);
|
|
|
|
goto leave;
|
2000-11-07 13:32:38 +00:00
|
|
|
}
|
2001-11-21 03:40:17 +00:00
|
|
|
_gpgme_data_set_mode (ciph, GPGME_DATA_MODE_IN);
|
|
|
|
|
|
|
|
err = _gpgme_engine_op_encrypt (ctx->engine, recp, plain, ciph, ctx->use_armor);
|
|
|
|
|
2000-11-07 13:32:38 +00:00
|
|
|
|
2001-11-21 03:40:17 +00:00
|
|
|
if (!err) /* And kick off the process. */
|
|
|
|
err = _gpgme_engine_start (ctx->engine, ctx);
|
2000-11-07 13:32:38 +00:00
|
|
|
|
|
|
|
leave:
|
2001-11-21 03:40:17 +00:00
|
|
|
if (err)
|
|
|
|
{
|
|
|
|
ctx->pending = 0;
|
|
|
|
_gpgme_engine_release (ctx->engine);
|
|
|
|
ctx->engine = NULL;
|
2000-11-07 13:32:38 +00:00
|
|
|
}
|
2001-11-21 03:40:17 +00:00
|
|
|
return err;
|
2000-11-07 13:32:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2000-11-13 13:25:22 +00:00
|
|
|
* gpgme_op_encrypt:
|
2000-11-07 13:32:38 +00:00
|
|
|
* @c: The context
|
|
|
|
* @recp: A set of recipients
|
|
|
|
* @in: plaintext input
|
|
|
|
* @out: ciphertext output
|
|
|
|
*
|
|
|
|
* This function encrypts @in to @out for all recipients from
|
|
|
|
* @recp. Other parameters are take from the context @c.
|
|
|
|
* The function does wait for the result.
|
|
|
|
*
|
|
|
|
* Return value: 0 on success or an errorcode.
|
|
|
|
**/
|
|
|
|
GpgmeError
|
2002-01-30 21:52:32 +00:00
|
|
|
gpgme_op_encrypt (GpgmeCtx ctx, GpgmeRecipients recp,
|
|
|
|
GpgmeData plain, GpgmeData cipher)
|
2000-11-07 13:32:38 +00:00
|
|
|
{
|
2002-01-30 21:52:32 +00:00
|
|
|
int err = gpgme_op_encrypt_start (ctx, recp, plain, cipher);
|
|
|
|
if (!err)
|
|
|
|
{
|
2002-02-06 01:20:49 +00:00
|
|
|
gpgme_wait (ctx, &err, 1);
|
2002-01-30 21:52:32 +00:00
|
|
|
/* Old gpg versions don't return status info for invalid
|
|
|
|
recipients, so we simply check whether we got any output at
|
|
|
|
all, and if not we assume that we don't have valid
|
|
|
|
recipients. */
|
2002-02-02 Marcus Brinkmann <marcus@g10code.de>
This patch has gotten a bit large... mmh. The main thing that
happens here is that error values are now not determined in the
operation function after gpgme_wait completed, but in the status
handler when EOF is received. It should always be the case that
either an error is flagged or EOF is received, so that after a
gpgme_wait you should never have the situation that no error is
flagged and EOF is not received. One problem is that the engine
status handlers don't have access to the context, a horrible
kludge works around this for now. All errors that happen during a
pending operation should be catched and reported in ctx->error,
including out-of-core and cancellation. This rounds up neatly a
couple of loose ends, and makes it possible to pass up any errors
in the communication with the backend as well. As a bonus, there
will be a function to access gpgme->wait, so that the operations
can truly be implemented with their _start function.
* engine-gpgsm.c (gpgsm_status_handler): Horrible kludge to report
error back to the context.
* rungpg.c (gpg_status_handler): Same horrible kludge applied here.
* engine-gpgsm.c (gpgsm_assuan_simple_command): Add error checking.
* wait.c (_gpgme_wait_on_condition): If canceled, set CTX->error
to a value indication that.
* verify.c (add_notation): Set error, not out_of_core.
(finish_sig): Likewise.
(gpgme_op_verify_start): Don't clear out_of_core.
(_gpgme_verify_status_handler): At EOF, clean up the notation data.
(gpgme_op_verify): And don't do it here.
* trustlist.c (trustlist_status_handler): Check error, not out_of_core.
(gpgme_op_trustlist_start): Don't clear out_of_core.
(gpgme_op_trustlist_next): Check error, not out_of_core.
(gpgme_op_trustlist_end): Likewise.
* ops.h (test_and_allocate_result): New macro.
(_gpgme_passphrase_result): Remove prototype.
* delete.c (gpgme_op_delete): Return error from context.
(delete_status_handler): Use macro test_and_allocate_result.
Perform error checking at EOF.
(gpgme_op_delete_start): Release result.
* passphrase.c (_gpgme_passphrase_status_handler): Use macro
test_and_allocate_result, and perform error checking here.
(_gpgme_passphrase_result): Function removed.
* sign.c (gpgme_op_sign_start): Do not set out_of_core to zero.
(gpgme_op_sign): Just return the error value from the context.
(sign_status_handler): Only progress if no error is set yet. If
we process an EOF, set the resulting error value (if any).
* decrypt.c (_gpgme_decrypt_result): Function removed.
(create_result_struct): Function removed.
(_gpgme_decrypt_status_handler): Use macro test_and_allocate_result,
caclulate error on EOF, do not progress with errors.
(_gpgme_decrypt_start): Do not set out_of_core to zero.
(gpgme_op_decrypt): Just return the error value from the context.
* encrypt.c (encrypt_status_handler): Perform the error checking
here.
(gpgme_op_encrypt_start): Do not clear out_of_core.
* export.c (export_status_handler): Return if error is set in context.
(gpgme_op_export_start): Release result.
(gpgme_op_export): Return error from context.
* decrypt-verify.c (gpgme_op_decrypt_verify): Return the error in
the context.
* genkey.c (genkey_status_handler): Use macro
test_and_allocate_result. Perform error checking at EOF.
(gpgme_op_genkey): Just return the error from context.
* import.c (gpgme_op_import): Return the error from context.
(import_status_handler): Use macro test_and_allocate_result.
* keylist.c (gpgme_op_keylist_start): Do not clear out_of_core.
(gpgme_op_keylist_next): Return error of context.
(keylist_colon_handler): Set error instead out_of_code.
(finish_key): Likewise.
* context.h: Remove member out_of_core, add member error.
* gpgme.c (_gpgme_release_result): Clear error flag.
* engine.h (_gpgme_engine_get_error): New prototype.
* engine.c (_gpgme_engine_get_error): New function.
* engine-gpgsm.c (_gpgme_gpgsm_get_error): New function.
* engine-gpgsm.c (map_assuan_error): New function.
(gpgsm_assuan_simple_command): Change return type to GpgmeError,
use the new function to map error values.
(gpgsm_set_fd): Change return type tp GpgmeError.
(_gpgme_gpgsm_op_decrypt): Change type of ERR to GpgmeError.
(gpgsm_set_recipients): Likewise. Change type of return value
equivalently. Adjust error values.
(_gpgme_gpgsm_op_import): Likewise.
(_gpgme_gpgsm_op_sign): Likewise.
(struct gpgsm_object_s): New member error.
(gpgsm_status_handler): Set error if error occurs. Determine
error number from ERR line received. If assuan_read_line fails,
terminate the connection.
2002-02-02 03:52:59 +00:00
|
|
|
if (!ctx->error && gpgme_data_get_type (cipher) == GPGME_DATA_TYPE_NONE)
|
|
|
|
ctx->error = mk_error (No_Recipients);
|
|
|
|
err = ctx->error;
|
2000-11-09 16:35:35 +00:00
|
|
|
}
|
2002-01-30 21:52:32 +00:00
|
|
|
return err;
|
2000-11-07 13:32:38 +00:00
|
|
|
}
|