Exemplo n.º 1
0
        /// <summary>
        /// A constructor used for fast deserializing
        /// </summary>
        /// <param name="myObjectLocation">the location of this object (ObjectPath and ObjectName) of the requested file within the file system</param>
        /// <param name="mySerializedData">A bunch of bytes[] containing the serialized FileObject</param>
        public FileObject(ObjectLocation myObjectLocation, Byte[] mySerializedData, IIntegrityCheck myIntegrityCheckAlgorithm, ISymmetricEncryption myEncryptionAlgorithm)
        {
            if (myObjectLocation == null || myObjectLocation.Length == 0)
                throw new ArgumentNullException("Invalid myObjectLocation!");

            if (mySerializedData == null || mySerializedData.Length == 0)
                throw new ArgumentNullException("mySerializedData must not be null or its length be zero!");

            Deserialize(mySerializedData, myIntegrityCheckAlgorithm, myEncryptionAlgorithm, false);
            _isNew = false;
        }
        public bool IsEqual(IIntegrityCheck otherCheck)
        {
            var typedOtherCheck = otherCheck as CreateForeignKeyProperties;
            if (typedOtherCheck != null
                && typedOtherCheck._association == _association)
            {
                return true;
            }

            return false;
        }
        public bool IsEqual(IIntegrityCheck otherCheck)
        {
            var typedOtherCheck = otherCheck as InferReferentialConstraints;
            if (typedOtherCheck != null
                && typedOtherCheck._association == _association)
            {
                return true;
            }

            return false;
        }
        public bool IsEqual(IIntegrityCheck otherCheck)
        {
            var typedOtherCheck = otherCheck as EnforceEntitySetMappingRules;
            if (typedOtherCheck != null
                && typedOtherCheck._entitySetMapping == _entitySetMapping)
            {
                return true;
            }

            return false;
        }
Exemplo n.º 5
0
        public bool IsEqual(IIntegrityCheck otherCheck)
        {
            var typedOtherCheck = otherCheck as InferReferentialConstraints;

            if (typedOtherCheck != null &&
                typedOtherCheck._association == _association)
            {
                return(true);
            }

            return(false);
        }
        public bool IsEqual(IIntegrityCheck otherCheck)
        {
            var typedOtherCheck = otherCheck as EnforceEntitySetMappingRules;

            if (typedOtherCheck != null &&
                typedOtherCheck._entitySetMapping == _entitySetMapping)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 7
0
        public bool IsEqual(IIntegrityCheck otherCheck)
        {
            var typedOtherCheck = otherCheck as CreateForeignKeyProperties;

            if (typedOtherCheck != null &&
                typedOtherCheck._association == _association)
            {
                return(true);
            }

            return(false);
        }
        internal void AddIntegrityCheck(IIntegrityCheck newCheck)
        {
            foreach (var check in _integrityChecks)
            {
                // don't add duplicate checks
                if (check.IsEqual(newCheck))
                {
                    return;
                }
            }

            _integrityChecks.Enqueue(newCheck);
        }
        public bool IsEqual(IIntegrityCheck otherCheck)
        {
            var typedOtherCheck = otherCheck as PropagateStoragePropertyFacetsToConceptualModel;

            if (typedOtherCheck != null)
            {
                if (typedOtherCheck._artifact.Uri.Equals(_artifact.Uri))
                {
                    return(true);
                }
            }

            return(false);
        }
        public bool IsEqual(IIntegrityCheck otherCheck)
        {
            var typedOtherCheck = otherCheck as PropagateViewKeysToStorageModel;
            if (typedOtherCheck != null)
            {
                if (typedOtherCheck._conceptualEntityType == _conceptualEntityType)
                {
                    return true;
                }
                else if (typedOtherCheck._conceptualEntityTypes != null
                         && _conceptualEntityTypes != null
                         && new HashSet<EntityType>(_conceptualEntityTypes).SetEquals(typedOtherCheck._conceptualEntityTypes))
                {
                    return true;
                }
            }

            return false;
        }
Exemplo n.º 11
0
        public bool IsEqual(IIntegrityCheck otherCheck)
        {
            var typedOtherCheck = otherCheck as PropagateViewKeysToStorageModel;

            if (typedOtherCheck != null)
            {
                if (typedOtherCheck._conceptualEntityType == _conceptualEntityType)
                {
                    return(true);
                }
                else if (typedOtherCheck._conceptualEntityTypes != null &&
                         _conceptualEntityTypes != null &&
                         new HashSet <EntityType>(_conceptualEntityTypes).SetEquals(typedOtherCheck._conceptualEntityTypes))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 12
0
        public bool IsEqual(IIntegrityCheck otherCheck)
        {
            var typedOtherCheck = otherCheck as PropagateStoreGeneratedPatternToStorageModel;

            if (typedOtherCheck == null)
            {
                return(false);
            }

            if (_artifact != null)
            {
                if (typedOtherCheck._artifact != null &&
                    _artifact.Uri.Equals(typedOtherCheck._artifact.Uri))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else if (_storageProperty != null)
            {
                if (typedOtherCheck._storageProperty != null &&
                    _storageProperty.Equals(typedOtherCheck._storageProperty))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            Debug.Fail("Both _artifact and _storageProperty are null");
            return(false);
        }
        public bool IsEqual(IIntegrityCheck otherCheck)
        {
            var typedOtherCheck = otherCheck as PropagateStoreGeneratedPatternToStorageModel;
            if (typedOtherCheck == null)
            {
                return false;
            }

            if (_artifact != null)
            {
                if (typedOtherCheck._artifact != null
                    && _artifact.Uri.Equals(typedOtherCheck._artifact.Uri))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else if (_storageProperty != null)
            {
                if (typedOtherCheck._storageProperty != null
                    && _storageProperty.Equals(typedOtherCheck._storageProperty))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }

            Debug.Fail("Both _artifact and _storageProperty are null");
            return false;
        }
Exemplo n.º 14
0
        /// <summary>
        /// This will serialize the whole AFSObject including the common header of an
        /// AAFSObject and the actual AFSObject
        /// </summary>
        /// <param name="myIntegrityCheckAlgorithm"></param>
        /// <param name="myEncryptionAlgorithm"></param>
        /// <param name="myCacheSerializeData"></param>
        /// <returns></returns>
        public Byte[] Serialize(IIntegrityCheck myIntegrityCheckAlgorithm, ISymmetricEncryption myEncryptionAlgorithm, Boolean myCacheSerializeData)
        {
            #region Data

            Int32 IntegrityCheckValue_Length = 0;
            Byte[] IntegrityCheckValue = null;
            Int64 IntegrityCheckValue_Position = 0;

            Int32 EncryptionParameters_Length = 0;
            Byte DataPadding_Length = 0;
            Int32 AdditionalPadding_Length = 0;
            Byte[] _TmpSerializedAGraphStructure = null;

            #endregion

            try
            {

                #region Init SerializationWriter

                SerializationWriter writer = new SerializationWriter();

                #endregion

                #region Pad the length of the EncryptionParameters

                EncryptionParameters = Encoding.Default.GetBytes("-HIGHSECUREDATA-");
                EncryptionParameters_Length = sones.Lib.BufferHelper.AlignBufferLength(EncryptionParameters.Length, 8);

                #endregion

                #region Serialize AAFSObjectHeader

                Byte[] AAFSObjectHeader = new Byte[HeaderLength];

                AAFSObjectHeader[0] = HeaderVersion;

                if (myIntegrityCheckAlgorithm != null)
                    IntegrityCheckValue_Length = myIntegrityCheckAlgorithm.HashSize;

                if (IntegrityCheckValue_Length % 8 == 0)
                    AAFSObjectHeader[1] = (Byte)(IntegrityCheckValue_Length / 8);
                else AAFSObjectHeader[1] = (Byte)((IntegrityCheckValue_Length / 8) + 1);

                if (EncryptionParameters_Length % 8 == 0)
                    AAFSObjectHeader[2] = (Byte)(EncryptionParameters_Length / 8);
                else AAFSObjectHeader[2] = (Byte)((EncryptionParameters_Length / 8) + 1);

                AAFSObjectHeader[3] = (Byte)(DataPadding_Length);
                AAFSObjectHeader[4] = (Byte)(AdditionalPadding_Length / 256);
                AAFSObjectHeader[5] = (Byte)(AdditionalPadding_Length % 256);
                AAFSObjectHeader[6] = 0x00;
                AAFSObjectHeader[7] = 0x00;

                writer.WriteBytesDirect(AAFSObjectHeader);                      // 8 Bytes
                IntegrityCheckValue_Position = writer.BaseStream.Position;
                writer.WriteBytesDirect(new Byte[IntegrityCheckValue_Length]);      // n or at least 16 Bytes
                writer.WriteBytesDirect(EncryptionParameters);                      // m Bytes

                #endregion

                #region Serialize StructureVersion, ObjectUUID and the Inner Object

                writer.WriteBytesDirect(BitConverter.GetBytes(_StructureVersion));
                ObjectUUID.Serialize(ref writer);        // n or at least 16 Bytes

                Serialize(ref writer);

                #endregion

                _TmpSerializedAGraphStructure = writer.ToArray();

                #region Encrypt
                #endregion

                #region Add IntegrityCheck

                if (myIntegrityCheckAlgorithm != null && IntegrityCheckValue_Length > 0)
                {

                    IntegrityCheckValue = myIntegrityCheckAlgorithm.GetHashValueAsByteArray(_TmpSerializedAGraphStructure);

                    // If the returned array is shorter than expected => pad with 0x00
                    // And if it is longer just copy the number of expected bytes
                    Array.Copy(IntegrityCheckValue, 0, _TmpSerializedAGraphStructure, IntegrityCheckValue_Position, IntegrityCheckValue.Length);

                }

                #endregion

                isDirty = false;

                if (myCacheSerializeData)
                    _SerializedAGraphStructure = _TmpSerializedAGraphStructure;

                return _TmpSerializedAGraphStructure;

            }

            catch (SerializationException e)
            {
                throw new SerializationException(e.Message, e);
            }
        }
Exemplo n.º 15
0
 /// <summary>
 /// This will call the normal Deserialize method and afterwards it will
 /// copy the content of all AGraphStructure and AAFSObject properties
 /// to the clone.
 /// </summary>
 /// <param name="mySerializedData">The fastserialized object as an array of bytes</param>
 /// <param name="myAAFSObject">The AAFSObject to copy the content from</param>
 public void Deserialize(Byte[] mySerializedData, IIntegrityCheck myIntegrityCheckAlgorithm, ISymmetricEncryption myEncryptionAlgorithm, AFSObject myAAFSObject)
 {
     Deserialize(mySerializedData, myIntegrityCheckAlgorithm, myEncryptionAlgorithm, false);
     CloneObjectOntology(myAAFSObject);
 }
Exemplo n.º 16
0
        public Exceptional Deserialize(Byte[] mySerializedData, IIntegrityCheck myIntegrityCheckAlgorithm, ISymmetricEncryption myEncryptionAlgorithm, Boolean myIgnoreIntegrityCheckFailures)
        {
            #region Data

            Byte[] IntegrityCheckValue;
            int IntegrityCheckValue_Length;
            Int64 IntegrityCheckValue_Position;
            Byte[] actualIntegrityCheckValue;

            Byte[] EncryptionParameters;
            int EncryptionParameters_Length;

            int DataPadding_Length;
            int AdditionalPadding_Length = 0;

            #endregion

            #region Check if data is larger than the minimum allowed size

            if (mySerializedData == null)
                throw new GraphFSException_InvalidInformationHeader("The information header is invalid!");

            if (mySerializedData.Length < 8)
                throw new GraphFSException_InvalidInformationHeader("The information header is invalid!");

            #endregion

            try
            {

                #region Init reader

                var _SerializationReader = new SerializationReader(mySerializedData);

                #endregion

                #region Read HeaderVersion

                var _NewHeaderVersion = _SerializationReader.ReadByte();

                #endregion

                #region Read Length of the Integrity Check Value

                // Multiply the value of the first byte with 8
                IntegrityCheckValue_Length = _SerializationReader.ReadByte() << 3;

                if (IntegrityCheckValue_Length > mySerializedData.Length - HeaderLength)
                    throw new GraphFSException_InvalidIntegrityCheckLengthField("The length of the integrity check value is invalid!");

                // HACK: Remeber that a IntegrityCheckValue of 0 will circumvent the whole integrity checking!
                if (myIntegrityCheckAlgorithm != null)
                    if ((IntegrityCheckValue_Length > 0) && (IntegrityCheckValue_Length != myIntegrityCheckAlgorithm.HashSize))
                        throw new GraphFSException_InvalidIntegrityCheckLengthField("The length of the integrity check value is " + IntegrityCheckValue_Length + ", but " + myIntegrityCheckAlgorithm.HashSize + " was expected!");

                #endregion

                #region Read Length of the Encryption Parameters

                // Multiply the value of the second byte with 8
                EncryptionParameters_Length = _SerializationReader.ReadByte() << 3;

                if (EncryptionParameters_Length > mySerializedData.Length - HeaderLength - IntegrityCheckValue_Length)
                    throw new GraphFSException_InvalidEncryptionParametersLengthField("The length of the encryption parameters is invalid!");

                #endregion

                #region Read Padding lengths

                DataPadding_Length = (Int32)_SerializationReader.ReadByte();
                AdditionalPadding_Length = (Int32)(256 * _SerializationReader.ReadByte() + _SerializationReader.ReadByte()) << 3;

                if ((HeaderLength + IntegrityCheckValue_Length + EncryptionParameters_Length + AdditionalPadding_Length) >= mySerializedData.Length)
                    throw new GraphFSException_InvalidAdditionalPaddingLengthField("The length of the additional padding is invalid!");

                _SerializationReader.ReadBytesDirect(2);  // Read reserved bytes

                #endregion

                #region Read Integrity Check Value and Encryption Parameters

                IntegrityCheckValue_Position = _SerializationReader.BaseStream.Position;

                if (IntegrityCheckValue_Length > 0)
                    IntegrityCheckValue = _SerializationReader.ReadBytesDirect(IntegrityCheckValue_Length);

                if (EncryptionParameters_Length > 0)
                    EncryptionParameters = _SerializationReader.ReadBytesDirect(EncryptionParameters_Length);

                #endregion

                #region Verify the integrity of the data

                if (myIntegrityCheckAlgorithm != null && IntegrityCheckValue_Length > 0)
                {

                    // Save the read IntegrityCheckValue
                    IntegrityCheckValue = new Byte[IntegrityCheckValue_Length];
                    Array.Copy(mySerializedData, IntegrityCheckValue_Position, IntegrityCheckValue, 0, IntegrityCheckValue_Length);

                    // Zero the IntegrityCheckValue within the serialized data
                    Byte[] AllZeros = new Byte[IntegrityCheckValue_Length];
                    Array.Copy(AllZeros, 0, mySerializedData, IntegrityCheckValue_Position, IntegrityCheckValue_Length);

                    // Calculate the actual IntegrityCheckValue
                    actualIntegrityCheckValue = myIntegrityCheckAlgorithm.GetHashValueAsByteArray(mySerializedData);

                    // Compare read and actual IntegrityCheckValue
                    if (IntegrityCheckValue.CompareByteArray(actualIntegrityCheckValue) != 0 && myIgnoreIntegrityCheckFailures == false)
                        throw new GraphFSException_IntegrityCheckFailed(String.Concat("The IntegrityCheck failed as ", actualIntegrityCheckValue.ToHexString(), " is not equal to the expected ", IntegrityCheckValue.ToHexString()));

                }

                #endregion

                #region Decrypt the remaining data

                //EncryptedData_Length      = (UInt64) (mySerializedData.Length - (HeaderLength + IntegrityCheckValue_Length + EncryptionParameters_Length + AdditionalPadding_Length));
                //EncryptedData             = new Byte[EncryptedData_Length];
                //Array.Copy(mySerializedData, HeaderLength + IntegrityCheckValue_Length + EncryptionParameters_Length, EncryptedData, 0, (Int64) EncryptedData_Length);

                //#endregion

                //#region Decrypt Data

                // Decrypt Data, sooon...!

                //if ( (UInt64) DataPadding_Length >= EncryptedData_Length)
                //    throw new GraphFSException_InvalidDataPaddingLengthField("The length of the data padding is invalid!");

                //DecryptedData = new Byte[EncryptedData_Length - (UInt64) DataPadding_Length];
                //Array.Copy(EncryptedData, 0, DecryptedData, 0, (Int64) (EncryptedData_Length - (UInt64) DataPadding_Length));

                #endregion

                #region Deserialize Inner Object

                _StructureVersion = BitConverter.ToUInt16(_SerializationReader.ReadBytesDirect(2), 0);
                ObjectUUID = new ObjectUUID();
                ObjectUUID.Deserialize(ref _SerializationReader); // n or at least 16 Bytes

                Deserialize(ref _SerializationReader);

                #endregion

            }

            catch (GraphFSException_IntegrityCheckFailed e)
            {
                throw new GraphFSException_IntegrityCheckFailed("The AGraphStructure could not be deserialized as its integrity is corrupted!\n\n" + e);
            }

            catch (Exception e)
            {
                throw new GraphFSException_AGraphStructureCouldNotBeDeserialized("The AGraphStructure could not be deserialized!\n\n" + e);
            }

            _SerializedAGraphStructure = mySerializedData;

            return new Exceptional();
        }
Exemplo n.º 17
0
 /// <summary>
 /// A constructor of the INode used for fast deserializing
 /// </summary>
 /// <param name="mySerializedData">A bunch of bytes[] containing the serialized INode</param>
 public INode(Byte[] mySerializedData, IIntegrityCheck myIntegrityCheckAlgorithm, ISymmetricEncryption myEncryptionAlgorithm)
 {
     Deserialize(mySerializedData, myIntegrityCheckAlgorithm, myEncryptionAlgorithm);
     _isNew = false;
 }
 public bool IsEqual(IIntegrityCheck otherCheck)
 {
     // only allow one of these checks to run.  
     return (otherCheck is CheckArtifactBindings);
 }
Exemplo n.º 19
0
 public bool IsEqual(IIntegrityCheck otherCheck)
 {
     // only allow one of these checks to run.
     return(otherCheck is CheckArtifactBindings);
 }
        internal void AddIntegrityCheck(IIntegrityCheck newCheck)
        {
            foreach (var check in _integrityChecks)
            {
                // don't add duplicate checks
                if (check.IsEqual(newCheck))
                {
                    return;
                }
            }

            _integrityChecks.Enqueue(newCheck);
        }