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

setting a FriendlyName for a Windows certificate #9

Merged
merged 3 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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"
dgkanatsios marked this conversation as resolved.
Show resolved Hide resolved
} 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).
Loading