test/message_api_test.cc
author Volker Birk <vb@pep.foundation>
Sat, 30 Dec 2017 16:06:57 +0100
changeset 2338 b70a6082836b
parent 2333 10a26f0f071d
child 2340 5c5ef77d15da
permissions -rw-r--r--
settings enc_format to PEP_enc_none now legal in encrypt_message()
     1 // This file is under GNU General Public License 3.0
     2 // see LICENSE.txt
     3 
     4 #include <stdlib.h>
     5 #include <string.h>
     6 #include "platform.h"
     7 #include <iostream>
     8 #include <fstream>
     9 #include <assert.h>
    10 #include "mime.h"
    11 #include "message_api.h"
    12 
    13 using namespace std;
    14 
    15 void test_MIME_decrypt_message()
    16 {
    17 	static const std::string private_key =
    18         "-----BEGIN PGP PRIVATE KEY BLOCK-----\n"
    19         "\n"
    20         "lQOmBFpCxkEBCCC8ugYsWOsv966JOl5Ahdw6YiobbU9peFLV8aMBOG+oNIPs3BQj\n"
    21         "u3FUugkVqA5In93oqVgNZ2LU6Y/RWldN+Pc4IMf6qSZnTBj/1ffBjuqAow1hPEYV\n"
    22         "354LNYoQtJXioY0X8FjRgt+NoBPphRbo+XJ0uIQckJey6uvvtukEZkMLM1ur1aID\n"
    23         "9biJZ7yXtJM7KxN5792Vo2gGp/1hlFW6SfM7E0g60L5DT8C/BsYeKtMmxKNZngo6\n"
    24         "ZBxLDAcxMcT5UpRW79B34pTINZAEsvLeT7TLajzqP/OggUrFkkwLr3KJk09aFF+6\n"
    25         "TN6CI2fDdSqdoPVEgNrZE9zFqAgVWOdhLOHRpXgt7wARAQABAAgZATpqsN4xRaIk\n"
    26         "giMdmujkGoMqB/ypoCOW0mqcp3ThESSqWR/Dh8n//k+poHj0Atf7fzie6JNsKruM\n"
    27         "Yo3mdIzyuuxHsONp6xEtNnkDgEB4WTb2btQQFrNaWXNTPzGVqiBoBShcw5xI7SiG\n"
    28         "CKaDlCePbaAHyBHO0uzBdVFo6czqkceXSJ+hNDY7xbURbkgIA5SGJ+8cssmcKKoc\n"
    29         "LDY34S3Pu0gG3+K6gSedYaHAqVVQn8dmEitvDFQ96sTNIpPiMp5Tc+/8UXziF91f\n"
    30         "XRrXYX9o3nkCvz01qtjR4LQVDztysm3/VmDcsjqhzALiiBLigyglpE5DEp0+wMUq\n"
    31         "gw5TpWZ63lf6XjEEEM+c+D3HHsEnh24+DNU2OyfFZGpp9olSaTDcXtEBuBTt/Uhy\n"
    32         "NnqF4MswQ2me4Lfr4D4sUS5jtsKkee+2IQuwtg/bBVYsL6MfV2llJco2vrOCb6y8\n"
    33         "u9CnQhRbVBd6kBMiJeE50Ijk3jP78GrkPm3rGWKCWRuXVr07+U2MsEnvSkkBfpEE\n"
    34         "EOi2NcXCCJux9xZv0xOyWogXDVLVrrhs8/PGjJO1IeaMtmrzleo3azUbWus/BYLA\n"
    35         "vJkO+PElg/MCc2ub5hFs7IqSbLmteWFiSOzTcdHNWeqETsixAc8dpbq0zhkPwdzA\n"
    36         "otLEBS3mpaB29Bpt9lzgewHoVI/o/OvUFFaP+b1Fd4wOJH8EELZPWw+85tSB1l63\n"
    37         "4B+77YoBc9wDBFg7Pt4Eo0eghFZ/159YTA1bcr3fZ8bYIgiHHNLC/Fsx+sUu00PC\n"
    38         "ctLrOxGRbuDyNy2rsezf8Bz8xpihBPuBmSbKoaZguSazgpuC1LPkVbQQVaN1h+Ir\n"
    39         "9/tJufw+hT9Eggvx5xtCo7GD1trnx0xLKbQhVGVzdCBUb25pIDxlbmdpbmUtMzIy\n"
    40         "QHBlcHRlc3QuY2g+iQE8BBMBCAAiBQJaQsZBAhsDBgsJCAcDAgYVCAIJCgsEFgID\n"
    41         "AQIeAQIXgAAKCRCvYy6fx5m31NWeCCCXgm1J7Pq4ECKaMZcp7WoWguXQW+Ellgrx\n"
    42         "B6EjZmvy1iB0RYaDz6F0HCXd0WtC2YDlkxJ47rKBHsnmcyHbFNlY0fgc5Uhs7apI\n"
    43         "bBMHHRGwl8pie05DqxQ0jBxO2esk/IPJDhLXw7gZvaY/9PUS669QWoq+L/Hhph8V\n"
    44         "5v65jnw2937bOaf6wvEUUj2cg6cUaPTZSXv26vxUrT8RD+DxbQiNjJIeGRfVj3QY\n"
    45         "9GCTcp45ZaB8kLQEVayFrC3Jougcklk5DS1zlFCHiYLa4cco/68XHL7/CFdIxxsK\n"
    46         "Rd/3FYWX6zfQZJs5U6KmGy18cXvk0OOtTru9aNHR0YiLj4Vs8K+mWA10vZ0DpgRa\n"
    47         "QsZBAQggwrnOsiJ3JNB+mTm9pZbX4mUkw7OXrar1CvOVDqrnI+H+Z9/DC1FDEupw\n"
    48         "8mD3fFV4veO6smjb9wWAXhmU88OxXziChM8WJlWz2GrZPoM2DIYu1gLycp7wo1Md\n"
    49         "mzhd/5tpBWMJ4gGS9AjvQc5ffk7JVBAnmhh4ZtdoEctHMJs7+1RhXE7KUM1QWjew\n"
    50         "2GAVAaw+KsuXvqsF8soXvlFaHe9sTHKXKUD/MN4WWPR3SIvC4yoadlUpCMfooXf8\n"
    51         "ZCFLbVirkqGy5AakF7thlaTq7bxEX5BQbP/DjVuTTd311jk4x7oT+1bT7D6iIoES\n"
    52         "DKfYijw+059CrCbjFUn3/RRg5sx/55FA2XEAEQEAAQAIHiu228SYwSeGGM2cLUt1\n"
    53         "vBxKeYDnmeb2aJFfUnia/E3NZ7f4/0fUo9qkv9th0l1asMLsU1bG/I6NcR5u3sYE\n"
    54         "iham0IIxHTdY6QluHzwN573TB8OqoLQDo2D/ATf95PhDcsWvUKIomU1ojhG3Wy+3\n"
    55         "TzIseD97O9hWhjnsaRxr1QDclghnNffz589T40wAQAkdQlfDuBABberGNR0DsCZq\n"
    56         "w1xx1+EaEt8o7sXfRMFKoBLJzya0toJNIBGdXCXVPFPtYx6RAiD1KoufgXwVCBaL\n"
    57         "CHc8QvurgyMBghc9pBcdGs60fNhWn1U4qeWzPOHO95ZWVFObBiuGqkX25revf1Dg\n"
    58         "RTY5OsBTBBDdnMElWA+l6ctlSX8vNUQBin7aPbHu1HrmUxH9EiKwUd6jdoFmssw7\n"
    59         "soohAfYJCsuTQLHPI+9W6okF4rjlvl0aS2cN4HSbLjTwdNiUgIHVKJPDq8WDgCsV\n"
    60         "bR09wsLkohmoX/qZFEQMKdr7A2ar64zQzpx6ZFB0kS71Fr6+rFUAIzePBBDg8QXr\n"
    61         "J/R6iZYnMNv/mzyNunbM3B7siwbILS1kLeS6lTYeaKORa7JFRc776rkWV//P1Soc\n"
    62         "nW2byeBxNxOmdNXlNsA6Gg8O4rn3rxEgBZlsOYUG1ZcPZZu8kNFkLTYP+mgFIP3I\n"
    63         "izn858IbnNFm0HjRMGiS+zip2r/rgbniIhLQ2l7/BBCL+2x0+Ww5I/el6A7k+y2X\n"
    64         "3xazBVOQfpPl9BgMdsuO0BBlN5RpbTfE8TVpWneeamAuRJh7ArApbAS508Thw7Sj\n"
    65         "8iLKXj5yScAEC2WO9ZsHqJ/RN3VyhCCI0u3Y75wB3qfcroZUlwvQb/WfH8/vHr2O\n"
    66         "E72YoprbNOmRFZ7LZkRX56URRn2JASMEGAEIAAkFAlpCxkECGwwACgkQr2Mun8eZ\n"
    67         "t9RozQggkb/Lb08g4w99CcXq6hV28D5bOHjiEx4XNdkeLVExhfk1zgQ9lf4rjyb2\n"
    68         "ox+e3Dc5S590NoYg/35vd/QWPsg1JiCvAu296lzOLtIiTAI1KGUJdbsLxRIduOU7\n"
    69         "6n/KVxRG4w4kJqpbu+UzBY7KtDbWzapJx8v0sdsTOVxg7kFxvYtra5TRaPfce4EX\n"
    70         "ox2V2HPhtFNSILH8Jqh/R0PV5RRbNFHZA4cKXkBJMw3BcpbpXeLCXiD6P3FNVSKh\n"
    71         "Rkd3JY0XJhwbvGPCRWkobtxkieZe0bCmKu8+gw0Zqm2QNA7J6iMT4rMZWH9k7lpp\n"
    72         "okyt7GheXlwKEtVQSAcH/NalK9Q+ckaQttA=\n"
    73         "=KACn\n"
    74         "-----END PGP PRIVATE KEY BLOCK-----\n"
    75         "\n";
    76 
    77     static const std::string mimetext =
    78         "To: denden@peptest.ch\r\n"
    79         "From: Lars Rohwedder <roker@pep-project.org>\r\n"
    80         "Subject: Test for ENGINE-322\r\n"
    81         "Message-ID: <4b2d328c-b284-e359-1c2c-fe136358b8a6@pep-project.org>\r\n"
    82         "Date: Thu, 28 Dec 2017 22:00:47 +0100\r\n"
    83         "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0)\r\n"
    84         " Gecko/20100101 Thunderbird/52.5.0\r\n"
    85         "MIME-Version: 1.0\r\n"
    86         "Content-Type: text/plain; charset=utf-8\r\n"
    87         "Content-Language: en-US\r\n"
    88         "Content-Transfer-Encoding: 8bit\r\n"
    89         "\r\n"
    90         "-----BEGIN PGP MESSAGE-----\r\n"
    91         "Charset: utf-8\r\n"
    92         "\r\n"
    93         "hQEQA30SSxlFRbxRAQgggvPrko4vJ988ylqdGF7/Jtw/61VddHg7rjOTG7yZiq2J\r\n"
    94         "p0lXb0N9Bz8SON/m4NWWS5ij0Bj1wMdTgLowLxMz0PfCIyyiQIfqEBAXUcAOQh2f\r\n"
    95         "Pg2iZbynrQ1T4M/D0BlIn2bfXb790Cni+o1OmWTCx4wC6AKtGvlonLAIsH1hUfs+\r\n"
    96         "yKOyCCNaNSmyAPeF3F5v7iEO5Eez1R/UrtxcYj2QmCdVt5v0AuAlm5HVPJgj7wCd\r\n"
    97         "MeRmK4a1+sM51CcCf6Tk9uZbIVrr/XkyGVPmmHTK8E4QmvmL6PGeuIitwqKe80/L\r\n"
    98         "XH4ZYPXIxVU9o5HoSo3YJ3BSKLQzCoDRCD8JlCo08K6mrpuFAgwD42RJLbKIaR4B\r\n"
    99         "EADNgisKiIku4SrBmBkryyKMYmOTW0QKnY/wfNselpzuj5cMpKA4e60x/wEQRIvC\r\n"
   100         "m1ZO7LjhbVjNf6ws2FgytnTRf+8R/R8mp6/XIDeUvaBvUku5yoRjTeznFRwpj6yT\r\n"
   101         "WfQMlLojI2fe+y5fHKIIjTpW5HOQQv7sZ4UzE+jRpRErRVq4UI49l7yTBnG0j75w\r\n"
   102         "UZTt05OnJMQrCCiD7Fu9xDw5If3x884GehKpFGm6XqZ8V7NhwGk6mf62rZEouBQh\r\n"
   103         "AhTu/irkz30PpWY3gGj2YF0PIaQmweb9u2izox1kTfq2xRfPLg/4cOgBKy1/Xeea\r\n"
   104         "IVeaACAcoNdJaYuZCSe9CMbr5s7kusE22/6fB0L1itGr09EzhwGJS/+XSt0IwcJw\r\n"
   105         "7XDUGtmYXuTy08wUKU9McxXJ8nlUkXF9ZcswVxHKG36ZRfzx5eBPjzSnDo8EZHs2\r\n"
   106         "wr7wnS8s8J+AvB7kZYFChAct4KH9OwT3/2pSdhd8/sSCkj2zGtrB+8h2QkIE4csD\r\n"
   107         "rIHtBp4oWCJq1XOKYPvdGqWBxZ/7086kksB99Eyn+sy5C0iNTbEdUN4JkIYq1C0n\r\n"
   108         "DExbr+dqip65DEJRj7TPfwTJ5D28djPYutanSRfJS/niPqztWu0R1ISucw1TMdGU\r\n"
   109         "NcqsqQLPYzTV6xTq+bgBsi8DO4tXkcOpf7eDEP+5kDOncNLpAZGc9NUnVa/jpkYO\r\n"
   110         "XE+CNJ5SYQPdsGcir9JNXNTDgKAGSTI7OAU/ZxOcMCsmctJATcAZERFgvUy8YZN1\r\n"
   111         "3X4Ii6osc8u6shJrjL/detZs8LH8wSe6NYQdtipQo4ySAYQAO9tXdoRrfktXrYus\r\n"
   112         "eLh86toD19D5R9RxHnVEMQP5CdNWgvX7X4ngK94kJq18QCDa1bZXhHBKmWOnAtyL\r\n"
   113         "zpcUNnCWo2gml6GX2kyuL+5Ji6afwKHZg+iag8wBDLGQ+hoOMnzk1iP4DFeQ7iZN\r\n"
   114         "Qvd4mWWASd2BCnf9ulKiMw1wdzN2mpYRNo+nRHx0Zu50VUyj0xMm8VSyUZis5+YH\r\n"
   115         "I3Se7UEeS6ppLsiGcyaJDCMp/38xt5SU5NY4wAAubc6MJclECcvSkM1W/20wQ4di\r\n"
   116         "z5FhKHlqZaPTXN02h0P78wKDDwJr7fFvqtB8G2LgtwbXAkOUvn8vbomQLHBkQ+GH\r\n"
   117         "AuXqBGxKrIwyIEjLZf6hDz++0fDa/ACeFynpxNl1ehmvCl5CsEMcCiM+Ic2pZ/ML\r\n"
   118         "+Hle0GWEKej4WBzXi0j4pzR4WZFt9XCv5+yYAg+UHKc2Kn0Q+bC1AZYxhQDicTP9\r\n"
   119         "qNKTLBHRAeJoQ1y4vHXYGwRGH+penfJiKsQsyOOeoQlZar8tvRYR77K8FhxBtnYK\r\n"
   120         "Xrv+rb1BT/2Ey7P4jb8PiZpbic7ACu1MjFdmlPKrExe5+MY+Pr9ms+hxJrdBH736\r\n"
   121         "K6dojmWUQKpJRzue2lWsfESLxIVeB+vmbg2zU3PflCmMIsRNh2US7vZj2WdgqSqz\r\n"
   122         "wR2eTG4MgPVy4iiGOVT2JWS5t+KXm3kwUZTy9Twi6P1ebNm/B8KQwlutssdWip2q\r\n"
   123         "hON1aFYa4L601zrHgow592PdBkRPQZGiXNHffCvHgsxBHsj4G4JWZhmIkEK/cIWl\r\n"
   124         "RanlZdQG6UPHkoUomh7hauUUgcYe4FWt4NBKdiba36Y=\r\n"
   125         "=1lFj\r\n"
   126         "-----END PGP MESSAGE-----\r\n"
   127         "\r\n";
   128 
   129 	PEP_SESSION session;
   130 	PEP_STATUS status1 = init(&session);
   131 	assert(status1 == PEP_STATUS_OK);
   132 	assert(session);
   133 
   134 	// import secret key
   135 	identity_list* pk = NULL; 
   136 	status1 = import_key( session, private_key.c_str(), private_key.size(), &pk );
   137 	assert(status1 == PEP_STATUS_OK);
   138 	std::cout << "Imported " << identity_list_length(pk) << " private key(s)." << endl;
   139 	
   140 	char* plaintext = nullptr;
   141 	stringlist_t* keys_used = nullptr;
   142 	PEP_rating rating;
   143 	PEP_decrypt_flags_t dec_flags;
   144 	
   145 	PEP_STATUS status2 = MIME_decrypt_message(session, mimetext.c_str(), mimetext.length(),
   146 		&plaintext, &keys_used, &rating, &dec_flags);
   147 	
   148 	std::cout << "MIME_decrypt_message returned " << status2 << std::hex << " (0x" << status2 << ")" << endl;
   149 	
   150 	assert(status2 == PEP_DECRYPTED);
   151 	assert(plaintext);
   152 	
   153 	pEp_free(plaintext);
   154 	
   155 	identity_list* il = pk;
   156 	while(il)
   157 	{
   158 		std::cout << "Delete test key \"" << il->ident->fpr << "\"" << endl;
   159 		delete_keypair( session, il->ident->fpr );
   160 		il = il->next;
   161 	}
   162 	free_identity_list(pk);
   163 }
   164 
   165 
   166 int main() {
   167     cout << "\n*** message_api_test ***\n\n";
   168     test_MIME_decrypt_message();
   169 
   170     PEP_SESSION session;
   171     
   172     cout << "calling init()\n";
   173     PEP_STATUS status1 = init(&session);
   174     assert(status1 == PEP_STATUS_OK);
   175     assert(session);
   176     cout << "init() completed.\n";
   177 
   178     // message_api test code
   179 
   180     cout << "creating message…\n";
   181     pEp_identity * me2 = new_identity("pep.test.alice@pep-project.org", NULL, PEP_OWN_USERID, "Alice Test");
   182     // pEp_identity * me2 = new_identity("test@nokey.plop", NULL, PEP_OWN_USERID, "Test no key");
   183     identity_list *to2 = new_identity_list(new_identity("pep.test.bob@pep-project.org", NULL, "42", "Bob Test"));
   184     // identity_list *to2 = new_identity_list(new_identity("still@nokey.blup", NULL, "42", "Still no key"));
   185     message *msg2 = new_message(PEP_dir_outgoing);
   186     assert(msg2);
   187     msg2->from = me2;
   188     msg2->to = to2;
   189     msg2->shortmsg = strdup("hello, world");
   190     msg2->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   191     cout << "message created.\n";
   192 
   193     char *text2 = nullptr;
   194     PEP_STATUS status2 = mime_encode_message(msg2, false, &text2);
   195     assert(status2 == PEP_STATUS_OK);
   196     assert(text2);
   197 
   198     cout << "decrypted:\n\n";
   199     cout << text2 << "\n";
   200 
   201     free(text2);
   202 
   203     cout << "encrypting message as MIME multipart…\n";
   204     message *enc_msg2 = nullptr;
   205     cout << "calling encrypt_message()\n";
   206     status2 = encrypt_message(session, msg2, NULL, &enc_msg2, PEP_enc_PGP_MIME, 0);
   207     cout << "encrypt_message() returns " << status2 << '.' << endl;
   208     assert(status2 == PEP_STATUS_OK);
   209     assert(enc_msg2);
   210     cout << "message encrypted.\n";
   211     
   212     status2 = mime_encode_message(enc_msg2, false, &text2);
   213     assert(status2 == PEP_STATUS_OK);
   214     assert(text2);
   215 
   216     cout << "encrypted:\n\n";
   217     cout << text2 << "\n";
   218 
   219     message *msg3 = nullptr;
   220     PEP_STATUS status3 = mime_decode_message(text2, strlen(text2), &msg3);
   221     assert(status3 == PEP_STATUS_OK);
   222     const string string3 = text2;
   223     //free(text2);
   224 
   225     unlink("msg4.asc");
   226     ofstream outFile3("msg4.asc");
   227     outFile3.write(string3.c_str(), string3.size());
   228     outFile3.close();
   229 
   230     message *msg4 = nullptr;
   231     stringlist_t *keylist4 = nullptr;
   232     PEP_rating rating;
   233     PEP_decrypt_flags_t flags;
   234     
   235     PEP_STATUS status4 = decrypt_message(session, enc_msg2, &msg4, &keylist4, &rating, &flags);
   236     assert(status4 == PEP_STATUS_OK);
   237     assert(msg4);
   238     assert(keylist4);
   239     assert(rating);
   240     PEP_comm_type ct = enc_msg2->from->comm_type;
   241     assert(ct == PEP_ct_pEp || ct == PEP_ct_pEp_unconfirmed || ct == PEP_ct_OpenPGP || ct == PEP_ct_OpenPGP_unconfirmed );
   242 
   243     free_stringpair_list(enc_msg2->opt_fields);
   244     enc_msg2->opt_fields = NULL;
   245 
   246     cout << "keys used:";
   247 
   248     for (stringlist_t* kl4 = keylist4; kl4 && kl4->value; kl4 = kl4->next)
   249     {
   250         cout << " " << kl4->value;
   251     }
   252     cout << "\n\n";
   253 
   254     free_stringlist(keylist4);
   255 
   256     cout << "opening msg_no_key.asc for reading\n";
   257     ifstream inFile3 ("msg_no_key.asc");
   258     assert(inFile3.is_open());
   259 
   260     string text3;
   261 
   262     cout << "reading msg_no_key.asc sample\n";
   263     while (!inFile3.eof()) {
   264         static string line;
   265         getline(inFile3, line);
   266         text3 += line + "\r\n";
   267     }
   268     inFile3.close();
   269 
   270     message *msg5 = nullptr;
   271     PEP_STATUS status5 = mime_decode_message(text3.c_str(), text3.length(), &msg5);
   272     assert(status5 == PEP_STATUS_OK);
   273 
   274     message *msg6 = nullptr;
   275     stringlist_t *keylist5 = nullptr;
   276     PEP_rating rating2;
   277     PEP_decrypt_flags_t flags2;
   278     PEP_STATUS status6 = decrypt_message(session, msg5, &msg6, &keylist5, &rating2, &flags2);
   279     assert(status6 == PEP_DECRYPT_NO_KEY);
   280     assert(msg6 == NULL);
   281     assert(keylist5 == NULL);
   282     assert(rating2 == PEP_rating_have_no_key);
   283     cout << "rating :" << rating2 << "\n";
   284     free_stringlist(keylist5);
   285 
   286     cout << "\nTesting MIME_encrypt_message / MIME_decrypt_message...\n\n";
   287 
   288     cout << "opening alice_bob_encrypt_test_plaintext_mime.eml for reading\n";
   289     ifstream inFile4 ("test_mails/alice_bob_encrypt_test_plaintext_mime.eml");
   290     assert(inFile4.is_open());
   291     
   292     string text4;
   293     
   294     cout << "reading alice_bob_encrypt_test_plaintext_mime.eml sample\n";
   295     while (!inFile4.eof()) {
   296         static string line;
   297         getline(inFile4, line);
   298         text4 += line + "\r\n";
   299     }
   300     inFile4.close();
   301     
   302     const char* out_msg_plain = text4.c_str();
   303     
   304 //    const char* out_msg_plain = "From: krista@kgrothoff.org\nTo: Volker <vb@pep-project.org>\nSubject: Test\nContent-Type: text/plain; charset=utf-8\nContent-Language: en-US\nContent-Transfer-Encoding:quoted-printable\n\ngaga\n\n";
   305     char* enc_msg = NULL;
   306     char* dec_msg = NULL;
   307 
   308     PEP_STATUS status7 = MIME_encrypt_message(session, text4.c_str(), text4.length(), NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
   309 //    PEP_STATUS status7 = MIME_encrypt_message(session, out_msg_plain, strlen(out_msg_plain), NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
   310     assert(status7 == PEP_STATUS_OK);
   311     
   312     cout << enc_msg << endl;
   313 
   314     string text5 = enc_msg;
   315     
   316     PEP_decrypt_flags_t dec_flags;
   317     stringlist_t* keys_used;
   318     
   319     PEP_STATUS status8 = MIME_decrypt_message(session, text5.c_str(), text5.length(), &dec_msg, &keys_used, &rating, &dec_flags);
   320     assert(status8 == PEP_STATUS_OK);
   321     
   322     cout << dec_msg << endl;
   323     
   324     
   325     cout << "freeing messages…\n";
   326     free_message(msg4);
   327     free_message(msg3);
   328     free_message(msg2);
   329     free_message(enc_msg2);
   330     free_message(msg6);
   331     free_message(msg5);
   332     cout << "done.\n";
   333 
   334     free(enc_msg);
   335     free(dec_msg);
   336     cout << "calling release()\n";
   337     release(session);
   338     return 0;
   339 }