Skip to content

Commit 54f2b70

Browse files
committed
vcsim: Avoid use of sha1 for stable UUIDs (OIDs)
api: soap.ThumbprintsSHA1 returns an empty string when GODEBUG contains "fips140=only" Fixes #3766 Signed-off-by: Doug MacEachern <[email protected]>
1 parent a5da4f5 commit 54f2b70

File tree

8 files changed

+28
-16
lines changed

8 files changed

+28
-16
lines changed

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,16 @@ go-test: ## Runs go unit tests with race detector enabled
152152
-v $(TEST_OPTS) \
153153
./...
154154

155+
.PHONY: go-fips140-test
156+
go-fips140-test: ## Test simulator can be used with fips140=only
157+
GODEBUG=fips140=only $(GO) test ./property
158+
159+
go-test: ## Runs go unit tests with race detector enabled
155160
.PHONY: govc-test
156161
govc-test: install
157162
govc-test: ## Runs govc bats tests
158163
./govc/test/images/update.sh
159164
(cd govc/test && ./vendor/github.com/bats-core/bats-core/bin/bats -t .)
160165

161166
.PHONY: test
162-
test: go-test govc-test ## Runs go-test and govc-test
167+
test: go-test go-fips140-test govc-test ## Runs go-test and govc-test

govc/test/vcsim.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,13 @@ EOF
212212

213213
# VM uuids are stable, based on path to .vmx
214214
run govc object.collect -s vm/DC0_H0_VM0 config.uuid config.instanceUuid
215-
assert_success "$(printf "265104de-1472-547c-b873-6dc7883fb6cb\nb4689bed-97f0-5bcd-8a4c-07477cc8f06f")"
215+
assert_success "$(printf "63d40cc5-9cba-5cc1-884a-f7f19070ecea\nb170c191-7587-5f8e-9a15-08c6a0a11ca5")"
216216

217217
dups=$(govc object.collect -s -type m / config.uuid | sort | uniq -d | wc -l)
218218
assert_equal 0 "$dups"
219219

220220
run govc object.collect -s host/DC0_H0/DC0_H0 summary.hardware.uuid
221-
assert_success dcf7fb3c-4a1c-5a05-b730-5e09f3704e2f
221+
assert_success efc5827c-ee19-5d35-84ef-a77d6ea6ee4c
222222

223223
dups=$(govc object.collect -s -type m / summary.hardware.uuid | sort | uniq -d | wc -l)
224224
assert_equal 0 "$dups"

internal/helpers.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package internal
66

77
import (
88
"context"
9+
"crypto/sha256"
910
"encoding/xml"
1011
"fmt"
1112
"io"
@@ -17,6 +18,8 @@ import (
1718
"slices"
1819
"strings"
1920

21+
"github.com/google/uuid"
22+
2023
"github.com/vmware/govmomi/vim25"
2124
"github.com/vmware/govmomi/vim25/mo"
2225
"github.com/vmware/govmomi/vim25/soap"
@@ -168,3 +171,8 @@ func (arg ReflectManagedMethodExecuterSoapArgument) Value() []string {
168171
func EsxcliName(name string) string {
169172
return strings.ReplaceAll(strings.Title(name), ".", "")
170173
}
174+
175+
// OID returns a stable UUID based on input s
176+
func OID(s string) uuid.UUID {
177+
return uuid.NewHash(sha256.New(), uuid.NameSpaceOID, []byte(s), 5)
178+
}

simulator/object.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ package simulator
77
import (
88
"bytes"
99

10-
"github.com/google/uuid"
11-
10+
"github.com/vmware/govmomi/internal"
1211
"github.com/vmware/govmomi/vim25/methods"
1312
"github.com/vmware/govmomi/vim25/soap"
1413
"github.com/vmware/govmomi/vim25/types"
@@ -44,12 +43,7 @@ func SetCustomValue(ctx *Context, req *types.SetCustomValue) soap.HasFault {
4443

4544
// newUUID returns a stable UUID string based on input s
4645
func newUUID(s string) string {
47-
return sha1UUID(s).String()
48-
}
49-
50-
// sha1UUID returns a stable UUID based on input s
51-
func sha1UUID(s string) uuid.UUID {
52-
return uuid.NewSHA1(uuid.NameSpaceOID, []byte(s))
46+
return internal.OID(s).String()
5347
}
5448

5549
// deepCopy uses xml encode/decode to copy src to dst

simulator/virtual_disk_manager.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
"strconv"
1111
"strings"
1212

13-
"github.com/google/uuid"
14-
1513
"github.com/vmware/govmomi/internal"
1614
"github.com/vmware/govmomi/vim25/methods"
1715
"github.com/vmware/govmomi/vim25/mo"
@@ -246,7 +244,7 @@ func virtualDiskUUID(dc *types.ManagedObjectReference, file string) string {
246244
if dc != nil {
247245
file = dc.String() + file
248246
}
249-
return uuid.NewSHA1(uuid.NameSpaceOID, []byte(file)).String()
247+
return newUUID(file)
250248
}
251249

252250
func (m *VirtualDiskManager) QueryVirtualDiskUuid(ctx *Context, req *types.QueryVirtualDiskUuid) soap.HasFault {

simulator/virtual_machine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func NewVirtualMachine(ctx *Context, parent types.ManagedObjectReference, spec *
121121
spec.Files.VmPathName = vmx.String()
122122

123123
dsPath := path.Dir(spec.Files.VmPathName)
124-
vm.uid = sha1UUID(spec.Files.VmPathName)
124+
vm.uid = internal.OID(spec.Files.VmPathName)
125125

126126
defaults := types.VirtualMachineConfigSpec{
127127
NumCPUs: 1,

simulator/vpx/service_content.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package vpx
77
import (
88
"github.com/google/uuid"
99

10+
"github.com/vmware/govmomi/internal"
1011
"github.com/vmware/govmomi/vim25/types"
1112
)
1213

@@ -29,7 +30,7 @@ var ServiceContent = types.ServiceContent{
2930
ProductLineId: "vpx",
3031
ApiType: "VirtualCenter",
3132
ApiVersion: "6.5",
32-
InstanceUuid: uuid.NewSHA1(uuid.NameSpaceOID, uuid.NodeID()).String(),
33+
InstanceUuid: internal.OID(string(uuid.NodeID())).String(),
3334
LicenseProductName: "VMware VirtualCenter Server",
3435
LicenseProductVersion: "6.0",
3536
},

vim25/soap/client.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,16 @@ func (c *Client) loadThumbprints(name string) error {
397397
return scanner.Err()
398398
}
399399

400+
var fips140 = strings.Contains(os.Getenv("GODEBUG"), "fips140=only")
401+
400402
// ThumbprintSHA1 returns the thumbprint of the given cert in the same format used by the SDK and Client.SetThumbprint.
401403
//
402404
// See: SSLVerifyFault.Thumbprint, SessionManagerGenericServiceTicket.Thumbprint, HostConnectSpec.SslThumbprint
405+
// When GODEBUG contains "fips140=only", this function returns an empty string.
403406
func ThumbprintSHA1(cert *x509.Certificate) string {
407+
if fips140 {
408+
return ""
409+
}
404410
sum := sha1.Sum(cert.Raw)
405411
hex := make([]string, len(sum))
406412
for i, b := range sum {

0 commit comments

Comments
 (0)