Bladeren bron

Added key size and block size to DB in case they change.

Added subdirectories for stored files.
tags/2.0.3
Teknikode 4 jaren geleden
bovenliggende
commit
47cc6f3a9b

+ 2
- 0
Teknik/App_Start/BundleConfig.cs Bestand weergeven

@@ -8,7 +8,9 @@ namespace Teknik
// For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
public static void RegisterBundles(BundleCollection bundles)
{
#if !DEBUG
BundleTable.EnableOptimizations = true;
#endif

bundles.Add(new StyleBundle("~/Content/Common").Include(
"~/Content/bootstrap.css",

+ 3
- 3
Teknik/Areas/Upload/Controllers/UploadController.cs Bestand weergeven

@@ -30,11 +30,11 @@ namespace Teknik.Areas.Upload.Controllers
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Upload(string fileType, string iv, HttpPostedFileWrapper data)
public ActionResult Upload(string fileType, string iv, int keySize, int blockSize, HttpPostedFileWrapper data)
{
if (data.ContentLength <= Config.UploadConfig.MaxUploadSize)
{
Models.Upload upload = Uploader.SaveFile(data, fileType, iv);
Models.Upload upload = Uploader.SaveFile(data, fileType, iv, null, keySize, blockSize);
if (upload != null)
{
return Json(new { result = new { name = upload.Url, url = Url.SubRouteUrl("upload", "Upload.Download", new { file = upload.Url }) } }, "text/plain");
@@ -74,7 +74,7 @@ namespace Teknik.Areas.Upload.Controllers
// Read in the file
byte[] encData = System.IO.File.ReadAllBytes(upload.FileName);
// Decrypt the data
byte[] data = AES.Decrypt(encData, upload.Key, upload.IV, Config.UploadConfig.KeySize, Config.UploadConfig.IVSize);
byte[] data = AES.Decrypt(encData, upload.Key, upload.IV, upload.KeySize, upload.BlockSize);

// Create File
var cd = new System.Net.Mime.ContentDisposition

+ 4
- 0
Teknik/Areas/Upload/Models/Upload.cs Bestand weergeven

@@ -28,6 +28,10 @@ namespace Teknik.Areas.Upload.Models

public string IV { get; set; }

public int KeySize { get; set; }

public int BlockSize { get; set; }

public string DeleteKey { get; set; }
}
}

+ 5
- 3
Teknik/Areas/Upload/Scripts/Upload.js Bestand weergeven

@@ -156,9 +156,9 @@ function encryptFile(file, callback) {
// When the file has been loaded, encrypt it
reader.onload = (function (callback) {
return function (e) {
// Create random key and iv
var keyStr = randomString(keySize, '#aA');
var ivStr = randomString(ivSize, '#aA');
// Create random key and iv (divide size by 8 for character length)
var keyStr = randomString((keySize / 8), '#aA');
var ivStr = randomString((blockSize / 8), '#aA');

var worker = new Worker(encScriptSrc);

@@ -222,6 +222,8 @@ function uploadFile(data, key, iv, filetype, fileID)
var fd = new FormData();
fd.append('fileType', filetype);
fd.append('iv', iv);
fd.append('keySize', keySize);
fd.append('blockSize', blockSize);
fd.append('data', blob);
fd.append('__RequestVerificationToken', $('#__AjaxAntiForgeryForm input[name=__RequestVerificationToken]').val());


+ 14
- 2
Teknik/Areas/Upload/Uploader.cs Bestand weergeven

@@ -12,19 +12,29 @@ namespace Teknik.Areas.Upload
{
public static Models.Upload SaveFile(HttpPostedFileWrapper file, string contentType)
{
return SaveFile(file, contentType, null, null);
return SaveFile(file, contentType, null, null, 256, 128);
}

public static Models.Upload SaveFile(HttpPostedFileWrapper file, string contentType, string iv)
{
return SaveFile(file, contentType, iv, null);
return SaveFile(file, contentType, iv, null, 256, 128);
}

public static Models.Upload SaveFile(HttpPostedFileWrapper file, string contentType, string iv, string key)
{
return SaveFile(file, contentType, iv, key, 256, 128);
}

public static Models.Upload SaveFile(HttpPostedFileWrapper file, string contentType, string iv, string key, int keySize, int blockSize)
{
Config config = Config.Load();
TeknikEntities db = new TeknikEntities();

if (!Directory.Exists(config.UploadConfig.UploadDirectory))
{
Directory.CreateDirectory(config.UploadConfig.UploadDirectory);
}

// Generate a unique file name that does not currently exist
string fileName = Utility.GenerateUniqueFileName(config.UploadConfig.UploadDirectory, config.UploadConfig.FileExtension, 10);

@@ -48,6 +58,8 @@ namespace Teknik.Areas.Upload
upload.ContentLength = file.ContentLength;
upload.Key = key;
upload.IV = iv;
upload.KeySize = keySize;
upload.BlockSize = blockSize;

db.Uploads.Add(upload);
db.SaveChanges();

+ 2
- 0
Teknik/Areas/Upload/ViewModels/DownloadViewModel.cs Bestand weergeven

@@ -12,5 +12,7 @@ namespace Teknik.Areas.Upload.ViewModels
public string ContentType { get; set; }
public int ContentLength { get; set; }
public string IV { get; set; }
public int keySize { get; set; }
public int blockSize { get; set; }
}
}

+ 1
- 1
Teknik/Areas/Upload/Views/Upload/Index.cshtml Bestand weergeven

@@ -10,7 +10,7 @@
var maxUploadSize = @Model.Config.UploadConfig.MaxUploadSize;
var chunkSize = @Model.Config.UploadConfig.ChunkSize;
var keySize = @Model.Config.UploadConfig.KeySize;
var ivSize = @Model.Config.UploadConfig.IVSize;
var blockSize = @Model.Config.UploadConfig.BlockSize;
</script>

@Styles.Render("~/Content/upload")

+ 3
- 3
Teknik/Configuration/UploadConfig.cs Bestand weergeven

@@ -16,7 +16,7 @@ namespace Teknik.Configuration
public int UrlLength { get; set; }
public int DeleteKeyLength { get; set; }
public int KeySize { get; set; }
public int IVSize { get; set; }
public int BlockSize { get; set; }
public bool IncludeExtension { get; set; }
// The size of the chunk that the file will be encrypted/decrypted in (bytes)
public int ChunkSize { get; set; }
@@ -33,8 +33,8 @@ namespace Teknik.Configuration
FileExtension = "enc";
UrlLength = 6;
DeleteKeyLength = 24;
KeySize = 32;
IVSize = 16;
KeySize = 256;
BlockSize = 128;
IncludeExtension = true;
ChunkSize = 1024;
}

+ 12
- 0
Teknik/Helpers/Utility.cs Bestand weergeven

@@ -65,9 +65,21 @@ namespace Teknik
if (Directory.Exists(path))
{
string filename = RandomString(length);
string subDir = filename[0].ToString();
path = Path.Combine(path, subDir);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
while (File.Exists(Path.Combine(path, string.Format("{0}.{1}", filename, extension))))
{
filename = RandomString(length);
subDir = filename[0].ToString();
path = Path.Combine(path, subDir);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
}

return Path.Combine(path, string.Format("{0}.{1}", filename, extension));

+ 39
- 39
Teknik/Web.config Bestand weergeven

@@ -1,88 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</configSections>
<connectionStrings configSource="ConnectionStrings.config" />
<connectionStrings configSource="ConnectionStrings.config"/>
<!-- Create ConnectionStrings.config and add your connection string-->
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="RouteDebugger:Enabled" value="false" />
<add key="webpages:Version" value="3.0.0.0"/>
<add key="webpages:Enabled" value="false"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
<add key="RouteDebugger:Enabled" value="false"/>
</appSettings>
<system.web>
<customErrors mode="Off" />
<authentication mode="Forms" />
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" maxRequestLength="1048576" />
<pages buffer="true" enableViewState="false" />
<customErrors mode="Off"/>
<authentication mode="Forms"/>
<compilation debug="true" targetFramework="4.5.2"/>
<httpRuntime targetFramework="4.5.2" maxRequestLength="1048576"/>
<pages buffer="true" enableViewState="false"/>
</system.web>
<system.webServer>
<modules>
<remove name="FormsAuthentication" />
<add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />
<add name="PerfModule" type="Teknik.Modules.PerformanceMonitorModule, Teknik" />
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
<remove name="FormsAuthentication"/>
<add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule"/>
<add name="PerfModule" type="Teknik.Modules.PerformanceMonitorModule, Teknik"/>
<remove name="UrlRoutingModule-4.0"/>
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition=""/>
</modules>
<staticContent>
<mimeMap fileExtension="woff" mimeType="application/font-woff" />
<mimeMap fileExtension="woff2" mimeType="application/font-woff" />
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" cacheControlCustom="public" />
<mimeMap fileExtension="woff" mimeType="application/font-woff"/>
<mimeMap fileExtension="woff2" mimeType="application/font-woff"/>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" cacheControlCustom="public"/>
</staticContent>
<urlCompression doDynamicCompression="true" doStaticCompression="true" dynamicCompressionBeforeCache="true" />
<urlCompression doDynamicCompression="true" doStaticCompression="true" dynamicCompressionBeforeCache="true"/>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
<requestLimits maxAllowedContentLength="1073741824"/>
</requestFiltering>
</security>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed"/>
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
<parameter value="mssqllocaldb"/>
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
</entityFramework>
</configuration>

Laden…
Annuleren
Opslaan