rocket-js 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -11
- data/Rakefile +33 -47
- data/lib/rocket/js.rb +0 -2
- data/lib/rocket/js/builder.rb +2 -2
- data/lib/rocket/js/cli.rb +1 -1
- data/rocket-js.gemspec +23 -80
- data/src/vendor/web-socket-js/FABridge.js +604 -0
- data/src/vendor/web-socket-js/README.txt +109 -0
- data/src/vendor/web-socket-js/WebSocketMain.swf +0 -0
- data/src/vendor/web-socket-js/WebSocketMainInsecure.zip +0 -0
- data/src/vendor/web-socket-js/flash-src/WebSocket.as +473 -0
- data/src/vendor/web-socket-js/flash-src/WebSocketMain.as +88 -0
- data/src/vendor/web-socket-js/flash-src/WebSocketMainInsecure.as +19 -0
- data/src/vendor/web-socket-js/flash-src/WebSocketStateEvent.as +32 -0
- data/src/vendor/web-socket-js/flash-src/bridge/FABridge.as +943 -0
- data/src/vendor/web-socket-js/flash-src/build.sh +10 -0
- data/src/vendor/web-socket-js/flash-src/com/adobe/net/proxies/RFC2817Socket.as +204 -0
- data/src/vendor/web-socket-js/flash-src/com/gsolo/encryption/MD5.as +375 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/Crypto.as +287 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/cert/MozillaRootCertificates.as +3235 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/cert/X509Certificate.as +218 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/cert/X509CertificateCollection.as +57 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/HMAC.as +82 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/IHMAC.as +27 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/IHash.as +21 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/MAC.as +137 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/MD2.as +124 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/MD5.as +204 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHA1.as +106 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHA224.as +28 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHA256.as +115 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHABase.as +71 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/prng/ARC4.as +90 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/prng/IPRNG.as +20 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/prng/Random.as +119 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/prng/TLSPRF.as +142 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/rsa/RSAKey.as +339 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/AESKey.as +2797 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/BlowFishKey.as +375 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/CBCMode.as +55 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/CFB8Mode.as +61 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/CFBMode.as +64 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/CTRMode.as +58 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/DESKey.as +365 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/ECBMode.as +86 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/ICipher.as +21 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/IMode.as +15 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/IPad.as +32 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/IStreamCipher.as +21 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/ISymmetricKey.as +35 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/IVMode.as +110 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/NullPad.as +34 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/OFBMode.as +52 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/PKCS5.as +44 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/SSLPad.as +44 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/SimpleIVMode.as +60 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/TLSPad.as +42 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/TripleDESKey.as +88 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/XTeaKey.as +94 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/aeskey.pl +29 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/dump.txt +2304 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/AESKeyTest.as +1220 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/ARC4Test.as +58 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/BigIntegerTest.as +39 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/BlowFishKeyTest.as +148 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/CBCModeTest.as +160 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/CFB8ModeTest.as +71 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/CFBModeTest.as +98 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/CTRModeTest.as +109 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/DESKeyTest.as +112 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/ECBModeTest.as +151 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/HMACTest.as +184 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/ITestHarness.as +20 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/MD2Test.as +56 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/MD5Test.as +58 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/OFBModeTest.as +101 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/RSAKeyTest.as +92 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/SHA1Test.as +198 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/SHA224Test.as +58 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/SHA256Test.as +60 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/TLSPRFTest.as +51 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/TestCase.as +42 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/TripleDESKeyTest.as +59 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/XTeaKeyTest.as +66 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/BulkCiphers.as +102 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/CipherSuites.as +117 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/IConnectionState.as +14 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/ISecurityParameters.as +29 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/KeyExchanges.as +24 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/MACs.as +38 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/SSLConnectionState.as +171 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/SSLEvent.as +26 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/SSLSecurityParameters.as +340 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSConfig.as +70 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSConnectionState.as +151 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSEngine.as +895 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSError.as +39 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSEvent.as +27 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSSecurityParameters.as +197 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSSocket.as +370 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSSocketEvent.as +26 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSTest.as +180 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/math/BarrettReduction.as +90 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/math/BigInteger.as +1543 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/math/ClassicReduction.as +35 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/math/IReduction.as +11 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/math/MontgomeryReduction.as +85 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/math/NullReduction.as +34 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/math/bi_internal.as +11 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/ArrayUtil.as +25 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/Base64.as +189 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/Hex.as +66 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/Memory.as +28 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/ByteString.as +43 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/DER.as +210 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/IAsn1Type.as +21 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/Integer.as +44 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/OID.as +35 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/ObjectIdentifier.as +112 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/PEM.as +118 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/PrintableString.as +49 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/Sequence.as +90 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/Set.as +27 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/Type.as +94 -0
- data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/UTCTime.as +60 -0
- data/src/vendor/web-socket-js/sample.html +76 -0
- data/src/vendor/web-socket-js/swfobject.js +4 -0
- data/src/vendor/web-socket-js/web_socket.js +388 -0
- metadata +163 -30
- data/lib/rocket/js/version.rb +0 -14
- data/rocket-0.0.1.min.js +0 -45
@@ -0,0 +1,28 @@
|
|
1
|
+
/**
|
2
|
+
* Memory
|
3
|
+
*
|
4
|
+
* A class with a few memory-management methods, as much as
|
5
|
+
* such a thing exists in a Flash player.
|
6
|
+
* Copyright (c) 2007 Henri Torgemane
|
7
|
+
*
|
8
|
+
* See LICENSE.txt for full license information.
|
9
|
+
*/
|
10
|
+
package com.hurlant.util
|
11
|
+
{
|
12
|
+
import flash.net.LocalConnection;
|
13
|
+
import flash.system.System;
|
14
|
+
|
15
|
+
public class Memory
|
16
|
+
{
|
17
|
+
public static function gc():void {
|
18
|
+
// force a GC
|
19
|
+
try {
|
20
|
+
new LocalConnection().connect('foo');
|
21
|
+
new LocalConnection().connect('foo');
|
22
|
+
} catch (e:*) {}
|
23
|
+
}
|
24
|
+
public static function get used():uint {
|
25
|
+
return System.totalMemory;
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
/**
|
2
|
+
* ByteString
|
3
|
+
*
|
4
|
+
* An ASN1 type for a ByteString, represented with a ByteArray
|
5
|
+
* Copyright (c) 2007 Henri Torgemane
|
6
|
+
*
|
7
|
+
* See LICENSE.txt for full license information.
|
8
|
+
*/
|
9
|
+
package com.hurlant.util.der
|
10
|
+
{
|
11
|
+
import flash.utils.ByteArray;
|
12
|
+
import com.hurlant.util.Hex;
|
13
|
+
|
14
|
+
public class ByteString extends ByteArray implements IAsn1Type
|
15
|
+
{
|
16
|
+
private var type:uint;
|
17
|
+
private var len:uint;
|
18
|
+
|
19
|
+
public function ByteString(type:uint = 0x04, length:uint = 0x00) {
|
20
|
+
this.type = type;
|
21
|
+
this.len = length;
|
22
|
+
}
|
23
|
+
|
24
|
+
public function getLength():uint
|
25
|
+
{
|
26
|
+
return len;
|
27
|
+
}
|
28
|
+
|
29
|
+
public function getType():uint
|
30
|
+
{
|
31
|
+
return type;
|
32
|
+
}
|
33
|
+
|
34
|
+
public function toDER():ByteArray {
|
35
|
+
return DER.wrapDER(type, this);
|
36
|
+
}
|
37
|
+
|
38
|
+
override public function toString():String {
|
39
|
+
return DER.indent+"ByteString["+type+"]["+len+"]["+Hex.fromArray(this)+"]";
|
40
|
+
}
|
41
|
+
|
42
|
+
}
|
43
|
+
}
|
@@ -0,0 +1,210 @@
|
|
1
|
+
/**
|
2
|
+
* DER
|
3
|
+
*
|
4
|
+
* A basic class to parse DER structures.
|
5
|
+
* It is very incomplete, but sufficient to extract whatever data we need so far.
|
6
|
+
* Copyright (c) 2007 Henri Torgemane
|
7
|
+
*
|
8
|
+
* See LICENSE.txt for full license information.
|
9
|
+
*/
|
10
|
+
package com.hurlant.util.der
|
11
|
+
{
|
12
|
+
import com.hurlant.math.BigInteger;
|
13
|
+
|
14
|
+
import flash.utils.ByteArray;
|
15
|
+
import com.hurlant.util.der.Sequence;
|
16
|
+
import com.hurlant.util.Hex;
|
17
|
+
|
18
|
+
// goal 1: to be able to parse an RSA Private Key PEM file.
|
19
|
+
// goal 2: to parse an X509v3 cert. kinda.
|
20
|
+
|
21
|
+
/**
|
22
|
+
* DER for dummies:
|
23
|
+
* http://luca.ntop.org/Teaching/Appunti/asn1.html
|
24
|
+
*
|
25
|
+
* This class does the bare minimum to get by. if that.
|
26
|
+
*/
|
27
|
+
public class DER
|
28
|
+
{
|
29
|
+
public static var indent:String = "";
|
30
|
+
|
31
|
+
public static function parse(der:ByteArray, structure:*=null):IAsn1Type {
|
32
|
+
/* if (der.position==0) {
|
33
|
+
trace("DER.parse: "+Hex.fromArray(der));
|
34
|
+
}
|
35
|
+
*/ // type
|
36
|
+
var type:int = der.readUnsignedByte();
|
37
|
+
var constructed:Boolean = (type&0x20)!=0;
|
38
|
+
type &=0x1F;
|
39
|
+
// length
|
40
|
+
var len:int = der.readUnsignedByte();
|
41
|
+
if (len>=0x80) {
|
42
|
+
// long form of length
|
43
|
+
var count:int = len & 0x7f;
|
44
|
+
len = 0;
|
45
|
+
while (count>0) {
|
46
|
+
len = (len<<8) | der.readUnsignedByte();
|
47
|
+
count--;
|
48
|
+
}
|
49
|
+
}
|
50
|
+
// data
|
51
|
+
var b:ByteArray
|
52
|
+
switch (type) {
|
53
|
+
case 0x00: // WHAT IS THIS THINGY? (seen as 0xa0)
|
54
|
+
// (note to self: read a spec someday.)
|
55
|
+
// for now, treat as a sequence.
|
56
|
+
case 0x10: // SEQUENCE/SEQUENCE OF. whatever
|
57
|
+
// treat as an array
|
58
|
+
var p:int = der.position;
|
59
|
+
var o:Sequence = new Sequence(type, len);
|
60
|
+
var arrayStruct:Array = structure as Array;
|
61
|
+
if (arrayStruct!=null) {
|
62
|
+
// copy the array, as we destroy it later.
|
63
|
+
arrayStruct = arrayStruct.concat();
|
64
|
+
}
|
65
|
+
while (der.position < p+len) {
|
66
|
+
var tmpStruct:Object = null
|
67
|
+
if (arrayStruct!=null) {
|
68
|
+
tmpStruct = arrayStruct.shift();
|
69
|
+
}
|
70
|
+
if (tmpStruct!=null) {
|
71
|
+
while (tmpStruct && tmpStruct.optional) {
|
72
|
+
// make sure we have something that looks reasonable. XXX I'm winging it here..
|
73
|
+
var wantConstructed:Boolean = (tmpStruct.value is Array);
|
74
|
+
var isConstructed:Boolean = isConstructedType(der);
|
75
|
+
if (wantConstructed!=isConstructed) {
|
76
|
+
// not found. put default stuff, or null
|
77
|
+
o.push(tmpStruct.defaultValue);
|
78
|
+
o[tmpStruct.name] = tmpStruct.defaultValue;
|
79
|
+
// try the next thing
|
80
|
+
tmpStruct = arrayStruct.shift();
|
81
|
+
} else {
|
82
|
+
break;
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}
|
86
|
+
if (tmpStruct!=null) {
|
87
|
+
var name:String = tmpStruct.name;
|
88
|
+
var value:* = tmpStruct.value;
|
89
|
+
if (tmpStruct.extract) {
|
90
|
+
// we need to keep a binary copy of this element
|
91
|
+
var size:int = getLengthOfNextElement(der);
|
92
|
+
var ba:ByteArray = new ByteArray;
|
93
|
+
ba.writeBytes(der, der.position, size);
|
94
|
+
o[name+"_bin"] = ba;
|
95
|
+
}
|
96
|
+
var obj:IAsn1Type = DER.parse(der, value);
|
97
|
+
o.push(obj);
|
98
|
+
o[name] = obj;
|
99
|
+
} else {
|
100
|
+
o.push(DER.parse(der));
|
101
|
+
}
|
102
|
+
}
|
103
|
+
return o;
|
104
|
+
case 0x11: // SET/SET OF
|
105
|
+
p = der.position;
|
106
|
+
var s:Set = new Set(type, len);
|
107
|
+
while (der.position < p+len) {
|
108
|
+
s.push(DER.parse(der));
|
109
|
+
}
|
110
|
+
return s;
|
111
|
+
case 0x02: // INTEGER
|
112
|
+
// put in a BigInteger
|
113
|
+
b = new ByteArray;
|
114
|
+
der.readBytes(b,0,len);
|
115
|
+
b.position=0;
|
116
|
+
return new Integer(type, len, b);
|
117
|
+
case 0x06: // OBJECT IDENTIFIER:
|
118
|
+
b = new ByteArray;
|
119
|
+
der.readBytes(b,0,len);
|
120
|
+
b.position=0;
|
121
|
+
return new ObjectIdentifier(type, len, b);
|
122
|
+
default:
|
123
|
+
trace("I DONT KNOW HOW TO HANDLE DER stuff of TYPE "+type);
|
124
|
+
// fall through
|
125
|
+
case 0x03: // BIT STRING
|
126
|
+
if (der[der.position]==0) {
|
127
|
+
//trace("Horrible Bit String pre-padding removal hack."); // I wish I had the patience to find a spec for this.
|
128
|
+
der.position++;
|
129
|
+
len--;
|
130
|
+
}
|
131
|
+
case 0x04: // OCTET STRING
|
132
|
+
// stuff in a ByteArray for now.
|
133
|
+
var bs:ByteString = new ByteString(type, len);
|
134
|
+
der.readBytes(bs,0,len);
|
135
|
+
return bs;
|
136
|
+
case 0x05: // NULL
|
137
|
+
// if len!=0, something's horribly wrong.
|
138
|
+
// should I check?
|
139
|
+
return null;
|
140
|
+
case 0x13: // PrintableString
|
141
|
+
var ps:PrintableString = new PrintableString(type, len);
|
142
|
+
ps.setString(der.readMultiByte(len, "US-ASCII"));
|
143
|
+
return ps;
|
144
|
+
case 0x22: // XXX look up what this is. openssl uses this to store my email.
|
145
|
+
case 0x14: // T61String - an horrible format we don't even pretend to support correctly
|
146
|
+
ps = new PrintableString(type, len);
|
147
|
+
ps.setString(der.readMultiByte(len, "latin1"));
|
148
|
+
return ps;
|
149
|
+
case 0x17: // UTCTime
|
150
|
+
var ut:UTCTime = new UTCTime(type, len);
|
151
|
+
ut.setUTCTime(der.readMultiByte(len, "US-ASCII"));
|
152
|
+
return ut;
|
153
|
+
}
|
154
|
+
}
|
155
|
+
|
156
|
+
private static function getLengthOfNextElement(b:ByteArray):int {
|
157
|
+
var p:uint = b.position;
|
158
|
+
// length
|
159
|
+
b.position++;
|
160
|
+
var len:int = b.readUnsignedByte();
|
161
|
+
if (len>=0x80) {
|
162
|
+
// long form of length
|
163
|
+
var count:int = len & 0x7f;
|
164
|
+
len = 0;
|
165
|
+
while (count>0) {
|
166
|
+
len = (len<<8) | b.readUnsignedByte();
|
167
|
+
count--;
|
168
|
+
}
|
169
|
+
}
|
170
|
+
len += b.position-p; // length of length
|
171
|
+
b.position = p;
|
172
|
+
return len;
|
173
|
+
}
|
174
|
+
private static function isConstructedType(b:ByteArray):Boolean {
|
175
|
+
var type:int = b[b.position];
|
176
|
+
return (type&0x20)!=0;
|
177
|
+
}
|
178
|
+
|
179
|
+
public static function wrapDER(type:int, data:ByteArray):ByteArray {
|
180
|
+
var d:ByteArray = new ByteArray;
|
181
|
+
d.writeByte(type);
|
182
|
+
var len:int = data.length;
|
183
|
+
if (len<128) {
|
184
|
+
d.writeByte(len);
|
185
|
+
} else if (len<256) {
|
186
|
+
d.writeByte(1 | 0x80);
|
187
|
+
d.writeByte(len);
|
188
|
+
} else if (len<65536) {
|
189
|
+
d.writeByte(2 | 0x80);
|
190
|
+
d.writeByte(len>>8);
|
191
|
+
d.writeByte(len);
|
192
|
+
} else if (len<65536*256) {
|
193
|
+
d.writeByte(3 | 0x80);
|
194
|
+
d.writeByte(len>>16);
|
195
|
+
d.writeByte(len>>8);
|
196
|
+
d.writeByte(len);
|
197
|
+
} else {
|
198
|
+
d.writeByte(4 | 0x80);
|
199
|
+
d.writeByte(len>>24);
|
200
|
+
d.writeByte(len>>16);
|
201
|
+
d.writeByte(len>>8);
|
202
|
+
d.writeByte(len);
|
203
|
+
}
|
204
|
+
d.writeBytes(data);
|
205
|
+
d.position=0;
|
206
|
+
return d;
|
207
|
+
|
208
|
+
}
|
209
|
+
}
|
210
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
/**
|
2
|
+
* IAsn1Type
|
3
|
+
*
|
4
|
+
* An interface for Asn-1 types.
|
5
|
+
* Copyright (c) 2007 Henri Torgemane
|
6
|
+
*
|
7
|
+
* See LICENSE.txt for full license information.
|
8
|
+
*/
|
9
|
+
package com.hurlant.util.der
|
10
|
+
{
|
11
|
+
import flash.utils.ByteArray;
|
12
|
+
|
13
|
+
public interface IAsn1Type
|
14
|
+
{
|
15
|
+
function getType():uint;
|
16
|
+
function getLength():uint;
|
17
|
+
|
18
|
+
function toDER():ByteArray;
|
19
|
+
|
20
|
+
}
|
21
|
+
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
/**
|
2
|
+
* Integer
|
3
|
+
*
|
4
|
+
* An ASN1 type for an Integer, represented with a BigInteger
|
5
|
+
* Copyright (c) 2007 Henri Torgemane
|
6
|
+
*
|
7
|
+
* See LICENSE.txt for full license information.
|
8
|
+
*/
|
9
|
+
package com.hurlant.util.der
|
10
|
+
{
|
11
|
+
import com.hurlant.math.BigInteger;
|
12
|
+
import flash.utils.ByteArray;
|
13
|
+
|
14
|
+
public class Integer extends BigInteger implements IAsn1Type
|
15
|
+
{
|
16
|
+
private var type:uint;
|
17
|
+
private var len:uint;
|
18
|
+
|
19
|
+
public function Integer(type:uint, length:uint, b:ByteArray) {
|
20
|
+
this.type = type;
|
21
|
+
this.len = length;
|
22
|
+
super(b);
|
23
|
+
}
|
24
|
+
|
25
|
+
public function getLength():uint
|
26
|
+
{
|
27
|
+
return len;
|
28
|
+
}
|
29
|
+
|
30
|
+
public function getType():uint
|
31
|
+
{
|
32
|
+
return type;
|
33
|
+
}
|
34
|
+
|
35
|
+
override public function toString(radix:Number=0):String {
|
36
|
+
return DER.indent+"Integer["+type+"]["+len+"]["+super.toString(16)+"]";
|
37
|
+
}
|
38
|
+
|
39
|
+
public function toDER():ByteArray {
|
40
|
+
return null;
|
41
|
+
}
|
42
|
+
|
43
|
+
}
|
44
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
/**
|
2
|
+
* OID
|
3
|
+
*
|
4
|
+
* A list of various ObjectIdentifiers.
|
5
|
+
* Copyright (c) 2007 Henri Torgemane
|
6
|
+
*
|
7
|
+
* See LICENSE.txt for full license information.
|
8
|
+
*/
|
9
|
+
package com.hurlant.util.der
|
10
|
+
{
|
11
|
+
public class OID
|
12
|
+
{
|
13
|
+
|
14
|
+
public static const RSA_ENCRYPTION:String = "1.2.840.113549.1.1.1";
|
15
|
+
public static const MD2_WITH_RSA_ENCRYPTION:String = "1.2.840.113549.1.1.2";
|
16
|
+
public static const MD5_WITH_RSA_ENCRYPTION:String = "1.2.840.113549.1.1.4";
|
17
|
+
public static const SHA1_WITH_RSA_ENCRYPTION:String = "1.2.840.113549.1.1.5";
|
18
|
+
public static const MD2_ALGORITHM:String = "1.2.840.113549.2.2";
|
19
|
+
public static const MD5_ALGORITHM:String = "1.2.840.113549.2.5";
|
20
|
+
public static const DSA:String = "1.2.840.10040.4.1";
|
21
|
+
public static const DSA_WITH_SHA1:String = "1.2.840.10040.4.3";
|
22
|
+
public static const DH_PUBLIC_NUMBER:String = "1.2.840.10046.2.1";
|
23
|
+
public static const SHA1_ALGORITHM:String = "1.3.14.3.2.26";
|
24
|
+
|
25
|
+
public static const COMMON_NAME:String = "2.5.4.3";
|
26
|
+
public static const SURNAME:String = "2.5.4.4";
|
27
|
+
public static const COUNTRY_NAME:String = "2.5.4.6";
|
28
|
+
public static const LOCALITY_NAME:String = "2.5.4.7";
|
29
|
+
public static const STATE_NAME:String = "2.5.4.8";
|
30
|
+
public static const ORGANIZATION_NAME:String = "2.5.4.10";
|
31
|
+
public static const ORG_UNIT_NAME:String = "2.5.4.11";
|
32
|
+
public static const TITLE:String = "2.5.4.12";
|
33
|
+
|
34
|
+
}
|
35
|
+
}
|
@@ -0,0 +1,112 @@
|
|
1
|
+
/**
|
2
|
+
* ObjectIdentifier
|
3
|
+
*
|
4
|
+
* An ASN1 type for an ObjectIdentifier
|
5
|
+
* We store the oid in an Array.
|
6
|
+
* Copyright (c) 2007 Henri Torgemane
|
7
|
+
*
|
8
|
+
* See LICENSE.txt for full license information.
|
9
|
+
*/
|
10
|
+
package com.hurlant.util.der
|
11
|
+
{
|
12
|
+
import flash.utils.ByteArray;
|
13
|
+
|
14
|
+
public class ObjectIdentifier implements IAsn1Type
|
15
|
+
{
|
16
|
+
private var type:uint;
|
17
|
+
private var len:uint;
|
18
|
+
private var oid:Array;
|
19
|
+
|
20
|
+
public function ObjectIdentifier(type:uint, length:uint, b:*) {
|
21
|
+
this.type = type;
|
22
|
+
this.len = length;
|
23
|
+
if (b is ByteArray) {
|
24
|
+
parse(b as ByteArray);
|
25
|
+
} else if (b is String) {
|
26
|
+
generate(b as String);
|
27
|
+
} else {
|
28
|
+
throw new Error("Invalid call to new ObjectIdentifier");
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
private function generate(s:String):void {
|
33
|
+
oid = s.split(".");
|
34
|
+
}
|
35
|
+
|
36
|
+
private function parse(b:ByteArray):void {
|
37
|
+
// parse stuff
|
38
|
+
// first byte = 40*value1 + value2
|
39
|
+
var o:uint = b.readUnsignedByte();
|
40
|
+
var a:Array = []
|
41
|
+
a.push(uint(o/40));
|
42
|
+
a.push(uint(o%40));
|
43
|
+
var v:uint = 0;
|
44
|
+
while (b.bytesAvailable>0) {
|
45
|
+
o = b.readUnsignedByte();
|
46
|
+
var last:Boolean = (o&0x80)==0;
|
47
|
+
o &= 0x7f;
|
48
|
+
v = v*128 + o;
|
49
|
+
if (last) {
|
50
|
+
a.push(v);
|
51
|
+
v = 0;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
oid = a;
|
55
|
+
}
|
56
|
+
|
57
|
+
public function getLength():uint
|
58
|
+
{
|
59
|
+
return len;
|
60
|
+
}
|
61
|
+
|
62
|
+
public function getType():uint
|
63
|
+
{
|
64
|
+
return type;
|
65
|
+
}
|
66
|
+
|
67
|
+
public function toDER():ByteArray {
|
68
|
+
var tmp:Array = [];
|
69
|
+
tmp[0] = oid[0]*40 + oid[1];
|
70
|
+
for (var i:int=2;i<oid.length;i++) {
|
71
|
+
var v:int = parseInt(oid[i]);
|
72
|
+
if (v<128) {
|
73
|
+
tmp.push(v);
|
74
|
+
} else if (v<128*128) {
|
75
|
+
tmp.push( (v>>7)|0x80 );
|
76
|
+
tmp.push( v&0x7f );
|
77
|
+
} else if (v<128*128*128) {
|
78
|
+
tmp.push( (v>>14)|0x80 );
|
79
|
+
tmp.push( (v>>7)&0x7f | 0x80 );
|
80
|
+
tmp.push( v&0x7f);
|
81
|
+
} else if (v<128*128*128*128) {
|
82
|
+
tmp.push( (v>>21)|0x80 );
|
83
|
+
tmp.push( (v>>14) & 0x7f | 0x80 );
|
84
|
+
tmp.push( (v>>7) & 0x7f | 0x80 );
|
85
|
+
tmp.push( v & 0x7f );
|
86
|
+
} else {
|
87
|
+
throw new Error("OID element bigger than we thought. :(");
|
88
|
+
}
|
89
|
+
}
|
90
|
+
len = tmp.length;
|
91
|
+
if (type==0) {
|
92
|
+
type = 6;
|
93
|
+
}
|
94
|
+
tmp.unshift(len); // assume length is small enough to fit here.
|
95
|
+
tmp.unshift(type);
|
96
|
+
var b:ByteArray = new ByteArray;
|
97
|
+
for (i=0;i<tmp.length;i++) {
|
98
|
+
b[i] = tmp[i];
|
99
|
+
}
|
100
|
+
return b;
|
101
|
+
}
|
102
|
+
|
103
|
+
public function toString():String {
|
104
|
+
return DER.indent+oid.join(".");
|
105
|
+
}
|
106
|
+
|
107
|
+
public function dump():String {
|
108
|
+
return "OID["+type+"]["+len+"]["+toString()+"]";
|
109
|
+
}
|
110
|
+
|
111
|
+
}
|
112
|
+
}
|