28 #include "yassl_imp.hpp"
29 #include "yassl_error.hpp"
30 #include "crypto_wrapper.hpp"
31 #include "cert_wrapper.hpp"
34 #include "openssl/ssl.h"
37 #if !defined(_POSIX_THREADS) && defined(__hpux)
39 #define _POSIX_THREADS
47 namespace STL = STL_NAMESPACE;
54 enum RecordLayerState {
62 handShakeNotReady = 0,
74 serverKeyExchangeComplete,
75 serverHelloDoneComplete,
76 serverFinishedComplete
84 clientKeyExchangeComplete,
85 clientFinishedComplete
102 ACCEPT_FIRST_REPLY_DONE,
104 ACCEPT_SECOND_REPLY_DONE,
105 ACCEPT_FINISHED_DONE,
106 ACCEPT_THIRD_REPLY_DONE
112 RecordLayerState recordLayer_;
113 HandShakeState handshakeLayer_;
114 ClientState clientState_;
115 ServerState serverState_;
116 ConnectState connectState_;
117 AcceptState acceptState_;
118 char errorString_[MAX_ERROR_SZ];
123 const RecordLayerState& getRecord()
const;
124 const HandShakeState& getHandShake()
const;
125 const ClientState& getClient()
const;
126 const ServerState& getServer()
const;
127 const ConnectState& GetConnect()
const;
128 const AcceptState& GetAccept()
const;
129 const char* getString()
const;
130 YasslError What()
const;
132 RecordLayerState& useRecord();
133 HandShakeState& useHandShake();
134 ClientState& useClient();
135 ServerState& useServer();
136 ConnectState& UseConnect();
137 AcceptState& UseAccept();
139 void SetError(YasslError);
167 #undef X509_NAME // wincrypt.h clash
178 const char* GetName()
const;
180 size_t GetLength()
const;
207 X509(
const char*
i,
size_t,
const char* s,
size_t,
231 void assign(
const byte* b, uint s) { int_.assign(b,s); }
237 opaque sessionID_[ID_LEN];
238 opaque master_secret_[SECRET_LEN];
239 Cipher suite_[SUITE_LEN];
249 const opaque* GetID()
const;
250 const opaque* GetSecret()
const;
251 const Cipher* GetSuite()
const;
252 uint GetBornOn()
const;
253 uint GetTimeOut()
const;
254 X509* GetPeerX509()
const;
255 void SetTimeOut(uint);
261 void CopyX509(
X509*);
267 STL::list<SSL_SESSION*> list_;
275 void add(
const SSL&);
276 void remove(
const opaque*);
281 friend void Session_initialize();
289 #ifdef _POSIX_THREADS
290 typedef pthread_t THREAD_ID_T;
292 typedef DWORD THREAD_ID_T;
297 THREAD_ID_T threadID_;
304 STL::list<ThreadError> list_;
309 int Lookup(
bool peek);
315 friend Errors& GetErrors();
334 bool multipleProtocol_;
337 bool multipleProtocol =
false);
340 ConnectionEnd getSide()
const;
342 void setVerifyPeer();
343 void setVerifyNone();
344 void setFailNoCert();
346 bool verifyPeer()
const;
347 bool verifyNone()
const;
348 bool failNoCert()
const;
349 bool multipleProtocol()
const;
358 byte suites_[MAX_SUITE_SZ];
361 Ciphers() : setSuites_(
false), suiteSz_(0) {}
379 Accept, Connect, AcceptGood, ConnectGood, AcceptRenegotiate,
380 ConnectRenegotiate, Hits, CbHits, CacheFull, Misses, Timeouts,
Number,
381 GetCacheSize, VerifyMode, VerifyDepth
391 long acceptRenegotiate_;
392 long connectRenegotiate_;
405 Stats() : accept_(0), connect_(0), acceptGood_(0), connectGood_(0),
406 acceptRenegotiate_(0), connectRenegotiate_(0), hits_(0), cbHits_(0),
407 cacheFull_(0), misses_(0), timeouts_(0), number_(0), getCacheSize_(0),
408 verifyMode_(0), verifyDepth_(0)
419 typedef STL::list<x509*> CertList;
427 pem_password_cb passwordCb_;
429 bool sessionCacheOff_;
430 bool sessionCacheFlushOff_;
433 VerifyCallback verifyCallback_;
438 const x509* getCert()
const;
439 const x509* getKey()
const;
441 const Ciphers& GetCiphers()
const;
442 const DH_Parms& GetDH_Parms()
const;
443 const Stats& GetStats()
const;
444 const VerifyCallback getVerifyCallback()
const;
445 pem_password_cb GetPasswordCb()
const;
446 void* GetUserData()
const;
447 bool GetSessionCacheOff()
const;
448 bool GetSessionCacheFlushOff()
const;
450 void setVerifyPeer();
451 void setVerifyNone();
452 void setFailNoCert();
453 void setVerifyCallback(VerifyCallback);
454 bool SetCipherList(
const char*);
455 bool SetDH(
const DH&);
456 void SetPasswordCb(pem_password_cb cb);
457 void SetUserData(
void*);
458 void SetSessionCacheOff();
459 void SetSessionCacheFlushOff();
461 void IncrementStats(StatsField);
462 void AddCA(
x509* ca);
463 const CertList& GetCA_List()
const;
465 friend int read_file(
SSL_CTX*,
const char*,
int, CertType);
483 const Digest& get_digest()
const;
516 const MD5& get_MD5()
const;
517 const SHA& get_SHA()
const;
519 const Hashes& get_certVerify()
const;
534 typedef STL::list<input_buffer*> inputList;
535 typedef STL::list<output_buffer*> outputList;
540 outputList handShakeList_;
547 const inputList& getData()
const;
548 const outputList& getHandShake()
const;
550 inputList& useData();
551 outputList& useHandShake();
574 const SSL_CTX* GetContext()
const;
578 bool get_resuming()
const;
584 void set_resuming(
bool b);
608 const Crypto& getCrypto()
const;
609 const Security& getSecurity()
const;
610 const States& getStates()
const;
613 const Socket& getSocket()
const;
614 YasslError GetError()
const;
615 bool GetMultiProtocol()
const;
616 bool CompressionOn()
const;
626 bool HasData()
const;
627 bool GetQuietShutdown()
const;
630 void set_pending(Cipher suite);
631 void set_random(
const opaque*, ConnectionEnd);
632 void set_sessionID(
const opaque*);
634 void set_preMaster(
const opaque*, uint);
635 void set_masterSecret(
const opaque*);
636 void SetError(YasslError);
637 int SetCompression();
638 void UnSetCompression();
639 void SetQuietShutdown(
bool mode);
643 bool isTLSv1_1()
const;
645 void makeMasterSecret();
646 void makeTLSMasterSecret();
648 void fillData(
Data&);
649 void PeekData(
Data&);
654 void verifyState(ClientState);
655 void verifyState(ServerState);
656 void verfiyHandShakeComplete();
657 void matchSuite(
const opaque*, uint length);
659 void deriveTLSKeys();
660 void Send(
const byte*, uint);
661 void SendWriteBuffered();
664 uint get_SEQIncrement(
bool);
666 const byte* get_macSecret(
bool);
668 void storeKeys(
const opaque*);
670 void verifyClientState(HandShakeType);
671 void verifyServerState(HandShakeType);
674 const SSL& operator=(
const SSL&);
684 void c32to24(uint32, uint24&);
685 void c24to32(
const uint24, uint32&);
687 uint32 c24to32(
const uint24);
689 void ato16(
const opaque*, uint16&);
690 void ato24(
const opaque*, uint24&);
692 void c16toa(uint16, opaque*);
693 void c24toa(
const uint24, opaque*);
694 void c32toa(uint32 u32, opaque*);
699 #endif // yaSSL_INT_HPP