Skip to content

Commit fa730e2

Browse files
committed
#1234 : Added support of shared secret to file commands.
1 parent a07d321 commit fa730e2

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

Modules/Remoting Tests - Download with RemoteScriptCall.Tests.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ Describe "Download with RemoteScriptCall" {
1414
}
1515
New-Item -Path $destinationMediaPath -ItemType Directory | Out-Null
1616

17-
$session = New-ScriptSession -Username "sitecore\admin" -Password "b" -ConnectionUri $protocolHost
17+
$sharedSecret = '7AF6F59C14A05786E97012F054D1FB98AC756A2E54E5C9ACBAEE147D9ED0E0DB'
18+
#$session = New-ScriptSession -Username "sitecore\admin" -Password "b" -ConnectionUri $protocolHost
19+
$session = New-ScriptSession -Username "sitecore\admin" -SharedSecret $sharedSecret -ConnectionUri $protocolHost
1820
}
1921
AfterEach {
2022
Stop-ScriptSession -Session $session

Modules/Remoting Tests - Upload with RemoteScriptCall.Tests.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ if(!$protocolHost){
1111

1212
Describe "Upload with RemoteScriptCall" {
1313
BeforeEach {
14-
$session = New-ScriptSession -Username "sitecore\admin" -Password "b" -ConnectionUri $protocolHost
14+
$sharedSecret = '7AF6F59C14A05786E97012F054D1FB98AC756A2E54E5C9ACBAEE147D9ED0E0DB'
15+
#$session = New-ScriptSession -Username "sitecore\admin" -Password "b" -ConnectionUri $protocolHost
16+
$session = New-ScriptSession -Username "sitecore\admin" -SharedSecret $sharedSecret -ConnectionUri $protocolHost
1517
$localFilePath = Join-Path -Path $PSScriptRoot -ChildPath "spe-test"
1618
}
1719
AfterEach {

Modules/SPE/Receive-RemoteItem.ps1

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ function Receive-RemoteItem {
136136
if($Session) {
137137
$Username = $Session.Username
138138
$Password = $Session.Password
139+
$SharedSecret = $Session.SharedSecret
139140
$Credential = $Session.Credential
140141
$UseDefaultCredentials = $Session.UseDefaultCredentials
141142
$ConnectionUri = $Session | ForEach-Object { $_.Connection.BaseUri }
@@ -164,9 +165,15 @@ function Receive-RemoteItem {
164165
$handler = New-Object System.Net.Http.HttpClientHandler
165166
$handler.AutomaticDecompression = [System.Net.DecompressionMethods]::GZip -bor [System.Net.DecompressionMethods]::Deflate
166167
$client = New-Object -TypeName System.Net.Http.Httpclient $handler
167-
$authBytes = [System.Text.Encoding]::GetEncoding("iso-8859-1").GetBytes("$($Username):$($Password)")
168-
$client.DefaultRequestHeaders.Authorization = New-Object System.Net.Http.Headers.AuthenticationHeaderValue("Basic", [System.Convert]::ToBase64String($authBytes))
169-
168+
169+
if(![string]::IsNullOrEmpty($SharedSecret)) {
170+
$token = New-Jwt -Algorithm 'HS256' -Issuer 'SPE Remoting' -Audience ($uri.GetLeftPart([System.UriPartial]::Authority)) -Name $Username -SecretKey $SharedSecret -ValidforSeconds 30
171+
$client.DefaultRequestHeaders.Authorization = New-Object System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", $token)
172+
} else {
173+
$authBytes = [System.Text.Encoding]::GetEncoding("iso-8859-1").GetBytes("$($Username):$($Password)")
174+
$client.DefaultRequestHeaders.Authorization = New-Object System.Net.Http.Headers.AuthenticationHeaderValue("Basic", [System.Convert]::ToBase64String($authBytes))
175+
}
176+
170177
if($Credential) {
171178
$handler.Credentials = $Credential
172179
}

Modules/SPE/SPE.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
RootModule = '.\SPE.psm1'
1212

1313
# Version number of this module.
14-
ModuleVersion = '6.2.0'
14+
ModuleVersion = '6.3.0'
1515

1616
# ID used to uniquely identify this module
1717
GUID = 'cf8d3b69-b293-4d8b-9974-e1ab80509724'
@@ -23,7 +23,7 @@
2323
CompanyName = 'Sitecore PowerShell Extensions'
2424

2525
# Copyright statement for this module
26-
Copyright = '(c) 2010-2020 Adam Najmanowicz, Michael West. All rights Reserved.'
26+
Copyright = '(c) 2010-2021 Adam Najmanowicz, Michael West. All rights Reserved.'
2727

2828
# Description of the functionality provided by this module
2929
Description = 'The SPE Remoting module provides remote connectivity to a Sitecore instance. The Sitecore PowerShell Extensions (SPE) module must be installed and configured to accept remoting connections.'

Modules/SPE/Send-RemoteItem.ps1

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ function Send-RemoteItem {
142142
if($Session) {
143143
$Username = $Session.Username
144144
$Password = $Session.Password
145+
$SharedSecret = $Session.SharedSecret
145146
$Credential = $Session.Credential
146147
$UseDefaultCredentials = $Session.UseDefaultCredentials
147148
$ConnectionUri = $Session | ForEach-Object { $_.Connection.BaseUri }
@@ -172,8 +173,14 @@ function Send-RemoteItem {
172173
$handler = New-Object System.Net.Http.HttpClientHandler
173174
$handler.AutomaticDecompression = [System.Net.DecompressionMethods]::GZip -bor [System.Net.DecompressionMethods]::Deflate
174175
$client = New-Object -TypeName System.Net.Http.Httpclient $handler
175-
$authBytes = [System.Text.Encoding]::GetEncoding("iso-8859-1").GetBytes("$($Username):$($Password)")
176-
$client.DefaultRequestHeaders.Authorization = New-Object System.Net.Http.Headers.AuthenticationHeaderValue("Basic", [System.Convert]::ToBase64String($authBytes))
176+
177+
if(![string]::IsNullOrEmpty($SharedSecret)) {
178+
$token = New-Jwt -Algorithm 'HS256' -Issuer 'SPE Remoting' -Audience ($uri.GetLeftPart([System.UriPartial]::Authority)) -Name $Username -SecretKey $SharedSecret -ValidforSeconds 30
179+
$client.DefaultRequestHeaders.Authorization = New-Object System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", $token)
180+
} else {
181+
$authBytes = [System.Text.Encoding]::GetEncoding("iso-8859-1").GetBytes("$($Username):$($Password)")
182+
$client.DefaultRequestHeaders.Authorization = New-Object System.Net.Http.Headers.AuthenticationHeaderValue("Basic", [System.Convert]::ToBase64String($authBytes))
183+
}
177184

178185
if($Credential) {
179186
$client.Credentials = $Credential

0 commit comments

Comments
 (0)