public ArchiveCryptManager() { path = PathOption.GetInstance(); encryptor = new EncryptionOption(); compressor = new CompressionOption(); compressAndEncrypt = new CompressAndEncryptOption(); }
public StreamInfo CreateStream( string name, CompressionOption compressionOption, EncryptionOption encryptionOption) { return((StreamInfo)_storageRootType.InvokeMember("CreateStream", InstanceMethodBindFlags, null, _storageRoot, new object[3] { name, compressionOption, encryptionOption })); }
/// <summary> /// Creates a new instance relative to the given parent /// </summary> /// <param name="parent">The parent storage</param> /// <param name="streamName">Path to stream under parent storage</param> /// <param name="compressionOption">CompressionOption</param> /// <param name="encryptionOption">EncryptionOption</param> internal StreamInfo(StorageInfo parent, string streamName, CompressionOption compressionOption, EncryptionOption encryptionOption) { // Parameter validation CU.CheckAgainstNull(parent, "parent"); CU.CheckStringAgainstNullAndEmpty(streamName, "streamName"); // Parse path relative to given parent. BuildStreamInfoRelativeToStorage(parent, streamName); _compressionOption = compressionOption; _encryptionOption = encryptionOption; _streamReference = new CompoundFileStreamReference(this.parentStorage.FullNameInternal, this.core.streamName); }
// Inspect the transforms applied this stream and retreive the compression and // RM encryption options private void EnsureTransformInformation() { if (_needToGetTransformInfo && InternalExists()) { _encryptionOption = EncryptionOption.None; _compressionOption = CompressionOption.NotCompressed; //If the StreamInfo exists we go on to check if correct transform has been //applied to the Stream DataSpaceManager dsm = parentStorage.Root.GetDataSpaceManager(); List <IDataTransform> transforms = dsm.GetTransformsForStreamInfo(this); foreach (IDataTransform dataTransform in transforms) { string id = dataTransform.TransformIdentifier as string; if (id != null) { id = id.ToUpperInvariant(); if (String.CompareOrdinal(id, RightsManagementEncryptionTransform.ClassTransformIdentifier.ToUpperInvariant()) == 0 && (dataTransform as RightsManagementEncryptionTransform) != null) { _encryptionOption = EncryptionOption.RightsManagement; } else if (String.CompareOrdinal(id, CompressionTransform.ClassTransformIdentifier.ToUpperInvariant()) == 0 && (dataTransform as CompressionTransform) != null) { // We don't persist the compression level used during compression process // When we access the stream, all we can determine is whether it is compressed or not // In all our scenarios, the level we use is Level 9 which is equivalent to Maximum _compressionOption = CompressionOption.Maximum; } } } _needToGetTransformInfo = false; } }
public StreamInfo CreateStream (string name, CompressionOption compressionOption, EncryptionOption encryptionOption) { throw new NotImplementedException (); }
/***********************************************************************/ // public Methods /// <summary> /// Creates "this" stream /// </summary> /// <param name="name">Name of stream</param> /// <param name="compressionOption">CompressionOptiont</param> /// <param name="encryptionOption">EncryptionOption</param> /// <returns>Reference to new stream</returns> public StreamInfo CreateStream( string name, CompressionOption compressionOption, EncryptionOption encryptionOption ) { CheckDisposedStatus(); //check the arguments if( null == name ) throw new ArgumentNullException("name"); // Stream names: we preserve casing, but do case-insensitive comparison (Native CompoundFile API behavior) if (((IEqualityComparer) CU.StringCaseInsensitiveComparer).Equals(name, EncryptedPackageEnvelope.PackageStreamName)) throw new ArgumentException(SR.Get(SRID.StreamNameNotValid,name)); //create a new streaminfo object StreamInfo streamInfo = new StreamInfo(this, name, compressionOption, encryptionOption); if (streamInfo.InternalExists()) { throw new IOException(SR.Get(SRID.StreamAlreadyExist)); } //Define the compression and encryption options in the dataspacemanager DataSpaceManager manager = Root.GetDataSpaceManager(); string dataSpaceLabel = null; if (manager != null) { //case : Compression option is set. Stream need to be compressed. Define compression transform. //At this time, we only treat CompressionOption - Normal and None. The rest are treated as Normal if (compressionOption != CompressionOption.NotCompressed) { //If it is not defined already, define it. if (!manager.TransformLabelIsDefined(sc_compressionTransformName)) manager.DefineTransform(CompressionTransform.ClassTransformIdentifier, sc_compressionTransformName); } //case : Encryption option is set. Stream need to be encrypted. Define encryption transform. if (encryptionOption == EncryptionOption.RightsManagement) { //If it not defined already, define it. if (!manager.TransformLabelIsDefined(EncryptedPackageEnvelope.EncryptionTransformName)) { //We really cannot define RM transform completely here because the transform initialization cannot be done here without publishlicense and cryptoprovider. //However it will always be defined because this method is accessed only through an EncryptedPackageEnvelope and RM transform is always defined in EncryptedPackageEnvelope.Create() throw new SystemException(SR.Get(SRID.RightsManagementEncryptionTransformNotFound)); } } //Now find the dataspace label that we need to define these transforms in. //CASE: When both CompressionOption and EncryptionOption are set if ( (compressionOption != CompressionOption.NotCompressed) && (encryptionOption == EncryptionOption.RightsManagement) ) { dataSpaceLabel = sc_dataspaceLabelRMEncryptionNormalCompression; if (!manager.DataSpaceIsDefined(dataSpaceLabel)) { string[] transformStack = new string[2]; //compress the data first. then encrypt it. This ordering will cause the content to be compressed, then encrypted, then written to the stream. transformStack[0] = EncryptedPackageEnvelope.EncryptionTransformName; transformStack[1] = sc_compressionTransformName; manager.DefineDataSpace(transformStack, dataSpaceLabel); } } //CASE : when CompressionOption alone is set else if ( (compressionOption != CompressionOption.NotCompressed) && (encryptionOption == EncryptionOption.None) ) { dataSpaceLabel = sc_dataspaceLabelNoEncryptionNormalCompression; if (!manager.DataSpaceIsDefined(dataSpaceLabel)) { string[] transformStack = new string[1]; transformStack[0] = sc_compressionTransformName; manager.DefineDataSpace(transformStack, dataSpaceLabel); } } //CASE : when EncryptionOption alone is set else if (encryptionOption == EncryptionOption.RightsManagement) { dataSpaceLabel = EncryptedPackageEnvelope.DataspaceLabelRMEncryptionNoCompression; if (!manager.DataSpaceIsDefined(dataSpaceLabel)) { string[] transformStack = new string[1]; transformStack[0] = EncryptedPackageEnvelope.EncryptionTransformName; manager.DefineDataSpace(transformStack, dataSpaceLabel); } } //All the other cases are not handled at this point. } //create the underlying stream if (null == dataSpaceLabel) streamInfo.Create(); //create the stream with default parameters else streamInfo.Create(dataSpaceLabel); //create the stream in the defined dataspace return streamInfo; }
// Inspect the transforms applied this stream and retreive the compression and // RM encryption options private void EnsureTransformInformation() { if (_needToGetTransformInfo && InternalExists()) { _encryptionOption = EncryptionOption.None; _compressionOption = CompressionOption.NotCompressed; //If the StreamInfo exists we go on to check if correct transform has been //applied to the Stream DataSpaceManager dsm = parentStorage.Root.GetDataSpaceManager(); List<IDataTransform> transforms = dsm.GetTransformsForStreamInfo(this); foreach (IDataTransform dataTransform in transforms) { string id = dataTransform.TransformIdentifier as string; if (id != null) { id = id.ToUpperInvariant(); if (String.CompareOrdinal(id, RightsManagementEncryptionTransform.ClassTransformIdentifier.ToUpperInvariant()) == 0 && (dataTransform as RightsManagementEncryptionTransform) != null) { _encryptionOption = EncryptionOption.RightsManagement; } else if (String.CompareOrdinal(id, CompressionTransform.ClassTransformIdentifier.ToUpperInvariant()) == 0 && (dataTransform as CompressionTransform) != null) { // We don't persist the compression level used during compression process // When we access the stream, all we can determine is whether it is compressed or not // In all our scenarios, the level we use is Level 9 which is equivalent to Maximum _compressionOption = CompressionOption.Maximum; } } } _needToGetTransformInfo = false; } }
/// <summary> /// Creates a new instance relative to the given parent /// </summary> /// <param name="parent">The parent storage</param> /// <param name="streamName">Path to stream under parent storage</param> /// <param name="compressionOption">CompressionOption</param> /// <param name="encryptionOption">EncryptionOption</param> internal StreamInfo( StorageInfo parent, string streamName, CompressionOption compressionOption, EncryptionOption encryptionOption ) { // Parameter validation CU.CheckAgainstNull( parent, "parent" ); CU.CheckStringAgainstNullAndEmpty( streamName, "streamName" ); // Parse path relative to given parent. BuildStreamInfoRelativeToStorage( parent, streamName); _compressionOption = compressionOption; _encryptionOption = encryptionOption; _streamReference = new CompoundFileStreamReference(this.parentStorage.FullNameInternal, this.core.streamName); }
private static IOption CreateShellOptionInternal(Category shellSubCategory, OptionDefType uiOption, string defaultValue) { IOption shellOption = null; string s = !string.IsNullOrEmpty(string.Concat(uiOption.Text)) ? string.Concat(uiOption.Text) : defaultValue; if (string.IsNullOrEmpty(s)) { s = string.Empty; } bool canOverride = uiOption.IsOverrideAllowed; switch (uiOption.DataType) { case OptionDataTypeEnum.Boolean: { bool val = GetBool(s); shellOption = new BoolOption(uiOption.Name, val, val, canOverride) { DisplayName = uiOption.DisplayText, Description = uiOption.DisplayText, Category = shellSubCategory == null ? null : shellSubCategory.Parent, SubCategory = shellSubCategory }; break; } case OptionDataTypeEnum.Integer: { int val = GetInt(s); shellOption = new IntegerOption(uiOption.Name, val, val, canOverride) { DisplayName = uiOption.DisplayText, Description = uiOption.DisplayText, Category = shellSubCategory == null ? null : shellSubCategory.Parent, SubCategory = shellSubCategory }; break; } case OptionDataTypeEnum.String: { if (uiOption.Encrypted) { shellOption = new EncryptionOption(uiOption.Name, s, s, canOverride) { DisplayName = uiOption.DisplayText, Description = uiOption.DisplayText, Category = shellSubCategory == null ? null : shellSubCategory.Parent, SubCategory = shellSubCategory }; } else { shellOption = new StringOption(uiOption.Name, s, s, canOverride) { DisplayName = uiOption.DisplayText, Description = uiOption.DisplayText, Category = shellSubCategory == null ? null : shellSubCategory.Parent, SubCategory = shellSubCategory, IsPrimaryKey = uiOption.IsPrimaryKey }; } break; } case OptionDataTypeEnum.Color: { var val = GetColor(s); shellOption = new ColorOption(uiOption.Name, val, val, canOverride) { DisplayName = uiOption.DisplayText, Description = uiOption.DisplayText, Category = shellSubCategory == null ? null : shellSubCategory.Parent, SubCategory = shellSubCategory }; break; } case OptionDataTypeEnum.KeyValueRange: { int val = GetInt(s); shellOption = new EnumOption(uiOption.Name, val, val, canOverride, GetEnumValues(uiOption)) { DisplayName = uiOption.DisplayText, Description = uiOption.DisplayText, Category = shellSubCategory == null ? null : shellSubCategory.Parent, SubCategory = shellSubCategory }; break; } case OptionDataTypeEnum.Format: case OptionDataTypeEnum.Range: default: { // do nothing. these need to be converted #if DEBUG throw new NotImplementedException(); #else break; #endif } } return shellOption; }
/// <summary> /// /// </summary> /// <param name="message"></param> /// <param name="exchangeName"></param> /// <param name="basicProperties"></param> private void Write(MessageBase message, string exchangeName, IBasicProperties basicProperties, EncryptionOption encryptionOption, MessageTagCollection tags) { if (message == null) { throw new ArgumentNullException(nameof(message)); } //message.ClientName = _clientName; var envelope = MessageEnvelope.WrapMessage(message, "", this.ParentMessageClient, encryptionOption); byte[] hashedMessage = envelope.Serialize(); //TODO: Move this into the message serialization? basicProperties.Headers = new Dictionary <string, object>(); basicProperties.Headers.Add(new MessageSenderTag(this._clientName).GetMangledTagAndValue(), ""); foreach (var tag in tags) { string mangledTag = tag.GetMangledTagName(); if (!basicProperties.Headers.ContainsKey(mangledTag)) { basicProperties.Headers.Add(mangledTag, ""); } // If this is a tag with a value (not just a tag) if (tag.HasValue) { basicProperties.Headers.Add(tag.GetMangledTagAndValue(), ""); } } lock (Channel) { Channel.BasicPublish( exchange: exchangeName, routingKey: queueInfo.QueueName, basicProperties: basicProperties, hashedMessage); } }
/// <summary> /// /// </summary> /// <param name="message"></param> /// <param name="exchangeName"></param> private void Write(MessageBase message, string exchangeName, EncryptionOption encryptionOptions, MessageTagCollection tags) { Write(message, exchangeName, Channel.CreateBasicProperties(), encryptionOptions, tags); }
public static MessageEnvelope WrapMessage(MessageBase message, string recipientIdentityHash, MessageClientBase messageClient, EncryptionOption encryptionOption) { if (string.IsNullOrEmpty(recipientIdentityHash) && encryptionOption == EncryptionOption.EncryptWithPrivateKey) { throw new ArgumentOutOfRangeException(nameof(recipientIdentityHash), $"{nameof(recipientIdentityHash)} cannot be empty if encryption is set to private key."); } if (messageClient == null) { throw new ArgumentNullException(nameof(messageClient)); } var wrapper = new MessageEnvelope(); wrapper.Message = message; wrapper.SenderIdentityHash = messageClient.Identity.IdentityHash; wrapper._messageClient = messageClient; wrapper._encryptionOption = encryptionOption; wrapper.RecipientIdentityHash = recipientIdentityHash; wrapper.Timestamp = DateTime.Now; return(wrapper); }
/// <summary> /// CreateStream /// </summary> /// <param name="name"></param> /// <param name="compressionOption"></param> /// <param name="encryptionOption"></param> /// <returns></returns> public StreamInfo CreateStream(string name, CompressionOption compressionOption, EncryptionOption encryptionOption) { object retVal = null; try { retVal = _storageRootType.InvokeMember("CreateStream", InstanceMethodBindFlags, null, _storageRoot, new object[3] { name, compressionOption, encryptionOption }); } catch (TargetInvocationException e) { throw e.InnerException; } return((StreamInfo)retVal); }
public StreamInfo CreateStream(string name, CompressionOption compressionOption, EncryptionOption encryptionOption) { throw new NotImplementedException(); }
/// <summary> /// Serializes the message into a binary format. /// </summary> /// <returns></returns> internal byte[] Serialize(MessageClientBase messageClient, string clientName, EncryptionOption encryptionOption) { var formatter = new BinaryFormatter(); byte[] data; using (MemoryStream stream = new MemoryStream()) { formatter.Serialize(stream, this); stream.Seek(0, SeekOrigin.Begin); data = new byte[stream.Length]; if (stream.Read(data, 0, data.Length) != data.Length) { throw new Exception(); } } byte[] iv = null; MessageSerializationWrapper header; if (encryptionOption == EncryptionOption.EncryptWithPrivateKey) { (data, iv) = messageClient.EncryptDataWithClientKey(data, clientName); } else if (encryptionOption == EncryptionOption.EncryptWithSystemSharedKey) { (data, iv) = messageClient.EncryptDataWithSystemSharedKey(data); } byte[] signature = messageClient.SignData(data); if (encryptionOption != EncryptionOption.None) { header = new MessageSerializationWrapper(signature, iv, encryptionOption); } else { header = new MessageSerializationWrapper(signature); } byte[] output = new byte[header.Length + data.Length]; header.CopyTo(output, 0); data.CopyTo(output, header.Length); return(output); }