////////////////////////////////////////////////////////////////////////// // Stub ////////////////////////////////////////////////////////////////////////// public static void stub(string podName, DirectoryInfo outDir, bool verbose) { writeLine(" .NET Stub [" + podName + "]"); string fanHome = SysProps.getProperty("fan.home"); string podPath = fanHome + "\\lib\\fan\\" + podName + ".pod"; string target = new FileInfo(outDir + "\\" + podName + ".dll").FullName; if (verbose) { writeLine(" <- " + podPath); Pod pod = Pod.doFind(podName, true, null); List list = pod.types(); string pre = "Fan." + FanUtil.upper(podName) + "."; for (int i = 0; i < list.sz(); i++) { writeLine(" " + pre + (list.get(i) as Type).name()); } writeLine(" -> " + target); } FStore store = new FStore(new ZipFile(podPath)); FPod fpod = new FPod(podName, store); fpod.read(); FTypeEmit.emitPod(fpod, false, target); }
private void Serialise() { if (_text == null && _data != null) { var serialFormat = (SerialFormat)SysProps.GetValue(SysPropName.SAlg, 0); switch (serialFormat) { case SerialFormat.Binary: // try Binary serialiser _text = BinarySerializerHelper.SerializeToString(_data); SysProps.Set(SysPropName.SAlg, (int)SerialFormat.Binary); break; case SerialFormat.Soap: // try Soap serialiser _text = SoapSerializerHelper.SerializeToString(_data); SysProps.Set(SysPropName.SAlg, (int)SerialFormat.Soap); break; case SerialFormat.Json: // try Json serialiser _text = JsonSerializerHelper.SerializeToString(_data); SysProps.Set(SysPropName.SAlg, (int)SerialFormat.Json); break; case SerialFormat.Xml: try { _text = XmlSerializerHelper.SerializeToString(_dataTypeType, _data); SysProps.Set(SysPropName.SAlg, (int)SerialFormat.Xml); } catch (Exception excp) { throw new ApplicationException( "The XmlSerializer has thrown an exception: '" + excp.GetType().Name + "'. " + "If your intent was to use the BinaryFormatter or SoapFormatter for serialisation, " + "then you should set the SerialFormat property appropriately.", excp); } break; default: // use default xml serialiser try { _text = XmlSerializerHelper.SerializeToString(_dataTypeType, _data); SysProps.Set(SysPropName.SAlg, (int)SerialFormat.Xml); } catch (Exception excp) { throw new ApplicationException( "The XmlSerializer has thrown an exception: '" + excp.GetType().Name + "'. " + "If your intent was to use the BinaryFormatter or SoapFormatter for serialisation, " + "then you should set the SerialFormat property appropriately.", excp); } break; } } }
// constructors /// <summary> /// /// </summary> /// <param name="moduleInfo"></param> /// <param name="cryptoManager"></param> /// <param name="itemKind"></param> /// <param name="transient"></param> /// <param name="appScope"></param> /// <param name="name"></param> /// <param name="props"></param> /// <param name="data"></param> /// <param name="dataType"></param> /// <param name="serialFormat"></param> /// <param name="lifetime"></param> public ServerItem( IModuleInfo moduleInfo, ICryptoManager cryptoManager, ItemKind itemKind, bool transient, string appScope, string name, NamedValueSet props, object data, Type dataType, SerialFormat serialFormat, TimeSpan lifetime) : base(itemKind, transient, name, appScope) { _moduleInfo = moduleInfo ?? throw new ArgumentNullException(nameof(moduleInfo)); _cryptoManager = cryptoManager ?? throw new ArgumentNullException(nameof(cryptoManager)); if (dataType == null) { throw new ArgumentNullException(nameof(dataType)); } SysProps.Set(SysPropName.SAlg, (int)serialFormat); AppProps.Add(props); _data = data; _dataTypeType = dataType; DataTypeName = dataType.FullName; _lifetime = lifetime; }
private void Decrypt() { if (_zData == null) { // do asymmetric decryption 1st, if required if (_xData == null) { var yAlg = SysProps.GetValue(SysPropName.YAlg, 0); var yrki = SysProps.GetValue <string>(SysPropName.YRKI, null); if ((yAlg > 0) && (yrki != null)) { _xData = _cryptoManager.DecryptWithSecretKey(yrki, YData); } else { _xData = YData; } //_YData = null; } // now do symmetric decryption 2nd, if required var xAlg = SysProps.GetValue(SysPropName.XAlg, 0); var xtki = SysProps.GetValue <string>(SysPropName.XTKI, null); if ((xAlg > 0) && (xtki != null)) { _zData = _cryptoManager.DecryptWithTranspKey(xtki, _xData); } else { _zData = _xData; } _xData = null; } }
/// <summary> /// /// </summary> /// <param name="text"></param> /// <param name="dataType"></param> public void SetText(string text, Type dataType) { CheckNotFrozen(); _text = text; SysProps.Set(SysPropName.SAlg, (int)SerialFormat.Undefined); _data = null; _dataTypeType = dataType; DataTypeName = dataType.FullName; }
/// <summary> /// /// </summary> /// <param name="itemKind"></param> /// <param name="transient"></param> /// <param name="appScope"></param> /// <param name="name"></param> /// <param name="props"></param> /// <param name="serialisedData"></param> /// <param name="dataTypeName"></param> /// <param name="lifetime"></param> public ServerItem( ItemKind itemKind, bool transient, string appScope, string name, NamedValueSet props, string serialisedData, string dataTypeName, TimeSpan lifetime) : base(itemKind, transient, name, appScope) { AppProps.Add(props); _text = serialisedData; SysProps.Set(SysPropName.SAlg, (int)SerialFormat.Undefined); DataTypeName = dataTypeName; _lifetime = lifetime; }
private void Deserialise(Type userDataType) { if (_data == null) { // decompress 1st if required Decompress(); // now deserialise Type dataTypeType = userDataType ?? _dataTypeType; if ((dataTypeType == null) && !String.IsNullOrEmpty(DataTypeName)) { dataTypeType = Type.GetType(DataTypeName); } var serialFormat = (SerialFormat)SysProps.GetValue(SysPropName.SAlg, (int)SerialFormat.Undefined); if (String.IsNullOrEmpty(_text)) { // null data object _data = null; } else if (serialFormat == SerialFormat.Binary) { // use Binary deserialiser _data = BinarySerializerHelper.DeserializeFromString(_text); } else if (serialFormat == SerialFormat.Soap) { // use Soap deserialiser _data = SoapSerializerHelper.DeserializeFromString(_text); } else if (serialFormat == SerialFormat.Json) { // use Json deserialiser _data = JsonSerializerHelper.DeserializeFromString(dataTypeType, _text); } else if (dataTypeType != null) { // try default xml serialiser _data = XmlSerializerHelper.DeserializeFromString(dataTypeType, _text); } else { throw new ApplicationException("Cannot deserialise!"); } } }
// mutable props private void Authenticate() { if (_ySignedState == 0) { var yAlg = SysProps.GetValue(SysPropName.YAlg, 0); var yski = SysProps.GetValue <string>(SysPropName.YSKI, null); if ((yAlg > 0) && (yski != null)) { if (_cryptoManager.VerifySignature(yski, YData, YSign)) { _ySignedState = 1; // success } } else { // cannot authenticate _ySignedState = -1; } } }
public int EstimatedSizeInBytes(bool excludeDataBody) { // the calculated overhead is actually 1745 bytes, but we are allowing for // errors and variations in both the header and body fragments, of up to 250 bytes. const int bytesPerStringChar = 2; // 16-bit Unicode strings int result = 2000; // overhead result += Name?.Length * bytesPerStringChar ?? 0; result += DataTypeName?.Length * bytesPerStringChar ?? 0; result += AppScope?.Length * bytesPerStringChar ?? 0; result += NetScope?.Length * bytesPerStringChar ?? 0; result += (AppProps.Serialise().Length *bytesPerStringChar); // hack - slow - todo - use Text property result += (SysProps.Serialise().Length *bytesPerStringChar); // hack - slow - todo - use Text property if (!excludeDataBody) { result += YData?.Length ?? 0; result += YSign?.Length ?? 0; } const int bufferBytesPerByte = 2; return(result * bufferBytesPerByte); }
////////////////////////////////////////////////////////////////////////// // Run Methods ////////////////////////////////////////////////////////////////////////// public static int run(string reserved) { try { sysInit(reserved); SysProps.putProperty("fan.appDir", "$home/tmp/test/"); //bool self = false; bool verbose = false; ArrayList targets = new ArrayList(); string[] args = Tool.getArgv(); if (args.Length == 0) { help(); return(-1); } // process args for (int i = 0; i < args.Length; i++) { string a = args[i]; if (a.Length == 0) { continue; } if (a == "-help" || a == "-h" || a == "-?") { help(); return(-1); } if (a == "-version") { Fan.version("Fantom Test"); return(-1); } else if (a == "-v") { verbose = true; FanSysTest.verbose = true; //fanx.test.Test.verbose = true; } else if (a == "-all") { targets.Add("*"); } else if (a[0] == '-') { writeLine("WARNING: Unknown option " + a); } else { targets.Add(a); } } if (targets.Count == 0) { help(); return(-1); } string[] t = (string[])targets.ToArray(System.Type.GetType("System.String")); return(new Fant().test(t, verbose)); } catch (System.Exception e) { Err.dumpStack(e); return(-1); } }
/// <summary> /// /// </summary> public void Freeze() { if (_frozen) { return; } if (Name == null) { throw new ApplicationException("Item name not set!"); } TimeSpan maxLifetime = DateTimeOffset.MaxValue - DateTimeOffset.Now - TimeSpan.FromDays(1); if (_lifetime > maxLifetime) { _lifetime = maxLifetime; } if (_lifetime < TimeSpan.Zero) { _lifetime = TimeSpan.Zero; } Created = DateTimeOffset.Now; Expires = Created.Add(_lifetime); // serialise the data if required Serialise(); if (DataTypeName == null) { DataTypeName = ""; } if (_text == null) { //_Text = ""; SysProps.Set(SysPropName.SAlg, (int)SerialFormat.Undefined); } SysProps.Set(SysPropName.TLen, _text?.Length ?? 0); // compress the data _zData = CompressionHelper.CompressToBuffer(_text); SysProps.Set(SysPropName.ZAlg, 1); SysProps.Set(SysPropName.ZLen, _zData?.Length ?? 0); // do symmetric encryption 1st, if required var xtki = SysProps.GetValue <String>(SysPropName.XTKI, null); if (xtki != null) { _xData = _cryptoManager.EncryptWithTranspKey(xtki, _zData); SysProps.Set(SysPropName.XAlg, 1); } else { _xData = _zData; } SysProps.Set(SysPropName.XLen, _xData?.Length ?? 0); // do asymmetric encryption 2nd, if required var yrki = SysProps.GetValue <String>(SysPropName.YRKI, null); if (yrki != null) { SysProps.Set(SysPropName.YAlg, 1); YData = _cryptoManager.EncryptWithPublicKey(yrki, _xData); } else { YData = _xData; } YDataHash = CalculateBufferHash(YData); SysProps.Set(SysPropName.YLen, YData?.Length ?? 0); // do public signature 3rd, if required var yski = SysProps.GetValue <String>(SysPropName.YSKI, null); if (yski != null) { SysProps.Set(SysPropName.YAlg, 1); YSign = _cryptoManager.CreateSignature(yski, YData); } // add other publisher properties SysProps.Set(SysPropName.ApplName, _moduleInfo.ApplName); SysProps.Set(SysPropName.ApplFVer, _moduleInfo.ApplFVer); SysProps.Set(SysPropName.ApplPTok, _moduleInfo.ApplPTok); SysProps.Set(SysPropName.CoreFVer, _moduleInfo.CoreFVer); SysProps.Set(SysPropName.CorePTok, _moduleInfo.CorePTok); SysProps.Set(SysPropName.HostName, _moduleInfo.HostName); SysProps.Set(SysPropName.UserName, _moduleInfo.UserName); SysProps.Set(SysPropName.UserWDom, _moduleInfo.UserWDom); SysProps.Set(SysPropName.UserIdentity, _moduleInfo.Name); SysProps.Set(SysPropName.UserFullName, _moduleInfo.UserFullName); SysProps.Set(SysPropName.OrgEnvId, EnvHelper.EnvName(_moduleInfo.ConfigEnv)); SysProps.Set(SysPropName.NodeGuid, _moduleInfo.NodeGuid); // done _frozen = true; }