You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
2.4 KiB

8 years ago
  1. #include "message_api.h"
  2. #include "keymanagement.h"
  3. #include <libetpan/libetpan.h>
  4. #include <assert.h>
  5. #include <string.h>
  6. PEP_STATUS encrypt_message(
  7. PEP_SESSION session,
  8. const message *src,
  9. stringlist_t * extra,
  10. message **dst
  11. )
  12. {
  13. PEP_STATUS status = PEP_STATUS_OK;
  14. assert(session);
  15. assert(src);
  16. assert(dst);
  17. *dst = NULL;
  18. message *msg = new_message(src->dir, src->from, src->to, NULL);
  19. if (msg == NULL)
  20. return PEP_OUT_OF_MEMORY;
  21. src->from->me = true;
  22. status = myself(session, src->from);
  23. if (status != PEP_STATUS_OK) {
  24. free_message(msg);
  25. return status;
  26. }
  27. stringlist_t * keys = new_stringlist(src->from->fpr);
  28. if (keys == NULL) {
  29. free_message(msg);
  30. return PEP_OUT_OF_MEMORY;
  31. }
  32. stringlist_t *_x;
  33. for (_x = extra; _x && _x->value; _x = _x->next) {
  34. if (stringlist_add(keys, _x->value) == NULL) {
  35. free_message(msg);
  36. free_stringlist(keys);
  37. return PEP_OUT_OF_MEMORY;
  38. }
  39. }
  40. identity_list * _il;
  41. for (_il = src->to; _il && _il->ident; _il = _il->next) {
  42. status = update_identity(session, _il->ident);
  43. if (status != PEP_STATUS_OK) {
  44. free_message(msg);
  45. free_stringlist(keys);
  46. return status;
  47. }
  48. if (_il->ident->fpr) {
  49. if (stringlist_add(keys, _il->ident->fpr) == NULL) {
  50. free_message(msg);
  51. free_stringlist(keys);
  52. return PEP_OUT_OF_MEMORY;
  53. }
  54. }
  55. else
  56. status = PEP_KEY_NOT_FOUND;
  57. }
  58. int _own_keys = 1;
  59. if (extra)
  60. _own_keys += stringlist_length(extra);
  61. if (stringlist_length(keys) > _own_keys) {
  62. char *ptext = NULL;
  63. char *ctext = NULL;
  64. size_t csize = 0;
  65. // TODO: set ptext to MIME text
  66. status = encrypt_and_sign(session, keys, ptext, strlen(ptext), &ctext, &csize);
  67. if (ctext) {
  68. msg->longmsg = ctext;
  69. msg->longmsg_size = csize;
  70. *dst = msg;
  71. }
  72. else
  73. free_message(msg);
  74. free(ptext);
  75. }
  76. else
  77. free_message(msg);
  78. free_stringlist(keys);
  79. return status;
  80. }
  81. PEP_STATUS decrypt_message(
  82. PEP_SESSION session,
  83. const message *src,
  84. message **dst
  85. )
  86. {
  87. PEP_STATUS status = PEP_STATUS_OK;
  88. return status;
  89. }