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 progress_regex = new Regex (@"([0-9]+)%", RegexOptions.Compiled);
|
||||||
private Regex speed_regex = new Regex (@"([0-9\.]+) ([KM])iB/s", 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 {
|
private string crypto_salt {
|
||||||
get {
|
get {
|
||||||
|
@ -259,7 +260,11 @@ namespace SparkleLib.Git {
|
||||||
|
|
||||||
// Store the password
|
// Store the password
|
||||||
string password_file_path = new string [] { TargetFolder, ".git", "info", "encryption_password" }.Combine ();
|
string password_file_path = new string [] { TargetFolder, ".git", "info", "encryption_password" }.Combine ();
|
||||||
File.WriteAllText (password_file_path, password);
|
|
||||||
|
if (this.crypto_password_is_hashed)
|
||||||
|
File.WriteAllText (password_file_path, password.SHA256 (this.crypto_salt));
|
||||||
|
else
|
||||||
|
File.WriteAllText (password_file_path, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -279,28 +284,40 @@ namespace SparkleLib.Git {
|
||||||
|
|
||||||
Process process = new Process ();
|
Process process = new Process ();
|
||||||
process.EnableRaisingEvents = true;
|
process.EnableRaisingEvents = true;
|
||||||
|
process.StartInfo.FileName = "openssl";
|
||||||
process.StartInfo.WorkingDirectory = TargetFolder;
|
process.StartInfo.WorkingDirectory = TargetFolder;
|
||||||
process.StartInfo.UseShellExecute = false;
|
process.StartInfo.UseShellExecute = false;
|
||||||
process.StartInfo.RedirectStandardOutput = true;
|
process.StartInfo.RedirectStandardOutput = true;
|
||||||
process.StartInfo.CreateNoWindow = true;
|
process.StartInfo.CreateNoWindow = true;
|
||||||
|
|
||||||
process.StartInfo.FileName = "openssl";
|
string [] possible_passwords = new string [] {
|
||||||
process.StartInfo.Arguments = "enc -d -aes-256-cbc -base64 -pass pass:\"" + password + "\"" +
|
password.SHA256 (this.crypto_salt),
|
||||||
" -in \"" + password_check_file_path + "\"";
|
password
|
||||||
|
};
|
||||||
|
|
||||||
SparkleLogger.LogInfo ("Cmd | " + System.IO.Path.GetFileName (process.StartInfo.WorkingDirectory),
|
int i = 0;
|
||||||
System.IO.Path.GetFileName (process.StartInfo.FileName) + " " + process.StartInfo.Arguments);
|
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 + "\"";
|
||||||
|
|
||||||
process.Start ();
|
SparkleLogger.LogInfo ("Cmd | " + System.IO.Path.GetFileName (process.StartInfo.WorkingDirectory),
|
||||||
process.WaitForExit ();
|
System.IO.Path.GetFileName (process.StartInfo.FileName) + " " + process.StartInfo.Arguments);
|
||||||
|
|
||||||
if (process.ExitCode == 0) {
|
process.Start ();
|
||||||
File.Delete (password_check_file_path);
|
process.WaitForExit ();
|
||||||
return true;
|
|
||||||
|
|
||||||
} else {
|
if (process.ExitCode == 0) {
|
||||||
return false;
|
if (i > 0)
|
||||||
|
crypto_password_is_hashed = false;
|
||||||
|
|
||||||
|
File.Delete (password_check_file_path);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue