Ejemplo n.º 1
0
        public void TrustPackageWithUpdate()
        {
            string package    = Path.Combine(DataDirectory, "Package", "signedpackage.zip");
            string temp       = Path.Combine(TempDirectory, "signedpackage.zip");
            string keyFile    = Path.Combine(DataDirectory, "Key", "private.asc");
            string key        = File.ReadAllText(keyFile);
            string passphrase = File.ReadAllText(Path.Combine(DataDirectory, "Key", "passphrase.txt"));
            string publicKey  = File.ReadAllText(Path.Combine(DataDirectory, "Key", "public.asc"));

            File.Copy(package, temp);

            Truster.Updated += Truster_Updated;

            Exception ex = Record.Exception(() => Truster.TrustPackage(temp, key, passphrase));

            Assert.Null(ex);

            bool verified = false;

            Packaging.Operations.PackageVerifier verifier = new Packaging.Operations.PackageVerifier();
            verifier.TrustPGPPublicKey = publicKey;

            ex = Record.Exception(() => verified = verifier.VerifyPackage(temp));

            Assert.Null(ex);
            Assert.True(verified);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="PackageVerifier"/> class.
        /// </summary>
        public PackageVerifier()
        {
            Verifier = new Packaging.Operations.PackageVerifier();

            Uri    codeBaseUri  = new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
            string codeBasePath = Uri.UnescapeDataString(codeBaseUri.AbsolutePath);
            string dirPath      = Path.GetDirectoryName(codeBasePath);

            DataDirectory = Path.Combine(dirPath, "Data");

            TempDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

            Directory.CreateDirectory(TempDirectory);
        }
Ejemplo n.º 3
0
        public void CreatePackageNoChecksum()
        {
            string manifest = Path.Combine(DataDirectory, "Manifest", "nochecksummanifest.json");
            string package  = Path.Combine(TempDirectory, "package.zip");

            Exception ex = Record.Exception(() => Creator.CreatePackage(PayloadDirectory, manifest, package));

            Assert.Null(ex);

            bool verified = false;

            ex = Record.Exception(() => verified = new Packaging.Operations.PackageVerifier().VerifyPackage(package));

            Assert.Null(ex);
            Assert.True(verified);
        }
Ejemplo n.º 4
0
        public void CreatePackagePackageExistsOverwrite()
        {
            string manifest = Path.Combine(DataDirectory, "Manifest", "manifest.json");
            string package  = Path.Combine(TempDirectory, "package.zip");

            File.WriteAllText(package, string.Empty);

            Exception ex = Record.Exception(() => Creator.CreatePackage(PayloadDirectory, manifest, package, true));

            Assert.Null(ex);

            bool verified = false;

            ex = Record.Exception(() => verified = new Packaging.Operations.PackageVerifier().VerifyPackage(package));

            Assert.Null(ex);
            Assert.True(verified);
        }
Ejemplo n.º 5
0
        public void CreateSignedPackage()
        {
            string manifest        = Path.Combine(DataDirectory, "Manifest", "manifest.json");
            string package         = Path.Combine(TempDirectory, "signedpackage.zip");
            string privateKeyFile  = Path.Combine(DataDirectory, "Key", "private.asc");
            string privateKey      = File.ReadAllText(privateKeyFile);
            string passphrase      = File.ReadAllText(Path.Combine(DataDirectory, "Key", "passphrase.txt"));
            string keybaseUsername = File.ReadAllText(Path.Combine(DataDirectory, "Key", "keybaseUsername.txt"));

            Exception ex = Record.Exception(() => Creator.CreatePackage(PayloadDirectory, manifest, package, true, privateKey, passphrase, keybaseUsername));

            Assert.Null(ex);

            bool verified = false;

            ex = Record.Exception(() => verified = new Packaging.Operations.PackageVerifier().VerifyPackage(package));

            Assert.Null(ex);
            Assert.True(verified);
        }