AzureCheckTest 0.1.23
See the version list below for details.
dotnet add package AzureCheckTest --version 0.1.23
NuGet\Install-Package AzureCheckTest -Version 0.1.23
<PackageReference Include="AzureCheckTest" Version="0.1.23" />
<PackageVersion Include="AzureCheckTest" Version="0.1.23" />
<PackageReference Include="AzureCheckTest" />
paket add AzureCheckTest --version 0.1.23
#r "nuget: AzureCheckTest, 0.1.23"
#:package AzureCheckTest@0.1.23
#addin nuget:?package=AzureCheckTest&version=0.1.23
#tool nuget:?package=AzureCheckTest&version=0.1.23
IsAzureVM function (azurecheck.h)
The IsAzureVM function checks if the Windows Virtual Machine is on Azure using the attested metadata service.
This function uses the attested Azure IMDS Service which sends signed responses with trusted certificates. IsAzureVM will do attestation verifying those certificates and get the parameters decrypted from the response. For current Azure Instance Metadata Service (IMDS) attestation, refer here.
Syntax
HRESULT IsAzureVM (
[in] DWORD flags,
[in, optional] LPCWSTR nonce,
[in, out] AZURE_HOST_TYPE azureHostType,
[in, out, optional] AZURE_METADATA* response,
[out] BOOL* isAzureVM
);
Parameters
[in] flags
Flags which determine additional validations.
| Value | Meaning |
|---|---|
| AZURECHECK_USE_DIRECTACCESS 0x000000001 | Skip proxy configuration. Do direct HTTP Access on IMDS endpoint. |
| AZURECHECK_USE_NONCE 0x000000002 | Send nonce and validate it with IMDS response. If nonce not provided, a nonce will be generated using calling process name. |
| AZURECHECK_CERT_PINNING 0x000000100 | Do intermediate certificate check. |
[in, optional] nonce
A pointer to a string variable that contains the custom nonce which the calling application will validate with.
[in, out] azureHostType
A pointer to the AZURE_HOST_TYPE enumeration.
AZURE_HOST_TYPE
Syntax
typedef enum
{
AZURE_HOST_INVALID = 0,
AZURE_CLOUD,
AZURE_STACK,
AZURE_STACK_HCI,
AZURE_PRODUCT_MAX
} AZURE_HOST_TYPE;
Members
| Value | Meaning |
|---|---|
| AZURE_CLOUD | Azure VMs created with ARM (Azure Resource Manager) or created by using the classic deployment model. |
| AZURE_STACK | Azure VMs created with Azure Stack Hub. |
| AZURE_STACK_HCI | Azure VMs created with Azure Stack Hybrid Computing Instance (HCI) v2 product. |
If the value is AZURE_HOST_INVALID, then the API will determine the host product type and set the type accordingly.
If any other value is provided, then the API will attest if current VM is hosted on that specific host product.
[in, out, optional] response
A pointer to the AZURE_METADATA structure to be converted. It is a decrypted metadata from IMDS response. For more information, refer to Azure Instance Metadata Service for Windows - Azure Virtual Machines | Microsoft Docs
AZURE_METADATA
Syntax
typedef struct _tagAzureMetadataResponse
{
LPCWSTR nonce;
LPCWSTR plan;
LPCWSTR timeStampCreatedOn;
LPCWSTR timeStampExpiresOn;
LPCWSTR vmId;
LPCWSTR subscriptionId;
LPCWSTR sku;
LPCWSTR licenseType;
} AZURE_METADATA;
Members
| Data | Description |
|---|---|
| nonce | A string that can be optionally provided with the request. If no nonce was supplied, the current Coordinated Universal Time timestamp is used. |
| plan | The Azure Marketplace Image plan. Contains the plan ID (name), product image or offer (product), and publisher ID (publisher). |
| timeStampCreatedOn | The UTC timestamp for when the signed document was created |
| timeStampExpiresOn | The UTC timestamp for when the signed document expires |
| vmId | Unique identifier for the VM |
| subscriptionId | Azure subscription for the Virtual Machine |
| sku | Specific SKU for the VM image (correlates to compute/sku property from the Instance Metadata endpoint [/metadata/instance]) |
| licenseType | Type of license for Azure Hybrid Benefit. This is only present for AHB-enabled VMs. |
[out] isAzureVM
A pointer to Boolean value which indicates whether the VM is running in Azure.
Return value
Returns a HRESULT
Remarks
- Windows.h header file must be included.
- COM library must be initialized before the operation and closed after the operation.
- This function/API must always be used from its latest NuGet package Microsoft.Windows.AzureCheck
Example
#include <iostream>
#include <windows.h>
#include <azurecheck.h>
int main()
{
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
BOOL isAzureVM = FALSE;
AZURE_HOST_TYPE host_type = AZURE_HOST_TYPE::AZURE_HOST_INVALID;
AZURE_METADATA metadata = {};
HRESULT hrResult = IsAzureVM(0, NULL, &host_type, &metadata, &isAzureVM);
if (FAILED(hrResult)) {
std::cerr << "Call to IsAzureVM failed with this error: 0x" << std::hex << hrResult << std::endl;
}
else {
std::cout << "Is the code running in Azure? " << isAzureVM << std::endl;
std::cout << "Host type: " << host_type << std::endl;
}
CoUninitialize();
}
Requirements
| Minimum supported client | Windows Vista |
|---|---|
| Minimum supported server | Windows Server 2008 |
| Target Platform | Windows |
| Header | azurecheck.h |
| Library | azurecheck.lib |
| DLL | azurecheck.dll |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| native | native is compatible. |
| Windows | win32 is compatible. |
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 0.1.30 | 628 | 2/2/2023 | |
| 0.1.23 | 434 | 2/2/2023 | |
| 0.1.22 | 472 | 2/2/2023 | |
| 0.1.21 | 483 | 2/2/2023 | |
| 0.1.20 | 459 | 2/2/2023 | |
| 0.1.19 | 448 | 2/2/2023 | |
| 0.1.18 | 481 | 2/1/2023 | |
| 0.1.17 | 451 | 2/1/2023 | |
| 0.1.16 | 456 | 2/1/2023 | |
| 0.1.15 | 442 | 2/1/2023 | |
| 0.1.14 | 491 | 1/3/2023 | |
| 0.1.13 | 499 | 1/3/2023 | |
| 0.1.12 | 511 | 1/3/2023 | |
| 0.1.6 | 500 | 11/21/2022 | |
| 0.1.5-preview | 313 | 11/21/2022 |