PageRenderTime 29ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/CipherSuites.as

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
ActionScript | 117 lines | 85 code | 17 blank | 15 comment | 1 complexity | 57a6f5055bc96953e79c7ce9a8b560b0 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /**
  2. * CipherSuites
  3. *
  4. * An enumeration of cipher-suites available for TLS to use, along with
  5. * their properties, and some convenience methods
  6. * Copyright (c) 2007 Henri Torgemane
  7. *
  8. * See LICENSE.txt for full license information.
  9. */
  10. package com.hurlant.crypto.tls {
  11. import com.hurlant.crypto.hash.MD5;
  12. import com.hurlant.crypto.hash.SHA1;
  13. public class CipherSuites {
  14. // only the lines marked "ok" are currently implemented.
  15. // rfc 2246
  16. public static const TLS_NULL_WITH_NULL_NULL:uint = 0x0000; // ok
  17. public static const TLS_RSA_WITH_NULL_MD5:uint = 0x0001; // ok
  18. public static const TLS_RSA_WITH_NULL_SHA:uint = 0x0002; // ok
  19. public static const TLS_RSA_WITH_RC4_128_MD5:uint = 0x0004; // ok
  20. public static const TLS_RSA_WITH_RC4_128_SHA:uint = 0x0005; // ok
  21. public static const TLS_RSA_WITH_IDEA_CBC_SHA:uint = 0x0007;
  22. public static const TLS_RSA_WITH_DES_CBC_SHA:uint = 0x0009; // ok
  23. public static const TLS_RSA_WITH_3DES_EDE_CBC_SHA:uint = 0x000A; // ok
  24. public static const TLS_DH_DSS_WITH_DES_CBC_SHA:uint = 0x000C;
  25. public static const TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA:uint = 0x000D;
  26. public static const TLS_DH_RSA_WITH_DES_CBC_SHA:uint = 0x000F;
  27. public static const TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA:uint = 0x0010;
  28. public static const TLS_DHE_DSS_WITH_DES_CBC_SHA:uint = 0x0012;
  29. public static const TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA:uint = 0x0013;
  30. public static const TLS_DHE_RSA_WITH_DES_CBC_SHA:uint = 0x0015;
  31. public static const TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA:uint = 0x0016;
  32. public static const TLS_DH_anon_WITH_RC4_128_MD5:uint = 0x0018;
  33. public static const TLS_DH_anon_WITH_DES_CBC_SHA:uint = 0x001A;
  34. public static const TLS_DH_anon_WITH_3DES_EDE_CBC_SHA:uint = 0x001B;
  35. // rfc3268
  36. public static const TLS_RSA_WITH_AES_128_CBC_SHA:uint = 0x002F; // ok
  37. public static const TLS_DH_DSS_WITH_AES_128_CBC_SHA:uint = 0x0030;
  38. public static const TLS_DH_RSA_WITH_AES_128_CBC_SHA:uint = 0x0031;
  39. public static const TLS_DHE_DSS_WITH_AES_128_CBC_SHA:uint = 0x0032;
  40. public static const TLS_DHE_RSA_WITH_AES_128_CBC_SHA:uint = 0x0033;
  41. public static const TLS_DH_anon_WITH_AES_128_CBC_SHA:uint = 0x0034;
  42. public static const TLS_RSA_WITH_AES_256_CBC_SHA:uint = 0x0035; // ok
  43. public static const TLS_DH_DSS_WITH_AES_256_CBC_SHA:uint = 0x0036;
  44. public static const TLS_DH_RSA_WITH_AES_256_CBC_SHA:uint = 0x0037;
  45. public static const TLS_DHE_DSS_WITH_AES_256_CBC_SHA:uint = 0x0038;
  46. public static const TLS_DHE_RSA_WITH_AES_256_CBC_SHA:uint = 0x0039;
  47. public static const TLS_DH_anon_WITH_AES_256_CBC_SHA:uint = 0x003A;
  48. private static var _props:Array;
  49. init();
  50. private static function init():void {
  51. _props = [];
  52. _props[TLS_NULL_WITH_NULL_NULL] = new CipherSuites(BulkCiphers.NULL, MACs.NULL, KeyExchanges.NULL);
  53. _props[TLS_RSA_WITH_NULL_MD5] = new CipherSuites(BulkCiphers.NULL, MACs.MD5, KeyExchanges.RSA);
  54. _props[TLS_RSA_WITH_NULL_SHA] = new CipherSuites(BulkCiphers.NULL, MACs.SHA1, KeyExchanges.RSA);
  55. _props[TLS_RSA_WITH_RC4_128_MD5] = new CipherSuites(BulkCiphers.RC4_128, MACs.MD5, KeyExchanges.RSA);
  56. _props[TLS_RSA_WITH_RC4_128_SHA] = new CipherSuites(BulkCiphers.RC4_128, MACs.SHA1, KeyExchanges.RSA);
  57. _props[TLS_RSA_WITH_DES_CBC_SHA] = new CipherSuites(BulkCiphers.DES_CBC, MACs.SHA1, KeyExchanges.RSA);
  58. _props[TLS_RSA_WITH_3DES_EDE_CBC_SHA] = new CipherSuites(BulkCiphers.DES3_EDE_CBC, MACs.SHA1, KeyExchanges.RSA);
  59. _props[TLS_RSA_WITH_AES_128_CBC_SHA] = new CipherSuites(BulkCiphers.AES_128, MACs.SHA1, KeyExchanges.RSA);
  60. _props[TLS_RSA_WITH_AES_256_CBC_SHA] = new CipherSuites(BulkCiphers.AES_256, MACs.SHA1, KeyExchanges.RSA);
  61. // ...
  62. // more later
  63. }
  64. private static function getProp(cipher:uint):CipherSuites {
  65. var p:CipherSuites = _props[cipher];
  66. if (p==null) {
  67. throw new Error("Unknown cipher "+cipher.toString(16));
  68. }
  69. return p;
  70. }
  71. public static function getBulkCipher(cipher:uint):uint {
  72. return getProp(cipher).cipher;
  73. }
  74. public static function getMac(cipher:uint):uint {
  75. return getProp(cipher).hash;
  76. }
  77. public static function getKeyExchange(cipher:uint):uint {
  78. return getProp(cipher).key;
  79. }
  80. public static function getDefaultSuites():Array {
  81. // a list of acceptable ciphers, sorted by preference.
  82. return [
  83. TLS_RSA_WITH_AES_256_CBC_SHA,
  84. TLS_RSA_WITH_3DES_EDE_CBC_SHA,
  85. TLS_RSA_WITH_AES_128_CBC_SHA,
  86. TLS_RSA_WITH_RC4_128_SHA,
  87. TLS_RSA_WITH_RC4_128_MD5,
  88. TLS_RSA_WITH_DES_CBC_SHA
  89. ];
  90. }
  91. public var cipher:uint;
  92. public var hash:uint;
  93. public var key:uint;
  94. public function CipherSuites(cipher:uint, hash:uint, key:uint) {
  95. this.cipher = cipher;
  96. this.hash = hash;
  97. this.key = key;
  98. }
  99. }
  100. }