PageRenderTime 45ms CodeModel.GetById 38ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 1ms

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

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
ActionScript | 70 lines | 50 code | 8 blank | 12 comment | 6 complexity | e1ae1f100da110731c30ca4e6a322aa2 MD5 | raw file
 1/**
 2 * TLSConfig
 3 * 
 4 * A set of configuration parameters for use by a TLSSocket or a TLSEngine.
 5 * Most parameters are optional and will be set to appropriate default values for most use.
 6 * 
 7 * Copyright (c) 2007 Henri Torgemane
 8 * 
 9 * See LICENSE.txt for full license information.
10 */
11package com.hurlant.crypto.tls {
12	import flash.utils.ByteArray;
13	import com.hurlant.util.der.PEM;
14	import com.hurlant.crypto.rsa.RSAKey;
15	import com.hurlant.crypto.cert.X509CertificateCollection;
16	import com.hurlant.crypto.cert.MozillaRootCertificates;
17	
18	public class TLSConfig {
19		public var entity:uint; // SERVER | CLIENT
20		
21		public var certificate:ByteArray;
22		public var privateKey:RSAKey;
23		
24		public var cipherSuites:Array;
25		
26		public var compressions:Array;
27		public var ignoreCommonNameMismatch:Boolean = false;
28		public var trustAllCertificates:Boolean = false;
29		public var trustSelfSignedCertificates:Boolean = false;
30		public var promptUserForAcceptCert:Boolean = false;
31		public var CAStore:X509CertificateCollection;
32		public var localKeyStore:X509CertificateCollection;
33		public var version:uint;
34		
35		public function TLSConfig(	entity:uint, cipherSuites:Array = null, compressions:Array = null, 
36									certificate:ByteArray = null, privateKey:RSAKey = null, CAStore:X509CertificateCollection = null, ver:uint = 0x00) {
37			this.entity = entity;
38			this.cipherSuites = cipherSuites;
39			this.compressions = compressions;
40			this.certificate = certificate;
41			this.privateKey = privateKey;
42			this.CAStore = CAStore;
43			this.version = ver;
44			// default settings.
45			if (cipherSuites==null) {
46				this.cipherSuites = CipherSuites.getDefaultSuites();
47			}
48			if (compressions==null) {
49				this.compressions = [TLSSecurityParameters.COMPRESSION_NULL];
50			}
51			
52			if (CAStore==null) {
53				this.CAStore = new MozillaRootCertificates;
54			}
55			
56			if (ver==0x00) {
57				// Default to TLS
58				this.version = TLSSecurityParameters.PROTOCOL_VERSION;
59			} 
60		}
61		
62		public function setPEMCertificate(cert:String, key:String = null):void {
63			if (key == null) {
64				key = cert; // for folks who like to concat those two in one file.
65			}
66			certificate = PEM.readCertIntoArray(cert);
67			privateKey = PEM.readRSAPrivateKey(key);
68		}
69	}
70}