PageRenderTime 343ms CodeModel.GetById 93ms app.highlight 122ms RepoModel.GetById 120ms app.codeStats 0ms

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

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
ActionScript | 117 lines | 85 code | 17 blank | 15 comment | 1 complexity | 57a6f5055bc96953e79c7ce9a8b560b0 MD5 | raw file
  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 */
 10package 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}