public void TestPEM()
 {
     byte[] p7bData = File.ReadAllBytes(@"Certificates\Bundles\bundlePEM.p7b");
     AnchorBundle bundle = null;
     Assert.DoesNotThrow(() => bundle = new AnchorBundle(p7bData));
     Assert.True(!bundle.Certificates.IsNullOrEmpty());
 }
Beispiel #2
0
        public void CreateBundleWithMetadataTest()
        {
            //Arrange
            Bundler bundle = new Bundler();
            const string outputFileName = @"TestBundleWithMetadata.p7b";

            //Act
            IResourceProvider resourceProvider =
                new FileResourceProvider(Path.Combine(Directory.GetCurrentDirectory()
                                                  , @"Certificates\nhind\IncomingAnchors"),
                                     Path.Combine(Directory.GetCurrentDirectory(), outputFileName)
                                     , null
                                     , @"<TrustBundle><Profile>The Good Guys</Profile><DistributionPoint>http://bundler.lab/testComunity/pack.p7b</DistributionPoint></TrustBundle>");
            byte[] cmsdata = bundle.Create(resourceProvider);

            //Assert (Using agent bundler resolver code)
            Assert.DoesNotThrow(() => resourceProvider.StoreBundle(cmsdata));
            byte[] p7BData = File.ReadAllBytes(Path.Combine(Directory.GetCurrentDirectory(), outputFileName));
            AnchorBundle anchorBundle = null;
            Assert.DoesNotThrow(() => anchorBundle = new AnchorBundle(p7BData));
            Assert.True(!anchorBundle.Certificates.IsNullOrEmpty());
            Assert.Equal(4, anchorBundle.Certificates.Count);
            Assert.NotNull(anchorBundle.Metadata);
            Assert.Equal(@"<TrustBundle><Profile>The Good Guys</Profile><DistributionPoint>http://bundler.lab/testComunity/pack.p7b</DistributionPoint></TrustBundle>", anchorBundle.Metadata);

        }
Beispiel #3
0
        public void CreateBundleTest()
        {
            //Arrange
            Bundler bundle = new Bundler();
            const string outputFileName = @"TestBundle.p7m";

            //Act
            IResourceProvider resourceProvider =
                new FileResourceProvider(
                    Path.Combine(Directory.GetCurrentDirectory()
                    , @"Certificates\nhind\IncomingAnchors")
                    , Path.Combine(Directory.GetCurrentDirectory()
                    , outputFileName));
            byte[] cmsdata = bundle.Create(resourceProvider);

            //Assert (Using agent bundler resolver code)
            Assert.DoesNotThrow(() => resourceProvider.StoreBundle(cmsdata));
            byte[] p7BData = File.ReadAllBytes(Path.Combine(Directory.GetCurrentDirectory(), outputFileName));
            AnchorBundle anchorBundle = null;
            Assert.DoesNotThrow(() => anchorBundle = new AnchorBundle(p7BData));
            Assert.True(!anchorBundle.Certificates.IsNullOrEmpty());
            Assert.Equal(4, anchorBundle.Certificates.Count);
            Assert.Null(anchorBundle.Metadata);
            
            
        }
 public void TestWithMetadata()
 {
     byte[] p7bData = File.ReadAllBytes(@"Certificates\Bundles\bundleWithMetadata.p7b");
     AnchorBundle bundle = null;
     Assert.DoesNotThrow(() => bundle = new AnchorBundle(p7bData));
     Assert.True(!bundle.Certificates.IsNullOrEmpty());
     Assert.True(bundle.Certificates.Count == 2);
     Assert.True(!string.IsNullOrEmpty(bundle.Metadata));
 }
 public void TestSigned()
 {
     X509Certificate2 signingCert = AgentTester.LoadPrivateCerts("redmond").First();
     X509Certificate2Collection certs = AgentTester.LoadPrivateCerts("nhind").GetAllCertificates();
                 
     byte[] p7sData = null;
     Assert.DoesNotThrow(() => p7sData = AnchorBundle.CreateSigned(certs, signingCert));
     Assert.True(!p7sData.IsNullOrEmpty());
     
     AnchorBundle bundle = null;
     Assert.DoesNotThrow(() => bundle = new AnchorBundle(p7sData, true));
     Assert.True(!bundle.Certificates.IsNullOrEmpty());
     Assert.True(certs.Count == bundle.Certificates.Count);
 }
        public void CreateBundleTest()
        {
            BundleAnchorsCommand cmd = new BundleAnchorsCommand();
            string[] ignoreArray = new string[] {"Direct.Drhisp.Com Root CAKey.der"};
            cmd.Name = @".\Certificates\nhind\IncomingAnchors";
            cmd.Ignore = ignoreArray;

            IEnumerator result = cmd.Invoke().GetEnumerator();
            result.MoveNext();
            byte[] cmsdata = (byte [])result.Current;


            //Assert (Using agent bundler resolver code)
            AnchorBundle anchorBundle = null;
            Assert.DoesNotThrow(() => anchorBundle = new AnchorBundle(cmsdata));
            Assert.True(!anchorBundle.Certificates.IsNullOrEmpty());
            Assert.Equal(4, anchorBundle.Certificates.Count);
            Assert.Null(anchorBundle.Metadata);
        }
        public void CreateBundleWithMetadataTest()
        {
            BundleAnchorsCommand cmd = new BundleAnchorsCommand();
            string[] ignoreArray = new string[] { "Direct.Drhisp.Com Root CAKey.der" };
            cmd.Name = @".\Certificates\nhind\IncomingAnchors";
            cmd.Ignore = ignoreArray;
            cmd.Metadata = @"<TrustBundle><Profile>The Good Guys</Profile><DistributionPoint>http://bundler.lab/testComunity/pack.p7b</DistributionPoint></TrustBundle>";

            IEnumerator result = cmd.Invoke().GetEnumerator();
            result.MoveNext();
            byte[] cmsdata = (byte[])result.Current;


            //Assert (Using agent bundler resolver code)
            AnchorBundle anchorBundle = null;
            Assert.DoesNotThrow(() => anchorBundle = new AnchorBundle(cmsdata));
            Assert.True(!anchorBundle.Certificates.IsNullOrEmpty());
            Assert.Equal(4, anchorBundle.Certificates.Count);
            Assert.Equal(@"<TrustBundle><Profile>The Good Guys</Profile><DistributionPoint>http://bundler.lab/testComunity/pack.p7b</DistributionPoint></TrustBundle>", anchorBundle.Metadata);

        }
        /// <summary>
        /// Downloads the bundle and returns the certificates contained within.
        /// Does not validate signatures
        /// </summary>
        /// <param name="bundleUri">Uri from where to retreive the bundle</param>
        /// <returns>Collection of X509 Certificates</returns>
        public X509Certificate2Collection DownloadCertificates(Uri bundleUri)
        {
            AnchorBundle bundle = this.Download(bundleUri);

            return(bundle.Certificates);
        }
        public void CreateSigneBundleTest()
        {
            BundleAnchorsCommand cmd = new BundleAnchorsCommand();
            string[] ignoreArray = new string[] { "Direct.Drhisp.Com Root CAKey.der" };
            cmd.Name = @".\Certificates\nhind\IncomingAnchors";
            cmd.Ignore = ignoreArray;

            IEnumerator result = cmd.Invoke().GetEnumerator();
            result.MoveNext();
           

            SignBundleCommand signCmd = new SignBundleCommand();
            
            var secString = new SecureString();
            foreach (var secchar in "passw0rd!".ToCharArray())
            {
                secString.AppendChar(secchar);
            }
            signCmd.Name = @".\Certificates\redmond\Private\redmond.pfx";
            signCmd.PassKey = secString;
            signCmd.Bundle = (byte[])result.Current;

            result = signCmd.Invoke().GetEnumerator();
            result.MoveNext();
            byte[] signedCmsdata = (byte[])result.Current;

            //Assert (Using agent bundler resolver code)
            AnchorBundle anchorBundle = null;
            Assert.DoesNotThrow(() => anchorBundle = new AnchorBundle(signedCmsdata, true));
            Assert.True(!anchorBundle.Certificates.IsNullOrEmpty());
            Assert.Equal(4, anchorBundle.Certificates.Count);
            Assert.Null(anchorBundle.Metadata);
        }
Beispiel #10
0
        public void CreateSignedBundleTest()
        {
            //Arrange
            Bundler bundle = new Bundler();
            const string outputFileName = @"TestBundleWithMetadata.p7m";

            var secString = new SecureString();
            foreach (var secchar in "passw0rd!".ToCharArray())
            {
                secString.AppendChar(secchar);
            }


            //Act
            IResourceProvider resourceProvider =
                new FileResourceProvider(
                    Path.Combine(Directory.GetCurrentDirectory(), @"Certificates\nhind\IncomingAnchors")
                    , Path.Combine(Directory.GetCurrentDirectory(), outputFileName));
            ISignProvider signProvider =
                new FileSignerProvider(
                    Path.Combine(Directory.GetCurrentDirectory(), @"Certificates\redmond\Private\redmond.pfx"),
                    secString);
            byte[] cmsdata = bundle.Create(resourceProvider, signProvider);

            //Assert (Using agent bundler resolver code)
            Assert.DoesNotThrow(() => resourceProvider.StoreBundle(cmsdata));
            byte[] p7BData = File.ReadAllBytes(Path.Combine(Directory.GetCurrentDirectory(), outputFileName));
            AnchorBundle anchorBundle = null;
            Assert.DoesNotThrow(() => anchorBundle = new AnchorBundle(p7BData, true));
            Assert.True(!anchorBundle.Certificates.IsNullOrEmpty());
            Assert.Equal(4, anchorBundle.Certificates.Count);
            Assert.Null(anchorBundle.Metadata);


        }