/* * (C) 2015,2016 Jack Lloyd * * Botan is released under the Simplified BSD License (see license.txt) */ #include "fuzzers.h" #include const char* fixed_rsa_key = "-----BEGIN PRIVATE KEY-----\n" "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCe6qqpMQVJ7zCJ\n" "oSnpxia0yO6M7Ie3FGqPcd0DzueC+kWPvuHQ+PpP5vfO6qqRaDVII37PFX5NUZQm\n" "GK/rAm7spjIHTCMgqSZ8pN13LU8m1gDwIdu9al16LXN9zZjB67uLlFn2trtLi234\n" "i0cnyeF8IC0cz7tgCOzMSVEBcqJjkdgGrZ3WUgOXecVm2lXVrYlEiaSxFp4VOE9k\n" "RFeVrELCjmNtc4hRd1yJsF+vObCtvyqGYQE1Qcb0MVSQDBHMkiUVmO6zuW7td5ef\n" "O/1OyntQJGyVa+SnWbkSLCybta2J7MreHENrF5GA0K1KL140SNRHeWifRMuNQua7\n" "qmKXMBTFAgMBAAECggEAIk3fxyQI0zvpy1vZ01ft1QqmzA7nAPNMSWi33/GS8iga\n" "SfxXfKeySPs/tQ/dAARxs//NiOBH4mLgyxR7LQzaawU5OXALCSraXv+ruuUx990s\n" "WKnGaG4EfbJAAwEVn47Gbkv425P4fEc91vAhzQn8PbIoatbAyOtESpjs/pYDTeC/\n" "mnJId8gqO90cqyRECEMjk9sQ8iEjWPlik4ayGlUVbeeMu6/pJ9F8IZEgkLZiNDAB\n" "4anmOFaT7EmqUjI4IlcaqfbbXyDXlvWUYukidEss+CNvPuqbQHBDnpFVvBxdDR2N\n" "Uj2D5Xd5blcIe2/+1IVRnznjoQ5zvutzb7ThBmMehQKBgQDOITKG0ht2kXLxjVoR\n" "r/pVpx+f3hs3H7wE0+vrLHoQgkVjpMWXQ47YuZTT9rCOOYNI2cMoH2D27t1j78/B\n" "9kGYABUVpvQQ+6amqJDI1eYI6e68TPueEDjeALfSCdmPNiI3lZZrCIK9XLpkoy8K\n" "tGYBRRJ+JJxjj1zPXj9SGshPgwKB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ZUMRAw\n" "DgYDVQQIDAdWZXJtb250MRYwFAYDVQQHDA1UaGUgSW50ZXJuZXRzMRQwEgYDVQQK\n" "DAtNYW5nb3MgUiBVczEbMBkGA1UEAwwSc2VydmVyLmV4YW1wbGUuY29tMIIBIjAN\n" "BgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnuqqqTEFSe8wiaEp6cYmtMjujOyH\n" "txRqj3HdA87ngvpFj77h0Pj6T+b3zuqqkWg1SCN+zxV+TVGUJhiv6wJu7KYyB0wj\n" "IKkmfKTddy1PJtYA8CHbvWpdei1zfc2Yweu7i5RZ9ra7S4tt+ItHJ8nhfCAtHM+7\n" "YAjszElRAXKiY5HYBq2d1lIDl3nFZtpV1a2JRImksRaeFThPZERXlaxCwo5jbXOI\n" "UXdcibBfrzmwrb8qhmEBNUHG9DFUkAwRzJIlFZjus7lu7XeXnzv9Tsp7UCRslWvk\n" "p1m5Eiwsm7WtiezK3hxDaxeRgNCtSi9eNEjUR3lon0TLjULmu6pilzAUxQIDAQAB\n" "MA0GCSqGSIb3DQEBCwUAA4IBAQA1eZGc/4V7z/E/6eG0hVkzoAZeuTcSP7WqBSx+\n" "OP2yh0163UYjoa6nehmkKYQQ9PbYPZGzIcl+dBFyYzy6jcp0NdtzpWnTFrjl4rMq\n" "akcQ1D0LTYjJXVP9G/vF/SvatOFeVTnQmLlLt/a8ZtRUINqejeZZPzH8ifzFW6tu\n" "mlhTVIEKyPHpxClh5Y3ubw/mZYygekFTqMkTx3FwJxKU8J6rYGZxanWAODUIvCUo\n" "Fxer1qC5Love3uWl3vXPLEZWZdORnExSRByzz2immBP2vX4zYZoeZRhTQ9ae1TIV\n" "Dk02a/1AOJZdZReDbgXhlqaUx5pk/rzo4mDzvu5HSCeXmClz\n" "-----END CERTIFICATE-----\n"; class Fuzzer_TLS_Server_Creds : public Botan::Credentials_Manager { public: Fuzzer_TLS_Server_Creds() { Botan::DataSource_Memory cert_in(fixed_rsa_cert); Botan::DataSource_Memory key_in(fixed_rsa_key); m_rsa_cert.reset(new Botan::X509_Certificate(cert_in)); //m_rsa_key.reset(Botan::PKCS8::load_key(key_in, fuzzer_rng()); } std::vector cert_chain( const std::vector& algos, const std::string& /*type*/, const std::string& /*hostname*/) override { std::vector v; for(auto algo : algos) { if(algo == "RSA") { v.push_back(*m_rsa_cert); break; } } return v; } Botan::Private_Key* private_key_for(const Botan::X509_Certificate& /*cert*/, const std::string& /*type*/, const std::string& /*context*/) override { return m_rsa_key.get(); } std::string psk_identity_hint(const std::string&, const std::string&) override { return "psk_hint"; } std::string psk_identity(const std::string&, const std::string&, const std::string&) override { return "psk_id"; } Botan::SymmetricKey psk(const std::string&, const std::string&, const std::string&) override { return Botan::SymmetricKey("AABBCCDDEEFF00112233445566778899"); } private: std::unique_ptr m_rsa_cert; std::unique_ptr m_rsa_key; }; void fuzz(const uint8_t in[], size_t len) { if(len == 0) return; auto dev_null = [](const uint8_t[], size_t) {}; auto ignore_alerts = [](Botan::TLS::Alert, const uint8_t[], size_t) {}; auto ignore_hs = [](const Botan::TLS::Session&) { return true; }; Botan::TLS::Session_Manager_Noop session_manager; Botan::TLS::Policy policy; Botan::TLS::Server_Information info("server.name", 443); Fuzzer_TLS_Server_Creds creds; auto next_proto_fn = [](const std::vector& protos) -> std::string { if(protos.size() > 1) return protos[0]; else return "fuzzed"; }; const bool is_datagram = (len % 2 == 0); Botan::TLS::Server server(dev_null, dev_null, ignore_alerts, ignore_hs, session_manager, creds, policy, fuzzer_rng(), next_proto_fn, is_datagram); try { server.received_data(in, len); } catch(std::exception& e) { } }