From b678db282ad99ca0d4eddcaad3620ea62b412377 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Fri, 15 May 2020 22:48:05 -0500 Subject: [PATCH] work on keyring --- tests/keyring/add.cs | 48 +++++++++++++++++++ .../chestcrypto/identity/ephemeralkey.cs | 24 ++++++++++ .../chestcrypto/identity/identity.cs | 36 ++++++++++++++ .../{ => keys}/doublekey/exceptions.cs | 0 .../{ => keys}/doublekey/private.cs | 0 .../{ => keys}/doublekey/public.cs | 0 .../chestcrypto/{ => keys}/keygen.cs | 0 treasurechest/keyring/file.cs | 18 +++++++ treasurechest/keyring/keyring.cs | 19 +++++++- 9 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 tests/keyring/add.cs create mode 100644 treasurechest/chestcrypto/identity/ephemeralkey.cs create mode 100644 treasurechest/chestcrypto/identity/identity.cs rename treasurechest/chestcrypto/{ => keys}/doublekey/exceptions.cs (100%) rename treasurechest/chestcrypto/{ => keys}/doublekey/private.cs (100%) rename treasurechest/chestcrypto/{ => keys}/doublekey/public.cs (100%) rename treasurechest/chestcrypto/{ => keys}/keygen.cs (100%) create mode 100644 treasurechest/keyring/file.cs diff --git a/tests/keyring/add.cs b/tests/keyring/add.cs new file mode 100644 index 0000000..9584744 --- /dev/null +++ b/tests/keyring/add.cs @@ -0,0 +1,48 @@ +using NUnit.Framework; +using System; +using System.IO; +using Sodium; +using System.Collections.Generic; +using keyring; +using chestcrypto; + +namespace KeyRingTests +{ + public class Tests + { + [SetUp] + public void Setup() + { + } + + [Test] + public void TestKeyRingStore() + { + string tempFile = Path.GetTempFileName(); + KeyRing keyRing = new KeyRing(); + byte[] signingKey = PublicKeyAuth.GenerateKeyPair().PublicKey; + byte[] encryptionKey = PublicKeyBox.GenerateKeyPair().PublicKey; + + byte[] combinedKey = new byte[signingKey.Length + encryptionKey.Length]; + Buffer.BlockCopy(signingKey, 0, combinedKey, 0, signingKey.Length); + Buffer.BlockCopy(encryptionKey, 0, combinedKey, signingKey.Length, encryptionKey.Length); + DoublePublicKey combo = new DoublePublicKey(signingKey, encryptionKey); + keyRing.addPublicKey(combo); + + List storedKeys = keyRing.getIdentityPublicKeys(); + bool success = false; + storedKeys.ForEach(delegate(byte[] key) + { + if (key.Equals(combinedKey)){ + success = true; + } + }); + if (! success){ + Assert.Fail(); + } + + + } + + } +} \ No newline at end of file diff --git a/treasurechest/chestcrypto/identity/ephemeralkey.cs b/treasurechest/chestcrypto/identity/ephemeralkey.cs new file mode 100644 index 0000000..c6e2452 --- /dev/null +++ b/treasurechest/chestcrypto/identity/ephemeralkey.cs @@ -0,0 +1,24 @@ +namespace chestcrypto{ + + namespace identity{ + internal class EphemeralKey{ + + private int epochTime; + private int secondsToExpire; + private byte[] key = new byte[32]; + private bool isPrivate; + + private Identity identity; + + public EphemeralKey(Identity user){ + identity = user; + } + public EphemeralKey(Identity identity, byte[] key, int secondsToExpire){ + + } + + + } + } + +} \ No newline at end of file diff --git a/treasurechest/chestcrypto/identity/identity.cs b/treasurechest/chestcrypto/identity/identity.cs new file mode 100644 index 0000000..b9df173 --- /dev/null +++ b/treasurechest/chestcrypto/identity/identity.cs @@ -0,0 +1,36 @@ +using System.Collections.Generic; + +namespace chestcrypto{ + + namespace identity { + internal class Identity { + private DoublePrivateKey privateKey; + private DoublePublicKey publicKey; + + private List ephemeralKeys = new List(); + + public DoublePublicKey getDoublePublicKey(){return publicKey;} + + + public Identity(){} + public Identity (List ephemeralKeys){ + + } + public Identity(DoublePublicKey publicKey){ + + } + public Identity(DoublePrivateKey privateKey){ + + } + public Identity(DoublePrivateKey privateKey, List ephemeralKeys){ + + } + public Identity(DoublePublicKey publicKey, List ephemeralKeys){ + + } + + + } + + } +} \ No newline at end of file diff --git a/treasurechest/chestcrypto/doublekey/exceptions.cs b/treasurechest/chestcrypto/keys/doublekey/exceptions.cs similarity index 100% rename from treasurechest/chestcrypto/doublekey/exceptions.cs rename to treasurechest/chestcrypto/keys/doublekey/exceptions.cs diff --git a/treasurechest/chestcrypto/doublekey/private.cs b/treasurechest/chestcrypto/keys/doublekey/private.cs similarity index 100% rename from treasurechest/chestcrypto/doublekey/private.cs rename to treasurechest/chestcrypto/keys/doublekey/private.cs diff --git a/treasurechest/chestcrypto/doublekey/public.cs b/treasurechest/chestcrypto/keys/doublekey/public.cs similarity index 100% rename from treasurechest/chestcrypto/doublekey/public.cs rename to treasurechest/chestcrypto/keys/doublekey/public.cs diff --git a/treasurechest/chestcrypto/keygen.cs b/treasurechest/chestcrypto/keys/keygen.cs similarity index 100% rename from treasurechest/chestcrypto/keygen.cs rename to treasurechest/chestcrypto/keys/keygen.cs diff --git a/treasurechest/keyring/file.cs b/treasurechest/keyring/file.cs new file mode 100644 index 0000000..c8d4a79 --- /dev/null +++ b/treasurechest/keyring/file.cs @@ -0,0 +1,18 @@ +using chestcrypto; + +namespace keyring{ + + internal class KeyRingFile + { + private string storageFile = null; + + internal KeyRingFile(string filePath){ + storageFile = filePath; + } + + internal void write(byte[] data){ + + } + } + +} \ No newline at end of file diff --git a/treasurechest/keyring/keyring.cs b/treasurechest/keyring/keyring.cs index 7c7f1d4..6928f7f 100644 --- a/treasurechest/keyring/keyring.cs +++ b/treasurechest/keyring/keyring.cs @@ -1,19 +1,36 @@ using chestcrypto; +using chestcrypto.identity; +using System.Collections.Generic; namespace keyring{ public class KeyRing { private string storageFile = null; + private List identities = new List(); + public KeyRing(string storageFile){ } + public KeyRing(){} + + public List getIdentityPublicKeys(){ + List pubKeys; + identities.ForEach(delegate(Identity identity){ + pubKeys.Add(identity.getDoublePublicKey().getRawDouble()); + }); + } public void addPublicKey(DoublePublicKey key){ + // Create an Identity with a public key if it does not exist already + + + Identity newIdentity = new Identity(key); + } - public void deleteKey(DoublePrivateKey key){ + public void deletePublicKey(DoublePublicKey key){ } }