Skip to content

Commit

Permalink
Use Locate to find openssl command
Browse files Browse the repository at this point in the history
  • Loading branch information
uenz committed Oct 25, 2021
1 parent 85f3d44 commit 7681312
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
1 change: 1 addition & 0 deletions SparkleShare/Common/BaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public virtual void Initialize ()
Logger.LogInfo ("Environment", "SparkleShare " + version);
Logger.LogInfo ("Environment", "Git LFS " + Sparkles.Git.GitCommand.GitLFSVersion);
Logger.LogInfo ("Environment", "Git " + Sparkles.Git.GitCommand.GitVersion);
Logger.LogInfo ("Environment", Sparkles.OpenSSLCommand.OpenSSLVersion);
Logger.LogInfo ("Environment", InstallationInfo.OperatingSystem + " " + InstallationInfo.OperatingSystemVersion);

UserAuthenticationInfo = new SSHAuthenticationInfo ();
Expand Down
6 changes: 3 additions & 3 deletions Sparkles/Git/Git.Fetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@ public override void EnableFetchedRepoCrypto (string password)
var git_config_required = new GitCommand (TargetFolder, "config filter.encryption.required true");

var git_config_smudge = new GitCommand (TargetFolder, "config filter.encryption.smudge " +
string.Format ("\"openssl enc -d -aes-256-cbc -base64 -S {0} -pass file:{1} -md sha256\"", password_salt, password_file));
string.Format ("\"'{0}' enc -d -aes-256-cbc -base64 -S {1} -pass file:{2} -md sha256\"", OpenSSLCommand.OpenSSLCommandPath, password_salt, password_file));

var git_config_clean = new GitCommand (TargetFolder, "config filter.encryption.clean " +
string.Format ("\"openssl enc -e -aes-256-cbc -base64 -S {0} -pass file:{1} -md sha256\"", password_salt, password_file));
string.Format ("\"'{0}' enc -e -aes-256-cbc -base64 -S {1} -pass file:{2} -md sha256\"", OpenSSLCommand.OpenSSLCommandPath, password_salt, password_file));

git_config_required.StartAndWaitForExit ();
git_config_smudge.StartAndWaitForExit ();
Expand Down Expand Up @@ -272,7 +272,7 @@ public override bool IsFetchedRepoPasswordCorrect (string password)
string args = string.Format ("enc -d -aes-256-cbc -base64 -S {0} -pass pass:{1} -in \"{2}\" -md sha256",
password_salt, password.SHA256 (password_salt), password_check_file_path);

var process = new Command ("openssl", args);
var process = new OpenSSLCommand (args);

process.StartInfo.WorkingDirectory = TargetFolder;
process.StartAndWaitForExit ();
Expand Down
57 changes: 57 additions & 0 deletions Sparkles/OpenSSLCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// SparkleShare, a collaboration and sharing tool.
// Copyright (C) 2010 Hylke Bons <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.


using System.IO;

namespace Sparkles
{
public class OpenSSLCommand : Command
{
public static string OpenSSLBinary = "openssl";
public static string OpenSSLPath = Path.GetDirectoryName(LocateCommand(OpenSSLBinary)).Replace("\\", "/");

public static string OpenSSLCommandPath
{
get
{
return LocateCommand(OpenSSLBinary).Replace("\\", "/");
}
}


public OpenSSLCommand(string command, string args) :
base(Path.Combine(OpenSSLPath, command), args)
{
}
public OpenSSLCommand(string args) : base(OpenSSLCommandPath, args)
{
}
public static string OpenSSLVersion
{
get {
var openssl_version = new Command (OpenSSLCommandPath, "version", false);

string [] version = openssl_version.StartAndReadStandardOutput ().Split (' ');
string version_string = version [0];
if (version.Length >= 2) {
version_string= version [0] + " " + version [1];
}
return version_string;
}
}
}
}
3 changes: 3 additions & 0 deletions Sparkles/Sparkles.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
<Compile Include="Command.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="OpenSSLCommand.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="SSHCommand.cs">
<SubType>Component</SubType>
</Compile>
Expand Down

0 comments on commit 7681312

Please sign in to comment.