fetcher git: Use hashed password to encrypt files
This commit is contained in:
parent
4757b86ddb
commit
3776dedd8c
|
@ -34,6 +34,7 @@ namespace SparkleLib.Git {
|
|||
private Regex progress_regex = new Regex (@"([0-9]+)%", RegexOptions.Compiled);
|
||||
private Regex speed_regex = new Regex (@"([0-9\.]+) ([KM])iB/s", RegexOptions.Compiled);
|
||||
|
||||
private bool crypto_password_is_hashed = true;
|
||||
|
||||
private string crypto_salt {
|
||||
get {
|
||||
|
@ -259,6 +260,10 @@ namespace SparkleLib.Git {
|
|||
|
||||
// Store the password
|
||||
string password_file_path = new string [] { TargetFolder, ".git", "info", "encryption_password" }.Combine ();
|
||||
|
||||
if (this.crypto_password_is_hashed)
|
||||
File.WriteAllText (password_file_path, password.SHA256 (this.crypto_salt));
|
||||
else
|
||||
File.WriteAllText (password_file_path, password);
|
||||
}
|
||||
|
||||
|
@ -279,13 +284,20 @@ namespace SparkleLib.Git {
|
|||
|
||||
Process process = new Process ();
|
||||
process.EnableRaisingEvents = true;
|
||||
process.StartInfo.FileName = "openssl";
|
||||
process.StartInfo.WorkingDirectory = TargetFolder;
|
||||
process.StartInfo.UseShellExecute = false;
|
||||
process.StartInfo.RedirectStandardOutput = true;
|
||||
process.StartInfo.CreateNoWindow = true;
|
||||
|
||||
process.StartInfo.FileName = "openssl";
|
||||
process.StartInfo.Arguments = "enc -d -aes-256-cbc -base64 -pass pass:\"" + password + "\"" +
|
||||
string [] possible_passwords = new string [] {
|
||||
password.SHA256 (this.crypto_salt),
|
||||
password
|
||||
};
|
||||
|
||||
int i = 0;
|
||||
foreach (string possible_password in possible_passwords) {
|
||||
process.StartInfo.Arguments = "enc -d -aes-256-cbc -base64 -pass pass:\"" + possible_password + "\"" +
|
||||
" -in \"" + password_check_file_path + "\"";
|
||||
|
||||
SparkleLogger.LogInfo ("Cmd | " + System.IO.Path.GetFileName (process.StartInfo.WorkingDirectory),
|
||||
|
@ -295,12 +307,17 @@ namespace SparkleLib.Git {
|
|||
process.WaitForExit ();
|
||||
|
||||
if (process.ExitCode == 0) {
|
||||
if (i > 0)
|
||||
crypto_password_is_hashed = false;
|
||||
|
||||
File.Delete (password_check_file_path);
|
||||
return true;
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue