SecurityParameters.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Collections;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Tls
  7. {
  8. public sealed class SecurityParameters
  9. {
  10. internal int m_entity = -1;
  11. internal bool m_secureRenegotiation = false;
  12. internal int m_cipherSuite = Tls.CipherSuite.TLS_NULL_WITH_NULL_NULL;
  13. internal short m_maxFragmentLength = -1;
  14. internal int m_prfAlgorithm = -1;
  15. internal int m_prfCryptoHashAlgorithm = -1;
  16. internal int m_prfHashLength = -1;
  17. internal int m_verifyDataLength = -1;
  18. internal TlsSecret m_baseKeyClient = null;
  19. internal TlsSecret m_baseKeyServer = null;
  20. internal TlsSecret m_earlyExporterMasterSecret = null;
  21. internal TlsSecret m_earlySecret = null;
  22. internal TlsSecret m_exporterMasterSecret = null;
  23. internal TlsSecret m_handshakeSecret = null;
  24. internal TlsSecret m_masterSecret = null;
  25. internal TlsSecret m_trafficSecretClient = null;
  26. internal TlsSecret m_trafficSecretServer = null;
  27. internal byte[] m_clientRandom = null;
  28. internal byte[] m_serverRandom = null;
  29. internal byte[] m_sessionHash = null;
  30. internal byte[] m_sessionID = null;
  31. internal byte[] m_pskIdentity = null;
  32. internal byte[] m_srpIdentity = null;
  33. internal byte[] m_tlsServerEndPoint = null;
  34. internal byte[] m_tlsUnique = null;
  35. internal bool m_encryptThenMac = false;
  36. internal bool m_extendedMasterSecret = false;
  37. internal bool m_extendedPadding = false;
  38. internal bool m_truncatedHmac = false;
  39. internal ProtocolName m_applicationProtocol = null;
  40. internal bool m_applicationProtocolSet = false;
  41. internal short[] m_clientCertTypes = null;
  42. internal IList m_clientServerNames = null;
  43. internal IList m_clientSigAlgs = null;
  44. internal IList m_clientSigAlgsCert = null;
  45. internal int[] m_clientSupportedGroups = null;
  46. internal IList m_serverSigAlgs = null;
  47. internal IList m_serverSigAlgsCert = null;
  48. internal int[] m_serverSupportedGroups = null;
  49. internal int m_keyExchangeAlgorithm = -1;
  50. internal Certificate m_localCertificate = null;
  51. internal Certificate m_peerCertificate = null;
  52. internal ProtocolVersion m_negotiatedVersion = null;
  53. internal int m_statusRequestVersion = 0;
  54. // TODO[tls-ops] Investigate whether we can handle verify data using TlsSecret
  55. internal byte[] m_localVerifyData = null;
  56. internal byte[] m_peerVerifyData = null;
  57. internal void Clear()
  58. {
  59. this.m_sessionHash = null;
  60. this.m_sessionID = null;
  61. this.m_clientCertTypes = null;
  62. this.m_clientServerNames = null;
  63. this.m_clientSigAlgs = null;
  64. this.m_clientSigAlgsCert = null;
  65. this.m_clientSupportedGroups = null;
  66. this.m_serverSigAlgs = null;
  67. this.m_serverSigAlgsCert = null;
  68. this.m_serverSupportedGroups = null;
  69. this.m_statusRequestVersion = 0;
  70. this.m_baseKeyClient = ClearSecret(m_baseKeyClient);
  71. this.m_baseKeyServer = ClearSecret(m_baseKeyServer);
  72. this.m_earlyExporterMasterSecret = ClearSecret(m_earlyExporterMasterSecret);
  73. this.m_earlySecret = ClearSecret(m_earlySecret);
  74. this.m_exporterMasterSecret = ClearSecret(m_exporterMasterSecret);
  75. this.m_handshakeSecret = ClearSecret(m_handshakeSecret);
  76. this.m_masterSecret = ClearSecret(m_masterSecret);
  77. }
  78. public ProtocolName ApplicationProtocol
  79. {
  80. get { return m_applicationProtocol; }
  81. }
  82. public TlsSecret BaseKeyClient
  83. {
  84. get { return m_baseKeyClient; }
  85. }
  86. public TlsSecret BaseKeyServer
  87. {
  88. get { return m_baseKeyServer; }
  89. }
  90. public int CipherSuite
  91. {
  92. get { return m_cipherSuite; }
  93. }
  94. public short[] ClientCertTypes
  95. {
  96. get { return m_clientCertTypes; }
  97. }
  98. public byte[] ClientRandom
  99. {
  100. get { return m_clientRandom; }
  101. }
  102. public IList ClientServerNames
  103. {
  104. get { return m_clientServerNames; }
  105. }
  106. public IList ClientSigAlgs
  107. {
  108. get { return m_clientSigAlgs; }
  109. }
  110. public IList ClientSigAlgsCert
  111. {
  112. get { return m_clientSigAlgsCert; }
  113. }
  114. public int[] ClientSupportedGroups
  115. {
  116. get { return m_clientSupportedGroups; }
  117. }
  118. public TlsSecret EarlyExporterMasterSecret
  119. {
  120. get { return m_earlyExporterMasterSecret; }
  121. }
  122. public TlsSecret EarlySecret
  123. {
  124. get { return m_earlySecret; }
  125. }
  126. public TlsSecret ExporterMasterSecret
  127. {
  128. get { return m_exporterMasterSecret; }
  129. }
  130. public int Entity
  131. {
  132. get { return m_entity; }
  133. }
  134. public TlsSecret HandshakeSecret
  135. {
  136. get { return m_handshakeSecret; }
  137. }
  138. public bool IsApplicationProtocolSet
  139. {
  140. get { return m_applicationProtocolSet; }
  141. }
  142. public bool IsEncryptThenMac
  143. {
  144. get { return m_encryptThenMac; }
  145. }
  146. public bool IsExtendedMasterSecret
  147. {
  148. get { return m_extendedMasterSecret; }
  149. }
  150. public bool IsExtendedPadding
  151. {
  152. get { return m_extendedPadding; }
  153. }
  154. public bool IsSecureRenegotiation
  155. {
  156. get { return m_secureRenegotiation; }
  157. }
  158. public bool IsTruncatedHmac
  159. {
  160. get { return m_truncatedHmac; }
  161. }
  162. public int KeyExchangeAlgorithm
  163. {
  164. get { return m_keyExchangeAlgorithm; }
  165. }
  166. public Certificate LocalCertificate
  167. {
  168. get { return m_localCertificate; }
  169. }
  170. public byte[] LocalVerifyData
  171. {
  172. get { return m_localVerifyData; }
  173. }
  174. public TlsSecret MasterSecret
  175. {
  176. get { return m_masterSecret; }
  177. }
  178. public short MaxFragmentLength
  179. {
  180. get { return m_maxFragmentLength; }
  181. }
  182. public ProtocolVersion NegotiatedVersion
  183. {
  184. get { return m_negotiatedVersion; }
  185. }
  186. public Certificate PeerCertificate
  187. {
  188. get { return m_peerCertificate; }
  189. }
  190. public byte[] PeerVerifyData
  191. {
  192. get { return m_peerVerifyData; }
  193. }
  194. public int PrfAlgorithm
  195. {
  196. get { return m_prfAlgorithm; }
  197. }
  198. public int PrfCryptoHashAlgorithm
  199. {
  200. get { return m_prfCryptoHashAlgorithm; }
  201. }
  202. public int PrfHashLength
  203. {
  204. get { return m_prfHashLength; }
  205. }
  206. public byte[] PskIdentity
  207. {
  208. get { return m_pskIdentity; }
  209. }
  210. public byte[] ServerRandom
  211. {
  212. get { return m_serverRandom; }
  213. }
  214. public IList ServerSigAlgs
  215. {
  216. get { return m_serverSigAlgs; }
  217. }
  218. public IList ServerSigAlgsCert
  219. {
  220. get { return m_serverSigAlgsCert; }
  221. }
  222. public int[] ServerSupportedGroups
  223. {
  224. get { return m_serverSupportedGroups; }
  225. }
  226. public byte[] SessionHash
  227. {
  228. get { return m_sessionHash; }
  229. }
  230. public byte[] SessionID
  231. {
  232. get { return m_sessionID; }
  233. }
  234. public byte[] SrpIdentity
  235. {
  236. get { return m_srpIdentity; }
  237. }
  238. public int StatusRequestVersion
  239. {
  240. get { return m_statusRequestVersion; }
  241. }
  242. public byte[] TlsServerEndPoint
  243. {
  244. get { return m_tlsServerEndPoint; }
  245. }
  246. public byte[] TlsUnique
  247. {
  248. get { return m_tlsUnique; }
  249. }
  250. public TlsSecret TrafficSecretClient
  251. {
  252. get { return m_trafficSecretClient; }
  253. }
  254. public TlsSecret TrafficSecretServer
  255. {
  256. get { return m_trafficSecretServer; }
  257. }
  258. public int VerifyDataLength
  259. {
  260. get { return m_verifyDataLength; }
  261. }
  262. public bool IsRenegotiating { get; set; }
  263. public Certificate PreRenegotiatingServerCert { get; set; }
  264. private static TlsSecret ClearSecret(TlsSecret secret)
  265. {
  266. if (null != secret)
  267. {
  268. secret.Destroy();
  269. }
  270. return null;
  271. }
  272. }
  273. }
  274. #pragma warning restore
  275. #endif