Skip to content

Commit

Permalink
setting a FriendlyName for a Windows certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
dgkanatsios committed May 22, 2024
1 parent 1d7c96d commit 4739967
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
40 changes: 40 additions & 0 deletions windows_set_certificate_friendlyname/PF_StartupScript.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<#
.SYNOPSIS
<Overview of script>
.DESCRIPTION
<Brief description of script>
.NOTES
Version: 1.0
Author: <Name>
Creation Date: <Date>
Purpose/Change: Initial script development
#>

# Set Error Action to Stop
$ErrorActionPreference = "Stop"

# Grab the script path
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
echo "the current script path is $scriptPath"

# these are some of the env variables that are available to you
echo "PlayFab Title ID is $env:PF_TITLE_ID" # e.g. 59F84
echo "PlayFab Build ID is $env:PF_BUILD_ID" # Guid, e.g. 09d91059-22d3-4d0a-8c99-f34f80525aae
echo "PlayFab Virtual Machine ID is $env:PF_VM_ID" # e.g. vmss:SouthCentralUs:2458795A9259968E_12fe54be-fae1-41aa-83d9-09b809d5ef01:09d91059-22d3-4d0a-8c99-f34f80525aae
echo "Region where the VM is deployed is $env:PF_REGION" # e.g. SouthCentralUs
echo "Shared content folder is $env:PF_SHARED_CONTENT_FOLDER_VM" # e.g. D:\sharedcontentfolder (All servers running on this VM have access to this folder through the PF_SHARED_CONTENT_FOLDER env variable.)

# ACTION: Specify the correct subject name for your certificate
$subjectName = "DC=..., O=..., OU=..., CN=..."

# Find the certificate by subject name in the machine store
$cert = Get-ChildItem -Path Cert:\LocalMachine\My | Where-Object { $_.SubjectName.Name -eq $subjectName }

if ($cert) {
# ACTION: specify a proper friendly name for your certificate
$cert.FriendlyName = "My cert friendly name"
$cert | Out-Null # Suppress output
Write-Host "Friendly name set to 'My cert friendly name' for the certificate with subject name: $subjectName"
} else {
Write-Host "Certificate with subject name '$subjectName' not found."
}
5 changes: 5 additions & 0 deletions windows_set_certificate_friendlyname/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Windows - set certificate with friendly name

Sometimes our game server code needs to access a certificate by its friendly name. The friendly name property is a Windows only property which is not guaranteed to be present when PlayFab copies the cert into the VM. However, sometimes we cannot change the game server code to reference the certificate with more standard methods (e.g. Subject, Thumbprint, etc). This script helps you set the friendly name of a certificate in the Windows certificate store.

**NOTE**: Script is applicable only to PlayFab Builds using Windows processes. In this case, certs are deployed to the local machine store of the VM so the VmStartupScript can access them and set the friendly name. If you are running Builds using Windows containers, you can use a similar script on your StartGameCommand (before you start your game server).

0 comments on commit 4739967

Please sign in to comment.