1
#include <botan/cms_dec.h>
6
int main(int argc, char* argv[])
10
printf("Usage: %s <filename>\n", argv[0]);
14
LibraryInitializer init;
17
X509_Certificate mycert("mycert.pem");
18
PKCS8_PrivateKey* mykey = PKCS8::load_key("mykey.pem", "cut");
20
X509_Certificate yourcert("yourcert.pem");
21
X509_Certificate cacert("cacert.pem");
22
X509_Certificate int_ca("int_ca.pem");
25
store.add_cert(mycert);
26
store.add_cert(yourcert);
27
store.add_cert(cacert, true);
28
store.add_cert(int_ca);
30
DataSource_Stream message(argv[1]);
34
CMS_Decoder decoder(message, store, ui, mykey);
36
while(decoder.layer_type() != CMS_Decoder::DATA)
38
CMS_Decoder::Status status = decoder.layer_status();
39
CMS_Decoder::Content_Type content = decoder.layer_type();
41
if(status == CMS_Decoder::FAILURE)
43
std::cout << "Failure reading CMS data" << std::endl;
47
if(content == CMS_Decoder::DIGESTED)
49
std::cout << "Digested data, hash = " << decoder.layer_info()
51
std::cout << "Hash is "
52
<< ((status == CMS_Decoder::GOOD) ? "good" : "bad")
56
if(content == CMS_Decoder::SIGNED)
58
// how to handle multiple signers? they can all exist within a
61
std::cout << "Signed by " << decoder.layer_info() << std::endl;
62
//std::cout << "Sign time: " << decoder.xxx() << std::endl;
63
std::cout << "Signature is ";
64
if(status == CMS_Decoder::GOOD)
66
else if(status == CMS_Decoder::BAD)
68
else if(status == CMS_Decoder::NO_KEY)
69
std::cout << "(cannot check, no known cert)";
70
std::cout << std::endl;
72
if(content == CMS_Decoder::ENVELOPED ||
73
content == CMS_Decoder::COMPRESSED ||
74
content == CMS_Decoder::AUTHENTICATED)
76
if(content == CMS_Decoder::ENVELOPED)
77
std::cout << "Enveloped";
78
if(content == CMS_Decoder::COMPRESSED)
79
std::cout << "Compressed";
80
if(content == CMS_Decoder::AUTHENTICATED)
83
std::cout << ", algo = " << decoder.layer_info() << std::endl;
85
if(content == CMS_Decoder::AUTHENTICATED)
87
std::cout << "MAC status is ";
88
if(status == CMS_Decoder::GOOD)
90
else if(status == CMS_Decoder::BAD)
92
else if(status == CMS_Decoder::NO_KEY)
93
std::cout << "(cannot check, no key)";
94
std::cout << std::endl;
100
if(decoder.layer_type() == CMS_Decoder::DATA)
101
std::cout << "Message is \"" << decoder.get_data()
104
std::cout << "No data anywhere?" << std::endl;
106
catch(std::exception& e)
108
std::cerr << e.what() << std::endl;