void GPGWrapper::init() { if (initialized) return; initialized = true; gpgme_check_version(NULL); setlocale(LC_ALL, ""); gpgme_set_locale(NULL, LC_CTYPE, setlocale(LC_CTYPE, NULL)); #ifdef LC_MESSAGES gpgme_set_locale(NULL, LC_MESSAGES, setlocale(LC_MESSAGES, NULL)); #endif gpgme_error_t error = gpgme_new(&context); fail_if_err(error, L"Nie uda³o siê zainicjowaæ kontekstu GPG."); gpgme_set_textmode(context, 1); gpgme_set_armor(context, 1); error = gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP); fail_if_err(error, L"Nie zainstalowano OpenPGP."); error = gpgme_set_protocol(context, GPGME_PROTOCOL_OpenPGP); fail_if_err(error, L"Nie uda³o siê ustawiæ OpenPGP."); privateKey = getPrivateKey(privateKeyId.c_str()); error = gpgme_signers_add(context, privateKey); fail_if_err(error, L"Nie uda³o siê ustawiæ klucza prywatnego."); }
ksba_cert_t get_one_cert (const char *fname) { gpg_error_t err; FILE *fp; ksba_reader_t r; ksba_cert_t cert; fp = fopen (fname, "r"); if (!fp) { fprintf (stderr, "%s:%d: can't open `%s': %s\n", __FILE__, __LINE__, fname, strerror (errno)); exit (1); } err = ksba_reader_new (&r); if (err) fail_if_err (err); err = ksba_reader_set_file (r, fp); fail_if_err (err); err = ksba_cert_new (&cert); if (err) fail_if_err (err); err = ksba_cert_read_der (cert, r); fail_if_err2 (fname, err); return cert; }
int main (int argc, char *argv[]) { int rc; npth_attr_t tattr; int state; npth_t tid1, tid2; void *retval; if (argc >= 2 && !strcmp (argv[1], "--verbose")) opt_verbose = 1; rc = npth_init (); fail_if_err (rc); rc = npth_mutex_init (&counter_mutex, NULL); fail_if_err (rc); rc = npth_attr_init (&tattr); fail_if_err (rc); rc = npth_attr_getdetachstate (&tattr, &state); fail_if_err (rc); if ( state != NPTH_CREATE_JOINABLE ) fail_msg ("new tattr is not joinable"); info_msg ("creating thread-one"); rc = npth_create (&tid1, &tattr, thread_one, NULL); fail_if_err (rc); npth_setname_np (tid1, "thread-one"); info_msg ("creating thread-two"); rc = npth_create (&tid2, &tattr, thread_two, NULL); fail_if_err (rc); npth_setname_np (tid2, "thread-two"); rc = npth_attr_destroy (&tattr); fail_if_err (rc); info_msg ("waiting for thread-one to terminate"); rc = npth_join (tid1, &retval); fail_if_err (rc); if (retval != (void*)4711) fail_msg ("thread-one returned an unexpected value"); info_msg ("waiting for thread-two to terminate"); rc = npth_join (tid2, &retval); fail_if_err (rc); if (retval != (void*)4722) fail_msg ("thread-two returned an unexpected value"); if (counter != 100) fail_msg ("counter value not as expected"); return 0; }
int main (int argc, char *argv[]) { gpgme_ctx_t ctx; gpgme_error_t err; gpgme_data_t out; const char *pattern1[] = { "DFN Top Level Certification Authority", NULL }; const char *pattern2[] = { "3CF405464F66ED4A7DF45BBDD1E4282E33BDB76E", "DFN Server Certification Authority", NULL }; init_gpgme (GPGME_PROTOCOL_CMS); err = gpgme_new (&ctx); fail_if_err (err); gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS); gpgme_set_armor (ctx, 1); /* Check exporting of one certificate. */ err = gpgme_data_new (&out); fail_if_err (err); err = gpgme_op_export_ext (ctx, pattern1, 0, out); fail_if_err (err); fflush (NULL); fputs ("Begin Result:\n", stdout); print_data (out); fputs ("End Result.\n", stdout); gpgme_data_release (out); /* Check exporting of 2 certificates. */ err = gpgme_data_new (&out); fail_if_err (err); err = gpgme_op_export_ext (ctx, pattern2, 0, out); fail_if_err (err); fflush (NULL); fputs ("Begin Result:\n", stdout); print_data (out); fputs ("End Result.\n", stdout); gpgme_data_release (out); gpgme_release (ctx); return 0; }
static void print_data (gpgme_data_t dh) { #define BUF_SIZE 512 char buf[BUF_SIZE + 1]; int ret; ret = gpgme_data_seek (dh, 0, SEEK_SET); if (ret) fail_if_err (gpgme_err_code_from_errno (errno)); while ((ret = gpgme_data_read (dh, buf, BUF_SIZE)) > 0) fwrite (buf, ret, 1, stdout); if (ret < 0) fail_if_err (gpgme_err_code_from_errno (errno)); }
int main (int argc, char **argv ) { gpgme_engine_info_t info; gpgme_error_t err; gpgme_check_version (NULL); err = gpgme_get_engine_info (&info); fail_if_err (err); check_engine_info (info, GPGME_PROTOCOL_OpenPGP, GPG_PATH, NEED_GPG_VERSION); info = info->next; #ifdef GPGSM_PATH check_engine_info (info, GPGME_PROTOCOL_CMS, GPGSM_PATH, NEED_GPGSM_VERSION); #else if (info) { fprintf (stderr, "Unexpected engine info.\n"); exit (1); } #endif return 0; }
static gpgme_error_t inq_cb (void *opaque, const char *name, const char *args, gpgme_data_t *r_data) { gpgme_data_t data; gpgme_error_t err; if (name) { printf ("INQ_CB: name=`%s' args=`%s'\n", name, args); /* There shall be no data object. */ assert (!*r_data); err = gpgme_data_new (&data); fail_if_err (err); *r_data = data; printf (" sending data object %p\n", data); } else /* Finished using the formerly returned data object. */ { printf ("INQ_CB: data object %p finished\n", *r_data); /* There shall be a data object so that it can be cleaned up. */ assert (r_data); gpgme_data_release (*r_data); } /* Uncomment the next lines and send a "SCD LEARN" to test sending cancel from in inquiry. */ /* if (name && !strcmp (name, "KNOWNCARDP")) */ /* return gpgme_error (GPG_ERR_ASS_CANCELED); */ return 0; }
void write_test (round_t round, gpgme_data_t data) { char buffer[1024]; size_t amt; amt = gpgme_data_write (data, text, strlen (text)); if (amt != strlen (text)) fail_if_err (gpgme_error_from_errno (errno)); gpgme_data_seek (data, 0, SEEK_SET); if (round == TEST_INOUT_NONE) read_once_test (round, data); else { amt = gpgme_data_read (data, buffer, sizeof (buffer)); if (amt != strlen (text2) || strncmp (buffer, text2, strlen (text2))) { fprintf (stderr, "%s:%d: (%i) gpgme_data_read returned wrong data\n", __FILE__, __LINE__, round); exit (1); } amt = gpgme_data_read (data, buffer, sizeof (buffer)); if (amt) { fprintf (stderr, "%s:%d: (%i) gpgme_data_read did not signal EOF\n", __FILE__, __LINE__, round); exit (1); } } }
int main (int argc, char *argv[]) { gpgme_ctx_t ctx; gpgme_error_t err; gpgme_data_t in, out; gpgme_decrypt_result_t decrypt_result; gpgme_verify_result_t verify_result; char *cipher_2_asc = make_filename ("cipher-2.asc"); char *agent_info; init_gpgme (GPGME_PROTOCOL_OpenPGP); err = gpgme_new (&ctx); fail_if_err (err); agent_info = getenv("GPG_AGENT_INFO"); if (!(agent_info && strchr (agent_info, ':'))) gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL); err = gpgme_data_new_from_file (&in, cipher_2_asc, 1); free (cipher_2_asc); fail_if_err (err); err = gpgme_data_new (&out); fail_if_err (err); err = gpgme_op_decrypt_verify (ctx, in, out); fail_if_err (err); decrypt_result = gpgme_op_decrypt_result (ctx); if (decrypt_result->unsupported_algorithm) { fprintf (stderr, "%s:%i: unsupported algorithm: %s\n", __FILE__, __LINE__, decrypt_result->unsupported_algorithm); exit (1); } print_data (out); verify_result = gpgme_op_verify_result (ctx); check_verify_result (verify_result, 0, "A0FF4590BB6122EDEF6E3C542D727CC768697734", GPG_ERR_NO_ERROR); gpgme_data_release (in); gpgme_data_release (out); gpgme_release (ctx); return 0; }
gpgme_key_t GPGWrapper::getKey(const char * identifier, bool isPrivate) { gpgme_key_t result; gpgme_error_t error = gpgme_op_keylist_start(context, identifier, isPrivate ? 1 : 0); fail_if_err(error, L"Nie uda³o siê zainicjowaæ pobierania klucza."); error = gpgme_op_keylist_next(context, &result); fail_if_err(error, L"Nie uda³o siê pobraæ klucza."); reciversIdToKey[identifier] = result; error = gpgme_op_keylist_end(context); fail_if_err(error, L"Nie uda³o siê zakoñczyæ pobieranie klucza."); return result; }
std::string GPGWrapper::encrypt(const std::string & recipientName, const std::string& message) { init(); ScopedGPGData clear_text, sign_text, encrypted_text; gpgme_error_t error = clear_text.init(message.c_str(), message.length()); fail_if_err(error, L"Nie uda³o siê zainicjowaæ danych do zaszyfrowana (clear_text)."); error = sign_text.init(); fail_if_err(error, L"Nie uda³o siê zainicjowaæ danych do zaszyfrowana (sign_text)."); error = gpgme_op_sign(context, clear_text.get(), sign_text.get(), GPGME_SIG_MODE_NORMAL); fail_if_err(error, L"Nie uda³o siê podpisaæ wiadomoœci."); error = gpgme_data_rewind(sign_text.get()); fail_if_err(error, L"Nie uda³o siê przewin¹æ na pocz¹tek podpisanego strumienia, aby go póŸniej zaszyfrowaæ."); error = encrypted_text.init(); fail_if_err(error, L"Nie uda³o siê zainicjowaæ danych do zaszyfrowana (encrypted_text)."); gpgme_key_t recipient = getPublicKey(recipientName.c_str()); gpgme_key_t recipients[2] = { NULL, NULL }; recipients[0] = recipient; error = gpgme_op_encrypt(context, recipients, GPGME_ENCRYPT_ALWAYS_TRUST, sign_text.get(), encrypted_text.get()); fail_if_err(error, L"Nie uda³o siê zaszyfrowaæ podpisanej wiadomoœci."); gpgme_encrypt_result_t result = gpgme_op_encrypt_result(context); fail_if_err(result->invalid_recipients, L"Nie poprawny klucz szyfrowania odbiorcy."); return copyData(encrypted_text.get()); }
void setup(gpgme_ctx_t * context, telem_gpg_opts * options) { gpgme_error_t error; // gpgme_engine_info_t info; // Set the defaults setup_options(options); /* Initializes gpgme */ gpgme_check_version (NULL); /* Initialize the locale environment. */ setlocale (LC_ALL, ""); gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL)); #ifdef LC_MESSAGES gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL)); #endif error = gpgme_new(context); fail_if_err(error); /* Setting the output type must be done at the beginning */ gpgme_set_armor(*context, 1); /* Check OpenPGP */ // error = gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP); // fail_if_err(error); // error = gpgme_get_engine_info (&info); // fail_if_err(error); // while (info && info->protocol != gpgme_get_protocol(*context)) { // info = info->next; // } // /* TODO: we should test there *is* a suitable protocol */ // fprintf (stderr, "Engine OpenPGP %s is installed at %s\n", info->version, // info->file_name); /* And not "path" as the documentation says */ // Create the keyring_dir is it doesnt exist mkdirs(options->keyring_dir); /* Initializes the context */ error = gpgme_ctx_set_engine_info( *context, GPGME_PROTOCOL_OpenPGP, NULL, options->keyring_dir ); fail_if_err(error); }
int main (int argc, char *argv[]) { int rc; npth_mutex_t mutex; rc = npth_init (); fail_if_err (rc); rc = npth_mutex_init (&mutex, NULL); fail_if_err (rc); rc = npth_mutex_lock (&mutex); fail_if_err (rc); rc = npth_mutex_unlock (&mutex); fail_if_err (rc); return 0; }
void encrypt(const char *message, char *dest, const char *fingerprint) { gpgme_data_t in; gpgme_key_t key[2] = { NULL, NULL }; gpgme_encrypt_result_t result; init_cryptofox(); gpgme_set_armor (_cf_ctx, 1); _cf_err = gpgme_data_new_from_mem (&in, message, strlen(message), 0); fail_if_err (_cf_err); _cf_err = gpgme_data_new (&_cf_out); fail_if_err (_cf_err); // my key ([email protected]) _cf_err = gpgme_get_key (_cf_ctx, fingerprint, &key[0], 0); fail_if_err (_cf_err); // err = gpgme_get_key(ctx,"C0C13F91F6F111E8C66CA6E518A66F16FBFD6A72", // &key[1], 0); // fail_if_err (err); _cf_err = gpgme_op_encrypt (_cf_ctx, key, GPGME_ENCRYPT_ALWAYS_TRUST, in, _cf_out); fail_if_err (_cf_err); result = gpgme_op_encrypt_result (_cf_ctx); if (result->invalid_recipients) { fprintf (stderr, "Invalid recipient encountered: %s\n", result->invalid_recipients->fpr); exit (1); } int ret; ret = gpgme_data_seek(_cf_out, 0, SEEK_SET); if(ret) fail_if_err(gpgme_err_code_from_errno(errno)); gpgme_key_unref (key[0]); gpgme_data_release (in); gpgme_release (_cf_ctx); }
int main (int argc, char *argv[]) { gpgme_ctx_t ctx; gpgme_error_t err; gpgme_data_t in, out; gpgme_decrypt_result_t result; char *cipher_1_asc = make_filename ("cipher-1.asc"); char *agent_info; init_gpgme (GPGME_PROTOCOL_OpenPGP); err = gpgme_new (&ctx); fail_if_err (err); agent_info = getenv("GPG_AGENT_INFO"); if (!(agent_info && strchr (agent_info, ':'))) gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL); err = gpgme_data_new_from_file (&in, cipher_1_asc, 1); free (cipher_1_asc); fail_if_err (err); err = gpgme_data_new (&out); fail_if_err (err); err = gpgme_op_decrypt (ctx, in, out); fail_if_err (err); result = gpgme_op_decrypt_result (ctx); if (result->unsupported_algorithm) { fprintf (stderr, "%s:%i: unsupported algorithm: %s\n", __FILE__, __LINE__, result->unsupported_algorithm); exit (1); } print_data (out); gpgme_data_release (in); gpgme_data_release (out); gpgme_release (ctx); return 0; }
GPGWrapperDecryptedData GPGWrapper::decrypt(const std::string& message) { init(); ScopedGPGData clear_text, sign_text, encrypted_text; gpgme_error_t error = encrypted_text.init(message.c_str(), message.length()); fail_if_err(error, L"Nie uda³o siê zainicjowaæ danych do odszyfrowania (encrypted_text)."); error = sign_text.init(); fail_if_err(error, L"Nie uda³o siê zainicjowaæ danych do odszyfrowania (sign_text)."); error = gpgme_op_decrypt(context, encrypted_text.get(), sign_text.get()); fail_if_err(error, L"Nie uda³o siê odszyfrowaæ wiadomoœci."); error = gpgme_data_rewind(sign_text.get()); fail_if_err(error, L"Nie uda³o siê przewin¹æ na pocz¹tek podpisanego strumienia, aby go póŸniej zweryfikowaæ."); error = clear_text.init(); fail_if_err(error, L"Nie uda³o siê zainicjowaæ danych do odszyfrowania (clear_text)."); error = gpgme_op_verify(context, sign_text.get(), NULL, clear_text.get()); fail_if_err(error, L"Nie powiod³a siê próba potwierdzenia podpisu nadawcy."); GPGWrapperDecryptedData result; gpgme_verify_result_t verifyResult = gpgme_op_verify_result(context); if (verifyResult != NULL && verifyResult->signatures != NULL && verifyResult->signatures->summary & GPGME_SIGSUM_VALID) result.isSignValid = true; result.data = copyData(clear_text.get()); return result; }
int main (int argc, char **argv) { gpgme_ctx_t ctx; gpgme_error_t err; gpgme_data_t in; gpgme_import_result_t result; char *cert_1 = make_filename ("cert_dfn_pca01.der"); char *cert_2 = make_filename ("cert_dfn_pca15.der"); init_gpgme (GPGME_PROTOCOL_CMS); err = gpgme_new (&ctx); fail_if_err (err); gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS); err = gpgme_data_new_from_file (&in, cert_1, 1); free (cert_1); fail_if_err (err); err = gpgme_op_import (ctx, in); fail_if_err (err); result = gpgme_op_import_result (ctx); check_result (result, "DFA56FB5FC41E3A8921F77AD1622EEFD9152A5AD", 1, 1); gpgme_data_release (in); err = gpgme_data_new_from_file (&in, cert_2, 1); free (cert_2); fail_if_err (err); err = gpgme_op_import (ctx, in); fail_if_err (err); result = gpgme_op_import_result (ctx); check_result (result, "2C8F3C356AB761CB3674835B792CDA52937F9285", 1, 2); gpgme_data_release (in); gpgme_release (ctx); return 0; }
void import ( gpgme_ctx_t * context, telem_gpg_opts * options, int num_keys, char ** key_path ) { gpgme_error_t err; int url_mode = 0; int nul_mode = 0; gpgme_import_result_t impres; gpgme_data_t data; for (; num_keys; --num_keys, key_path++) { printf ("reading file `%s'\n", *key_path); err = gpgme_data_new_from_file(&data, *key_path, 1); fail_if_err(err); if (url_mode) gpgme_data_set_encoding( data, (nul_mode? GPGME_DATA_ENCODING_URL0 : GPGME_DATA_ENCODING_URL) ); err = gpgme_op_import(*context, data); fail_if_err(err); impres = gpgme_op_import_result(*context); if (!impres) { fprintf(stderr, "No import result returned\n"); exit(1); } print_import_result(impres); gpgme_data_release(data); } }
/* Create a request for the DER encoded certificate in the file CERT_FNAME and its issuer's certificate in the file ISSUER_CERT_FNAME. */ void one_request (const char *cert_fname, const char *issuer_cert_fname) { gpg_error_t err; ksba_cert_t cert = get_one_cert (cert_fname); ksba_cert_t issuer_cert = get_one_cert (issuer_cert_fname); ksba_ocsp_t ocsp; unsigned char *request; size_t requestlen; err = ksba_ocsp_new (&ocsp); fail_if_err (err); err = ksba_ocsp_add_target (ocsp, cert, issuer_cert); fail_if_err (err); ksba_cert_release (cert); ksba_cert_release (issuer_cert); if (!no_nonce) ksba_ocsp_set_nonce (ocsp, "ABCDEFGHIJKLMNOP", 16); err = ksba_ocsp_build_request (ocsp, &request, &requestlen); fail_if_err (err); ksba_ocsp_release (ocsp); printf ("OCSP request of length %u created\n", (unsigned int)requestlen); { FILE *fp = fopen ("a.req", "wb"); if (!fp) fail ("can't create output file `a.req'"); if (fwrite (request, requestlen, 1, fp) != 1) fail ("can't write output"); fclose (fp); } xfree (request); }
int main (int argc, char *argv[]) { gpgme_ctx_t ctx; gpgme_error_t err; gpgme_data_t in; gpgme_import_result_t result; char *pubkey_1_asc = make_filename ("pubkey-1.asc"); char *seckey_1_asc = make_filename ("seckey-1.asc"); init_gpgme (GPGME_PROTOCOL_OpenPGP); err = gpgme_new (&ctx); fail_if_err (err); err = gpgme_data_new_from_file (&in, pubkey_1_asc, 1); free (pubkey_1_asc); fail_if_err (err); err = gpgme_op_import (ctx, in); fail_if_err (err); result = gpgme_op_import_result (ctx); check_result (result, "ADAB7FCC1F4DE2616ECFA402AF82244F9CD9FD55", 0); gpgme_data_release (in); err = gpgme_data_new_from_file (&in, seckey_1_asc, 1); free (seckey_1_asc); fail_if_err (err); err = gpgme_op_import (ctx, in); fail_if_err (err); result = gpgme_op_import_result (ctx); check_result (result, "ADAB7FCC1F4DE2616ECFA402AF82244F9CD9FD55", 1); gpgme_data_release (in); gpgme_release (ctx); return 0; }
static void * thread_one (void *arg) { int rc, i; info_msg ("thread-one started"); npth_usleep (10); /* Give the other thread some time to start. */ for (i=0; i < 10; i++) { /* We would not need the mutex here, but we use it to allow the system to switch to another thread. */ rc = npth_mutex_lock (&counter_mutex); fail_if_err (rc); counter++; rc = npth_mutex_unlock (&counter_mutex); fail_if_err (rc); } info_msg ("thread-one terminated"); return (void*)4711; }
int main (int argc, char **argv) { gpgme_error_t err; gpgme_error_t op_err; gpgme_ctx_t ctx; const char *command; gpgme_check_version (NULL); #ifndef HAVE_W32_SYSTEM setlocale (LC_ALL, ""); gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL)); gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL)); #endif if (argc) { argc--; argv++; } command = argc? *argv : "NOP"; err = gpgme_new (&ctx); fail_if_err (err); err = gpgme_set_protocol (ctx, GPGME_PROTOCOL_ASSUAN); fail_if_err (err); err = gpgme_op_assuan_transact_ext (ctx, command, data_cb, NULL, inq_cb, NULL, status_cb, NULL, &op_err); fail_if_err (err || op_err); gpgme_release (ctx); return 0; }
int main (int argc, char *argv[]) { gpgme_ctx_t ctx; gpgme_error_t err; gpgme_data_t in, out; gpgme_verify_result_t result; char *agent_info; int i; init_gpgme (GPGME_PROTOCOL_OpenPGP); err = gpgme_new (&ctx); fail_if_err (err); agent_info = getenv ("GPG_AGENT_INFO"); if (!(agent_info && strchr (agent_info, ':'))) gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL); err = gpgme_data_new_from_mem (&in, "Hallo Leute\n", 12, 0); fail_if_err (err); err = gpgme_data_new (&out); fail_if_err (err); for (i = 0; i < sizeof (expected_notations) / sizeof (expected_notations[0]); i++) { err = gpgme_sig_notation_add (ctx, expected_notations[i].name, expected_notations[i].value, expected_notations[i].flags); fail_if_err (err); } err = gpgme_op_sign (ctx, in, out, GPGME_SIG_MODE_NORMAL); fail_if_err (err); gpgme_data_release (in); err = gpgme_data_new (&in); fail_if_err (err); gpgme_data_seek (out, 0, SEEK_SET); err = gpgme_op_verify (ctx, out, NULL, in); fail_if_err (err); result = gpgme_op_verify_result (ctx); check_result (result); gpgme_data_release (in); gpgme_data_release (out); gpgme_release (ctx); return 0; }
static void print_gpgconf_string (const char *cname, const char *name) { gpg_error_t err; gpgme_ctx_t ctx; gpgme_conf_comp_t conf_list, conf; gpgme_conf_opt_t opt; gpgme_conf_arg_t value; err = gpgme_new (&ctx); fail_if_err (err); err = gpgme_op_conf_load (ctx, &conf_list); fail_if_err (err); for (conf = conf_list; conf; conf = conf->next) { if ( !strcmp (conf->name, cname) ) { for (opt = conf->options; opt; opt = opt->next) if ( !(opt->flags & GPGME_CONF_GROUP) && !strcmp (opt->name, name)) { for (value = opt->value; value; value = value->next) { if (opt->type == GPGME_CONF_ALIAS_LIST) print_one_alias (value->value.string); } break; } break; } } gpgme_conf_release (conf_list); gpgme_release (ctx); }
void init_gpgme (gpgme_protocol_t proto) { gpgme_error_t err; gpgme_check_version (NULL); setlocale (LC_ALL, ""); gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL)); #ifndef HAVE_W32_SYSTEM gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL)); #endif err = gpgme_engine_check_version (proto); fail_if_err (err); }
static void * thread_two (void *arg) { int rc, i; info_msg ("thread-two started"); for (i=0; i < 10; i++) { rc = npth_mutex_lock (&counter_mutex); fail_if_err (rc); counter--; if (i == 5) { npth_t tid; info_msg ("creating thread-twoone"); rc = npth_create (&tid, NULL, thread_twoone, NULL); fail_if_err (rc); npth_usleep (10); /* Give new thread some time to start. */ } rc = npth_mutex_unlock (&counter_mutex); fail_if_err (rc); } info_msg ("busy waiting for thread twoone"); while (!thread_twoone_ready) npth_sleep (0); info_msg ("thread-two terminated"); return (void*)4722; }
int read_data(char *buf, int buf_size) { int ret; strcpy(buf,""); if((ret = gpgme_data_read(_cf_out, buf, buf_size)) > 0) buf[ret] = '\0'; if(ret < 0) fail_if_err(gpgme_err_code_from_errno(errno)); if(ret > 0) { return 1; } else { gpgme_data_release(_cf_out); return 0; } }
static void show_auditlog (gpgme_ctx_t ctx) { gpgme_error_t err; gpgme_data_t data; err = gpgme_data_new (&data); fail_if_err (err); err = gpgme_op_getauditlog (ctx, data, 0); if (err) { fprintf (stderr, "%s:%i: Can't get audit log: %s\n", __FILE__, __LINE__, gpgme_strerror (err)); if (gpgme_err_code (err) != GPG_ERR_ASS_UNKNOWN_CMD) got_errors = 1; } print_data (data); gpgme_data_release (data); }
int main (int argc, char **argv) { gpgme_ctx_t ctx; gpgme_error_t err; gpgme_data_t sig, text; gpgme_verify_result_t result; init_gpgme (GPGME_PROTOCOL_CMS); err = gpgme_new (&ctx); fail_if_err (err); gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS); /* Checking a valid message. */ err = gpgme_data_new_from_mem (&text, test_text1, strlen (test_text1), 0); fail_if_err (err); err = gpgme_data_new_from_mem (&sig, test_sig1, strlen (test_sig1), 0); fail_if_err (err); err = gpgme_op_verify (ctx, sig, text, NULL); fail_if_err (err); result = gpgme_op_verify_result (ctx); check_result (result, GPGME_SIGSUM_VALID | GPGME_SIGSUM_GREEN, "3CF405464F66ED4A7DF45BBDD1E4282E33BDB76E", GPG_ERR_NO_ERROR, GPGME_VALIDITY_FULL); show_auditlog (ctx); /* Checking a manipulated message. */ gpgme_data_release (text); err = gpgme_data_new_from_mem (&text, test_text1f, strlen (test_text1f), 0); fail_if_err (err); gpgme_data_seek (sig, 0, SEEK_SET); err = gpgme_op_verify (ctx, sig, text, NULL); fail_if_err (err); result = gpgme_op_verify_result (ctx); check_result (result, GPGME_SIGSUM_RED, "3CF405464F66ED4A7DF45BBDD1E4282E33BDB76E", GPG_ERR_BAD_SIGNATURE, GPGME_VALIDITY_UNKNOWN); show_auditlog (ctx); gpgme_data_release (text); gpgme_data_release (sig); gpgme_release (ctx); return got_errors? 1 : 0; }
static void * thread_twoone (void *arg) { int rc, i; npth_setname_np (npth_self (), "thread-twoone"); info_msg ("thread-twoone started"); rc = npth_detach (npth_self ()); fail_if_err (rc); while (counter < 100) { npth_usleep (1000); counter++; } info_msg ("thread-twoone terminated"); thread_twoone_ready = 1; return NULL; }