standard key set
Inheritance: IKeySet
Exemple #1
0
 public void TestPublicKeyExport()
 {
     var ks = new KeySet(Util.TestDataPath(TEST_DATA, "rsa.public"));
     var path = Path.Combine(Path.GetTempPath(), "dummy.pem");
     Console.WriteLine(path);
     ks.ExportPrimaryAsPkcs(path, () => "dummy");
 }
Exemple #2
0
        public override int Run(string[] remainingArguments)
        {
            var ret = 0;
            Crypter crypter = null;
            IKeySet ks = new KeySet(_location);

            Func<string> prompt = CachedPrompt.Password(Util.PromptForPassword).Prompt;

            IDisposable dks = null;
            if (!String.IsNullOrWhiteSpace(_crypterLocation))
            {
                if (_password)
                {
                    var cks = new PbeKeySet(_crypterLocation, prompt);
                    crypter = new Crypter(cks);
                    dks = cks;
                }
                else
                {
                    crypter = new Crypter(_crypterLocation);
                }
                ks = new EncryptedKeySet(ks, crypter);
            }
            else if (_password)
            {
                ks = new PbeKeySet(ks, prompt);
            }
            var d2ks = ks as IDisposable;

            using (crypter)
            using (dks)
            using (d2ks)
            using (var keySet = new MutableKeySet(ks))
            {
                var pubKeySet = keySet.PublicKey();
                if (pubKeySet != null)
                {
                    using (pubKeySet)
                    {
                        IKeySetWriter writer = new KeySetWriter(_destination, overwrite: false);

                        if (pubKeySet.Save(writer))
                        {
                            Console.WriteLine(Localized.MsgNewPublicKeySet);
                            ret = 0;
                        }
                        else
                        {
                            ret = -1;
                        }
                    }
                }
                else
                {
                    ret = -1;
                }
            }

            return ret;
        }
Exemple #3
0
        public void TestAddPadding()
        {
            string result;

            var path = Util.TestDataPath(TEST_DATA, "padding");
            var path2 = Util.TestDataPath(TEST_DATA, "padding.public");

            if (Directory.Exists(path))
                Directory.Delete(path, true);
            if (Directory.Exists(path2))
                Directory.Delete(path2, true);

            result = Util.KeyczarTool(create: null, location: path, purpose: "crypt", asymmetric: null);

            Expect(result, Is.StringContaining(KeyczarTool.Localized.MsgCreatedKeySet));

            result = Util.KeyczarTool(addkey: null, location: path, status: "primary", padding: "PKCS", size: "1024");

            Expect(result, Is.StringContaining(KeyczarTool.Localized.MsgCreatedKey));

            var ks = new KeySet(path);
            dynamic key = ks.GetKey(1);
            Expect((int) key.Size, Is.EqualTo(1024));
            Expect((string) key.Padding, Is.EqualTo("PKCS"));

            result = Util.KeyczarTool(pubkey: null, location: path, destination: path2);

            Expect(result, Is.StringContaining(KeyczarTool.Localized.MsgNewPublicKeySet));

            var ks2 = new KeySet(path);
            dynamic key2 = ks2.GetKey(1);
            Expect(key2.Size, Is.EqualTo(1024));
            Expect(key2.Padding, Is.EqualTo("PKCS"));

            Directory.Delete(path2, true);
            Directory.Delete(path, true);
        }
Exemple #4
0
        public void TestPublicVerifySizes(String subDir, string nestDir)
        {
            var subPath = Util.TestDataPath(TEST_DATA, subDir, nestDir);
            var ks = new KeySet(subPath);
            using (var verifier = new Verifier(subPath))
            using (var publicVerifier = new Verifier(subPath + ".public"))
            {
                foreach (var size in ks.Metadata.KeyType.KeySizeOptions)
                {
                    var activeSignature =
                        (WebBase64) File.ReadAllLines(Path.Combine(subPath, String.Format("{0}.out", size))).First();

                    Expect(verifier.Verify(input, activeSignature), Is.True);
                    Expect(publicVerifier.Verify(input, activeSignature), Is.True);
                }
            }
        }
Exemple #5
0
 public void TestSymetricKeyExport()
 {
     var ks = new KeySet(Util.TestDataPath(TEST_DATA, "aes"));
     Expect(() => ks.ExportPrimaryAsPkcs(Path.Combine(Path.GetTempPath(), "dummy.pem"), () => "dummy"),
            Throws.InstanceOf<InvalidKeyTypeException>());
 }
Exemple #6
0
        public void TestDemoteRevoke()
        {
            string result;

            var path = Util.TestDataPath(TEST_DATA, "demote");

            if (Directory.Exists(path))
                Directory.Delete(path, true);

            result = Util.KeyczarTool(create: null, location: path, purpose: "crypt");

            Expect(result, Is.StringContaining(KeyczarTool.Localized.MsgCreatedKeySet));

            result = Util.KeyczarTool(addkey: null, location: path, status: "primary");

            Expect(result, Is.StringContaining(KeyczarTool.Localized.MsgCreatedKey));

            result = Util.KeyczarTool(demote: null, location: path, version: 1);
            Expect(result, Is.StringContaining("ACTIVE"));

            result = Util.KeyczarTool(demote: null, location: path, version: 1);
            Expect(result, Is.StringContaining("INACTIVE"));

            result = Util.KeyczarTool(revoke: null, location: path, version: 1);
            Expect(result, Is.StringContaining(KeyczarTool.Localized.MsgRevokedVersion));

            var ks = new KeySet(path);
            Expect(ks.Metadata.Versions.Any(), Is.False);

            Directory.Delete(path, true);
        }