예제 #1
0
        /// <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;
        }