Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to verify default TLS is compatible with GutHub #34

Merged
merged 7 commits into from
Mar 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,5 @@ paket-files/
*.vlb

*.dsk

*.~dsk
10 changes: 5 additions & 5 deletions Delphi/Project/ExercismCLIInstaller.dproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{F8605FE1-AB97-4531-9853-D43F5A666830}</ProjectGuid>
<ProjectVersion>18.3</ProjectVersion>
<ProjectVersion>18.4</ProjectVersion>
<FrameworkType>VCL</FrameworkType>
<MainSource>ExercismCLIInstaller.dpr</MainSource>
<Base>True</Base>
Expand Down Expand Up @@ -93,8 +93,8 @@
<VerInfo_Debug>true</VerInfo_Debug>
<VerInfo_PreRelease>true</VerInfo_PreRelease>
<VerInfo_AutoIncVersion>true</VerInfo_AutoIncVersion>
<VerInfo_Keys>CompanyName=Exercism;FileDescription=$(MSBuildProjectName);FileVersion=2.0.1.14;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=2.0.1.0;Comments=</VerInfo_Keys>
<VerInfo_Build>14</VerInfo_Build>
<VerInfo_Keys>CompanyName=Exercism;FileDescription=$(MSBuildProjectName);FileVersion=2.0.1.15;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=2.0.1.0;Comments=</VerInfo_Keys>
<VerInfo_Build>15</VerInfo_Build>
<VerInfo_Release>1</VerInfo_Release>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2)'!=''">
Expand All @@ -109,9 +109,9 @@
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
<VerInfo_MajorVer>2</VerInfo_MajorVer>
<VerInfo_AutoIncVersion>true</VerInfo_AutoIncVersion>
<VerInfo_Keys>CompanyName=Exercism;FileDescription=$(MSBuildProjectName);FileVersion=2.0.2.11;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=2.0.2.0;Comments=</VerInfo_Keys>
<VerInfo_Keys>CompanyName=Exercism;FileDescription=$(MSBuildProjectName);FileVersion=2.0.2.14;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=2.0.2.0;Comments=</VerInfo_Keys>
<Icon_MainIcon>img\ExercismCLIInstaller_Icon.ico</Icon_MainIcon>
<VerInfo_Build>11</VerInfo_Build>
<VerInfo_Build>14</VerInfo_Build>
<VerInfo_Release>2</VerInfo_Release>
</PropertyGroup>
<ItemGroup>
Expand Down
50 changes: 49 additions & 1 deletion Delphi/Project/Source/uInstallLocationFrm.dfm
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
object frmInstallLocation: TfrmInstallLocation
Left = 0
Top = 0
ActiveControl = btnNext
BorderIcons = []
BorderStyle = bsDialog
Caption = 'Exercism CLI Install'
Expand All @@ -15,6 +14,7 @@ object frmInstallLocation: TfrmInstallLocation
Font.Style = []
OldCreateOrder = False
Position = poScreenCenter
OnActivate = FormActivate
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
Expand Down Expand Up @@ -70,6 +70,29 @@ object frmInstallLocation: TfrmInstallLocation
ShowHint = True
Transparent = True
end
object lblUpdateTLS: TOvcURL
Left = 189
Top = 248
Width = 262
Height = 13
Hint =
'https://support.microsoft.com/en-us/help/3140245/update-to-enabl' +
'e-tls-1-1-and-tls-1-2-as-a-default-secure-protocols-in'
Caption = 'Microsoft instructions for updating default TLS settings'
URL =
'https://support.microsoft.com/en-us/help/3140245/update-to-enabl' +
'e-tls-1-1-and-tls-1-2-as-a-default-secure-protocols-in'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = [fsUnderline]
ParentFont = False
ParentShowHint = False
ShowHint = True
Transparent = True
Visible = False
end
object Panel1: TPanel
Left = 0
Top = 0
Expand Down Expand Up @@ -185,6 +208,7 @@ object frmInstallLocation: TfrmInstallLocation
Width = 75
Height = 25
Caption = '&Next >'
Enabled = False
TabOrder = 2
OnClick = btnNextClick
end
Expand All @@ -211,4 +235,28 @@ object frmInstallLocation: TfrmInstallLocation
TabOrder = 4
OnClick = btnBrowseClick
end
object rcCheckTLSVersion: TRESTClient
Accept = 'application/json, text/plain; q=0.9, text/html;q=0.8,'
AcceptCharset = 'UTF-8, *;q=0.8'
BaseURL = 'https://www.howsmyssl.com/a/check'
Params = <>
HandleRedirects = True
RaiseExceptionOn500 = False
Left = 248
Top = 48
end
object rrCheckTLSVersion: TRESTRequest
Client = rcCheckTLSVersion
Params = <>
Response = rResponseCheckTLSVersion
SynchronizedEvents = False
Left = 328
Top = 52
end
object rResponseCheckTLSVersion: TRESTResponse
ContentType = 'application/json'
RootElement = 'tls_version'
Left = 416
Top = 48
end
end
104 changes: 103 additions & 1 deletion Delphi/Project/Source/uInstallLocationFrm.pas
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,43 @@ interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, uTypes, Vcl.StdCtrls, Vcl.ExtCtrls,
Vcl.Imaging.pngimage, System.UITypes, ovcurl;
Vcl.Imaging.pngimage, System.UITypes, ovcurl, IPPeerClient, REST.Client,
Data.Bind.Components, Data.Bind.ObjectScope;

type
ICheckTLS = interface(IInvokable)
['{2AED8C0C-BF88-4A06-A3B2-418799CD28EF}']
function GetTLSOK: boolean;
function GetStatusCode: integer;
function GetTLSVersion: string;
function GetMessageStr: string;
property TLSok: boolean read GetTLSOK;
property StatusCode: integer read GetStatusCode;
property TLSVersion: string read GetTLSVersion;
property ErrMessage: string read GetMessageStr;
end;

TCheckTLS = class(TInterfacedObject, ICheckTLS)
strict private
const
cDesiredVersion: double = 1.2;
var
fTLSVersion: string;
fTLSOK: boolean;
fStatusCode: integer;
fMessageStr: string;
function GetTLSOK: boolean;
function GetStatusCode: integer;
function GetTLSVersion: string;
function GetMessageStr: string;
public
constructor Create(aRESTRequest: TRestRequest; aRESTResponse: TRESTResponse);
property TLSok: boolean read GetTLSOK;
property StatusCode: integer read GetStatusCode;
property TLSVersion: string read GetTLSVersion;
property ErrMessage: string read GetMessageStr;
end;

TfrmInstallLocation = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Expand All @@ -21,10 +55,15 @@ TfrmInstallLocation = class(TForm)
Label5: TLabel;
OvcURL4: TOvcURL;
Image1: TImage;
rcCheckTLSVersion: TRESTClient;
rrCheckTLSVersion: TRESTRequest;
rResponseCheckTLSVersion: TRESTResponse;
lblUpdateTLS: TOvcURL;
procedure btnCancelClick(Sender: TObject);
procedure btnNextClick(Sender: TObject);
procedure btnBrowseClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
Expand Down Expand Up @@ -110,10 +149,73 @@ procedure TfrmInstallLocation.btnNextClick(Sender: TObject);
end;
end;

procedure TfrmInstallLocation.FormActivate(Sender: TObject);
var
CheckTLS: ICheckTLS;
begin
CheckTLS := TCheckTLS.Create(rrCheckTLSVersion, rResponseCheckTLSVersion);
btnNext.Enabled := CheckTLS.TLSok;
if not btnNext.Enabled then
begin
lblUpdateTLS.Visible := true;
MessageDlg(CheckTLS.ErrMessage,mtError,[mbok],0);
end;
end;

procedure TfrmInstallLocation.FormCreate(Sender: TObject);
begin
NextClicked := false;
SetWindowLong(Handle, GWL_EXSTYLE, WS_EX_APPWINDOW);
end;

{ TCheckTLS }

constructor TCheckTLS.Create(aRESTRequest: TRestRequest; aRESTResponse: TRESTResponse);
var
splitVersion: TArray<string>;
actualVersion: double;
begin
aRESTRequest.Execute;
fStatusCode := aRESTResponse.StatusCode;
fMessageStr := '';
fTLSOK := false;
fTLSVersion := '';
if fStatusCode = 200 then
begin
fTLSVersion := aRESTResponse.JSONText.Replace('"','');
splitVersion := fTLSVersion.Split([' ']);
actualVersion := splitVersion[1].ToDouble;
fTLSOK := actualVersion >= cDesiredVersion;
if not fTLSOK then
fMessageStr := format('TLS Version = %s, must be %0.1f or greater.'+#13#10+
'GitHub requires at least version 1.2'+#13#10+
'Please follow the link to Microsoft for instructions on updating Windows.',[splitVersion[1],cDesiredVersion]);
end
else
begin
fMessageStr := format('Err: REST Status Code %d', [fStatusCode]);
fTLSOk := false;
end;
end;

function TCheckTLS.GetMessageStr: string;
begin
result := fMessageStr;
end;

function TCheckTLS.GetStatusCode: integer;
begin
result := fStatusCode;
end;

function TCheckTLS.GetTLSOK: boolean;
begin
result := fTLSOk;
end;

function TCheckTLS.GetTLSVersion: string;
begin
result := fTLSVersion;
end;

end.