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,218 @@
|
|
1
|
+
/**
|
2
|
+
* X509Certificate
|
3
|
+
*
|
4
|
+
* A representation for a X509 Certificate, with
|
5
|
+
* methods to parse, verify and sign it.
|
6
|
+
* Copyright (c) 2007 Henri Torgemane
|
7
|
+
*
|
8
|
+
* See LICENSE.txt for full license information.
|
9
|
+
*/
|
10
|
+
package com.hurlant.crypto.cert {
|
11
|
+
import com.hurlant.crypto.hash.IHash;
|
12
|
+
import com.hurlant.crypto.hash.MD2;
|
13
|
+
import com.hurlant.crypto.hash.MD5;
|
14
|
+
import com.hurlant.crypto.hash.SHA1;
|
15
|
+
import com.hurlant.crypto.rsa.RSAKey;
|
16
|
+
import com.hurlant.util.ArrayUtil;
|
17
|
+
import com.hurlant.util.Base64;
|
18
|
+
import com.hurlant.util.der.ByteString;
|
19
|
+
import com.hurlant.util.der.DER;
|
20
|
+
import com.hurlant.util.der.OID;
|
21
|
+
import com.hurlant.util.der.ObjectIdentifier;
|
22
|
+
import com.hurlant.util.der.PEM;
|
23
|
+
import com.hurlant.util.der.PrintableString;
|
24
|
+
import com.hurlant.util.der.Sequence;
|
25
|
+
import com.hurlant.util.der.Type;
|
26
|
+
|
27
|
+
import flash.utils.ByteArray;
|
28
|
+
|
29
|
+
public class X509Certificate {
|
30
|
+
private var _loaded:Boolean;
|
31
|
+
private var _param:*;
|
32
|
+
private var _obj:Object;
|
33
|
+
public function X509Certificate(p:*) {
|
34
|
+
_loaded = false;
|
35
|
+
_param = p;
|
36
|
+
// lazy initialization, to avoid unnecessary parsing of every builtin CA at start-up.
|
37
|
+
}
|
38
|
+
private function load():void {
|
39
|
+
if (_loaded) return;
|
40
|
+
var p:* = _param;
|
41
|
+
var b:ByteArray;
|
42
|
+
if (p is String) {
|
43
|
+
b = PEM.readCertIntoArray(p as String);
|
44
|
+
} else if (p is ByteArray) {
|
45
|
+
b = p;
|
46
|
+
}
|
47
|
+
if (b!=null) {
|
48
|
+
_obj = DER.parse(b, Type.TLS_CERT);
|
49
|
+
_loaded = true;
|
50
|
+
} else {
|
51
|
+
throw new Error("Invalid x509 Certificate parameter: "+p);
|
52
|
+
}
|
53
|
+
}
|
54
|
+
public function isSigned(store:X509CertificateCollection, CAs:X509CertificateCollection, time:Date=null):Boolean {
|
55
|
+
load();
|
56
|
+
// check timestamps first. cheapest.
|
57
|
+
if (time==null) {
|
58
|
+
time = new Date;
|
59
|
+
}
|
60
|
+
var notBefore:Date = getNotBefore();
|
61
|
+
var notAfter:Date = getNotAfter();
|
62
|
+
if (time.getTime()<notBefore.getTime()) return false; // cert isn't born yet.
|
63
|
+
if (time.getTime()>notAfter.getTime()) return false; // cert died of old age.
|
64
|
+
// check signature.
|
65
|
+
var subject:String = getIssuerPrincipal();
|
66
|
+
// try from CA first, since they're treated better.
|
67
|
+
var parent:X509Certificate = CAs.getCertificate(subject);
|
68
|
+
var parentIsAuthoritative:Boolean = false;
|
69
|
+
if (parent == null) {
|
70
|
+
parent = store.getCertificate(subject);
|
71
|
+
if (parent == null) {
|
72
|
+
return false; // issuer not found
|
73
|
+
}
|
74
|
+
} else {
|
75
|
+
parentIsAuthoritative = true;
|
76
|
+
}
|
77
|
+
if (parent == this) { // pathological case. avoid infinite loop
|
78
|
+
return false; // isSigned() returns false if we're self-signed.
|
79
|
+
}
|
80
|
+
if (!(parentIsAuthoritative&&parent.isSelfSigned(time)) &&
|
81
|
+
!parent.isSigned(store, CAs, time)) {
|
82
|
+
return false;
|
83
|
+
}
|
84
|
+
var key:RSAKey = parent.getPublicKey();
|
85
|
+
return verifyCertificate(key);
|
86
|
+
}
|
87
|
+
public function isSelfSigned(time:Date):Boolean {
|
88
|
+
load();
|
89
|
+
|
90
|
+
var key:RSAKey = getPublicKey();
|
91
|
+
return verifyCertificate(key);
|
92
|
+
}
|
93
|
+
private function verifyCertificate(key:RSAKey):Boolean {
|
94
|
+
var algo:String = getAlgorithmIdentifier();
|
95
|
+
var hash:IHash;
|
96
|
+
var oid:String;
|
97
|
+
switch (algo) {
|
98
|
+
case OID.SHA1_WITH_RSA_ENCRYPTION:
|
99
|
+
hash = new SHA1;
|
100
|
+
oid = OID.SHA1_ALGORITHM;
|
101
|
+
break;
|
102
|
+
case OID.MD2_WITH_RSA_ENCRYPTION:
|
103
|
+
hash = new MD2;
|
104
|
+
oid = OID.MD2_ALGORITHM;
|
105
|
+
break;
|
106
|
+
case OID.MD5_WITH_RSA_ENCRYPTION:
|
107
|
+
hash = new MD5;
|
108
|
+
oid = OID.MD5_ALGORITHM;
|
109
|
+
break;
|
110
|
+
default:
|
111
|
+
return false;
|
112
|
+
}
|
113
|
+
var data:ByteArray = _obj.signedCertificate_bin;
|
114
|
+
var buf:ByteArray = new ByteArray;
|
115
|
+
key.verify(_obj.encrypted, buf, _obj.encrypted.length);
|
116
|
+
buf.position=0;
|
117
|
+
data = hash.hash(data);
|
118
|
+
var obj:Object = DER.parse(buf, Type.RSA_SIGNATURE);
|
119
|
+
if (obj.algorithm.algorithmId.toString() != oid) {
|
120
|
+
return false; // wrong algorithm
|
121
|
+
}
|
122
|
+
if (!ArrayUtil.equals(obj.hash, data)) {
|
123
|
+
return false; // hashes don't match
|
124
|
+
}
|
125
|
+
return true;
|
126
|
+
}
|
127
|
+
|
128
|
+
/**
|
129
|
+
* This isn't used anywhere so far.
|
130
|
+
* It would become useful if we started to offer facilities
|
131
|
+
* to generate and sign X509 certificates.
|
132
|
+
*
|
133
|
+
* @param key
|
134
|
+
* @param algo
|
135
|
+
* @return
|
136
|
+
*
|
137
|
+
*/
|
138
|
+
private function signCertificate(key:RSAKey, algo:String):ByteArray {
|
139
|
+
var hash:IHash;
|
140
|
+
var oid:String;
|
141
|
+
switch (algo) {
|
142
|
+
case OID.SHA1_WITH_RSA_ENCRYPTION:
|
143
|
+
hash = new SHA1;
|
144
|
+
oid = OID.SHA1_ALGORITHM;
|
145
|
+
break;
|
146
|
+
case OID.MD2_WITH_RSA_ENCRYPTION:
|
147
|
+
hash = new MD2;
|
148
|
+
oid = OID.MD2_ALGORITHM;
|
149
|
+
break;
|
150
|
+
case OID.MD5_WITH_RSA_ENCRYPTION:
|
151
|
+
hash = new MD5;
|
152
|
+
oid = OID.MD5_ALGORITHM;
|
153
|
+
break;
|
154
|
+
default:
|
155
|
+
return null
|
156
|
+
}
|
157
|
+
var data:ByteArray = _obj.signedCertificate_bin;
|
158
|
+
data = hash.hash(data);
|
159
|
+
var seq1:Sequence = new Sequence;
|
160
|
+
seq1[0] = new Sequence;
|
161
|
+
seq1[0][0] = new ObjectIdentifier(0,0, oid);
|
162
|
+
seq1[0][1] = null;
|
163
|
+
seq1[1] = new ByteString;
|
164
|
+
seq1[1].writeBytes(data);
|
165
|
+
data = seq1.toDER();
|
166
|
+
var buf:ByteArray = new ByteArray;
|
167
|
+
key.sign(data, buf, data.length);
|
168
|
+
return buf;
|
169
|
+
}
|
170
|
+
|
171
|
+
public function getPublicKey():RSAKey {
|
172
|
+
load();
|
173
|
+
var pk:ByteArray = _obj.signedCertificate.subjectPublicKeyInfo.subjectPublicKey as ByteArray;
|
174
|
+
pk.position = 0;
|
175
|
+
var rsaKey:Object = DER.parse(pk, [{name:"N"},{name:"E"}]);
|
176
|
+
return new RSAKey(rsaKey.N, rsaKey.E.valueOf());
|
177
|
+
}
|
178
|
+
|
179
|
+
/**
|
180
|
+
* Returns a subject principal, as an opaque base64 string.
|
181
|
+
* This is only used as a hash key for known certificates.
|
182
|
+
*
|
183
|
+
* Note that this assumes X509 DER-encoded certificates are uniquely encoded,
|
184
|
+
* as we look for exact matches between Issuer and Subject fields.
|
185
|
+
*
|
186
|
+
*/
|
187
|
+
public function getSubjectPrincipal():String {
|
188
|
+
load();
|
189
|
+
return Base64.encodeByteArray(_obj.signedCertificate.subject_bin);
|
190
|
+
}
|
191
|
+
/**
|
192
|
+
* Returns an issuer principal, as an opaque base64 string.
|
193
|
+
* This is only used to quickly find matching parent certificates.
|
194
|
+
*
|
195
|
+
* Note that this assumes X509 DER-encoded certificates are uniquely encoded,
|
196
|
+
* as we look for exact matches between Issuer and Subject fields.
|
197
|
+
*
|
198
|
+
*/
|
199
|
+
public function getIssuerPrincipal():String {
|
200
|
+
load();
|
201
|
+
return Base64.encodeByteArray(_obj.signedCertificate.issuer_bin);
|
202
|
+
}
|
203
|
+
public function getAlgorithmIdentifier():String {
|
204
|
+
return _obj.algorithmIdentifier.algorithmId.toString();
|
205
|
+
}
|
206
|
+
public function getNotBefore():Date {
|
207
|
+
return _obj.signedCertificate.validity.notBefore.date;
|
208
|
+
}
|
209
|
+
public function getNotAfter():Date {
|
210
|
+
return _obj.signedCertificate.validity.notAfter.date;
|
211
|
+
}
|
212
|
+
|
213
|
+
public function getCommonName():String {
|
214
|
+
var subject:Sequence = _obj.signedCertificate.subject;
|
215
|
+
return (subject.findAttributeValue(OID.COMMON_NAME) as PrintableString).getString();
|
216
|
+
}
|
217
|
+
}
|
218
|
+
}
|
@@ -0,0 +1,57 @@
|
|
1
|
+
/**
|
2
|
+
* X509CertificateCollection
|
3
|
+
*
|
4
|
+
* A class to store and index X509 Certificates by Subject.
|
5
|
+
* Copyright (c) 2007 Henri Torgemane
|
6
|
+
*
|
7
|
+
* See LICENSE.txt for full license information.
|
8
|
+
*/
|
9
|
+
package com.hurlant.crypto.cert {
|
10
|
+
|
11
|
+
public class X509CertificateCollection {
|
12
|
+
|
13
|
+
private var _map:Object;
|
14
|
+
|
15
|
+
public function X509CertificateCollection() {
|
16
|
+
_map = {};
|
17
|
+
}
|
18
|
+
|
19
|
+
/**
|
20
|
+
* Mostly meant for built-in CA loading.
|
21
|
+
* This entry-point allows to index CAs without parsing them.
|
22
|
+
*
|
23
|
+
* @param name A friendly name. not currently used
|
24
|
+
* @param subject base64 DER encoded Subject principal for the Cert
|
25
|
+
* @param pem PEM encoded certificate data
|
26
|
+
*
|
27
|
+
*/
|
28
|
+
public function addPEMCertificate(name:String, subject:String, pem:String):void {
|
29
|
+
_map[subject] = new X509Certificate(pem);
|
30
|
+
}
|
31
|
+
|
32
|
+
/**
|
33
|
+
* Adds a X509 certificate to the collection.
|
34
|
+
* This call will force the certificate to be parsed.
|
35
|
+
*
|
36
|
+
* @param cert A X509 certificate
|
37
|
+
*
|
38
|
+
*/
|
39
|
+
public function addCertificate(cert:X509Certificate):void {
|
40
|
+
var subject:String = cert.getSubjectPrincipal();
|
41
|
+
_map[subject] = cert;
|
42
|
+
}
|
43
|
+
|
44
|
+
/**
|
45
|
+
* Returns a X509 Certificate present in the collection, given
|
46
|
+
* a base64 DER encoded X500 Subject principal
|
47
|
+
*
|
48
|
+
* @param subject A Base64 DER-encoded Subject principal
|
49
|
+
* @return A matching certificate, or null.
|
50
|
+
*
|
51
|
+
*/
|
52
|
+
public function getCertificate(subject:String):X509Certificate {
|
53
|
+
return _map[subject];
|
54
|
+
}
|
55
|
+
|
56
|
+
}
|
57
|
+
}
|
@@ -0,0 +1,82 @@
|
|
1
|
+
/**
|
2
|
+
* HMAC
|
3
|
+
*
|
4
|
+
* An ActionScript 3 implementation of HMAC, Keyed-Hashing for Message
|
5
|
+
* Authentication, as defined by RFC-2104
|
6
|
+
* Copyright (c) 2007 Henri Torgemane
|
7
|
+
*
|
8
|
+
* See LICENSE.txt for full license information.
|
9
|
+
*/
|
10
|
+
package com.hurlant.crypto.hash
|
11
|
+
{
|
12
|
+
import flash.utils.ByteArray;
|
13
|
+
import com.hurlant.util.Hex;
|
14
|
+
|
15
|
+
public class HMAC implements IHMAC
|
16
|
+
{
|
17
|
+
private var hash:IHash;
|
18
|
+
private var bits:uint;
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Create a HMAC object, using a Hash function, and
|
22
|
+
* optionally a number of bits to return.
|
23
|
+
* The HMAC will be truncated to that size if needed.
|
24
|
+
*/
|
25
|
+
public function HMAC(hash:IHash, bits:uint=0) {
|
26
|
+
this.hash = hash;
|
27
|
+
this.bits = bits;
|
28
|
+
}
|
29
|
+
|
30
|
+
|
31
|
+
public function getHashSize():uint {
|
32
|
+
if (bits!=0) {
|
33
|
+
return bits/8;
|
34
|
+
} else {
|
35
|
+
return hash.getHashSize();
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
/**
|
40
|
+
* Compute a HMAC using a key and some data.
|
41
|
+
* It doesn't modify either, and returns a new ByteArray with the HMAC value.
|
42
|
+
*/
|
43
|
+
public function compute(key:ByteArray, data:ByteArray):ByteArray {
|
44
|
+
var hashKey:ByteArray;
|
45
|
+
if (key.length>hash.getInputSize()) {
|
46
|
+
hashKey = hash.hash(key);
|
47
|
+
} else {
|
48
|
+
hashKey = new ByteArray;
|
49
|
+
hashKey.writeBytes(key);
|
50
|
+
}
|
51
|
+
while (hashKey.length<hash.getInputSize()) {
|
52
|
+
hashKey[hashKey.length]=0;
|
53
|
+
}
|
54
|
+
var innerKey:ByteArray = new ByteArray;
|
55
|
+
var outerKey:ByteArray = new ByteArray;
|
56
|
+
for (var i:uint=0;i<hashKey.length;i++) {
|
57
|
+
innerKey[i] = hashKey[i] ^ 0x36;
|
58
|
+
outerKey[i] = hashKey[i] ^ 0x5c;
|
59
|
+
}
|
60
|
+
// inner + data
|
61
|
+
innerKey.position = hashKey.length;
|
62
|
+
innerKey.writeBytes(data);
|
63
|
+
var innerHash:ByteArray = hash.hash(innerKey);
|
64
|
+
// outer + innerHash
|
65
|
+
outerKey.position = hashKey.length;
|
66
|
+
outerKey.writeBytes(innerHash);
|
67
|
+
var outerHash:ByteArray = hash.hash(outerKey);
|
68
|
+
if (bits>0 && bits<8*outerHash.length) {
|
69
|
+
outerHash.length = bits/8;
|
70
|
+
}
|
71
|
+
return outerHash;
|
72
|
+
}
|
73
|
+
public function dispose():void {
|
74
|
+
hash = null;
|
75
|
+
bits = 0;
|
76
|
+
}
|
77
|
+
public function toString():String {
|
78
|
+
return "hmac-"+(bits>0?bits+"-":"")+hash.toString();
|
79
|
+
}
|
80
|
+
|
81
|
+
}
|
82
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
/**
|
2
|
+
* HMAC
|
3
|
+
*
|
4
|
+
* An ActionScript 3 interface for HMAC & MAC
|
5
|
+
* implementations.
|
6
|
+
*
|
7
|
+
* Loosely copyrighted by Bobby Parker
|
8
|
+
*
|
9
|
+
* See LICENSE.txt for full license information.
|
10
|
+
*/
|
11
|
+
package com.hurlant.crypto.hash
|
12
|
+
{
|
13
|
+
import flash.utils.ByteArray;
|
14
|
+
|
15
|
+
public interface IHMAC
|
16
|
+
{
|
17
|
+
function getHashSize():uint;
|
18
|
+
/**
|
19
|
+
* Compute a HMAC using a key and some data.
|
20
|
+
* It doesn't modify either, and returns a new ByteArray with the HMAC value.
|
21
|
+
*/
|
22
|
+
function compute(key:ByteArray, data:ByteArray):ByteArray;
|
23
|
+
function dispose():void;
|
24
|
+
function toString():String;
|
25
|
+
|
26
|
+
}
|
27
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
/**
|
2
|
+
* IHash
|
3
|
+
*
|
4
|
+
* An interface for each hash function to implement
|
5
|
+
* Copyright (c) 2007 Henri Torgemane
|
6
|
+
*
|
7
|
+
* See LICENSE.txt for full license information.
|
8
|
+
*/
|
9
|
+
package com.hurlant.crypto.hash
|
10
|
+
{
|
11
|
+
import flash.utils.ByteArray;
|
12
|
+
|
13
|
+
public interface IHash
|
14
|
+
{
|
15
|
+
function getInputSize():uint;
|
16
|
+
function getHashSize():uint;
|
17
|
+
function hash(src:ByteArray):ByteArray;
|
18
|
+
function toString():String;
|
19
|
+
function getPadSize():int;
|
20
|
+
}
|
21
|
+
}
|
@@ -0,0 +1,137 @@
|
|
1
|
+
/**
|
2
|
+
* MAC
|
3
|
+
*
|
4
|
+
* An ActionScript 3 implementation of MAC, Message Authentication Code
|
5
|
+
* for use with SSL 3.0.
|
6
|
+
* Loosely copyrighted by Bobby Parker.
|
7
|
+
* As3crypto copyrighted by Henri Torgemane.
|
8
|
+
*
|
9
|
+
* See LICENSE.txt for full license information.
|
10
|
+
*/
|
11
|
+
package com.hurlant.crypto.hash
|
12
|
+
{
|
13
|
+
import flash.utils.ByteArray;
|
14
|
+
import com.hurlant.util.Hex;
|
15
|
+
|
16
|
+
public class MAC implements IHMAC
|
17
|
+
{
|
18
|
+
private var hash:IHash;
|
19
|
+
private var bits:uint;
|
20
|
+
private var pad_1:ByteArray;
|
21
|
+
private var pad_2:ByteArray;
|
22
|
+
private var innerHash:ByteArray;
|
23
|
+
private var outerHash:ByteArray;
|
24
|
+
private var outerKey:ByteArray;
|
25
|
+
private var innerKey:ByteArray;
|
26
|
+
/**
|
27
|
+
* Create a MAC object (for SSL 3.0 ) and
|
28
|
+
* optionally a number of bits to return.
|
29
|
+
* The MAC will be truncated to that size if needed.
|
30
|
+
*/
|
31
|
+
public function MAC(hash:IHash, bits:uint=0) {
|
32
|
+
this.hash = hash;
|
33
|
+
this.bits = bits;
|
34
|
+
innerHash = new ByteArray();
|
35
|
+
outerHash = new ByteArray();
|
36
|
+
innerKey = new ByteArray();
|
37
|
+
outerKey = new ByteArray();
|
38
|
+
|
39
|
+
|
40
|
+
if (hash != null) {
|
41
|
+
var pad_size:int = hash.getPadSize();
|
42
|
+
pad_1 = new ByteArray();
|
43
|
+
pad_2 = new ByteArray();
|
44
|
+
|
45
|
+
for (var x:int = 0; x < pad_size; x++) {
|
46
|
+
pad_1.writeByte(0x36);
|
47
|
+
pad_2.writeByte(0x5c);
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
public function setPadSize(pad_size:int) : void { }
|
53
|
+
|
54
|
+
public function getHashSize():uint {
|
55
|
+
if (bits!=0) {
|
56
|
+
return bits/8;
|
57
|
+
} else {
|
58
|
+
return hash.getHashSize();
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
|
63
|
+
/**
|
64
|
+
* Compute a MAC using a key and some data.
|
65
|
+
*
|
66
|
+
*/
|
67
|
+
public function compute(key:ByteArray, data:ByteArray):ByteArray {
|
68
|
+
// take that incoming key and do hash(key + pad_2 + hash(key + pad_1 + sequence + length + record)
|
69
|
+
// note that data = (sequence + type + length + record)
|
70
|
+
|
71
|
+
if (pad_1 == null) {
|
72
|
+
var pad_size:int = hash.getPadSize();
|
73
|
+
pad_1 = new ByteArray();
|
74
|
+
pad_2 = new ByteArray();
|
75
|
+
|
76
|
+
for (var x:int = 0; x < pad_size; x++) {
|
77
|
+
pad_1.writeByte(0x36);
|
78
|
+
pad_2.writeByte(0x5c);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
// Do some preliminary checking on stuff
|
83
|
+
/*
|
84
|
+
if (key.length > hash.getInputSize()) {
|
85
|
+
hashKey = hash.hash(key);
|
86
|
+
} else {
|
87
|
+
hashKey = new ByteArray;
|
88
|
+
hashKey.writeBytes(key);
|
89
|
+
}
|
90
|
+
|
91
|
+
while (hashKey.length < hash.getInputSize() ) {
|
92
|
+
hashKey[hashKey.length] = 0;
|
93
|
+
} */
|
94
|
+
// Henri's conventions work just fine here..
|
95
|
+
|
96
|
+
innerKey.length = 0;
|
97
|
+
outerKey.length = 0;
|
98
|
+
// trace("MAC Key: " + Hex.fromArray(key));
|
99
|
+
// trace("Key Length: " + key.length);
|
100
|
+
// trace("Pad_1 : " + Hex.fromArray(pad_1));
|
101
|
+
// inner hash calc
|
102
|
+
innerKey.writeBytes(key);
|
103
|
+
innerKey.writeBytes(pad_1);
|
104
|
+
innerKey.writeBytes(data);
|
105
|
+
// trace("MAC Inner Key: " + Hex.fromArray(innerKey));
|
106
|
+
|
107
|
+
innerHash = hash.hash(innerKey);
|
108
|
+
// trace("MAC Inner Hash: " + Hex.fromArray(innerHash));
|
109
|
+
|
110
|
+
// outer hash calc
|
111
|
+
outerKey.writeBytes(key);
|
112
|
+
outerKey.writeBytes(pad_2);
|
113
|
+
outerKey.writeBytes(innerHash);
|
114
|
+
|
115
|
+
// trace("MAC Outer Key: " + Hex.fromArray(outerKey));
|
116
|
+
outerHash = hash.hash(outerKey);
|
117
|
+
|
118
|
+
|
119
|
+
if (bits > 0 && bits < 8*outerHash.length) {
|
120
|
+
outerHash.length = bits/8;
|
121
|
+
}
|
122
|
+
|
123
|
+
// trace("MAC for record: " + Hex.fromArray(outerHash));
|
124
|
+
return outerHash;
|
125
|
+
|
126
|
+
}
|
127
|
+
|
128
|
+
public function dispose():void {
|
129
|
+
hash = null;
|
130
|
+
bits = 0;
|
131
|
+
}
|
132
|
+
public function toString():String {
|
133
|
+
return "mac-"+(bits>0?bits+"-":"")+hash.toString();
|
134
|
+
}
|
135
|
+
|
136
|
+
}
|
137
|
+
}
|