comparison mcabber/src/pgp.c @ 1223:591d8b35c881

Disable gpg-agent Disable gpg-agent as it doesn't seem to work very well.
author Mikael Berthe <mikael@lilotux.net>
date Thu, 17 May 2007 10:55:49 +0200
parents 2de8f8ba1f34
children 80008fe2a4f2
comparison
equal deleted inserted replaced
1222:75aee46d3aee 1223:591d8b35c881
251 // The returned string must be freed with g_free() after use. 251 // The returned string must be freed with g_free() after use.
252 char *gpg_sign(const char *gpg_data) 252 char *gpg_sign(const char *gpg_data)
253 { 253 {
254 gpgme_ctx_t ctx; 254 gpgme_ctx_t ctx;
255 gpgme_data_t in, out; 255 gpgme_data_t in, out;
256 char *p;
257 char *signed_data = NULL; 256 char *signed_data = NULL;
258 size_t nread; 257 size_t nread;
259 gpgme_key_t key; 258 gpgme_key_t key;
260 gpgme_error_t err; 259 gpgme_error_t err;
260 //char *p;
261 261
262 if (!gpg.enabled || !gpg.private_key) 262 if (!gpg.enabled || !gpg.private_key)
263 return NULL; 263 return NULL;
264 264
265 err = gpgme_new(&ctx); 265 err = gpgme_new(&ctx);
271 271
272 gpgme_set_protocol(ctx, GPGME_PROTOCOL_OpenPGP); 272 gpgme_set_protocol(ctx, GPGME_PROTOCOL_OpenPGP);
273 gpgme_set_textmode(ctx, 0); 273 gpgme_set_textmode(ctx, 0);
274 gpgme_set_armor(ctx, 1); 274 gpgme_set_armor(ctx, 1);
275 275
276 /*
276 p = getenv("GPG_AGENT_INFO"); 277 p = getenv("GPG_AGENT_INFO");
277 if (!(p && strchr(p, ':'))) 278 if (!(p && strchr(p, ':')))
278 gpgme_set_passphrase_cb(ctx, passphrase_cb, 0); 279 gpgme_set_passphrase_cb(ctx, passphrase_cb, 0);
280 */
281 gpgme_set_passphrase_cb(ctx, passphrase_cb, 0);
279 282
280 err = gpgme_get_key(ctx, gpg.private_key, &key, 1); 283 err = gpgme_get_key(ctx, gpg.private_key, &key, 1);
281 if (err || !key) { 284 if (err || !key) {
282 scr_LogPrint(LPRINT_LOGNORM, "GPGME error: private key not found"); 285 scr_LogPrint(LPRINT_LOGNORM, "GPGME error: private key not found");
283 gpgme_release(ctx); 286 gpgme_release(ctx);
319 // The returned string must be freed with g_free() after use. 322 // The returned string must be freed with g_free() after use.
320 char *gpg_decrypt(const char *gpg_data) 323 char *gpg_decrypt(const char *gpg_data)
321 { 324 {
322 gpgme_ctx_t ctx; 325 gpgme_ctx_t ctx;
323 gpgme_data_t in, out; 326 gpgme_data_t in, out;
324 char *p, *data; 327 char *data;
325 char *decrypted_data = NULL; 328 char *decrypted_data = NULL;
326 size_t nread; 329 size_t nread;
327 gpgme_error_t err; 330 gpgme_error_t err;
328 const char prefix[] = "-----BEGIN PGP MESSAGE-----\n\n"; 331 const char prefix[] = "-----BEGIN PGP MESSAGE-----\n\n";
329 const char suffix[] = "\n-----END PGP MESSAGE-----\n"; 332 const char suffix[] = "\n-----END PGP MESSAGE-----\n";
333 //char *p;
330 334
331 if (!gpg.enabled) 335 if (!gpg.enabled)
332 return NULL; 336 return NULL;
333 337
334 err = gpgme_new(&ctx); 338 err = gpgme_new(&ctx);
338 return NULL; 342 return NULL;
339 } 343 }
340 344
341 gpgme_set_protocol(ctx, GPGME_PROTOCOL_OpenPGP); 345 gpgme_set_protocol(ctx, GPGME_PROTOCOL_OpenPGP);
342 346
347 /*
343 p = getenv("GPG_AGENT_INFO"); 348 p = getenv("GPG_AGENT_INFO");
344 if (!(p && strchr(p, ':'))) 349 if (!(p && strchr(p, ':')))
345 gpgme_set_passphrase_cb(ctx, passphrase_cb, 0); 350 gpgme_set_passphrase_cb(ctx, passphrase_cb, 0);
351 */
352 gpgme_set_passphrase_cb(ctx, passphrase_cb, 0);
346 353
347 // Surround the given data with the prefix & suffix 354 // Surround the given data with the prefix & suffix
348 data = g_new(char, sizeof(prefix) + sizeof(suffix) + strlen(gpg_data)); 355 data = g_new(char, sizeof(prefix) + sizeof(suffix) + strlen(gpg_data));
349 strcpy(data, prefix); 356 strcpy(data, prefix);
350 strcat(data, gpg_data); 357 strcat(data, gpg_data);