Skip to content

Commit

Permalink
Added Constants to unravel some of the mystery behind the vars
Browse files Browse the repository at this point in the history
  • Loading branch information
garrynewman committed Dec 31, 2019
1 parent 0df3906 commit 1794962
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 16 deletions.
44 changes: 44 additions & 0 deletions Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Garry.Control4.Jailbreak
{
public static class Constants
{
public const int Version = 1;

/// <summary>
/// The cert for composer needs to be named cacert-*.pem
/// </summary>
public const string ComposerCertName = "cacert-garry.pem";

/// <summary>
/// Needs to start with Composer_ and can be anything after
/// </summary>
public const string CertificateCN = "Composer_GarryComposerMod";

/// <summary>
/// Should always be this unless they change something internally
/// </summary>
public const string CertPassword = "R8lvpqtgYiAeyO8j8Pyd";

/// <summary>
/// How many days until the certificate expires. Doesn't seem any harm in setting this to
/// a huge value so you don't have to re-crack every year.
/// </summary>
public const int CertificateExpireDays = 3650;

/// <summary>
/// Where OpenSSL is installed (it's installed with Composer)
/// </summary>
public const string OpenSslExe = @"C:\Program Files (x86)\Control4\Composer\Pro\RemoteAccess\bin\openssl.exe";

/// <summary>
/// Where OpenSSL's Config is located (it's installed with Composer)
/// </summary>
public const string OpenSslConfig = @"C:\Program Files (x86)\Control4\Composer\Pro\RemoteAccess\config\openssl.cfg";
}
}
1 change: 1 addition & 0 deletions Control4.Jailbreak.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Constants.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
Expand Down
30 changes: 14 additions & 16 deletions UI/DirectorPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ bool GenerateCertificates( LogWindow log )
// Don't regenerate the certificates. They might be copying the folder
// over to another computer or some shit.
//
if ( System.IO.File.Exists( $"Certs/cacert-garry.pem" ) &&
if ( System.IO.File.Exists( $"Certs/{Constants.ComposerCertName}" ) &&
System.IO.File.Exists( $"Certs/composer.p12" ) &&
System.IO.File.Exists( $"Certs/private.key" ) &&
System.IO.File.Exists( $"Certs/public.pem" ) )
Expand All @@ -78,17 +78,15 @@ bool GenerateCertificates( LogWindow log )
return true;
}

var openssl = @"C:\Program Files (x86)\Control4\Composer\Pro\RemoteAccess\bin\openssl.exe";
if ( !System.IO.File.Exists( openssl ) )
if ( !System.IO.File.Exists( Constants.OpenSslExe ) )
{
log.WriteError( $"Couldn't find {openssl} - do you have composer installed?" );
log.WriteError( $"Couldn't find {Constants.OpenSslExe} - do you have composer installed?" );
return false;
}

var config = @"C:\Program Files (x86)\Control4\Composer\Pro\RemoteAccess\config\openssl.cfg";
if ( !System.IO.File.Exists( openssl ) )
if ( !System.IO.File.Exists( Constants.OpenSslConfig ) )
{
log.WriteError( $"Couldn't find {config} - do you have composer installed?" );
log.WriteError( $"Couldn't find {Constants.OpenSslConfig} - do you have composer installed?" );
return false;
}

Expand All @@ -102,32 +100,32 @@ bool GenerateCertificates( LogWindow log )
// generate a self signed private and public key
//
log.WriteNormal( "\nGenerating private + public keys\n" );
var exitCode = RunProcessPrintOutput( log, openssl, $"req -new -x509 -sha256 -nodes -days 3650 -newkey rsa:1024 -keyout \"Certs/private.key\" -subj \"/C=US/ST=Utah/L=Draper/O=Control4/OU=Controller Certificates/CN=Composer_GarryComposerMod/\" -out \"Certs/public.pem\" -config \"{config}\"" );
var exitCode = RunProcessPrintOutput( log, Constants.OpenSslExe, $"req -new -x509 -sha256 -nodes -days {Constants.CertificateExpireDays} -newkey rsa:1024 -keyout \"Certs/private.key\" -subj \"/C=US/ST=Utah/L=Draper/O=Control4/OU=Controller Certificates/CN={Constants.CertificateCN}/\" -out \"Certs/public.pem\" -config \"{Constants.OpenSslConfig}\"" );

if ( exitCode != 0 )
{
MessageBox.Show( $"Couldn't find {config} - do you have composer installed?", "Openssl.cfg not found", MessageBoxButtons.OK, MessageBoxIcon.Error );
log.WriteError( $"Failed." );
return false;
}

//
// Create the composer.p12 (public key) which sits in your composer config folder
//
log.WriteNormal( "Creating composer.p12\n" );
exitCode = RunProcessPrintOutput( log, openssl, $"pkcs12 -export -out \"Certs/composer.p12\" -inkey \"Certs/private.key\" -in \"Certs/public.pem\" -passout pass:R8lvpqtgYiAeyO8j8Pyd" );
exitCode = RunProcessPrintOutput( log, Constants.OpenSslExe, $"pkcs12 -export -out \"Certs/composer.p12\" -inkey \"Certs/private.key\" -in \"Certs/public.pem\" -passout pass:{Constants.CertPassword}" );

if ( exitCode != 0 )
{
MessageBox.Show( $"Couldn't find {config} - do you have composer installed?", "Openssl.cfg not found", MessageBoxButtons.OK, MessageBoxIcon.Error );
log.WriteError( $"Failed." );
return false;
}

//
// Get the text for the composer cacert-garry.pem
// Get the text for the composer cacert-*.pem
//
log.WriteNormal( "Creating cacert-garry.pem\n" );
var output = RunProcessGetOutput( openssl, $"x509 -in \"Certs/public.pem\" -text" );
System.IO.File.WriteAllText( "Certs/cacert-garry.pem", output );
log.WriteNormal( $"Creating {Constants.ComposerCertName}\n" );
var output = RunProcessGetOutput( Constants.OpenSslExe, $"x509 -in \"Certs/public.pem\" -text" );
System.IO.File.WriteAllText( $"Certs/{Constants.ComposerCertName}", output );

return true;

Expand All @@ -137,7 +135,7 @@ bool PatchComposer( LogWindow log )
{
var configFolder = $"{Environment.GetFolderPath( Environment.SpecialFolder.ApplicationData )}\\Control4\\Composer";

CopyFile( log, $"Certs/cacert-garry.pem", $"{configFolder}\\cacert-garry.pem" );
CopyFile( log, $"Certs/{Constants.ComposerCertName}", $"{configFolder}\\{Constants.ComposerCertName}" );
CopyFile( log, $"Certs/composer.p12", $"{configFolder}\\composer.p12" );

return true;
Expand Down
2 changes: 2 additions & 0 deletions UI/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public MainWindow()
{
InitializeComponent();

this.Text += $" - v{Constants.Version}";

MainTabControl.TabPages.Clear();

Director = new Director( this );
Expand Down

0 comments on commit 1794962

Please sign in to comment.