public bool UpdatePassword(byte[] userID, string password, string newPassword, string pepper) { if (userID == null) { throw new ArgumentNullException("userID"); } if (password == null) { throw new ArgumentNullException("password"); } if (newPassword == null) { throw new ArgumentNullException("newPassword"); } if (pepper == null) { throw new ArgumentNullException("pepper"); } byte[] privateKeyRaw = userKeys.Get(userID); { //verify password System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(privateKeyRaw); Stream cryptoStream = CreateCryptoStream(memoryStream, userID, password, pepper, CryptoStreamMode.Read); RSAParameters privateKey = DeserializeKey(cryptoStream); RSAParameters pubKey = GetPublicKey(userID); if ((ByteSequenceComparer.Shared.Compare(pubKey.Modulus, privateKey.Modulus) != 0) || (ByteSequenceComparer.Shared.Compare(pubKey.Exponent, privateKey.Exponent) != 0)) { return(false); } } MemoryStream newKeyStream = new MemoryStream(); Rijndael oldPassRij = CreateRijndael(userID, password, pepper); Rijndael newPassRij = CreateRijndael(userID, newPassword, pepper); System.Security.Cryptography.CryptoStream streamI = new CryptoStream(new System.IO.MemoryStream(privateKeyRaw), oldPassRij.CreateDecryptor(), CryptoStreamMode.Read); System.Security.Cryptography.CryptoStream streamO = new CryptoStream(newKeyStream, newPassRij.CreateEncryptor(), CryptoStreamMode.Write); var buffer = new byte[1024]; var read = streamI.Read(buffer, 0, buffer.Length); while (read > 0) { streamO.Write(buffer, 0, read); read = streamI.Read(buffer, 0, buffer.Length); } streamO.FlushFinalBlock(); byte[] newKeyRaw = newKeyStream.ToArray(); userKeys.Put(userID, newKeyRaw); return(true); }
public void SetRSAParameters(RSAParameters rsa) { //if (this.rsa == null) { this.rsa = rsa; meta = new RSAEncryptingKeyValueStorage(eMeta, rsa); symmetricKeys = new RSAEncryptingKeyValueStorage(eSymmetricKeys, rsa); try { eMeta.Get(System.Text.Encoding.Unicode.GetBytes("RepositoryConfigurationsKeyID").SHA256()); } catch { byte[] id = new byte[32]; byte[] key = new byte[32]; RandomNumberGenerator rng = RandomNumberGenerator.Create(); rng.GetBytes(id); rng.GetBytes(key); symmetricKeys.Put(id, key); meta.Put(System.Text.Encoding.Unicode.GetBytes("RepositoryConfigurationsKeyID").SHA256(), id); } if (rsa.InverseQ != null) { repositoryConfigurations = new AESEncryptingKeyValueStorage(eRepositoryConfigurations, symmetricKeys.Get(meta.Get(System.Text.Encoding.Unicode.GetBytes("RepositoryConfigurationsKeyID").SHA256()))); } //} else // throw new InvalidOperationException (); }
public byte[] GetMetaData(byte[] id) { if (id == null) { throw new ArgumentNullException("id"); } return(meta.Get(id)); }
public byte[] GetRawRepositoryInfo(byte[] repositoryID) { if (repositoryID == null) { throw new ArgumentNullException("repositoryID"); } return(repositories.Get(repositoryID)); }
public IEnumerable <byte[]> GetUserRepositories(byte[] userID) { if (userID == null) { throw new ArgumentNullException("userID"); } return(userRepositories.Get(userID)); }
public override byte[][] Get(byte[] key) { byte[] bytes = baseStorage.Get(key); if (bytes == null) { return(default(byte[][])); } return(Encode(bytes)); }
public override byte[] Get(byte[] key) { byte[] bytes = baseStorage.Get(key); if (bytes == null) { return(null); } return(Decrypt(bytes)); }
public RSAParameters GetPublicKey(byte[] userID) { if (userID == null) { throw new ArgumentNullException("userID"); } byte[] pubKeyRaw = userCerts.Get(userID); MemoryStream memoryStream = new MemoryStream(pubKeyRaw); var pubKey = DeserializeKey(memoryStream); return(pubKey); }
public IEnumerator <ChunkData> Pull(IEnumerable <byte[]> chunkIDs) { if (chunkIDs == null) { throw new ArgumentNullException("chunkIDs"); } foreach (byte[] chunkID in chunkIDs) { byte[] data; byte[][] dependencies; byte[][] signatures; data = ldata.Get(chunkID); dependencies = ldataDependencies.Get(chunkID); signatures = lsignatures.Get(chunkID); yield return(new ChunkData(chunkID, data, dependencies, signatures, this)); } }
public override byte[] Get(byte[] key) { return(Decrypt(baseStorage.Get(key))); }
//readonly DatabasePath path; public UserRepository(DatabasePath path, UserRepositoryConfiguration config) { if (path == null) { throw new ArgumentNullException("path"); } if (config == null) { throw new ArgumentNullException("config"); } Console.WriteLine("Reading KeyValueStores"); userNames = config.Users.OpenStorage <string> (path); userParents = config.UserParents.OpenStorage <byte[]> (path); userCerts = config.UserCerts.OpenStorage <byte[]> (path); userKeys = config.UserKeys.OpenStorage <byte[]> (path); userSigningCerts = config.UserSigningCerts.OpenStorage <byte[]> (path); userSigningKeys = config.UserSigningKeys.OpenStorage <byte[]> (path); userRepositories = config.UserRepositores.OpenStorage <byte[][]> (path); repositories = config.Repositores.OpenStorage <byte[]> (path); meta = config.Meta.OpenStorage <byte[]> (path); //permissions = new LevelDBKeyValueStorage<byte[]> (path.CreatePath (config.PermissionsPath)); genericRepositories = new SortedDictionary <byte[], GenericUserRepositoryCollection> (ByteSequenceComparer.Shared); loggedInUsers = new SortedDictionary <byte[], RSAParameters> (ByteSequenceComparer.Shared); Console.WriteLine("Done"); var e = userNames.GetEnumerator(); while (e.MoveNext()) { var user = e.Current; Console.WriteLine("user: {0}:{1}", user.Key, user.Value); genericRepositories.Add(user.Key, new GenericUserRepositoryCollection(path.CreatePath(user.Key.ToHexadecimal()), DeserializeKey(new MemoryStream(userCerts.Get(user.Key), false))) ); } }
public byte[][] GetRepositoryDependencies() { return(lmeta.Get(System.Text.Encoding.Unicode.GetBytes("Dependencies")).Expand()); }