Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/pgp.c @ 1238:80008fe2a4f2
Re-enable gpg-agent (revert 591d8b35c881)
Some people were actually using it... :)
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sat, 16 Jun 2007 12:30:43 +0200 |
parents | 591d8b35c881 |
children | f89844a0448a |
comparison
equal
deleted
inserted
replaced
1237:dcb99f0b5aaa | 1238:80008fe2a4f2 |
---|---|
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; | |
256 char *signed_data = NULL; | 257 char *signed_data = NULL; |
257 size_t nread; | 258 size_t nread; |
258 gpgme_key_t key; | 259 gpgme_key_t key; |
259 gpgme_error_t err; | 260 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 /* | |
277 p = getenv("GPG_AGENT_INFO"); | 276 p = getenv("GPG_AGENT_INFO"); |
278 if (!(p && strchr(p, ':'))) | 277 if (!(p && strchr(p, ':'))) |
279 gpgme_set_passphrase_cb(ctx, passphrase_cb, 0); | 278 gpgme_set_passphrase_cb(ctx, passphrase_cb, 0); |
280 */ | |
281 gpgme_set_passphrase_cb(ctx, passphrase_cb, 0); | |
282 | 279 |
283 err = gpgme_get_key(ctx, gpg.private_key, &key, 1); | 280 err = gpgme_get_key(ctx, gpg.private_key, &key, 1); |
284 if (err || !key) { | 281 if (err || !key) { |
285 scr_LogPrint(LPRINT_LOGNORM, "GPGME error: private key not found"); | 282 scr_LogPrint(LPRINT_LOGNORM, "GPGME error: private key not found"); |
286 gpgme_release(ctx); | 283 gpgme_release(ctx); |
322 // The returned string must be freed with g_free() after use. | 319 // The returned string must be freed with g_free() after use. |
323 char *gpg_decrypt(const char *gpg_data) | 320 char *gpg_decrypt(const char *gpg_data) |
324 { | 321 { |
325 gpgme_ctx_t ctx; | 322 gpgme_ctx_t ctx; |
326 gpgme_data_t in, out; | 323 gpgme_data_t in, out; |
327 char *data; | 324 char *p, *data; |
328 char *decrypted_data = NULL; | 325 char *decrypted_data = NULL; |
329 size_t nread; | 326 size_t nread; |
330 gpgme_error_t err; | 327 gpgme_error_t err; |
331 const char prefix[] = "-----BEGIN PGP MESSAGE-----\n\n"; | 328 const char prefix[] = "-----BEGIN PGP MESSAGE-----\n\n"; |
332 const char suffix[] = "\n-----END PGP MESSAGE-----\n"; | 329 const char suffix[] = "\n-----END PGP MESSAGE-----\n"; |
333 //char *p; | |
334 | 330 |
335 if (!gpg.enabled) | 331 if (!gpg.enabled) |
336 return NULL; | 332 return NULL; |
337 | 333 |
338 err = gpgme_new(&ctx); | 334 err = gpgme_new(&ctx); |
342 return NULL; | 338 return NULL; |
343 } | 339 } |
344 | 340 |
345 gpgme_set_protocol(ctx, GPGME_PROTOCOL_OpenPGP); | 341 gpgme_set_protocol(ctx, GPGME_PROTOCOL_OpenPGP); |
346 | 342 |
347 /* | |
348 p = getenv("GPG_AGENT_INFO"); | 343 p = getenv("GPG_AGENT_INFO"); |
349 if (!(p && strchr(p, ':'))) | 344 if (!(p && strchr(p, ':'))) |
350 gpgme_set_passphrase_cb(ctx, passphrase_cb, 0); | 345 gpgme_set_passphrase_cb(ctx, passphrase_cb, 0); |
351 */ | |
352 gpgme_set_passphrase_cb(ctx, passphrase_cb, 0); | |
353 | 346 |
354 // Surround the given data with the prefix & suffix | 347 // Surround the given data with the prefix & suffix |
355 data = g_new(char, sizeof(prefix) + sizeof(suffix) + strlen(gpg_data)); | 348 data = g_new(char, sizeof(prefix) + sizeof(suffix) + strlen(gpg_data)); |
356 strcpy(data, prefix); | 349 strcpy(data, prefix); |
357 strcat(data, gpg_data); | 350 strcat(data, gpg_data); |