func GetCertificateThumbprint()

in pkg/internal/crypto/crypto_windows.go [168:209]


func GetCertificateThumbprint(cert *syscall.CertContext) ([]byte, error) {
	// Call it once to retrieve the thumbprint size
	var cbComputedHash uint32
	ret, _, err := syscall.Syscall6(
		procCertGetCertificateContextProperty.Addr(),
		4,
		uintptr(unsafe.Pointer(cert)),            // pCertContext
		uintptr(CertHashPropID),                  // dwPropId
		uintptr(0),                               // pvData)
		uintptr(unsafe.Pointer(&cbComputedHash)), // pcbData
		0,
		0,
	)

	if ret == 0 {
		return nil, fmt.Errorf("VmExtension: Could not hash certificate due to '%d'", syscall.Errno(err))
	}

	// Create our buffer
	if cbComputedHash == 0 {
		return nil, nil
	}

	var computedHashBuffer = make([]byte, cbComputedHash)
	var pComputedHash *byte
	pComputedHash = &computedHashBuffer[0]
	ret, _, err = syscall.Syscall6(
		procCertGetCertificateContextProperty.Addr(),
		4,
		uintptr(unsafe.Pointer(cert)),            // pCertContext
		uintptr(CertHashPropID),                  // dwPropId
		uintptr(unsafe.Pointer(pComputedHash)),   // pvData)
		uintptr(unsafe.Pointer(&cbComputedHash)), // pcbData
		0,
		0,
	)
	if ret == 0 {
		return nil, fmt.Errorf("VmExtension: Could not hash certificate due to '%d'", syscall.Errno(err))
	}

	return computedHashBuffer, nil
}