rocket-js 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. data/.gitignore +0 -11
  2. data/Rakefile +33 -47
  3. data/lib/rocket/js.rb +0 -2
  4. data/lib/rocket/js/builder.rb +2 -2
  5. data/lib/rocket/js/cli.rb +1 -1
  6. data/rocket-js.gemspec +23 -80
  7. data/src/vendor/web-socket-js/FABridge.js +604 -0
  8. data/src/vendor/web-socket-js/README.txt +109 -0
  9. data/src/vendor/web-socket-js/WebSocketMain.swf +0 -0
  10. data/src/vendor/web-socket-js/WebSocketMainInsecure.zip +0 -0
  11. data/src/vendor/web-socket-js/flash-src/WebSocket.as +473 -0
  12. data/src/vendor/web-socket-js/flash-src/WebSocketMain.as +88 -0
  13. data/src/vendor/web-socket-js/flash-src/WebSocketMainInsecure.as +19 -0
  14. data/src/vendor/web-socket-js/flash-src/WebSocketStateEvent.as +32 -0
  15. data/src/vendor/web-socket-js/flash-src/bridge/FABridge.as +943 -0
  16. data/src/vendor/web-socket-js/flash-src/build.sh +10 -0
  17. data/src/vendor/web-socket-js/flash-src/com/adobe/net/proxies/RFC2817Socket.as +204 -0
  18. data/src/vendor/web-socket-js/flash-src/com/gsolo/encryption/MD5.as +375 -0
  19. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/Crypto.as +287 -0
  20. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/cert/MozillaRootCertificates.as +3235 -0
  21. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/cert/X509Certificate.as +218 -0
  22. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/cert/X509CertificateCollection.as +57 -0
  23. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/HMAC.as +82 -0
  24. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/IHMAC.as +27 -0
  25. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/IHash.as +21 -0
  26. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/MAC.as +137 -0
  27. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/MD2.as +124 -0
  28. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/MD5.as +204 -0
  29. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHA1.as +106 -0
  30. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHA224.as +28 -0
  31. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHA256.as +115 -0
  32. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHABase.as +71 -0
  33. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/prng/ARC4.as +90 -0
  34. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/prng/IPRNG.as +20 -0
  35. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/prng/Random.as +119 -0
  36. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/prng/TLSPRF.as +142 -0
  37. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/rsa/RSAKey.as +339 -0
  38. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/AESKey.as +2797 -0
  39. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/BlowFishKey.as +375 -0
  40. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/CBCMode.as +55 -0
  41. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/CFB8Mode.as +61 -0
  42. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/CFBMode.as +64 -0
  43. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/CTRMode.as +58 -0
  44. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/DESKey.as +365 -0
  45. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/ECBMode.as +86 -0
  46. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/ICipher.as +21 -0
  47. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/IMode.as +15 -0
  48. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/IPad.as +32 -0
  49. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/IStreamCipher.as +21 -0
  50. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/ISymmetricKey.as +35 -0
  51. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/IVMode.as +110 -0
  52. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/NullPad.as +34 -0
  53. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/OFBMode.as +52 -0
  54. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/PKCS5.as +44 -0
  55. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/SSLPad.as +44 -0
  56. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/SimpleIVMode.as +60 -0
  57. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/TLSPad.as +42 -0
  58. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/TripleDESKey.as +88 -0
  59. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/XTeaKey.as +94 -0
  60. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/aeskey.pl +29 -0
  61. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/dump.txt +2304 -0
  62. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/AESKeyTest.as +1220 -0
  63. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/ARC4Test.as +58 -0
  64. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/BigIntegerTest.as +39 -0
  65. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/BlowFishKeyTest.as +148 -0
  66. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/CBCModeTest.as +160 -0
  67. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/CFB8ModeTest.as +71 -0
  68. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/CFBModeTest.as +98 -0
  69. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/CTRModeTest.as +109 -0
  70. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/DESKeyTest.as +112 -0
  71. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/ECBModeTest.as +151 -0
  72. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/HMACTest.as +184 -0
  73. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/ITestHarness.as +20 -0
  74. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/MD2Test.as +56 -0
  75. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/MD5Test.as +58 -0
  76. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/OFBModeTest.as +101 -0
  77. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/RSAKeyTest.as +92 -0
  78. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/SHA1Test.as +198 -0
  79. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/SHA224Test.as +58 -0
  80. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/SHA256Test.as +60 -0
  81. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/TLSPRFTest.as +51 -0
  82. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/TestCase.as +42 -0
  83. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/TripleDESKeyTest.as +59 -0
  84. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/XTeaKeyTest.as +66 -0
  85. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/BulkCiphers.as +102 -0
  86. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/CipherSuites.as +117 -0
  87. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/IConnectionState.as +14 -0
  88. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/ISecurityParameters.as +29 -0
  89. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/KeyExchanges.as +24 -0
  90. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/MACs.as +38 -0
  91. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/SSLConnectionState.as +171 -0
  92. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/SSLEvent.as +26 -0
  93. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/SSLSecurityParameters.as +340 -0
  94. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSConfig.as +70 -0
  95. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSConnectionState.as +151 -0
  96. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSEngine.as +895 -0
  97. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSError.as +39 -0
  98. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSEvent.as +27 -0
  99. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSSecurityParameters.as +197 -0
  100. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSSocket.as +370 -0
  101. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSSocketEvent.as +26 -0
  102. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSTest.as +180 -0
  103. data/src/vendor/web-socket-js/flash-src/com/hurlant/math/BarrettReduction.as +90 -0
  104. data/src/vendor/web-socket-js/flash-src/com/hurlant/math/BigInteger.as +1543 -0
  105. data/src/vendor/web-socket-js/flash-src/com/hurlant/math/ClassicReduction.as +35 -0
  106. data/src/vendor/web-socket-js/flash-src/com/hurlant/math/IReduction.as +11 -0
  107. data/src/vendor/web-socket-js/flash-src/com/hurlant/math/MontgomeryReduction.as +85 -0
  108. data/src/vendor/web-socket-js/flash-src/com/hurlant/math/NullReduction.as +34 -0
  109. data/src/vendor/web-socket-js/flash-src/com/hurlant/math/bi_internal.as +11 -0
  110. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/ArrayUtil.as +25 -0
  111. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/Base64.as +189 -0
  112. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/Hex.as +66 -0
  113. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/Memory.as +28 -0
  114. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/ByteString.as +43 -0
  115. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/DER.as +210 -0
  116. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/IAsn1Type.as +21 -0
  117. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/Integer.as +44 -0
  118. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/OID.as +35 -0
  119. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/ObjectIdentifier.as +112 -0
  120. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/PEM.as +118 -0
  121. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/PrintableString.as +49 -0
  122. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/Sequence.as +90 -0
  123. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/Set.as +27 -0
  124. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/Type.as +94 -0
  125. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/UTCTime.as +60 -0
  126. data/src/vendor/web-socket-js/sample.html +76 -0
  127. data/src/vendor/web-socket-js/swfobject.js +4 -0
  128. data/src/vendor/web-socket-js/web_socket.js +388 -0
  129. metadata +163 -30
  130. data/lib/rocket/js/version.rb +0 -14
  131. data/rocket-0.0.1.min.js +0 -45
@@ -0,0 +1,66 @@
1
+ /**
2
+ * XTeaKeyTest
3
+ *
4
+ * A test class for XTeaKey
5
+ * Copyright (c) 2007 Henri Torgemane
6
+ *
7
+ * See LICENSE.txt for full license information.
8
+ */
9
+ package com.hurlant.crypto.tests
10
+ {
11
+ import com.hurlant.crypto.prng.Random;
12
+ import com.hurlant.crypto.symmetric.ECBMode;
13
+ import com.hurlant.crypto.symmetric.XTeaKey;
14
+ import com.hurlant.util.Hex;
15
+
16
+ import flash.utils.ByteArray;
17
+ import flash.utils.getTimer;
18
+
19
+ public class XTeaKeyTest extends TestCase
20
+ {
21
+ public function XTeaKeyTest(h:ITestHarness) {
22
+ super(h, "XTeaKey Test");
23
+ runTest(testGetBlockSize, "XTea Block Size");
24
+ runTest(testVectors, "XTea Test Vectors");
25
+
26
+ h.endTestCase();
27
+ }
28
+
29
+ public function testGetBlockSize():void {
30
+ var tea:XTeaKey = new XTeaKey(Hex.toArray("deadbabecafebeefdeadbabecafebeef"));
31
+ assert("tea blocksize", tea.getBlockSize()==8);
32
+ }
33
+
34
+ public function testVectors():void {
35
+ // blah.
36
+ // can't find working test vectors.
37
+ // algorithms should not get published without vectors :(
38
+ var keys:Array=[
39
+ "00000000000000000000000000000000",
40
+ "2b02056806144976775d0e266c287843"];
41
+ var pts:Array=[
42
+ "0000000000000000",
43
+ "74657374206d652e"];
44
+ var cts:Array=[
45
+ "2dc7e8d3695b0538",
46
+ "7909582138198783"];
47
+ // self-fullfilling vectors.
48
+ // oh well, at least I can decrypt what I produce. :(
49
+
50
+ for (var i:uint=0;i<keys.length;i++) {
51
+ var key:ByteArray = Hex.toArray(keys[i]);
52
+ var pt:ByteArray = Hex.toArray(pts[i]);
53
+ var tea:XTeaKey = new XTeaKey(key);
54
+ tea.encrypt(pt);
55
+ var out:String = Hex.fromArray(pt);
56
+ assert("comparing "+cts[i]+" to "+out, cts[i]==out);
57
+ // now go back to plaintext.
58
+ pt.position=0;
59
+ tea.decrypt(pt);
60
+ out = Hex.fromArray(pt);
61
+ assert("comparing "+pts[i]+" to "+out, pts[i]==out);
62
+ }
63
+ }
64
+
65
+ }
66
+ }
@@ -0,0 +1,102 @@
1
+ /**
2
+ * BulkCiphers
3
+ *
4
+ * An enumeration of bulk ciphers available for TLS, along with their properties,
5
+ * with a few convenience methods to go with it.
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.Crypto;
12
+ import flash.utils.ByteArray;
13
+ import com.hurlant.crypto.symmetric.ICipher;
14
+ import com.hurlant.crypto.symmetric.TLSPad;
15
+ import com.hurlant.crypto.symmetric.SSLPad;
16
+
17
+ public class BulkCiphers {
18
+ public static const STREAM_CIPHER:uint = 0;
19
+ public static const BLOCK_CIPHER:uint = 1;
20
+
21
+ public static const NULL:uint = 0;
22
+ public static const RC4_40:uint = 1;
23
+ public static const RC4_128:uint = 2
24
+ public static const RC2_CBC_40:uint = 3; // XXX I don't have that one.
25
+ public static const DES_CBC:uint = 4;
26
+ public static const DES3_EDE_CBC:uint = 5;
27
+ public static const DES40_CBC:uint = 6;
28
+ public static const IDEA_CBC:uint = 7; // XXX I don't have that one.
29
+ public static const AES_128:uint = 8;
30
+ public static const AES_256:uint = 9;
31
+
32
+ private static const algos:Array =
33
+ ['', 'rc4', 'rc4', '', 'des-cbc', '3des-cbc', 'des-cbc', '', 'aes', 'aes'];
34
+
35
+ private static var _props:Array;
36
+
37
+ init();
38
+ private static function init():void {
39
+ _props = [];
40
+ _props[NULL] = new BulkCiphers(STREAM_CIPHER, 0, 0, 0, 0, 0);
41
+ _props[RC4_40] = new BulkCiphers(STREAM_CIPHER, 5, 16, 40, 0, 0);
42
+ _props[RC4_128] = new BulkCiphers(STREAM_CIPHER, 16, 16, 128, 0, 0);
43
+ _props[RC2_CBC_40] = new BulkCiphers( BLOCK_CIPHER, 5, 16, 40, 8, 8);
44
+ _props[DES_CBC] = new BulkCiphers( BLOCK_CIPHER, 8, 8, 56, 8, 8);
45
+ _props[DES3_EDE_CBC] = new BulkCiphers( BLOCK_CIPHER, 24, 24, 168, 8, 8);
46
+ _props[DES40_CBC] = new BulkCiphers( BLOCK_CIPHER, 5, 8, 40, 8, 8);
47
+ _props[IDEA_CBC] = new BulkCiphers( BLOCK_CIPHER, 16, 16, 128, 8, 8);
48
+ _props[AES_128] = new BulkCiphers( BLOCK_CIPHER, 16, 16, 128, 16, 16);
49
+ _props[AES_256] = new BulkCiphers( BLOCK_CIPHER, 32, 32, 256, 16, 16);
50
+ }
51
+
52
+ private static function getProp(cipher:uint):BulkCiphers {
53
+ var p:BulkCiphers = _props[cipher];
54
+ if (p==null) {
55
+ throw new Error("Unknown bulk cipher "+cipher.toString(16));
56
+ }
57
+ return p;
58
+ }
59
+ public static function getType(cipher:uint):uint {
60
+ return getProp(cipher).type;
61
+ }
62
+ public static function getKeyBytes(cipher:uint):uint {
63
+ return getProp(cipher).keyBytes;
64
+ }
65
+ public static function getExpandedKeyBytes(cipher:uint):uint {
66
+ return getProp(cipher).expandedKeyBytes;
67
+ }
68
+ public static function getEffectiveKeyBits(cipher:uint):uint {
69
+ return getProp(cipher).effectiveKeyBits;
70
+ }
71
+ public static function getIVSize(cipher:uint):uint {
72
+ return getProp(cipher).IVSize;
73
+ }
74
+ public static function getBlockSize(cipher:uint):uint {
75
+ return getProp(cipher).blockSize;
76
+ }
77
+ public static function getCipher(cipher:uint, key:ByteArray, proto:uint):ICipher {
78
+ if (proto == TLSSecurityParameters.PROTOCOL_VERSION) {
79
+ return Crypto.getCipher(algos[cipher], key, new TLSPad);
80
+ } else {
81
+ return Crypto.getCipher(algos[cipher], key, new SSLPad);
82
+ }
83
+ }
84
+
85
+
86
+ private var type:uint;
87
+ private var keyBytes:uint;
88
+ private var expandedKeyBytes:uint;
89
+ private var effectiveKeyBits:uint;
90
+ private var IVSize:uint;
91
+ private var blockSize:uint;
92
+
93
+ public function BulkCiphers(t:uint, kb:uint, ekb:uint, fkb:uint, ivs:uint, bs:uint) {
94
+ type = t;
95
+ keyBytes = kb;
96
+ expandedKeyBytes = ekb;
97
+ effectiveKeyBits = fkb;
98
+ IVSize = ivs;
99
+ blockSize = bs;
100
+ }
101
+ }
102
+ }
@@ -0,0 +1,117 @@
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
+
14
+ public class CipherSuites {
15
+
16
+
17
+ // only the lines marked "ok" are currently implemented.
18
+
19
+ // rfc 2246
20
+
21
+ public static const TLS_NULL_WITH_NULL_NULL:uint = 0x0000; // ok
22
+ public static const TLS_RSA_WITH_NULL_MD5:uint = 0x0001; // ok
23
+ public static const TLS_RSA_WITH_NULL_SHA:uint = 0x0002; // ok
24
+ public static const TLS_RSA_WITH_RC4_128_MD5:uint = 0x0004; // ok
25
+ public static const TLS_RSA_WITH_RC4_128_SHA:uint = 0x0005; // ok
26
+ public static const TLS_RSA_WITH_IDEA_CBC_SHA:uint = 0x0007;
27
+ public static const TLS_RSA_WITH_DES_CBC_SHA:uint = 0x0009; // ok
28
+ public static const TLS_RSA_WITH_3DES_EDE_CBC_SHA:uint = 0x000A; // ok
29
+
30
+ public static const TLS_DH_DSS_WITH_DES_CBC_SHA:uint = 0x000C;
31
+ public static const TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA:uint = 0x000D;
32
+ public static const TLS_DH_RSA_WITH_DES_CBC_SHA:uint = 0x000F;
33
+ public static const TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA:uint = 0x0010;
34
+ public static const TLS_DHE_DSS_WITH_DES_CBC_SHA:uint = 0x0012;
35
+ public static const TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA:uint = 0x0013;
36
+ public static const TLS_DHE_RSA_WITH_DES_CBC_SHA:uint = 0x0015;
37
+ public static const TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA:uint = 0x0016;
38
+
39
+ public static const TLS_DH_anon_WITH_RC4_128_MD5:uint = 0x0018;
40
+ public static const TLS_DH_anon_WITH_DES_CBC_SHA:uint = 0x001A;
41
+ public static const TLS_DH_anon_WITH_3DES_EDE_CBC_SHA:uint = 0x001B;
42
+
43
+ // rfc3268
44
+
45
+ public static const TLS_RSA_WITH_AES_128_CBC_SHA:uint = 0x002F; // ok
46
+ public static const TLS_DH_DSS_WITH_AES_128_CBC_SHA:uint = 0x0030;
47
+ public static const TLS_DH_RSA_WITH_AES_128_CBC_SHA:uint = 0x0031;
48
+ public static const TLS_DHE_DSS_WITH_AES_128_CBC_SHA:uint = 0x0032;
49
+ public static const TLS_DHE_RSA_WITH_AES_128_CBC_SHA:uint = 0x0033;
50
+ public static const TLS_DH_anon_WITH_AES_128_CBC_SHA:uint = 0x0034;
51
+
52
+ public static const TLS_RSA_WITH_AES_256_CBC_SHA:uint = 0x0035; // ok
53
+ public static const TLS_DH_DSS_WITH_AES_256_CBC_SHA:uint = 0x0036;
54
+ public static const TLS_DH_RSA_WITH_AES_256_CBC_SHA:uint = 0x0037;
55
+ public static const TLS_DHE_DSS_WITH_AES_256_CBC_SHA:uint = 0x0038;
56
+ public static const TLS_DHE_RSA_WITH_AES_256_CBC_SHA:uint = 0x0039;
57
+ public static const TLS_DH_anon_WITH_AES_256_CBC_SHA:uint = 0x003A;
58
+
59
+ private static var _props:Array;
60
+
61
+ init();
62
+ private static function init():void {
63
+ _props = [];
64
+ _props[TLS_NULL_WITH_NULL_NULL] = new CipherSuites(BulkCiphers.NULL, MACs.NULL, KeyExchanges.NULL);
65
+ _props[TLS_RSA_WITH_NULL_MD5] = new CipherSuites(BulkCiphers.NULL, MACs.MD5, KeyExchanges.RSA);
66
+ _props[TLS_RSA_WITH_NULL_SHA] = new CipherSuites(BulkCiphers.NULL, MACs.SHA1, KeyExchanges.RSA);
67
+ _props[TLS_RSA_WITH_RC4_128_MD5] = new CipherSuites(BulkCiphers.RC4_128, MACs.MD5, KeyExchanges.RSA);
68
+ _props[TLS_RSA_WITH_RC4_128_SHA] = new CipherSuites(BulkCiphers.RC4_128, MACs.SHA1, KeyExchanges.RSA);
69
+ _props[TLS_RSA_WITH_DES_CBC_SHA] = new CipherSuites(BulkCiphers.DES_CBC, MACs.SHA1, KeyExchanges.RSA);
70
+ _props[TLS_RSA_WITH_3DES_EDE_CBC_SHA] = new CipherSuites(BulkCiphers.DES3_EDE_CBC, MACs.SHA1, KeyExchanges.RSA);
71
+ _props[TLS_RSA_WITH_AES_128_CBC_SHA] = new CipherSuites(BulkCiphers.AES_128, MACs.SHA1, KeyExchanges.RSA);
72
+ _props[TLS_RSA_WITH_AES_256_CBC_SHA] = new CipherSuites(BulkCiphers.AES_256, MACs.SHA1, KeyExchanges.RSA);
73
+
74
+ // ...
75
+ // more later
76
+ }
77
+
78
+ private static function getProp(cipher:uint):CipherSuites {
79
+ var p:CipherSuites = _props[cipher];
80
+ if (p==null) {
81
+ throw new Error("Unknown cipher "+cipher.toString(16));
82
+ }
83
+ return p;
84
+ }
85
+ public static function getBulkCipher(cipher:uint):uint {
86
+ return getProp(cipher).cipher;
87
+ }
88
+ public static function getMac(cipher:uint):uint {
89
+ return getProp(cipher).hash;
90
+ }
91
+ public static function getKeyExchange(cipher:uint):uint {
92
+ return getProp(cipher).key;
93
+ }
94
+
95
+ public static function getDefaultSuites():Array {
96
+ // a list of acceptable ciphers, sorted by preference.
97
+ return [
98
+ TLS_RSA_WITH_AES_256_CBC_SHA,
99
+ TLS_RSA_WITH_3DES_EDE_CBC_SHA,
100
+ TLS_RSA_WITH_AES_128_CBC_SHA,
101
+ TLS_RSA_WITH_RC4_128_SHA,
102
+ TLS_RSA_WITH_RC4_128_MD5,
103
+ TLS_RSA_WITH_DES_CBC_SHA
104
+ ];
105
+ }
106
+
107
+ public var cipher:uint;
108
+ public var hash:uint;
109
+ public var key:uint;
110
+
111
+ public function CipherSuites(cipher:uint, hash:uint, key:uint) {
112
+ this.cipher = cipher;
113
+ this.hash = hash;
114
+ this.key = key;
115
+ }
116
+ }
117
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * IConnectionState
3
+ *
4
+ * Interface for TLS/SSL Connection states.
5
+ *
6
+ * See LICENSE.txt for full license information.
7
+ */
8
+ package com.hurlant.crypto.tls {
9
+ import flash.utils.ByteArray;
10
+ public interface IConnectionState {
11
+ function decrypt(type:uint, length:uint, p:ByteArray) : ByteArray;
12
+ function encrypt(type:uint, p:ByteArray) : ByteArray;
13
+ }
14
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * ISecurityParameters
3
+ *
4
+ * This class encapsulates all the security parameters that get negotiated
5
+ * during the TLS handshake. It also holds all the key derivation 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 flash.utils.ByteArray;
12
+
13
+ public interface ISecurityParameters {
14
+ function get version() : uint;
15
+ function reset():void;
16
+ function getBulkCipher():uint;
17
+ function getCipherType():uint;
18
+ function getMacAlgorithm():uint;
19
+ function setCipher(cipher:uint):void;
20
+ function setCompression(algo:uint):void;
21
+ function setPreMasterSecret(secret:ByteArray):void;
22
+ function setClientRandom(secret:ByteArray):void;
23
+ function setServerRandom(secret:ByteArray):void;
24
+ function get useRSA():Boolean;
25
+ function computeVerifyData(side:uint, handshakeMessages:ByteArray):ByteArray;
26
+ function computeCertificateVerify( side:uint, handshakeRecords:ByteArray):ByteArray;
27
+ function getConnectionStates():Object;
28
+ }
29
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * KeyExchanges
3
+ *
4
+ * An enumeration of key exchange methods defined by TLS
5
+ * ( right now, only RSA is actually implemented )
6
+ * Copyright (c) 2007 Henri Torgemane
7
+ *
8
+ * See LICENSE.txt for full license information.
9
+ */
10
+ package com.hurlant.crypto.tls {
11
+ public class KeyExchanges {
12
+ public static const NULL:uint = 0;
13
+ public static const RSA:uint = 1;
14
+ public static const DH_DSS:uint = 2;
15
+ public static const DH_RSA:uint = 3;
16
+ public static const DHE_DSS:uint = 4;
17
+ public static const DHE_RSA:uint = 5;
18
+ public static const DH_anon:uint = 6;
19
+
20
+ public static function useRSA(p:uint):Boolean {
21
+ return (p==RSA);
22
+ }
23
+ }
24
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * MACs
3
+ *
4
+ * An enumeration of MACs implemented for TLS 1.0/SSL 3.0
5
+ * Copyright (c) 2007 Henri Torgemane
6
+ *
7
+ * See LICENSE.txt for full license information.
8
+ */
9
+ package com.hurlant.crypto.tls {
10
+ import com.hurlant.crypto.Crypto;
11
+ import com.hurlant.crypto.hash.HMAC;
12
+ import com.hurlant.crypto.hash.MAC;
13
+
14
+ public class MACs {
15
+ public static const NULL:uint = 0;
16
+ public static const MD5:uint = 1;
17
+ public static const SHA1:uint = 2;
18
+
19
+ public static function getHashSize(hash:uint):uint {
20
+ return [0,16,20][hash];
21
+ }
22
+
23
+ public static function getPadSize(hash:uint):int {
24
+ return [0, 48, 40][hash];
25
+ }
26
+
27
+ public static function getHMAC(hash:uint):HMAC {
28
+ if (hash==NULL) return null;
29
+ return Crypto.getHMAC(['',"md5","sha1"][hash]);
30
+ }
31
+
32
+ public static function getMAC(hash:uint):MAC {
33
+ return Crypto.getMAC(['', "md5", "sha1"][hash]);
34
+ }
35
+
36
+
37
+ }
38
+ }
@@ -0,0 +1,171 @@
1
+ /**
2
+ * TLSConnectionState
3
+ *
4
+ * This class encapsulates the read or write state of a TLS connection,
5
+ * and implementes the encrypting and hashing of packets.
6
+ * Copyright (c) 2007 Henri Torgemane
7
+ *
8
+ * See LICENSE.txt for full license information.
9
+ */
10
+ package com.hurlant.crypto.tls {
11
+ import flash.utils.IDataInput;
12
+ import flash.utils.ByteArray;
13
+ import com.hurlant.crypto.hash.MD5;
14
+ import com.hurlant.crypto.hash.MAC;
15
+ import com.hurlant.crypto.hash.IHash;
16
+ import com.hurlant.crypto.symmetric.ICipher;
17
+ import com.hurlant.crypto.symmetric.IVMode;
18
+ import com.hurlant.util.Hex;
19
+ import com.hurlant.util.ArrayUtil;
20
+
21
+ public class SSLConnectionState implements IConnectionState {
22
+
23
+ // compression state
24
+
25
+ // cipher state
26
+ private var bulkCipher:uint;
27
+ private var cipherType:uint;
28
+ private var CIPHER_key:ByteArray;
29
+ private var CIPHER_IV:ByteArray;
30
+ private var cipher:ICipher;
31
+ private var ivmode:IVMode;
32
+
33
+ // mac secret
34
+ private var macAlgorithm:uint;
35
+ private var MAC_write_secret:ByteArray;
36
+ private var mac:MAC;
37
+
38
+ // sequence number. uint64
39
+
40
+ private var seq_lo:uint = 0x0;
41
+ private var seq_hi:uint = 0x0;
42
+
43
+ public function SSLConnectionState(
44
+ bulkCipher:uint=0, cipherType:uint=0, macAlgorithm:uint=0,
45
+ mac_enc:ByteArray=null, key:ByteArray=null, IV:ByteArray=null) {
46
+ this.bulkCipher = bulkCipher;
47
+ this.cipherType = cipherType;
48
+ this.macAlgorithm = macAlgorithm;
49
+ MAC_write_secret = mac_enc;
50
+ mac = MACs.getMAC(macAlgorithm);
51
+
52
+ CIPHER_key = key;
53
+ CIPHER_IV = IV;
54
+ cipher = BulkCiphers.getCipher(bulkCipher, key, 0x0300);
55
+ if (cipher is IVMode) {
56
+ ivmode = cipher as IVMode;
57
+ ivmode.IV = IV;
58
+ }
59
+
60
+ }
61
+
62
+ public function decrypt(type:uint, length:uint, p:ByteArray):ByteArray {
63
+ // decompression is a nop.
64
+
65
+ if (cipherType == BulkCiphers.STREAM_CIPHER) {
66
+ if (bulkCipher == BulkCiphers.NULL) {
67
+ // no-op
68
+ } else {
69
+ cipher.decrypt(p);
70
+ }
71
+ } else {
72
+ p.position = 0;
73
+ // block cipher
74
+ if (bulkCipher == BulkCiphers.NULL) {
75
+
76
+ } else {
77
+ var nextIV:ByteArray = new ByteArray;
78
+ nextIV.writeBytes(p, p.length-CIPHER_IV.length, CIPHER_IV.length);
79
+ p.position = 0;
80
+ cipher.decrypt(p);
81
+
82
+ CIPHER_IV = nextIV;
83
+ ivmode.IV = nextIV;
84
+ }
85
+ }
86
+
87
+ if (macAlgorithm!=MACs.NULL) {
88
+ // there will be CTX delay here as well,
89
+ // I should probably optmize the hell out of it
90
+ var data:ByteArray = new ByteArray;
91
+ var len:uint = p.length - mac.getHashSize();
92
+ data.writeUnsignedInt(seq_hi);
93
+ data.writeUnsignedInt(seq_lo);
94
+
95
+ data.writeByte(type);
96
+ data.writeShort(len);
97
+ if (len!=0) {
98
+ data.writeBytes(p, 0, len);
99
+ }
100
+ var mac_enc:ByteArray = mac.compute(MAC_write_secret, data);
101
+ // compare "mac" with the last X bytes of p.
102
+ var mac_received:ByteArray = new ByteArray;
103
+ mac_received.writeBytes(p, len, mac.getHashSize());
104
+ if (ArrayUtil.equals(mac_enc, mac_received)) {
105
+ // happy happy joy joy
106
+ } else {
107
+ throw new TLSError("Bad Mac Data", TLSError.bad_record_mac);
108
+ }
109
+ p.length = len;
110
+ p.position = 0;
111
+ }
112
+ // increment seq
113
+ seq_lo++;
114
+ if (seq_lo==0) seq_hi++;
115
+ return p;
116
+ }
117
+ public function encrypt(type:uint, p:ByteArray):ByteArray {
118
+ var mac_enc:ByteArray = null;
119
+ if (macAlgorithm!=MACs.NULL) {
120
+ var data:ByteArray = new ByteArray;
121
+ // data.writeUnsignedInt(seq);
122
+
123
+ // Sequence
124
+ data.writeUnsignedInt(seq_hi);
125
+ data.writeUnsignedInt(seq_lo);
126
+
127
+ // Type
128
+ data.writeByte(type);
129
+
130
+ // Length
131
+ data.writeShort(p.length);
132
+
133
+ // The data
134
+ if (p.length!=0) {
135
+ data.writeBytes(p);
136
+ }
137
+
138
+ // trace("data for the MAC: " + Hex.fromArray(data));
139
+ mac_enc = mac.compute(MAC_write_secret, data);
140
+ // trace("MAC: " + Hex.fromArray( mac_enc ));
141
+ p.position = p.length;
142
+ p.writeBytes(mac_enc);
143
+ }
144
+
145
+ // trace("Record to encrypt: " + Hex.fromArray(p));
146
+
147
+ p.position = 0;
148
+ if (cipherType == BulkCiphers.STREAM_CIPHER) {
149
+ // stream cipher
150
+ if (bulkCipher == BulkCiphers.NULL) {
151
+ // no-op
152
+ } else {
153
+ cipher.encrypt(p);
154
+ }
155
+ } else {
156
+ // block cipher
157
+ cipher.encrypt(p);
158
+ // adjust IV
159
+ var nextIV:ByteArray = new ByteArray;
160
+ nextIV.writeBytes(p, p.length-CIPHER_IV.length, CIPHER_IV.length);
161
+ CIPHER_IV = nextIV;
162
+ ivmode.IV = nextIV;
163
+ }
164
+ // increment seq
165
+ seq_lo++;
166
+ if (seq_lo==0) seq_hi++;
167
+ return p;
168
+ }
169
+
170
+ }
171
+ }