Greenbone Vulnerability Management Libraries
10.0.0
|
GPGME utilities. More...
#include "gpgmeutils.h"
#include "fileutils.h"
#include <errno.h>
#include <gpg-error.h>
#include <locale.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
Go to the source code of this file.
Macros | |
#define | G_LOG_DOMAIN "util gpgme" |
GLib log domain. More... | |
Functions | |
void | log_gpgme (GLogLevelFlags level, gpg_error_t err, const char *fmt,...) |
Log function with extra gpg-error style output. More... | |
gpgme_ctx_t | gvm_init_gpgme_ctx_from_dir (const gchar *dir) |
Returns a new gpgme context. More... | |
int | gvm_gpg_import_from_string (gpgme_ctx_t ctx, const char *key_str, ssize_t key_len, gpgme_data_type_t key_type) |
Import a key or certificate given by a string. More... | |
static gpgme_key_t | find_email_encryption_key (gpgme_ctx_t ctx, const char *uid_email) |
Find a key that can be used to encrypt for an email recipient. More... | |
static int | encrypt_stream_internal (FILE *plain_file, FILE *encrypted_file, const char *key_str, ssize_t key_len, const char *uid_email, gpgme_protocol_t protocol, gpgme_data_type_t data_type) |
Encrypt a stream for a PGP public key, writing to another stream. More... | |
int | gvm_pgp_pubkey_encrypt_stream (FILE *plain_file, FILE *encrypted_file, const char *uid_email, const char *public_key_str, ssize_t public_key_len) |
Encrypt a stream for a PGP public key, writing to another stream. More... | |
int | gvm_smime_encrypt_stream (FILE *plain_file, FILE *encrypted_file, const char *uid_email, const char *certificate_str, ssize_t certificate_len) |
Encrypt a stream for a S/MIME certificate, writing to another stream. More... | |
GPGME utilities.
Definition in file gpgmeutils.c.
#define G_LOG_DOMAIN "util gpgme" |
GLib log domain.
Definition at line 41 of file gpgmeutils.c.
|
static |
Encrypt a stream for a PGP public key, writing to another stream.
The output will use ASCII armor mode and no compression.
[in] | plain_file | Stream / FILE* providing the plain text. |
[in] | encrypted_file | Stream to write the encrypted text to. |
[in] | key_str | String containing the public key or certificate. |
[in] | key_len | Length of key / certificate, -1 to use strlen. |
[in] | uid_email | Email address of key / certificate to use. |
[in] | protocol | The protocol to use, e.g. OpenPGP or CMS. |
[in] | data_type | The expected GPGME buffered data type. |
Definition at line 323 of file gpgmeutils.c.
References find_email_encryption_key(), gvm_file_remove_recurse(), and gvm_gpg_import_from_string().
Referenced by gvm_pgp_pubkey_encrypt_stream(), and gvm_smime_encrypt_stream().
|
static |
Find a key that can be used to encrypt for an email recipient.
[in] | ctx | The GPGME context. |
[in] | uid_email | The recipient email address to look for. |
Definition at line 252 of file gpgmeutils.c.
Referenced by encrypt_stream_internal().
int gvm_gpg_import_from_string | ( | gpgme_ctx_t | ctx, |
const char * | key_str, | ||
ssize_t | key_len, | ||
gpgme_data_type_t | key_type | ||
) |
Import a key or certificate given by a string.
[in] | ctx | The GPGME context to import the key / certificate into. |
[in] | key_str | Key or certificate string. |
[in] | key_len | Length of key/certificate string or -1 to use strlen. |
[in] | key_type | The expected key type. |
Definition at line 180 of file gpgmeutils.c.
Referenced by encrypt_stream_internal().
gpgme_ctx_t gvm_init_gpgme_ctx_from_dir | ( | const gchar * | dir | ) |
Returns a new gpgme context.
Inits a gpgme context with the custom gpg directory, protocol version etc. Returns the context or NULL if an error occurred. This function also does an gpgme initialization the first time it is called.
dir | Directory to use for gpg |
Definition at line 88 of file gpgmeutils.c.
References initialized, and log_gpgme().
int gvm_pgp_pubkey_encrypt_stream | ( | FILE * | plain_file, |
FILE * | encrypted_file, | ||
const char * | uid_email, | ||
const char * | public_key_str, | ||
ssize_t | public_key_len | ||
) |
Encrypt a stream for a PGP public key, writing to another stream.
The output will use ASCII armor mode and no compression.
[in] | plain_file | Stream / FILE* providing the plain text. |
[in] | encrypted_file | Stream to write the encrypted text to. |
[in] | uid_email | Email address of public key to use. |
[in] | public_key_str | String containing the public key. |
[in] | public_key_len | Length of public key or -1 to use strlen. |
Definition at line 431 of file gpgmeutils.c.
References encrypt_stream_internal().
int gvm_smime_encrypt_stream | ( | FILE * | plain_file, |
FILE * | encrypted_file, | ||
const char * | uid_email, | ||
const char * | certificate_str, | ||
ssize_t | certificate_len | ||
) |
Encrypt a stream for a S/MIME certificate, writing to another stream.
The output will use ASCII armor mode and no compression.
[in] | plain_file | Stream / FILE* providing the plain text. |
[in] | encrypted_file | Stream to write the encrypted text to. |
[in] | uid_email | Email address of certificate to use. |
[in] | certificate_str | String containing the public key. |
[in] | certificate_len | Length of public key or -1 to use strlen. |
Definition at line 455 of file gpgmeutils.c.
References encrypt_stream_internal().
void log_gpgme | ( | GLogLevelFlags | level, |
gpg_error_t | err, | ||
const char * | fmt, | ||
... | |||
) |
Log function with extra gpg-error style output.
If err
is not 0, the appropriate error string is appended to the output. It takes care to only add the error source string if it makes sense.
level | The GLib style log level |
err | An gpg-error value or 0 |
fmt | The printf style format string, followed by its arguments. |
Definition at line 57 of file gpgmeutils.c.
References G_LOG_DOMAIN.
Referenced by gvm_init_gpgme_ctx_from_dir().