Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
zmb3 committed Dec 19, 2024
1 parent d3a0484 commit ef2bab1
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions lib/devicetrust/native/device_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ func handleTPMActivateCredential(encryptedCredential, encryptedCredentialSecret
return windowsDevice.handleTPMActivateCredential(encryptedCredential, encryptedCredentialSecret)
}

// getDeviceSerial returns the serial number of the device.
func getDeviceSerial() (string, error) {
// ThinkPad P P14s:
// PS > Get-WmiObject Win32_BIOS | Select -ExpandProperty SerialNumber
// PF47WND6

type Win32_BIOS struct {
SerialNumber string
}
Expand All @@ -95,6 +98,10 @@ func getDeviceSerial() (string, error) {
}

func getReportedAssetTag() (string, error) {
// ThinkPad P P14s:
// PS > Get-WmiObject Win32_SystemEnclosure | Select -ExpandProperty SMBIOSAssetTag
// winaia_1337

type Win32_SystemEnclosure struct {
SMBIOSAssetTag string
}
Expand All @@ -109,6 +116,10 @@ func getReportedAssetTag() (string, error) {
}

func getDeviceModel() (string, error) {
// ThinkPad P P14s:
// PS> Get-WmiObject Win32_ComputerSystem | Select -ExpandProperty Model
// 21J50013US

type Win32_ComputerSystem struct {
Model string
}
Expand All @@ -122,6 +133,10 @@ func getDeviceModel() (string, error) {
}

func getDeviceBaseBoardSerial() (string, error) {
// ThinkPad P P14s:
// PS> Get-WmiObject Win32_BaseBoard | Select -ExpandProperty SerialNumber
// L1HF2CM03ZT

type Win32_BaseBoard struct {
SerialNumber string
}
Expand All @@ -134,16 +149,6 @@ func getDeviceBaseBoardSerial() (string, error) {
return bb.SerialNumber, nil
}

func getOSVersion() (string, error) {
ver := windows.RtlGetVersion()
return fmt.Sprintf("%v.%v.%v", ver.MajorVersion, ver.MinorVersion, ver.BuildNumber), nil
}

func getOSBuildNumber() (string, error) {
ver := windows.RtlGetVersion()
return strconv.FormatInt(int64(ver.BuildNumber), 10), nil
}

func collectDeviceData(_ CollectDataMode) (*devicepb.DeviceCollectedData, error) {
log.Debug("TPM: Collecting device data.")

Expand All @@ -152,15 +157,13 @@ func collectDeviceData(_ CollectDataMode) (*devicepb.DeviceCollectedData, error)
g.SetLimit(groupLimit)

// Run exec-ed commands concurrently.
var systemSerial, baseBoardSerial, reportedAssetTag, model, osVersion, osBuildNumber string
var systemSerial, baseBoardSerial, reportedAssetTag, model string
for _, spec := range []struct {
fn func() (string, error)
out *string
desc string
}{
{fn: getDeviceModel, out: &model, desc: "device model"},
{fn: getOSVersion, out: &osVersion, desc: "os version"},
{fn: getOSBuildNumber, out: &osBuildNumber, desc: "os build number"},
{fn: getDeviceSerial, out: &systemSerial, desc: "system serial"},
{fn: getDeviceBaseBoardSerial, out: &baseBoardSerial, desc: "base board serial"},
{fn: getReportedAssetTag, out: &reportedAssetTag, desc: "reported asset tag"},
Expand All @@ -178,6 +181,8 @@ func collectDeviceData(_ CollectDataMode) (*devicepb.DeviceCollectedData, error)
})
}

ver := windows.RtlGetVersion()

// We want to fetch as much info as possible, so errors are ignored.
_ = g.Wait()

Expand All @@ -196,8 +201,8 @@ func collectDeviceData(_ CollectDataMode) (*devicepb.DeviceCollectedData, error)
OsType: devicepb.OSType_OS_TYPE_WINDOWS,
SerialNumber: serial,
ModelIdentifier: model,
OsVersion: osVersion,
OsBuild: osBuildNumber,
OsVersion: fmt.Sprintf("%v.%v.%v", ver.MajorVersion, ver.MinorVersion, ver.BuildNumber),
OsBuild: strconv.FormatInt(int64(ver.BuildNumber), 10),
OsUsername: u.Username,
SystemSerialNumber: systemSerial,
BaseBoardSerialNumber: baseBoardSerial,
Expand Down

0 comments on commit ef2bab1

Please sign in to comment.