/** * TLS Messages * (C) 2004-2006 Jack Lloyd * * Released under the terms of the Botan license */ #ifndef BOTAN_TLS_MESSAGES_H__ #define BOTAN_TLS_MESSAGES_H__ #include #include #include #include #include #include #include namespace Botan { /** * TLS Handshake Message Base Class */ class BOTAN_DLL HandshakeMessage { public: void send(Record_Writer&, HandshakeHash&) const; virtual Handshake_Type type() const = 0; virtual ~HandshakeMessage() {} private: HandshakeMessage& operator=(const HandshakeMessage&) { return (*this); } virtual SecureVector serialize() const = 0; virtual void deserialize(const MemoryRegion&) = 0; }; /** * Client Hello Message */ class BOTAN_DLL Client_Hello : public HandshakeMessage { public: Handshake_Type type() const { return CLIENT_HELLO; } Version_Code version() const { return c_version; } SecureVector session_id() const { return sess_id; } std::vector ciphersuites() const { return suites; } std::vector compression_algos() const { return comp_algos; } SecureVector random() const { return c_random; } bool offered_suite(u16bit) const; Client_Hello(RandomNumberGenerator& rng, Record_Writer&, const Policy*, HandshakeHash&); Client_Hello(const MemoryRegion& buf) { deserialize(buf); } private: SecureVector serialize() const; void deserialize(const MemoryRegion&); Version_Code c_version; SecureVector sess_id, c_random; std::vector suites; std::vector comp_algos; }; /** * Client Key Exchange Message */ class BOTAN_DLL Client_Key_Exchange : public HandshakeMessage { public: Handshake_Type type() const { return CLIENT_KEX; } SecureVector pre_master_secret() const; SecureVector pre_master_secret(RandomNumberGenerator&, const PKCS8_PrivateKey*, Version_Code); Client_Key_Exchange(RandomNumberGenerator&, Record_Writer&, HandshakeHash&, const X509_PublicKey*, Version_Code, Version_Code); Client_Key_Exchange(const MemoryRegion&, const CipherSuite&, Version_Code); private: SecureVector serialize() const; void deserialize(const MemoryRegion&); SecureVector key_material, pre_master; bool include_length; }; /** * Certificate Message */ class BOTAN_DLL Certificate : public HandshakeMessage { public: Handshake_Type type() const { return CERTIFICATE; } std::vector cert_chain() const { return certs; } Certificate(Record_Writer&, const std::vector&, HandshakeHash&); Certificate(const MemoryRegion& buf) { deserialize(buf); } private: SecureVector serialize() const; void deserialize(const MemoryRegion&); std::vector certs; }; /** * Certificate Request Message */ class BOTAN_DLL Certificate_Req : public HandshakeMessage { public: Handshake_Type type() const { return CERTIFICATE_REQUEST; } std::vector acceptable_types() const { return types; } std::vector acceptable_CAs() const { return names; } /* TODO Certificate_Req(Record_Writer&, HandshakeHash&, const X509_Certificate&); */ Certificate_Req(Record_Writer&, HandshakeHash&, const std::vector&); Certificate_Req(const MemoryRegion& buf) { deserialize(buf); } private: SecureVector serialize() const; void deserialize(const MemoryRegion&); std::vector names; std::vector types; }; /** * Certificate Verify Message */ class BOTAN_DLL Certificate_Verify : public HandshakeMessage { public: Handshake_Type type() const { return CERTIFICATE_VERIFY; } bool verify(const X509_Certificate&, HandshakeHash&); Certificate_Verify(RandomNumberGenerator& rng, Record_Writer&, HandshakeHash&, const PKCS8_PrivateKey*); Certificate_Verify(const MemoryRegion& buf) { deserialize(buf); } private: SecureVector serialize() const; void deserialize(const MemoryRegion&); SecureVector signature; }; /** * Finished Message */ class BOTAN_DLL Finished : public HandshakeMessage { public: Handshake_Type type() const { return FINISHED; } bool verify(const MemoryRegion&, Version_Code, const HandshakeHash&, Connection_Side); Finished(Record_Writer&, Version_Code, Connection_Side, const MemoryRegion&, HandshakeHash&); Finished(const MemoryRegion& buf) { deserialize(buf); } private: SecureVector serialize() const; void deserialize(const MemoryRegion&); SecureVector compute_verify(const MemoryRegion&, HandshakeHash, Connection_Side, Version_Code); Connection_Side side; SecureVector verification_data; }; /** * Hello Request Message */ class BOTAN_DLL Hello_Request : public HandshakeMessage { public: Handshake_Type type() const { return HELLO_REQUEST; } Hello_Request(Record_Writer&); Hello_Request(const MemoryRegion& buf) { deserialize(buf); } private: SecureVector serialize() const; void deserialize(const MemoryRegion&); }; /** * Server Hello Message */ class BOTAN_DLL Server_Hello : public HandshakeMessage { public: Handshake_Type type() const { return SERVER_HELLO; } Version_Code version() { return s_version; } SecureVector session_id() const { return sess_id; } u16bit ciphersuite() const { return suite; } byte compression_algo() const { return comp_algo; } SecureVector random() const { return s_random; } Server_Hello(RandomNumberGenerator& rng, Record_Writer&, const Policy*, const std::vector&, const Client_Hello&, Version_Code, HandshakeHash&); Server_Hello(const MemoryRegion& buf) { deserialize(buf); } private: SecureVector serialize() const; void deserialize(const MemoryRegion&); Version_Code s_version; SecureVector sess_id, s_random; u16bit suite; byte comp_algo; }; /** * Server Key Exchange Message */ class BOTAN_DLL Server_Key_Exchange : public HandshakeMessage { public: Handshake_Type type() const { return SERVER_KEX; } X509_PublicKey* key() const; bool verify(const X509_Certificate&, const MemoryRegion&, const MemoryRegion&) const; Server_Key_Exchange(RandomNumberGenerator& rng, Record_Writer&, const X509_PublicKey*, const PKCS8_PrivateKey*, const MemoryRegion&, const MemoryRegion&, HandshakeHash&); Server_Key_Exchange(const MemoryRegion& buf) { deserialize(buf); } private: SecureVector serialize() const; SecureVector serialize_params() const; void deserialize(const MemoryRegion&); std::vector params; SecureVector signature; }; /** * Server Hello Done Message */ class BOTAN_DLL Server_Hello_Done : public HandshakeMessage { public: Handshake_Type type() const { return SERVER_HELLO_DONE; } Server_Hello_Done(Record_Writer&, HandshakeHash&); Server_Hello_Done(const MemoryRegion& buf) { deserialize(buf); } private: SecureVector serialize() const; void deserialize(const MemoryRegion&); }; } #endif