Ejemplo n.º 1
0
        public void CheckSignAttribute()
        {
            string outputPath = TestHelper.OutputPath;
            string xml        = string.Format(
                @"<?xml version='1.0'?>" +
                @"<Obfuscator>" +
                @"<Var name='InPath' value='{0}' />" +
                @"<Var name='OutPath' value='{1}' />" +
                @"<Var name='KeyFile' value='auto' />" +
                @"<Module file='$(InPath){2}AssemblyForSigning2.dll' />" +
                @"</Obfuscator>", TestHelper.InputPath, outputPath, Path.DirectorySeparatorChar);

            TestHelper.CleanInput();

            // build it with the keyfile option (embeds the public key, and signs the assembly)
            TestHelper.BuildAssembly("AssemblyForSigning2", string.Empty, null, false);

            var map      = TestHelper.Obfuscate(xml).Mapping;
            var assembly = Path.Combine(TestHelper.InputPath, "AssemblyForSigning2.dll");
            AssemblyDefinition inAssmDef = AssemblyDefinition.ReadAssembly(assembly);

            Assert.True(inAssmDef.MainModule.Attributes.HasFlag(ModuleAttributes.StrongNameSigned));

            AssemblyDefinition outAssmDef =
                AssemblyDefinition.ReadAssembly(Path.Combine(outputPath, "AssemblyForSigning2.dll"));

            Assert.True(outAssmDef.MainModule.Attributes.HasFlag(ModuleAttributes.StrongNameSigned));
        }
Ejemplo n.º 2
0
        // [Fact] no longer valid due to Cecil changes
        public void CheckCanObfuscateDelaySigned()
        {
            string xml = String.Format(
                @"<?xml version='1.0'?>" +
                @"<Obfuscator>" +
                @"<Var name='InPath' value='{0}' />" +
                @"<Var name='OutPath' value='{1}' />" +
                @"<Module file='$(InPath){2}AssemblyForSigning.dll' />" +
                @"</Obfuscator>", TestHelper.InputPath, TestHelper.OutputPath, Path.DirectorySeparatorChar);

            TestHelper.CleanInput();

            // build it with the delaysign option (embeds the public key, reserves space for the signature, but does not sign)
            TestHelper.BuildAssembly("AssemblyForSigning", String.Empty, "/delaysign /keyfile:" + Path.Combine(TestHelper.InputPath, @"SigningKey.snk"));

            // this should not throw
            TestHelper.Obfuscate(xml);
        }
Ejemplo n.º 3
0
        public void CheckCannotObfuscateSigned()
        {
            string xml = String.Format(
                @"<?xml version='1.0'?>" +
                @"<Obfuscator>" +
                @"<Var name='InPath' value='{0}' />" +
                @"<Var name='OutPath' value='{1}' />" +
                @"<Module file='$(InPath){2}AssemblyForSigning.dll' />" +
                @"</Obfuscator>", TestHelper.InputPath, TestHelper.OutputPath, Path.DirectorySeparatorChar);

            TestHelper.CleanInput();

            // build it with the keyfile option (embeds the public key, and signs the assembly)
            TestHelper.BuildAssembly("AssemblyForSigning", String.Empty, "/keyfile:" + Path.Combine(TestHelper.InputPath, @"SigningKey.snk"));
            var exception = Assert.Throws <ObfuscarException>(() => { TestHelper.Obfuscate(xml); });

            Assert.Equal("Obfuscating a signed assembly would result in an invalid assembly:  AssemblyForSigning; use the KeyFile property to set a key to use", exception.Message);
        }
Ejemplo n.º 4
0
        public void CheckCannotObfuscateSigned( )
        {
            string xml = String.Format(
                @"<?xml version='1.0'?>" +
                @"<Obfuscator>" +
                @"<Var name='InPath' value='{0}' />" +
                @"<Var name='OutPath' value='{1}' />" +
                @"<Module file='$(InPath)\AssemblyForSigning.dll' />" +
                @"</Obfuscator>", TestHelper.InputPath, TestHelper.OutputPath);

            TestHelper.CleanInput( );

            // build it with the keyfile option (embeds the public key, and signs the assembly)
            TestHelper.BuildAssembly("AssemblyForSigning", String.Empty, "/keyfile:" + TestHelper.InputPath + @"\SigningKey.snk");

            TestUtils.AssertThrows(delegate { TestHelper.Obfuscate(xml); }, typeof(ApplicationException),
                                   "signed assembly", "invalid", "AssemblyForSigning");
        }