SecurityParameters.cs 9.3 KB

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