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 SparkleGit git;
private bool use_git_bin; 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, public SparkleFetcher (string server, string required_fingerprint, string remote_path,

View file

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

View file

@ -35,6 +35,7 @@ namespace SparkleLib.Git {
{ {
// TODO: Set git locale to en-US // TODO: Set git locale to en-US
// Check if we should use git-bin
SparkleGit git = new SparkleGit (LocalPath, "config --get filter.bin.clean"); SparkleGit git = new SparkleGit (LocalPath, "config --get filter.bin.clean");
git.StartAndWaitForExit (); git.StartAndWaitForExit ();
@ -177,6 +178,22 @@ namespace SparkleLib.Git {
string message = FormatCommitMessage (); string message = FormatCommitMessage ();
Commit (message); 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; SparkleGit git;

View file

@ -160,7 +160,7 @@ namespace SparkleLib {
IsActive = false; IsActive = false;
// TODO: Find better way to determine if folder should have crypto setup // 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); Finished (repo_is_encrypted, IsFetchedRepoEmpty, Warnings);
} else { } else {
@ -207,18 +207,23 @@ namespace SparkleLib {
uri_builder.Password = ""; uri_builder.Password = "";
} }
string text = "Congratulations, you've successfully created a SparkleShare repository!" + n + // TODO: Find better way to determine if folder should have crypto setup
n + bool repo_is_encrypted = RemoteUrl.ToString ().Contains ("crypto");
"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;
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 () private string GetHostKey ()
{ {
string host = RemoteUrl.Host; string host = RemoteUrl.Host;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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