Browse Source

updates for database providers

pull/2/head
Kyle Spearrin 4 years ago
parent
commit
84b3694aa0
  1. 8
      src/CryptoAgent/Migrations/MySql/20210820155954_InitialCreate.Designer.cs
  2. 4
      src/CryptoAgent/Migrations/MySql/20210820155954_InitialCreate.cs
  3. 6
      src/CryptoAgent/Migrations/MySql/MySqlDatabaseContextModelSnapshot.cs
  4. 9
      src/CryptoAgent/Migrations/PostgreSql/20210820160016_InitialCreate.Designer.cs
  5. 4
      src/CryptoAgent/Migrations/PostgreSql/20210820160016_InitialCreate.cs
  6. 7
      src/CryptoAgent/Migrations/PostgreSql/PostgreSqlDatabaseContextModelSnapshot.cs
  7. 9
      src/CryptoAgent/Migrations/SqlServer/20210820154908_InitialCreate.Designer.cs
  8. 3
      src/CryptoAgent/Migrations/SqlServer/20210820154908_InitialCreate.cs
  9. 7
      src/CryptoAgent/Migrations/SqlServer/SqlServerDatabaseContextModelSnapshot.cs
  10. 8
      src/CryptoAgent/Migrations/Sqlite/20210820155938_InitialCreate.Designer.cs
  11. 3
      src/CryptoAgent/Migrations/Sqlite/20210820155938_InitialCreate.cs
  12. 6
      src/CryptoAgent/Migrations/Sqlite/SqliteDatabaseContextModelSnapshot.cs
  13. 7
      src/CryptoAgent/Repositories/EntityFramework/ApplicationDataRepository.cs
  14. 2
      src/CryptoAgent/Repositories/EntityFramework/DatabaseContext.cs
  15. 2
      src/CryptoAgent/Repositories/EntityFramework/UserKeyRepository.cs
  16. 6
      src/CryptoAgent/Repositories/Mongo/ApplicationDataRepository.cs
  17. 2
      src/CryptoAgent/Services/AwsKmsRsaKeyService.cs
  18. 2
      src/CryptoAgent/Services/AzureKeyVaultRsaKeyService.cs
  19. 2
      src/CryptoAgent/Services/GoogleCloudKmsRsaKeyService.cs
  20. 2
      src/CryptoAgent/Services/LocalCertificateRsaKeyService.cs

8
src/CryptoAgent/Migrations/MySql/20210817205815_InitialCreate.Designer.cs → src/CryptoAgent/Migrations/MySql/20210820155954_InitialCreate.Designer.cs generated

@ -9,7 +9,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; @@ -9,7 +9,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Bit.CryptoAgent.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20210817205815_InitialCreate")]
[Migration("20210820155954_InitialCreate")]
partial class InitialCreate
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -21,9 +21,15 @@ namespace Bit.CryptoAgent.Migrations.MySql @@ -21,9 +21,15 @@ namespace Bit.CryptoAgent.Migrations.MySql
modelBuilder.Entity("Bit.CryptoAgent.Repositories.EntityFramework.ApplicationData", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("SymmetricKey")
.HasColumnType("longtext");
b.HasKey("Id");
b.ToTable("ApplicationDatas");
});

4
src/CryptoAgent/Migrations/MySql/20210817205815_InitialCreate.cs → src/CryptoAgent/Migrations/MySql/20210820155954_InitialCreate.cs

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Bit.CryptoAgent.Migrations.MySql
@ -14,11 +15,14 @@ namespace Bit.CryptoAgent.Migrations.MySql @@ -14,11 +15,14 @@ namespace Bit.CryptoAgent.Migrations.MySql
name: "ApplicationDatas",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
SymmetricKey = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4")
},
constraints: table =>
{
table.PrimaryKey("PK_ApplicationDatas", x => x.Id);
})
.Annotation("MySql:CharSet", "utf8mb4");

6
src/CryptoAgent/Migrations/MySql/MySqlDatabaseContextModelSnapshot.cs

@ -19,9 +19,15 @@ namespace Bit.CryptoAgent.Migrations.MySql @@ -19,9 +19,15 @@ namespace Bit.CryptoAgent.Migrations.MySql
modelBuilder.Entity("Bit.CryptoAgent.Repositories.EntityFramework.ApplicationData", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("SymmetricKey")
.HasColumnType("longtext");
b.HasKey("Id");
b.ToTable("ApplicationDatas");
});

9
src/CryptoAgent/Migrations/PostgreSql/20210817205827_InitialCreate.Designer.cs → src/CryptoAgent/Migrations/PostgreSql/20210820160016_InitialCreate.Designer.cs generated

@ -10,7 +10,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; @@ -10,7 +10,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Bit.CryptoAgent.Migrations.PostgreSql
{
[DbContext(typeof(PostgreSqlDatabaseContext))]
[Migration("20210817205827_InitialCreate")]
[Migration("20210820160016_InitialCreate")]
partial class InitialCreate
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -23,9 +23,16 @@ namespace Bit.CryptoAgent.Migrations.PostgreSql @@ -23,9 +23,16 @@ namespace Bit.CryptoAgent.Migrations.PostgreSql
modelBuilder.Entity("Bit.CryptoAgent.Repositories.EntityFramework.ApplicationData", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("SymmetricKey")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("ApplicationDatas");
});

4
src/CryptoAgent/Migrations/PostgreSql/20210817205827_InitialCreate.cs → src/CryptoAgent/Migrations/PostgreSql/20210820160016_InitialCreate.cs

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Bit.CryptoAgent.Migrations.PostgreSql
{
@ -11,10 +12,13 @@ namespace Bit.CryptoAgent.Migrations.PostgreSql @@ -11,10 +12,13 @@ namespace Bit.CryptoAgent.Migrations.PostgreSql
name: "ApplicationDatas",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
SymmetricKey = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_ApplicationDatas", x => x.Id);
});
migrationBuilder.CreateTable(

7
src/CryptoAgent/Migrations/PostgreSql/PostgreSqlDatabaseContextModelSnapshot.cs

@ -21,9 +21,16 @@ namespace Bit.CryptoAgent.Migrations.PostgreSql @@ -21,9 +21,16 @@ namespace Bit.CryptoAgent.Migrations.PostgreSql
modelBuilder.Entity("Bit.CryptoAgent.Repositories.EntityFramework.ApplicationData", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("SymmetricKey")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("ApplicationDatas");
});

9
src/CryptoAgent/Migrations/SqlServer/20210817205227_InitialCreate.Designer.cs → src/CryptoAgent/Migrations/SqlServer/20210820154908_InitialCreate.Designer.cs generated

@ -10,7 +10,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; @@ -10,7 +10,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Bit.CryptoAgent.Migrations.SqlServer
{
[DbContext(typeof(SqlServerDatabaseContext))]
[Migration("20210817205227_InitialCreate")]
[Migration("20210820154908_InitialCreate")]
partial class InitialCreate
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -23,9 +23,16 @@ namespace Bit.CryptoAgent.Migrations.SqlServer @@ -23,9 +23,16 @@ namespace Bit.CryptoAgent.Migrations.SqlServer
modelBuilder.Entity("Bit.CryptoAgent.Repositories.EntityFramework.ApplicationData", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("SymmetricKey")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("ApplicationDatas");
});

3
src/CryptoAgent/Migrations/SqlServer/20210817205227_InitialCreate.cs → src/CryptoAgent/Migrations/SqlServer/20210820154908_InitialCreate.cs

@ -11,10 +11,13 @@ namespace Bit.CryptoAgent.Migrations.SqlServer @@ -11,10 +11,13 @@ namespace Bit.CryptoAgent.Migrations.SqlServer
name: "ApplicationDatas",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
SymmetricKey = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_ApplicationDatas", x => x.Id);
});
migrationBuilder.CreateTable(

7
src/CryptoAgent/Migrations/SqlServer/SqlServerDatabaseContextModelSnapshot.cs

@ -21,9 +21,16 @@ namespace Bit.CryptoAgent.Migrations.SqlServer @@ -21,9 +21,16 @@ namespace Bit.CryptoAgent.Migrations.SqlServer
modelBuilder.Entity("Bit.CryptoAgent.Repositories.EntityFramework.ApplicationData", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("SymmetricKey")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("ApplicationDatas");
});

8
src/CryptoAgent/Migrations/Sqlite/20210817205807_InitialCreate.Designer.cs → src/CryptoAgent/Migrations/Sqlite/20210820155938_InitialCreate.Designer.cs generated

@ -9,7 +9,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; @@ -9,7 +9,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Bit.CryptoAgent.Migrations.Sqlite
{
[DbContext(typeof(SqliteDatabaseContext))]
[Migration("20210817205807_InitialCreate")]
[Migration("20210820155938_InitialCreate")]
partial class InitialCreate
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -20,9 +20,15 @@ namespace Bit.CryptoAgent.Migrations.Sqlite @@ -20,9 +20,15 @@ namespace Bit.CryptoAgent.Migrations.Sqlite
modelBuilder.Entity("Bit.CryptoAgent.Repositories.EntityFramework.ApplicationData", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("SymmetricKey")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("ApplicationDatas");
});

3
src/CryptoAgent/Migrations/Sqlite/20210817205807_InitialCreate.cs → src/CryptoAgent/Migrations/Sqlite/20210820155938_InitialCreate.cs

@ -11,10 +11,13 @@ namespace Bit.CryptoAgent.Migrations.Sqlite @@ -11,10 +11,13 @@ namespace Bit.CryptoAgent.Migrations.Sqlite
name: "ApplicationDatas",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
SymmetricKey = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_ApplicationDatas", x => x.Id);
});
migrationBuilder.CreateTable(

6
src/CryptoAgent/Migrations/Sqlite/SqliteDatabaseContextModelSnapshot.cs

@ -18,9 +18,15 @@ namespace Bit.CryptoAgent.Migrations.Sqlite @@ -18,9 +18,15 @@ namespace Bit.CryptoAgent.Migrations.Sqlite
modelBuilder.Entity("Bit.CryptoAgent.Repositories.EntityFramework.ApplicationData", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("SymmetricKey")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("ApplicationDatas");
});

7
src/CryptoAgent/Repositories/EntityFramework/ApplicationDataRepository.cs

@ -14,14 +14,15 @@ namespace Bit.CryptoAgent.Repositories.EntityFramework @@ -14,14 +14,15 @@ namespace Bit.CryptoAgent.Repositories.EntityFramework
{
using var scope = ServiceScopeFactory.CreateScope();
var dbContext = GetDatabaseContext(scope);
return Task.FromResult(dbContext.ApplicationDatas.FirstOrDefault().SymmetricKey);
return Task.FromResult(dbContext.ApplicationDatas.FirstOrDefault()?.SymmetricKey);
}
public async Task UpdateSymmetricKeyAsync(string key)
{
using var scope = ServiceScopeFactory.CreateScope();
var dbContext = GetDatabaseContext(scope);
if (dbContext.ApplicationDatas.FirstOrDefault() == null)
var data = dbContext.ApplicationDatas.FirstOrDefault();
if (data == null)
{
await dbContext.AddAsync(new ApplicationData
{
@ -30,7 +31,7 @@ namespace Bit.CryptoAgent.Repositories.EntityFramework @@ -30,7 +31,7 @@ namespace Bit.CryptoAgent.Repositories.EntityFramework
}
else
{
dbContext.ApplicationDatas.FirstOrDefault().SymmetricKey = key;
data.SymmetricKey = key;
}
await dbContext.SaveChangesAsync();
}

2
src/CryptoAgent/Repositories/EntityFramework/DatabaseContext.cs

@ -63,9 +63,9 @@ namespace Bit.CryptoAgent.Repositories.EntityFramework @@ -63,9 +63,9 @@ namespace Bit.CryptoAgent.Repositories.EntityFramework
ServerVersion.AutoDetect(_settings.Database.MySqlConnectionString));
}
[Keyless]
public class ApplicationData
{
public int Id { get; set; }
public string SymmetricKey { get; set; }
}

2
src/CryptoAgent/Repositories/EntityFramework/UserKeyRepository.cs

@ -25,7 +25,7 @@ namespace Bit.CryptoAgent.Repositories.EntityFramework @@ -25,7 +25,7 @@ namespace Bit.CryptoAgent.Repositories.EntityFramework
using var scope = ServiceScopeFactory.CreateScope();
var dbContext = GetDatabaseContext(scope);
var entity = await dbContext.UserKeys.FindAsync(id);
return entity.ToUserKeyModel();
return entity?.ToUserKeyModel();
}
public virtual async Task UpdateAsync(UserKeyModel item)

6
src/CryptoAgent/Repositories/Mongo/ApplicationDataRepository.cs

@ -14,12 +14,16 @@ namespace Bit.CryptoAgent.Repositories.Mongo @@ -14,12 +14,16 @@ namespace Bit.CryptoAgent.Repositories.Mongo
public async Task<string> ReadSymmetricKeyAsync()
{
var document = await Collection.Find(new BsonDocument()).FirstOrDefaultAsync();
return document.SymmetricKey;
return document?.SymmetricKey;
}
public async Task UpdateSymmetricKeyAsync(string key)
{
var document = await Collection.Find(new BsonDocument()).FirstOrDefaultAsync();
if (document == null)
{
document = new ApplicationData();
}
document.SymmetricKey = key;
await Collection.ReplaceOneAsync(d => d.Id == document.Id, document, new ReplaceOptions
{

2
src/CryptoAgent/Services/AwsKmsRsaKeyService.cs

@ -83,7 +83,7 @@ namespace Bit.CryptoAgent.Services @@ -83,7 +83,7 @@ namespace Bit.CryptoAgent.Services
var response = await _kmsClient.GetPublicKeyAsync(request);
var rsa = RSA.Create();
rsa.ImportSubjectPublicKeyInfo(response.PublicKey.ToArray(), out _);
return rsa.ExportRSAPublicKey();
return rsa.ExportSubjectPublicKeyInfo();
}
}
}

2
src/CryptoAgent/Services/AzureKeyVaultRsaKeyService.cs

@ -53,7 +53,7 @@ namespace Bit.CryptoAgent.Services @@ -53,7 +53,7 @@ namespace Bit.CryptoAgent.Services
public async Task<byte[]> GetPublicKeyAsync()
{
var key = await GetKeyAsync();
return key.Key.ToRSA().ExportRSAPublicKey();
return key.Key.ToRSA().ExportSubjectPublicKeyInfo();
}
private async Task<CryptographyClient> GetCryptographyClientAsync()

2
src/CryptoAgent/Services/GoogleCloudKmsRsaKeyService.cs

@ -61,7 +61,7 @@ namespace Bit.CryptoAgent.Services @@ -61,7 +61,7 @@ namespace Bit.CryptoAgent.Services
public async Task<byte[]> GetPublicKeyAsync()
{
var rsa = await GetRsaPublicKeyAsync();
return rsa.ExportRSAPublicKey();
return rsa.ExportSubjectPublicKeyInfo();
}
private async Task<RSA> GetRsaPublicKeyAsync()

2
src/CryptoAgent/Services/LocalCertificateRsaKeyService.cs

@ -59,7 +59,7 @@ namespace Bit.CryptoAgent.Services @@ -59,7 +59,7 @@ namespace Bit.CryptoAgent.Services
public async Task<byte[]> GetPublicKeyAsync()
{
var certificate = await GetCertificateAsync();
return certificate.GetRSAPublicKey().ExportRSAPublicKey();
return certificate.GetRSAPublicKey().ExportSubjectPublicKeyInfo();
}
private async Task<X509Certificate2> GetCertificateAsync()

Loading…
Cancel
Save