crypto: use a random salt per repo, store it as a remote branch name

This commit is contained in:
Hylke Bons 2012-09-29 23:57:35 +02:00
parent 8084d07774
commit 475b82f43a
12 changed files with 128 additions and 26 deletions

View file

@ -30,7 +30,39 @@ namespace SparkleLib.Git {
private SparkleGit git;
private bool use_git_bin;
private string crypto_salt = "e0d592768d7cf99a"; // TODO: Make unique per repo
private string cached_salt;
private string crypto_salt {
get {
if (!string.IsNullOrEmpty (this.cached_salt))
return this.cached_salt;
// Check if the repo's salt is stored in a branch...
SparkleGit git = new SparkleGit (TargetFolder, "branch -a");
string [] branches = git.StartAndReadStandardOutput ().Split (Environment.NewLine.ToCharArray ());
// TODO double check env.newline ^
foreach (string branch in branches) {
if (branch.StartsWith (" remotes/origin/salt-")) {
this.cached_salt = branch.Substring (22);
break;
}
}
// ...if not, create a new salt for the repo
if (string.IsNullOrEmpty (this.cached_salt)) {
this.cached_salt = GenerateCryptoSalt ();
string salt_file_path = new string [] { TargetFolder, ".git", "salt" }.Combine ();
// Temporarily store the salt in a file, so the Repo can
// push it to a branch on the host later
File.WriteAllText (salt_file_path, this.cached_salt);
}
return this.cached_salt;
}
}
public SparkleFetcher (string server, string required_fingerprint, string remote_path,

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
@ -11,15 +11,22 @@
<RootNamespace>SparkleLib.Git</RootNamespace>
<AssemblyName>SparkleLib.Git</AssemblyName>
<FileAlignment>512</FileAlignment>
<ReleaseVersion />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<Optimize>True</Optimize>
<OutputPath>..\..\bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>False</Optimize>
<OutputPath>bin\Debug</OutputPath>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Service Include="{B4F97281-0DBD-4835-9ED8-7DFB966E87FF}" />
</ItemGroup>

View file

@ -35,6 +35,7 @@ namespace SparkleLib.Git {
{
// TODO: Set git locale to en-US
// Check if we should use git-bin
SparkleGit git = new SparkleGit (LocalPath, "config --get filter.bin.clean");
git.StartAndWaitForExit ();
@ -177,6 +178,22 @@ namespace SparkleLib.Git {
string message = FormatCommitMessage ();
Commit (message);
string salt_file_path = new string [] { LocalPath, ".git", "salt" }.Combine ();
// If the repo is encrypted, create a branch to
// store the in and push it to the host
if (File.Exists (salt_file_path)) {
string salt = File.ReadAllText (salt_file_path).Trim ();
SparkleGit git_salt = new SparkleGit (LocalPath, "branch salt-" + salt);
git_salt.StartAndWaitForExit ();
git_salt = new SparkleGit (LocalPath, "push origin salt-" + salt);
git_salt.StartAndWaitForExit ();
File.Delete (salt_file_path);
}
}
SparkleGit git;

View file

@ -160,7 +160,7 @@ namespace SparkleLib {
IsActive = false;
// TODO: Find better way to determine if folder should have crypto setup
bool repo_is_encrypted = RemoteUrl.ToString ().Contains ("crypto");
bool repo_is_encrypted = RemoteUrl.ToString ().Contains ("-crypto");
Finished (repo_is_encrypted, IsFetchedRepoEmpty, Warnings);
} else {
@ -207,18 +207,23 @@ namespace SparkleLib {
uri_builder.Password = "";
}
string text = "Congratulations, you've successfully created a SparkleShare repository!" + n +
n +
"Any files you add or change in this folder will be automatically synced to " + n +
uri_builder.ToString () + " and everyone connected to it." + n +
n +
"SparkleShare is an Open Source software program that helps people " + n +
"collaborate and share files. If you like what we do, please consider a small " + n +
"donation to support the project: http://sparkleshare.org/support-us/" + n +
n +
"Have fun! :)" + n;
// TODO: Find better way to determine if folder should have crypto setup
bool repo_is_encrypted = RemoteUrl.ToString ().Contains ("crypto");
File.WriteAllText (file_path, text);
if (!repo_is_encrypted) {
string text = "Congratulations, you've successfully created a SparkleShare repository!" + n +
n +
"Any files you add or change in this folder will be automatically synced to " + n +
uri_builder.ToString () + " and everyone connected to it." + n +
n +
"SparkleShare is an Open Source software program that helps people " + n +
"collaborate and share files. If you like what we do, please consider a small " + n +
"donation to support the project: http://www.sparkleshare.org/" + n +
n +
"Have fun! :)" + n;
File.WriteAllText (file_path, text);
}
}
@ -258,6 +263,23 @@ namespace SparkleLib {
}
protected string GenerateCryptoSalt ()
{
int seed = new Random ().Next (1, int.MaxValue);
string allowed_chars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789";
char [] chars = new char [256];
Random random = new Random (seed);
for (var i = 0; i < 256; i++)
chars [i] = allowed_chars [random.Next (0, allowed_chars.Length)];
string salt = new string (chars);
salt = salt.SHA1 ();
return salt.Substring (0, 16);
}
private string GetHostKey ()
{
string host = RemoteUrl.Host;

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
@ -9,14 +9,21 @@
<OutputType>Library</OutputType>
<RootNamespace>SparkleLib</RootNamespace>
<AssemblyName>SparkleLib</AssemblyName>
<ReleaseVersion />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<Optimize>False</Optimize>
<OutputPath>..\bin</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<ConsolePause>False</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>False</Optimize>
<OutputPath>bin\Debug</OutputPath>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
@ -36,14 +43,13 @@
<Compile Include="SparkleExceptions.cs" />
<Compile Include="SparkleUser.cs" />
<Compile Include="SparkleLogger.cs" />
<Compile Include="Defines.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<MonoDevelop>
<Properties>
<MonoDevelop.Autotools.MakefileInfo IntegrationEnabled="true" RelativeMakefileName="Makefile.am">
<BuildFilesVar Sync="true" Name="SOURCES" />
<MonoDevelop.Autotools.MakefileInfo IntegrationEnabled="True" RelativeMakefileName="Makefile.am">
<BuildFilesVar Sync="True" Name="SOURCES" />
<DeployFilesVar />
<ResourcesVar />
<OthersVar />

View file

@ -691,8 +691,7 @@ namespace SparkleShare {
Description = "You can find it in your SparkleShare folder";
// A button that opens the synced folder
Button open_folder_button = new Button (string.Format ("Open {0}",
System.IO.Path.GetFileName (Controller.PreviousPath)));
Button open_folder_button = new Button ("Show Folder");
open_folder_button.Clicked += delegate {
Controller.OpenFolderClicked ();

View file

@ -805,7 +805,7 @@ namespace SparkleShare {
OpenFolderButton = new NSButton () {
Title = string.Format ("Open {0}", Path.GetFileName (Controller.PreviousPath))
Title = "Show folder"
};
FinishButton = new NSButton () {

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
@ -33,6 +33,16 @@
<CodeSigningKey>Mac Developer</CodeSigningKey>
<PackageSigningKey>3rd Party Mac Developer Installer</PackageSigningKey>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>False</Optimize>
<OutputPath>bin\Debug</OutputPath>
<WarningLevel>4</WarningLevel>
<IncludeMonoRuntime>False</IncludeMonoRuntime>
<EnablePackageSigning>False</EnablePackageSigning>
<EnableCodeSigning>False</EnableCodeSigning>
<CreatePackage>False</CreatePackage>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />

View file

@ -10,12 +10,19 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Release|Any CPU = Release|Any CPU
Debug|Any CPU = Debug|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{009FDCD7-1D57-4202-BB6D-8477D8C6B8EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{009FDCD7-1D57-4202-BB6D-8477D8C6B8EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{009FDCD7-1D57-4202-BB6D-8477D8C6B8EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{009FDCD7-1D57-4202-BB6D-8477D8C6B8EE}.Release|Any CPU.Build.0 = Release|Any CPU
{2C914413-B31C-4362-93C7-1AE34F09112A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2C914413-B31C-4362-93C7-1AE34F09112A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2C914413-B31C-4362-93C7-1AE34F09112A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2C914413-B31C-4362-93C7-1AE34F09112A}.Release|Any CPU.Build.0 = Release|Any CPU
{CF5BC8DB-A633-4FCC-8A3E-E3AC9B59FABC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CF5BC8DB-A633-4FCC-8A3E-E3AC9B59FABC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CF5BC8DB-A633-4FCC-8A3E-E3AC9B59FABC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CF5BC8DB-A633-4FCC-8A3E-E3AC9B59FABC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection

View file

@ -563,6 +563,7 @@ namespace SparkleShare {
this.fetcher.Complete ();
string canonical_name = Path.GetFileNameWithoutExtension (this.fetcher.RemoteUrl.AbsolutePath);
canonical_name = canonical_name.Replace ("-crypto", "");
bool target_folder_exists = Directory.Exists (
Path.Combine (this.config.FoldersPath, canonical_name));

View file

@ -341,6 +341,7 @@ namespace SparkleShare {
public void AddPageCompleted (string address, string remote_path)
{
SyncingFolder = Path.GetFileNameWithoutExtension (remote_path);
SyncingFolder = SyncingFolder.Replace ("-crypto", "");
ProgressBarPercentage = 1.0;
ChangePageEvent (PageType.Syncing, null);

View file

@ -734,7 +734,7 @@ namespace SparkleShare {
};
Button open_folder_button = new Button () {
Content = string.Format ("Open {0}", Path.GetFileName (Controller.PreviousPath))
Content = "Show folder"
};
if (warnings.Length > 0) {