diff options
Diffstat (limited to 'misc/cms/tests')
-rw-r--r-- | misc/cms/tests/cacert.pem | 15 | ||||
-rw-r--r-- | misc/cms/tests/cms_dec.cpp | 111 | ||||
-rw-r--r-- | misc/cms/tests/cms_enc.cpp | 46 | ||||
-rw-r--r-- | misc/cms/tests/int_ca.pem | 18 | ||||
-rw-r--r-- | misc/cms/tests/mycert.pem | 19 | ||||
-rw-r--r-- | misc/cms/tests/mycert2.pem | 25 | ||||
-rw-r--r-- | misc/cms/tests/mykey.pem | 17 | ||||
-rw-r--r-- | misc/cms/tests/mykey2.pem | 11 | ||||
-rw-r--r-- | misc/cms/tests/yourcert.pem | 18 |
9 files changed, 280 insertions, 0 deletions
diff --git a/misc/cms/tests/cacert.pem b/misc/cms/tests/cacert.pem new file mode 100644 index 000000000..70263abe0 --- /dev/null +++ b/misc/cms/tests/cacert.pem @@ -0,0 +1,15 @@ +-----BEGIN CERTIFICATE----- +MIICYjCCAcugAwIBAgIRAMccNerZcWvudgzuyzcOVjgwDQYJKoZIhvcNAQEFBQAw +PTELMAkGA1UEBhMCUFIxEjAQBgNVBAoTCVByaW9uQ29ycDEaMBgGA1UEAxMRUHJp +b25Db3JwIFJvb3QgQ0EwHhcNMDMxMTA5MDEyNjA0WhcNMDQxMTA4MDEyNjM0WjA9 +MQswCQYDVQQGEwJQUjESMBAGA1UEChMJUHJpb25Db3JwMRowGAYDVQQDExFQcmlv +bkNvcnAgUm9vdCBDQTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAtXP7pUMt +iL/Vbz9keSw7V/UClsVoCnybHNoHt1hU8WXGInUeZdBmZdhga/N/ugH0LvvFyERT +63oJz92vbv7sSYjueaPFVP2g+CIJfZPsVsy5G91YyYUFxrevCkVB21VxcRqlflo8 +DokB3t58rJ4+OKkR9aqs/QMT8MS7z3J/FzkCAwEAAaNiMGAwHQYDVR0OBBYEFHL3 +F37cN9LKEouhUYfWMLDzsk92MBIGA1UdEwEB/wQIMAYBAf8CAQgwGwYDVR0RBBQw +EoEQY2FAcHJpb25jb3JwLmNvbTAOBgNVHQ8BAf8EBAMCAQYwDQYJKoZIhvcNAQEF +BQADgYEAZ+NKT1Y6ciyM2IInE7IXw+npYhzA22HsTk+vxJVOpBt+9wAucqpKxiVs +SbYtwabP/4DoKnurHRojoKTdkGGDkco+9Vmlt/9eiTa8WqIeiWnnPV4k1VeWdGA0 +nei/Ds0KG5crGtqmX8DUjz9r5E43pnEMR2T7LuDg/Ko/WZissh0= +-----END CERTIFICATE----- diff --git a/misc/cms/tests/cms_dec.cpp b/misc/cms/tests/cms_dec.cpp new file mode 100644 index 000000000..593cf2e09 --- /dev/null +++ b/misc/cms/tests/cms_dec.cpp @@ -0,0 +1,111 @@ +#include <botan/cms_dec.h> +using namespace Botan; + +#include <iostream> + +int main(int argc, char* argv[]) + { + if(argc != 2) + { + printf("Usage: %s <filename>\n", argv[0]); + return 1; + } + + LibraryInitializer init; + + try { + X509_Certificate mycert("mycert.pem"); + PKCS8_PrivateKey* mykey = PKCS8::load_key("mykey.pem", "cut"); + + X509_Certificate yourcert("yourcert.pem"); + X509_Certificate cacert("cacert.pem"); + X509_Certificate int_ca("int_ca.pem"); + + X509_Store store; + store.add_cert(mycert); + store.add_cert(yourcert); + store.add_cert(cacert, true); + store.add_cert(int_ca); + + DataSource_Stream message(argv[1]); + + User_Interface ui; + + CMS_Decoder decoder(message, store, ui, mykey); + + while(decoder.layer_type() != CMS_Decoder::DATA) + { + CMS_Decoder::Status status = decoder.layer_status(); + CMS_Decoder::Content_Type content = decoder.layer_type(); + + if(status == CMS_Decoder::FAILURE) + { + std::cout << "Failure reading CMS data" << std::endl; + break; + } + + if(content == CMS_Decoder::DIGESTED) + { + std::cout << "Digested data, hash = " << decoder.layer_info() + << std::endl; + std::cout << "Hash is " + << ((status == CMS_Decoder::GOOD) ? "good" : "bad") + << std::endl; + } + + if(content == CMS_Decoder::SIGNED) + { + // how to handle multiple signers? they can all exist within a + // single level... + + std::cout << "Signed by " << decoder.layer_info() << std::endl; + //std::cout << "Sign time: " << decoder.xxx() << std::endl; + std::cout << "Signature is "; + if(status == CMS_Decoder::GOOD) + std::cout << "valid"; + else if(status == CMS_Decoder::BAD) + std::cout << "bad"; + else if(status == CMS_Decoder::NO_KEY) + std::cout << "(cannot check, no known cert)"; + std::cout << std::endl; + } + if(content == CMS_Decoder::ENVELOPED || + content == CMS_Decoder::COMPRESSED || + content == CMS_Decoder::AUTHENTICATED) + { + if(content == CMS_Decoder::ENVELOPED) + std::cout << "Enveloped"; + if(content == CMS_Decoder::COMPRESSED) + std::cout << "Compressed"; + if(content == CMS_Decoder::AUTHENTICATED) + std::cout << "MACed"; + + std::cout << ", algo = " << decoder.layer_info() << std::endl; + + if(content == CMS_Decoder::AUTHENTICATED) + { + std::cout << "MAC status is "; + if(status == CMS_Decoder::GOOD) + std::cout << "valid"; + else if(status == CMS_Decoder::BAD) + std::cout << "bad"; + else if(status == CMS_Decoder::NO_KEY) + std::cout << "(cannot check, no key)"; + std::cout << std::endl; + } + } + decoder.next_layer(); + } + + if(decoder.layer_type() == CMS_Decoder::DATA) + std::cout << "Message is \"" << decoder.get_data() + << '"' << std::endl; + else + std::cout << "No data anywhere?" << std::endl; + } + catch(std::exception& e) + { + std::cerr << e.what() << std::endl; + } + return 0; + } diff --git a/misc/cms/tests/cms_enc.cpp b/misc/cms/tests/cms_enc.cpp new file mode 100644 index 000000000..0319925d8 --- /dev/null +++ b/misc/cms/tests/cms_enc.cpp @@ -0,0 +1,46 @@ +#include <botan/cms_enc.h> +using namespace Botan; + +#include <iostream> +#include <fstream> + +int main() + { + LibraryInitializer init; + + try { + PKCS8_PrivateKey* mykey = PKCS8::load_key("mykey.pem", "cut"); + + X509_Certificate mycert("mycert.pem"); + X509_Certificate mycert2("mycert2.pem"); + X509_Certificate yourcert("yourcert.pem"); + X509_Certificate cacert("cacert.pem"); + X509_Certificate int_ca("int_ca.pem"); + + X509_Store store; + store.add_cert(mycert); + store.add_cert(mycert2); + store.add_cert(yourcert); + store.add_cert(int_ca); + store.add_cert(cacert, true); + + const std::string msg = "prioncorp: we don't toy\n"; + + CMS_Encoder encoder(msg); + + encoder.compress("Zlib"); + encoder.digest(); + encoder.encrypt(mycert); + encoder.sign(store, *mykey); + + SecureVector<byte> raw = encoder.get_contents(); + std::ofstream out("out.der"); + + out.write((const char*)raw.ptr(), raw.size()); + } + catch(std::exception& e) + { + std::cerr << e.what() << std::endl; + } + return 0; + } diff --git a/misc/cms/tests/int_ca.pem b/misc/cms/tests/int_ca.pem new file mode 100644 index 000000000..85e35ab88 --- /dev/null +++ b/misc/cms/tests/int_ca.pem @@ -0,0 +1,18 @@ +-----BEGIN CERTIFICATE----- +MIIC3zCCAkigAwIBAgIRAIfaYqkyhxP/BUSIiqx9/bUwDQYJKoZIhvcNAQEFBQAw +PTELMAkGA1UEBhMCUFIxEjAQBgNVBAoTCVByaW9uQ29ycDEaMBgGA1UEAxMRUHJp +b25Db3JwIFJvb3QgQ0EwHhcNMDMxMTA5MDEzMjA1WhcNMDQxMTA4MDEzMjA1WjBu +MQswCQYDVQQGEwJVUzELMAkGA1UECBMCTUQxEjAQBgNVBAcTCUJhbHRpbW9yZTES +MBAGA1UEChMJUHJpb25Db3JwMRAwDgYDVQQLEwdUZXN0aW5nMRgwFgYDVQQDEw9Q +cmlvbiBQZXJzb25uZWwwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAL2cw+jh +K17j+SBFJqC2oaiPW70T1chtJ1EOtG+SovZXgmLk29fVJCWq1YuihGAOXJUBVGgS +1/IO2WhE3DaU2ekMiiXCQd1cVBLuhrg2aGzOGUifrvvgaLYUHRvctnuYBh/hm04+ +GFpWMeIaly9ZH+yImd6Td7n1yrzsq7Evl/+lAgMBAAGjga0wgaowHQYDVR0OBBYE +FEbeVBJJPVESjB0ZEYaorZU/WxVlMB8GA1UdIwQYMBaAFHL3F37cN9LKEouhUYfW +MLDzsk92MBIGA1UdEwEB/wQIMAYBAf8CAQgwGwYDVR0RBBQwEoEQcHBAcHJpb25j +b3JwLmNvbTAOBgNVHQ8BAf8EBAMCAQYwJwYDVR0lBCAwHgYIKwYBBQUHAwIGCCsG +AQUFBwMHBggrBgEFBQcDBDANBgkqhkiG9w0BAQUFAAOBgQAOBYopIXBr8rq95GW3 +l5I/8IKuUq0/jBzW9766uv1GJUS37CcsQ0isdDrBASZfae4nqWUTIRbEVZ6s0yNb +fauzzoPv13EwnxZECUKADJpLaYgH43v6oil47ljFuuhANQMMFAQ8kTwhUkM4F0eQ +VGBoTBmoIV2Vppf/MRIpQIq0pA== +-----END CERTIFICATE----- diff --git a/misc/cms/tests/mycert.pem b/misc/cms/tests/mycert.pem new file mode 100644 index 000000000..05082b3bf --- /dev/null +++ b/misc/cms/tests/mycert.pem @@ -0,0 +1,19 @@ +-----BEGIN CERTIFICATE----- +MIIDAzCCAmygAwIBAgIRAOVlsPFarxiOCqAgatU2fpgwDQYJKoZIhvcNAQEFBQAw +bjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAk1EMRIwEAYDVQQHEwlCYWx0aW1vcmUx +EjAQBgNVBAoTCVByaW9uQ29ycDEQMA4GA1UECxMHVGVzdGluZzEYMBYGA1UEAxMP +UHJpb24gUGVyc29ubmVsMB4XDTAzMTEwOTAxMzMzN1oXDTA0MTEwODAxMzMzN1ow +ZDELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAk1EMRIwEAYDVQQHEwlCYWx0aW1vcmUx +EjAQBgNVBAoTCVByaW9uQ29ycDEQMA4GA1UECxMHVGVzdGluZzEOMAwGA1UEAxMF +R1JPSUQwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAKf3JbJymfnnelEy4HrK +0wcwOCO6F6W1u98VV01RKEJtff/0m2QVVPRuHXtofZOWwwxZ9e4X2mB+Q1DQjkZM +Q9d/sPvNtIL47QVRNOc9EnfaoGbohlTT+dONj8eYWQ1PU5FtADAEXmXwTWsCk5eO +arpISIyda3bMycwx4hGkwcxHAgMBAAGjgaowgacwHQYDVR0OBBYEFFQgVRRLqxb8 +FJ+s7OQB++dmXdVmMB8GA1UdIwQYMBaAFEbeVBJJPVESjB0ZEYaorZU/WxVlMAwG +A1UdEwEB/wQCMAAwHgYDVR0RBBcwFYETZ3JvaWRAcHJpb25jb3JwLmNvbTAOBgNV +HQ8BAf8EBAMCBeAwJwYDVR0lBCAwHgYIKwYBBQUHAwIGCCsGAQUFBwMHBggrBgEF +BQcDBDANBgkqhkiG9w0BAQUFAAOBgQA2g/iN3cQUDqG5yEzoTtmvDlOkwRruYLOn +8/M7znnPk28l1QVtIy+mCgbFP5khNEHo3ogSjVI83FlRFDTx4mXV81hwK+xi/eLW +MeNfJdHxqRuMMbY9/a2To90jS0NRsCCI917QlT0iOVBpoe0i28Is7ofRZ0MKtZMY +cxcB6XWeug== +-----END CERTIFICATE----- diff --git a/misc/cms/tests/mycert2.pem b/misc/cms/tests/mycert2.pem new file mode 100644 index 000000000..d7efb31ea --- /dev/null +++ b/misc/cms/tests/mycert2.pem @@ -0,0 +1,25 @@ +-----BEGIN CERTIFICATE----- +MIIEHTCCA4agAwIBAgIRANP/9If4mMQ1Y+EIPrzxWg0wDQYJKoZIhvcNAQEFBQAw +bjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAk1EMRIwEAYDVQQHEwlCYWx0aW1vcmUx +EjAQBgNVBAoTCVByaW9uQ29ycDEQMA4GA1UECxMHVGVzdGluZzEYMBYGA1UEAxMP +UHJpb24gUGVyc29ubmVsMB4XDTAzMTExMjA0MzUxNFoXDTA0MTExMTA0MzUxNFow +ZDELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAk1EMRIwEAYDVQQHEwlCYWx0aW1vcmUx +EjAQBgNVBAoTCVByaW9uQ29ycDEQMA4GA1UECxMHVGVzdGluZzEOMAwGA1UEAxMF +R1JPSUQwggG3MIIBKwYHKoZIzjgEATCCAR4CgYEA/X9TgR11EilS30qcLuzk5/YR +t1I870QAwx4/gLZRJmlFXUAiUftZPY1Y+r/F9bow9subVWzXgTuAHTRv8mZgt2uZ +UKWkn5/oBHsQIsJPu6nX/rfGG/g7V+fGqKYVDwT7g/bTxR7DAjVUE1oWkTL2dfOu +K2HXKu/yIgMZndFIAccCFQCXYFCPFSMLzLKSuYKi64QL8Fgc9QKBgEaWA1EuMCeM +05R1ldsi7smCamMirclzRPQddAwyVyTI+e+6p9TYA/+MYJ3NEA68W9/PrXxqQl+u +p4bqIFDr6YNR6h/aH98k1pR6prmqI3ZpU4AvTX1KjsugbRl2iiSR/7FtDvnEOpm1 +9xZy/28KJLRE0HNtBNOKGhMi2vbN2IydA4GFAAKBgQDolXHX/FpKLzYJYlYXxS29 ++Fvug5lma45gnX68o5v+v5lrZgXJ3o6AP1WL9Y5rWrCwCNFMJ/60s9XxBPBXyD4H +bQp0nDFrtkigMrC/Ue/btjzLThKrGhnWNh0EYw/BURsbbaOnxzi8hpIc1n8qXDuK +hlkxUUvovfHj2E4G7IzKdaOBqzCBqDAdBgNVHQ4EFgQU84gmHCKCv04yWRXHbQPq +SX0fzBQwHwYDVR0jBBgwFoAURt5UEkk9URKMHRkRhqitlT9bFWUwDAYDVR0TAQH/ +BAIwADAfBgNVHREEGDAWgRRncm9pZEBicnV0YWx1bml0LmNvbTAOBgNVHQ8BAf8E +BAMCBsAwJwYDVR0lBCAwHgYIKwYBBQUHAwIGCCsGAQUFBwMHBggrBgEFBQcDBDAN +BgkqhkiG9w0BAQUFAAOBgQC4YptXYHJIs/mTaTnTKNSPYSEN8sYfuS5r6pRPbxsM +8uusP2vPgzAVCnQpg27/m9SdcAyZb+yiVCRZ5Kk5+CIKWfWNJDmcBxFJlL+UL7x0 +Qor1+B/IlmPNOZHlXDkpEFA6A9UC8aGYwA9DJmcdMdXxaQy2b1d9en0WyxBRQMnY +6A== +-----END CERTIFICATE----- diff --git a/misc/cms/tests/mykey.pem b/misc/cms/tests/mykey.pem new file mode 100644 index 000000000..46e94e140 --- /dev/null +++ b/misc/cms/tests/mykey.pem @@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cms/tests/mykey2.pem new file mode 100644 index 000000000..69cc76111 --- /dev/null +++ b/misc/cms/tests/mykey2.pem @@ -0,0 +1,11 @@ +-----BEGIN ENCRYPTED PRIVATE KEY----- +MIIBmTBDBgkqhkiG9w0BBQ0wNjAeBgkqhkiG9w0BBQwwEQQI3mP0zRQGjQgCAggA +AgEYMBQGCCqGSIb3DQMHBAiwp1QHcRxj0ASCAVCmM0QKIyYDS3iggiZjG300eV1N +MxFKSfre39BuMNZhd0hIA5T7F+Do84d1dwhK8wdxq5yLRq9pcHaLCYm0iPdtPzVO +OIunUD/3CudNHu6rdBE+rtfd8rLuzHnkgTJJY5wxIGaZdu7O7J8fuBPt5/gTF+an ++rO4U4ZJiFvCCfQzjQHyFUinVAxTE9OozguhcIj3TMnZQwSpXw8HYVVNO+WAN1n1 ++6moNYbKmd69hrKnmg3uxmV7hPBTeFssrdlny3G9yCb5bIPZ/URpv0sM/HLkH2Gl +3v0m50okhnkNIgUgQ45sg2/u6cyoMqxuP7te4jPWalWY0FFMt/Kx8O0eL9eZwcK3 +Vs0QYt6MzCRVRPsrdHFczOHT5Ygk3MW0ZP8uLNJjhDPVYCaJprIuk19wco0z8a7x +734n8uHqlpzOUE7LpGcmaIOeEe7fIr4ZnIfw7QU= +-----END ENCRYPTED PRIVATE KEY----- diff --git a/misc/cms/tests/yourcert.pem b/misc/cms/tests/yourcert.pem new file mode 100644 index 000000000..bea147354 --- /dev/null +++ b/misc/cms/tests/yourcert.pem @@ -0,0 +1,18 @@ +-----BEGIN CERTIFICATE----- +MIIC1zCCAkCgAwIBAgIRAOe/xWvUYwSm0TOMqoPF2u0wDQYJKoZIhvcNAQEFBQAw +PTELMAkGA1UEBhMCUFIxEjAQBgNVBAoTCVByaW9uQ29ycDEaMBgGA1UEAxMRUHJp +b25Db3JwIFJvb3QgQ0EwHhcNMDMxMTA5MDEyOTExWhcNMDQxMTA4MDEyOTExWjBn +MQswCQYDVQQGEwJSVTELMAkGA1UECBMCTUQxEjAQBgN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