From b60df56157ee1fd0bd4938799bac05a62fda91a1 Mon Sep 17 00:00:00 2001 From: lookshe Date: Sat, 14 Mar 2015 20:45:20 +0100 Subject: initial commit from working version --- .../flash-src/com/hurlant/util/der/ByteString.as | 43 +++++ .../flash-src/com/hurlant/util/der/DER.as | 210 +++++++++++++++++++++ .../flash-src/com/hurlant/util/der/IAsn1Type.as | 21 +++ .../flash-src/com/hurlant/util/der/Integer.as | 44 +++++ .../flash-src/com/hurlant/util/der/OID.as | 35 ++++ .../com/hurlant/util/der/ObjectIdentifier.as | 112 +++++++++++ .../flash-src/com/hurlant/util/der/PEM.as | 118 ++++++++++++ .../com/hurlant/util/der/PrintableString.as | 49 +++++ .../flash-src/com/hurlant/util/der/Sequence.as | 90 +++++++++ .../flash-src/com/hurlant/util/der/Set.as | 27 +++ .../flash-src/com/hurlant/util/der/Type.as | 94 +++++++++ .../flash-src/com/hurlant/util/der/UTCTime.as | 60 ++++++ 12 files changed, 903 insertions(+) create mode 100755 signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/ByteString.as create mode 100755 signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/DER.as create mode 100755 signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/IAsn1Type.as create mode 100755 signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/Integer.as create mode 100755 signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/OID.as create mode 100755 signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/ObjectIdentifier.as create mode 100755 signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/PEM.as create mode 100755 signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/PrintableString.as create mode 100755 signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/Sequence.as create mode 100755 signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/Set.as create mode 100755 signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/Type.as create mode 100755 signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/UTCTime.as (limited to 'signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der') diff --git a/signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/ByteString.as b/signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/ByteString.as new file mode 100755 index 0000000..fb8b280 --- /dev/null +++ b/signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/ByteString.as @@ -0,0 +1,43 @@ +/** + * ByteString + * + * An ASN1 type for a ByteString, represented with a ByteArray + * Copyright (c) 2007 Henri Torgemane + * + * See LICENSE.txt for full license information. + */ +package com.hurlant.util.der +{ + import flash.utils.ByteArray; + import com.hurlant.util.Hex; + + public class ByteString extends ByteArray implements IAsn1Type + { + private var type:uint; + private var len:uint; + + public function ByteString(type:uint = 0x04, length:uint = 0x00) { + this.type = type; + this.len = length; + } + + public function getLength():uint + { + return len; + } + + public function getType():uint + { + return type; + } + + public function toDER():ByteArray { + return DER.wrapDER(type, this); + } + + override public function toString():String { + return DER.indent+"ByteString["+type+"]["+len+"]["+Hex.fromArray(this)+"]"; + } + + } +} \ No newline at end of file diff --git a/signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/DER.as b/signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/DER.as new file mode 100755 index 0000000..bb5ecce --- /dev/null +++ b/signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/DER.as @@ -0,0 +1,210 @@ +/** + * DER + * + * A basic class to parse DER structures. + * It is very incomplete, but sufficient to extract whatever data we need so far. + * Copyright (c) 2007 Henri Torgemane + * + * See LICENSE.txt for full license information. + */ +package com.hurlant.util.der +{ + import com.hurlant.math.BigInteger; + + import flash.utils.ByteArray; + import com.hurlant.util.der.Sequence; + import com.hurlant.util.Hex; + + // goal 1: to be able to parse an RSA Private Key PEM file. + // goal 2: to parse an X509v3 cert. kinda. + + /** + * DER for dummies: + * http://luca.ntop.org/Teaching/Appunti/asn1.html + * + * This class does the bare minimum to get by. if that. + */ + public class DER + { + public static var indent:String = ""; + + public static function parse(der:ByteArray, structure:*=null):IAsn1Type { +/* if (der.position==0) { + trace("DER.parse: "+Hex.fromArray(der)); + } + */ // type + var type:int = der.readUnsignedByte(); + var constructed:Boolean = (type&0x20)!=0; + type &=0x1F; + // length + var len:int = der.readUnsignedByte(); + if (len>=0x80) { + // long form of length + var count:int = len & 0x7f; + len = 0; + while (count>0) { + len = (len<<8) | der.readUnsignedByte(); + count--; + } + } + // data + var b:ByteArray + switch (type) { + case 0x00: // WHAT IS THIS THINGY? (seen as 0xa0) + // (note to self: read a spec someday.) + // for now, treat as a sequence. + case 0x10: // SEQUENCE/SEQUENCE OF. whatever + // treat as an array + var p:int = der.position; + var o:Sequence = new Sequence(type, len); + var arrayStruct:Array = structure as Array; + if (arrayStruct!=null) { + // copy the array, as we destroy it later. + arrayStruct = arrayStruct.concat(); + } + while (der.position < p+len) { + var tmpStruct:Object = null + if (arrayStruct!=null) { + tmpStruct = arrayStruct.shift(); + } + if (tmpStruct!=null) { + while (tmpStruct && tmpStruct.optional) { + // make sure we have something that looks reasonable. XXX I'm winging it here.. + var wantConstructed:Boolean = (tmpStruct.value is Array); + var isConstructed:Boolean = isConstructedType(der); + if (wantConstructed!=isConstructed) { + // not found. put default stuff, or null + o.push(tmpStruct.defaultValue); + o[tmpStruct.name] = tmpStruct.defaultValue; + // try the next thing + tmpStruct = arrayStruct.shift(); + } else { + break; + } + } + } + if (tmpStruct!=null) { + var name:String = tmpStruct.name; + var value:* = tmpStruct.value; + if (tmpStruct.extract) { + // we need to keep a binary copy of this element + var size:int = getLengthOfNextElement(der); + var ba:ByteArray = new ByteArray; + ba.writeBytes(der, der.position, size); + o[name+"_bin"] = ba; + } + var obj:IAsn1Type = DER.parse(der, value); + o.push(obj); + o[name] = obj; + } else { + o.push(DER.parse(der)); + } + } + return o; + case 0x11: // SET/SET OF + p = der.position; + var s:Set = new Set(type, len); + while (der.position < p+len) { + s.push(DER.parse(der)); + } + return s; + case 0x02: // INTEGER + // put in a BigInteger + b = new ByteArray; + der.readBytes(b,0,len); + b.position=0; + return new Integer(type, len, b); + case 0x06: // OBJECT IDENTIFIER: + b = new ByteArray; + der.readBytes(b,0,len); + b.position=0; + return new ObjectIdentifier(type, len, b); + default: + trace("I DONT KNOW HOW TO HANDLE DER stuff of TYPE "+type); + // fall through + case 0x03: // BIT STRING + if (der[der.position]==0) { + //trace("Horrible Bit String pre-padding removal hack."); // I wish I had the patience to find a spec for this. + der.position++; + len--; + } + case 0x04: // OCTET STRING + // stuff in a ByteArray for now. + var bs:ByteString = new ByteString(type, len); + der.readBytes(bs,0,len); + return bs; + case 0x05: // NULL + // if len!=0, something's horribly wrong. + // should I check? + return null; + case 0x13: // PrintableString + var ps:PrintableString = new PrintableString(type, len); + ps.setString(der.readMultiByte(len, "US-ASCII")); + return ps; + case 0x22: // XXX look up what this is. openssl uses this to store my email. + case 0x14: // T61String - an horrible format we don't even pretend to support correctly + ps = new PrintableString(type, len); + ps.setString(der.readMultiByte(len, "latin1")); + return ps; + case 0x17: // UTCTime + var ut:UTCTime = new UTCTime(type, len); + ut.setUTCTime(der.readMultiByte(len, "US-ASCII")); + return ut; + } + } + + private static function getLengthOfNextElement(b:ByteArray):int { + var p:uint = b.position; + // length + b.position++; + var len:int = b.readUnsignedByte(); + if (len>=0x80) { + // long form of length + var count:int = len & 0x7f; + len = 0; + while (count>0) { + len = (len<<8) | b.readUnsignedByte(); + count--; + } + } + len += b.position-p; // length of length + b.position = p; + return len; + } + private static function isConstructedType(b:ByteArray):Boolean { + var type:int = b[b.position]; + return (type&0x20)!=0; + } + + public static function wrapDER(type:int, data:ByteArray):ByteArray { + var d:ByteArray = new ByteArray; + d.writeByte(type); + var len:int = data.length; + if (len<128) { + d.writeByte(len); + } else if (len<256) { + d.writeByte(1 | 0x80); + d.writeByte(len); + } else if (len<65536) { + d.writeByte(2 | 0x80); + d.writeByte(len>>8); + d.writeByte(len); + } else if (len<65536*256) { + d.writeByte(3 | 0x80); + d.writeByte(len>>16); + d.writeByte(len>>8); + d.writeByte(len); + } else { + d.writeByte(4 | 0x80); + d.writeByte(len>>24); + d.writeByte(len>>16); + d.writeByte(len>>8); + d.writeByte(len); + } + d.writeBytes(data); + d.position=0; + return d; + + } + } +} \ No newline at end of file diff --git a/signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/IAsn1Type.as b/signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/IAsn1Type.as new file mode 100755 index 0000000..f4f2112 --- /dev/null +++ b/signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/IAsn1Type.as @@ -0,0 +1,21 @@ +/** + * IAsn1Type + * + * An interface for Asn-1 types. + * Copyright (c) 2007 Henri Torgemane + * + * See LICENSE.txt for full license information. + */ +package com.hurlant.util.der +{ + import flash.utils.ByteArray; + + public interface IAsn1Type + { + function getType():uint; + function getLength():uint; + + function toDER():ByteArray; + + } +} \ No newline at end of file diff --git a/signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/Integer.as b/signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/Integer.as new file mode 100755 index 0000000..e2f045c --- /dev/null +++ b/signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/Integer.as @@ -0,0 +1,44 @@ +/** + * Integer + * + * An ASN1 type for an Integer, represented with a BigInteger + * Copyright (c) 2007 Henri Torgemane + * + * See LICENSE.txt for full license information. + */ +package com.hurlant.util.der +{ + import com.hurlant.math.BigInteger; + import flash.utils.ByteArray; + + public class Integer extends BigInteger implements IAsn1Type + { + private var type:uint; + private var len:uint; + + public function Integer(type:uint, length:uint, b:ByteArray) { + this.type = type; + this.len = length; + super(b); + } + + public function getLength():uint + { + return len; + } + + public function getType():uint + { + return type; + } + + override public function toString(radix:Number=0):String { + return DER.indent+"Integer["+type+"]["+len+"]["+super.toString(16)+"]"; + } + + public function toDER():ByteArray { + return null; + } + + } +} \ No newline at end of file diff --git a/signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/OID.as b/signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/OID.as new file mode 100755 index 0000000..4d43d95 --- /dev/null +++ b/signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/OID.as @@ -0,0 +1,35 @@ +/** + * OID + * + * A list of various ObjectIdentifiers. + * Copyright (c) 2007 Henri Torgemane + * + * See LICENSE.txt for full license information. + */ +package com.hurlant.util.der +{ + public class OID + { + + public static const RSA_ENCRYPTION:String = "1.2.840.113549.1.1.1"; + public static const MD2_WITH_RSA_ENCRYPTION:String = "1.2.840.113549.1.1.2"; + public static const MD5_WITH_RSA_ENCRYPTION:String = "1.2.840.113549.1.1.4"; + public static const SHA1_WITH_RSA_ENCRYPTION:String = "1.2.840.113549.1.1.5"; + public static const MD2_ALGORITHM:String = "1.2.840.113549.2.2"; + public static const MD5_ALGORITHM:String = "1.2.840.113549.2.5"; + public static const DSA:String = "1.2.840.10040.4.1"; + public static const DSA_WITH_SHA1:String = "1.2.840.10040.4.3"; + public static const DH_PUBLIC_NUMBER:String = "1.2.840.10046.2.1"; + public static const SHA1_ALGORITHM:String = "1.3.14.3.2.26"; + + public static const COMMON_NAME:String = "2.5.4.3"; + public static const SURNAME:String = "2.5.4.4"; + public static const COUNTRY_NAME:String = "2.5.4.6"; + public static const LOCALITY_NAME:String = "2.5.4.7"; + public static const STATE_NAME:String = "2.5.4.8"; + public static const ORGANIZATION_NAME:String = "2.5.4.10"; + public static const ORG_UNIT_NAME:String = "2.5.4.11"; + public static const TITLE:String = "2.5.4.12"; + + } +} \ No newline at end of file diff --git a/signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/ObjectIdentifier.as b/signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/ObjectIdentifier.as new file mode 100755 index 0000000..932acd7 --- /dev/null +++ b/signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/ObjectIdentifier.as @@ -0,0 +1,112 @@ +/** + * ObjectIdentifier + * + * An ASN1 type for an ObjectIdentifier + * We store the oid in an Array. + * Copyright (c) 2007 Henri Torgemane + * + * See LICENSE.txt for full license information. + */ +package com.hurlant.util.der +{ + import flash.utils.ByteArray; + + public class ObjectIdentifier implements IAsn1Type + { + private var type:uint; + private var len:uint; + private var oid:Array; + + public function ObjectIdentifier(type:uint, length:uint, b:*) { + this.type = type; + this.len = length; + if (b is ByteArray) { + parse(b as ByteArray); + } else if (b is String) { + generate(b as String); + } else { + throw new Error("Invalid call to new ObjectIdentifier"); + } + } + + private function generate(s:String):void { + oid = s.split("."); + } + + private function parse(b:ByteArray):void { + // parse stuff + // first byte = 40*value1 + value2 + var o:uint = b.readUnsignedByte(); + var a:Array = [] + a.push(uint(o/40)); + a.push(uint(o%40)); + var v:uint = 0; + while (b.bytesAvailable>0) { + o = b.readUnsignedByte(); + var last:Boolean = (o&0x80)==0; + o &= 0x7f; + v = v*128 + o; + if (last) { + a.push(v); + v = 0; + } + } + oid = a; + } + + public function getLength():uint + { + return len; + } + + public function getType():uint + { + return type; + } + + public function toDER():ByteArray { + var tmp:Array = []; + tmp[0] = oid[0]*40 + oid[1]; + for (var i:int=2;i>7)|0x80 ); + tmp.push( v&0x7f ); + } else if (v<128*128*128) { + tmp.push( (v>>14)|0x80 ); + tmp.push( (v>>7)&0x7f | 0x80 ); + tmp.push( v&0x7f); + } else if (v<128*128*128*128) { + tmp.push( (v>>21)|0x80 ); + tmp.push( (v>>14) & 0x7f | 0x80 ); + tmp.push( (v>>7) & 0x7f | 0x80 ); + tmp.push( v & 0x7f ); + } else { + throw new Error("OID element bigger than we thought. :("); + } + } + len = tmp.length; + if (type==0) { + type = 6; + } + tmp.unshift(len); // assume length is small enough to fit here. + tmp.unshift(type); + var b:ByteArray = new ByteArray; + for (i=0;i, null ]; ( apparently, that's an X-509 Algorithm Identifier. + if (arr[0][0].toString()!=OID.RSA_ENCRYPTION) { + return null; + } + // arr[1] is a ByteArray begging to be parsed as DER + arr[1].position = 1; // there's a 0x00 byte up front. find out why later. like, read a spec. + obj = DER.parse(arr[1]); + if (obj is Array) { + arr = obj as Array; + // arr[0] = modulus + // arr[1] = public expt. + return new RSAKey(arr[0], arr[1]); + } else { + return null; + } + } else { + // dunno + return null; + } + } + + public static function readCertIntoArray(str:String):ByteArray { + var tmp:ByteArray = extractBinary(CERTIFICATE_HEADER, CERTIFICATE_FOOTER, str); + return tmp; + } + + private static function extractBinary(header:String, footer:String, str:String):ByteArray { + var i:int = str.indexOf(header); + if (i==-1) return null; + i += header.length; + var j:int = str.indexOf(footer); + if (j==-1) return null; + var b64:String = str.substring(i, j); + // remove whitesapces. + b64 = b64.replace(/\s/mg, ''); + // decode + return Base64.decodeToByteArray(b64); + } + + } +} \ No newline at end of file diff --git a/signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/PrintableString.as b/signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/PrintableString.as new file mode 100755 index 0000000..ed1775e --- /dev/null +++ b/signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/PrintableString.as @@ -0,0 +1,49 @@ +/** + * PrintableString + * + * An ASN1 type for a PrintableString, held within a String + * Copyright (c) 2007 Henri Torgemane + * + * See LICENSE.txt for full license information. + */ +package com.hurlant.util.der +{ + import flash.utils.ByteArray; + + public class PrintableString implements IAsn1Type + { + protected var type:uint; + protected var len:uint; + protected var str:String; + + public function PrintableString(type:uint, length:uint) { + this.type = type; + this.len = length; + } + + public function getLength():uint + { + return len; + } + + public function getType():uint + { + return type; + } + + public function setString(s:String):void { + str = s; + } + public function getString():String { + return str; + } + + public function toString():String { + return DER.indent+str; + } + + public function toDER():ByteArray { + return null; // XXX not implemented + } + } +} \ No newline at end of file diff --git a/signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/Sequence.as b/signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/Sequence.as new file mode 100755 index 0000000..c352414 --- /dev/null +++ b/signaling-server/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/Sequence.as @@ -0,0 +1,90 @@ +/** + * Sequence + * + * An ASN1 type for a Sequence, implemented as an Array + * Copyright (c) 2007 Henri Torgemane + * + * See LICENSE.txt for full license information. + */ +package com.hurlant.util.der +{ + import flash.utils.ByteArray; + + public dynamic class Sequence extends Array implements IAsn1Type + { + protected var type:uint; + protected var len:uint; + + public function Sequence(type:uint = 0x30, length:uint = 0x00) { + this.type = type; + this.len = length; + } + + public function getLength():uint + { + return len; + } + + public function getType():uint + { + return type; + } + + public function toDER():ByteArray { + var tmp:ByteArray = new ByteArray; + for (var i:int=0;i