175 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
51 lines
1.8 KiB
C
51 lines
1.8 KiB
C
#ifndef GW_ACCOUNT_IDENTITY_COMPARE_PRIVATE_H
|
|
#define GW_ACCOUNT_IDENTITY_COMPARE_PRIVATE_H
|
|
|
|
#include <windows.h>
|
|
#include <stdint.h>
|
|
|
|
#define GW_ACCOUNT_IDENTITY_EXPECTED_ENV "GW_NATIVE_EXPECTED_ACCOUNT"
|
|
struct GwAccountIdentityComparison {
|
|
uint32_t expected_bytes;
|
|
/* 0=no comparator, 1=normalized match, 2=mismatch, 3=invalid input */
|
|
uint32_t code;
|
|
};
|
|
|
|
static inline unsigned char gw_identity_upper(unsigned char value) {
|
|
return value >= 'a' && value <= 'z'
|
|
? (unsigned char)(value - 'a' + 'A') : value;
|
|
}
|
|
|
|
/* The runner's private expected identity exists only in the child's process
|
|
* environment until Wire clears it before Source dispatch. Never log bytes. */
|
|
static inline struct GwAccountIdentityComparison gw_identity_compare_expected(
|
|
const unsigned char *actual, uint32_t actual_bytes) {
|
|
struct GwAccountIdentityComparison result = {0, 0};
|
|
char expected[33] = {0};
|
|
DWORD bytes = GetEnvironmentVariableA(GW_ACCOUNT_IDENTITY_EXPECTED_ENV,
|
|
expected, sizeof(expected));
|
|
uint32_t i;
|
|
if (!bytes) goto done;
|
|
if (bytes > 32 || !actual || !actual_bytes || actual_bytes > 32) {
|
|
result.code = 3;
|
|
goto done;
|
|
}
|
|
result.expected_bytes = bytes;
|
|
result.code = bytes == actual_bytes ? 1 : 2;
|
|
for (i = 0; i < bytes; ++i) {
|
|
unsigned char value = (unsigned char)expected[i];
|
|
if (value < 32 || value > 126) {result.code = 3; goto done;}
|
|
if (i < actual_bytes) {
|
|
unsigned char observed = actual[i];
|
|
if (observed < 32 || observed > 126) {result.code = 3; goto done;}
|
|
if (gw_identity_upper(value) != gw_identity_upper(observed))
|
|
result.code = 2;
|
|
}
|
|
}
|
|
done:
|
|
SecureZeroMemory(expected, sizeof(expected));
|
|
return result;
|
|
}
|
|
|
|
#endif
|