2023-03-08 04:06:47 +03:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* Network Level Authentication (NLA)
|
|
|
|
*
|
|
|
|
* Copyright 2023 Isaac Klein <fifthdegree@protonmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <freerdp/config.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2023-03-08 18:33:49 +03:00
|
|
|
#include <string.h>
|
2023-03-08 04:06:47 +03:00
|
|
|
|
|
|
|
#include <freerdp/crypto/crypto.h>
|
2023-04-25 12:20:00 +03:00
|
|
|
#include <freerdp/crypto/privatekey.h>
|
|
|
|
#include "../crypto/privatekey.h"
|
2023-07-02 19:16:01 +03:00
|
|
|
#include <freerdp/utils/http.h>
|
2023-03-08 17:18:00 +03:00
|
|
|
|
2023-07-02 19:16:01 +03:00
|
|
|
#ifdef WITH_AAD
|
2023-03-08 17:18:00 +03:00
|
|
|
#include <cjson/cJSON.h>
|
2023-03-10 13:54:16 +03:00
|
|
|
#endif
|
2023-03-08 17:18:00 +03:00
|
|
|
|
2023-03-08 04:06:47 +03:00
|
|
|
#include <winpr/crypto.h>
|
|
|
|
|
2023-03-08 22:26:33 +03:00
|
|
|
#include "transport.h"
|
|
|
|
|
|
|
|
#include "aad.h"
|
|
|
|
|
2023-07-02 19:16:01 +03:00
|
|
|
#ifdef WITH_AAD
|
2023-03-10 10:48:30 +03:00
|
|
|
#if CJSON_VERSION_MAJOR == 1
|
|
|
|
#if CJSON_VERSION_MINOR <= 7
|
|
|
|
#if CJSON_VERSION_PATCH < 13
|
|
|
|
#define USE_CJSON_COMPAT
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
2023-03-10 13:54:16 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
struct rdp_aad
|
|
|
|
{
|
|
|
|
AAD_STATE state;
|
|
|
|
rdpContext* rdpcontext;
|
|
|
|
rdpTransport* transport;
|
|
|
|
char* access_token;
|
2023-04-25 12:20:00 +03:00
|
|
|
rdpPrivateKey* key;
|
2023-03-10 13:54:16 +03:00
|
|
|
char* kid;
|
|
|
|
char* nonce;
|
|
|
|
char* hostname;
|
2023-07-02 19:16:01 +03:00
|
|
|
char* scope;
|
2023-03-10 13:54:16 +03:00
|
|
|
wLog* log;
|
|
|
|
};
|
2023-03-10 10:48:30 +03:00
|
|
|
|
2023-07-02 19:16:01 +03:00
|
|
|
#ifdef WITH_AAD
|
2023-03-08 04:06:47 +03:00
|
|
|
|
2023-04-25 12:20:00 +03:00
|
|
|
static BOOL get_encoded_rsa_params(wLog* wlog, rdpPrivateKey* key, char** e, char** n);
|
2023-03-08 04:06:47 +03:00
|
|
|
static BOOL generate_pop_key(rdpAad* aad);
|
|
|
|
|
2023-03-08 18:33:49 +03:00
|
|
|
static SSIZE_T stream_sprintf(wStream* s, const char* fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
const int rc = vsnprintf(NULL, 0, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
|
2023-03-09 23:13:51 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, (size_t)rc + 1))
|
2023-03-08 18:33:49 +03:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
char* ptr = Stream_PointerAs(s, char);
|
2023-03-09 23:13:51 +03:00
|
|
|
va_start(ap, fmt);
|
|
|
|
const int rc2 = vsnprintf(ptr, rc + 1, fmt, ap);
|
|
|
|
va_end(ap);
|
2023-03-08 18:33:49 +03:00
|
|
|
if (rc != rc2)
|
|
|
|
return -23;
|
|
|
|
if (!Stream_SafeSeek(s, (size_t)rc2))
|
|
|
|
return -3;
|
|
|
|
return rc2;
|
|
|
|
}
|
|
|
|
|
2023-03-08 18:14:43 +03:00
|
|
|
static BOOL json_get_object(wLog* wlog, cJSON* json, const char* key, cJSON** obj)
|
2023-03-08 17:18:00 +03:00
|
|
|
{
|
|
|
|
WINPR_ASSERT(json);
|
|
|
|
WINPR_ASSERT(key);
|
|
|
|
|
|
|
|
if (!cJSON_HasObjectItem(json, key))
|
2023-03-08 18:14:43 +03:00
|
|
|
{
|
|
|
|
WLog_Print(wlog, WLOG_ERROR, "[json] does not contain a key '%s'", key);
|
2023-03-08 17:18:00 +03:00
|
|
|
return FALSE;
|
2023-03-08 18:14:43 +03:00
|
|
|
}
|
2023-03-08 17:18:00 +03:00
|
|
|
|
|
|
|
cJSON* prop = cJSON_GetObjectItem(json, key);
|
|
|
|
if (!prop)
|
2023-03-08 18:14:43 +03:00
|
|
|
{
|
|
|
|
WLog_Print(wlog, WLOG_ERROR, "[json] object for key '%s' is NULL", key);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2023-03-09 23:13:51 +03:00
|
|
|
*obj = prop;
|
2023-03-08 18:14:43 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-07-20 12:46:03 +03:00
|
|
|
#if defined(USE_CJSON_COMPAT)
|
|
|
|
FREERDP_API double cJSON_GetNumberValue(const cJSON* const item);
|
|
|
|
double cJSON_GetNumberValue(const cJSON* const prop)
|
2023-03-08 18:14:43 +03:00
|
|
|
{
|
2023-07-20 12:46:03 +03:00
|
|
|
#ifndef NAN
|
|
|
|
#ifdef _WIN32
|
|
|
|
#define NAN sqrt(-1.0)
|
|
|
|
#define COMPAT_NAN_UNDEF
|
|
|
|
#else
|
|
|
|
#define NAN 0.0 / 0.0
|
|
|
|
#define COMPAT_NAN_UNDEF
|
|
|
|
#endif
|
|
|
|
#endif
|
2023-03-08 17:18:00 +03:00
|
|
|
|
|
|
|
if (!cJSON_IsNumber(prop))
|
2023-07-20 12:46:03 +03:00
|
|
|
return NAN;
|
2023-03-10 10:48:30 +03:00
|
|
|
char* val = cJSON_GetStringValue(prop);
|
|
|
|
if (!val)
|
2023-07-20 12:46:03 +03:00
|
|
|
return NAN;
|
2023-03-10 10:48:30 +03:00
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
char* endptr = NULL;
|
|
|
|
double dval = strtod(val, &endptr);
|
|
|
|
if (val == endptr)
|
2023-07-20 12:46:03 +03:00
|
|
|
return NAN;
|
2023-03-10 10:48:30 +03:00
|
|
|
if (endptr != NULL)
|
2023-07-20 12:46:03 +03:00
|
|
|
return NAN;
|
2023-03-10 10:48:30 +03:00
|
|
|
if (errno != 0)
|
2023-07-20 12:46:03 +03:00
|
|
|
return NAN;
|
|
|
|
return dval;
|
|
|
|
|
|
|
|
#ifdef COMPAT_NAN_UNDEF
|
|
|
|
#undef NAN
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static BOOL json_get_number(wLog* wlog, cJSON* json, const char* key, double* result)
|
|
|
|
{
|
|
|
|
BOOL rc = FALSE;
|
|
|
|
cJSON* prop = NULL;
|
|
|
|
if (!json_get_object(wlog, json, key, &prop))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!cJSON_IsNumber(prop))
|
|
|
|
{
|
|
|
|
WLog_Print(wlog, WLOG_ERROR, "[json] object for key '%s' is NOT a NUMBER", key);
|
2023-03-10 10:48:30 +03:00
|
|
|
goto fail;
|
2023-07-20 12:46:03 +03:00
|
|
|
}
|
|
|
|
|
2023-03-08 17:18:00 +03:00
|
|
|
*result = cJSON_GetNumberValue(prop);
|
2023-07-20 12:46:03 +03:00
|
|
|
|
2023-03-08 20:54:34 +03:00
|
|
|
rc = TRUE;
|
|
|
|
fail:
|
|
|
|
return rc;
|
2023-03-08 17:18:00 +03:00
|
|
|
}
|
|
|
|
|
2023-03-08 18:14:43 +03:00
|
|
|
static BOOL json_get_const_string(wLog* wlog, cJSON* json, const char* key, const char** result)
|
2023-03-08 17:18:00 +03:00
|
|
|
{
|
2023-03-08 20:54:34 +03:00
|
|
|
BOOL rc = FALSE;
|
2023-03-08 17:18:00 +03:00
|
|
|
WINPR_ASSERT(result);
|
|
|
|
|
|
|
|
*result = NULL;
|
|
|
|
|
2023-03-08 18:14:43 +03:00
|
|
|
cJSON* prop = NULL;
|
|
|
|
if (!json_get_object(wlog, json, key, &prop))
|
2023-03-08 17:18:00 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!cJSON_IsString(prop))
|
2023-03-08 18:14:43 +03:00
|
|
|
{
|
|
|
|
WLog_Print(wlog, WLOG_ERROR, "[json] object for key '%s' is NOT a STRING", key);
|
2023-03-08 20:54:34 +03:00
|
|
|
goto fail;
|
2023-03-08 18:14:43 +03:00
|
|
|
}
|
2023-03-08 17:18:00 +03:00
|
|
|
|
|
|
|
const char* str = cJSON_GetStringValue(prop);
|
2023-03-08 18:14:43 +03:00
|
|
|
if (!str)
|
|
|
|
WLog_Print(wlog, WLOG_ERROR, "[json] object for key '%s' is NULL", key);
|
2023-03-08 17:18:00 +03:00
|
|
|
*result = str;
|
2023-03-08 20:54:34 +03:00
|
|
|
rc = str != NULL;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
return rc;
|
2023-03-08 17:18:00 +03:00
|
|
|
}
|
|
|
|
|
2023-03-08 18:14:43 +03:00
|
|
|
static BOOL json_get_string_alloc(wLog* wlog, cJSON* json, const char* key, char** result)
|
2023-03-08 17:18:00 +03:00
|
|
|
{
|
|
|
|
const char* str = NULL;
|
2023-03-08 18:14:43 +03:00
|
|
|
if (!json_get_const_string(wlog, json, key, &str))
|
2023-03-08 17:18:00 +03:00
|
|
|
return FALSE;
|
|
|
|
free(*result);
|
|
|
|
*result = _strdup(str);
|
2023-03-08 18:33:49 +03:00
|
|
|
if (!*result)
|
|
|
|
WLog_Print(wlog, WLOG_ERROR, "[json] object for key '%s' strdup is NULL", key);
|
2023-03-08 17:18:00 +03:00
|
|
|
return *result != NULL;
|
|
|
|
}
|
|
|
|
|
2023-03-10 10:48:30 +03:00
|
|
|
#if defined(USE_CJSON_COMPAT)
|
2023-07-20 12:46:03 +03:00
|
|
|
FREERDP_API cJSON* cJSON_ParseWithLength(const char* value, size_t buffer_length);
|
|
|
|
|
|
|
|
cJSON* cJSON_ParseWithLength(const char* value, size_t buffer_length)
|
|
|
|
{
|
2023-03-10 10:48:30 +03:00
|
|
|
// Check for string '\0' termination.
|
|
|
|
const size_t slen = strnlen(value, buffer_length);
|
|
|
|
if (slen >= buffer_length)
|
|
|
|
return NULL;
|
|
|
|
return cJSON_Parse(value);
|
|
|
|
}
|
2023-07-20 12:46:03 +03:00
|
|
|
#endif
|
2023-07-02 19:16:01 +03:00
|
|
|
|
|
|
|
static BOOL aad_get_nonce(rdpAad* aad)
|
2023-03-08 18:33:49 +03:00
|
|
|
{
|
2023-07-02 19:16:01 +03:00
|
|
|
BOOL ret = FALSE;
|
|
|
|
BYTE* response = NULL;
|
|
|
|
long resp_code = 0;
|
|
|
|
size_t response_length = 0;
|
|
|
|
cJSON* json = NULL;
|
2023-03-08 18:33:49 +03:00
|
|
|
|
2023-07-02 19:16:01 +03:00
|
|
|
if (!freerdp_http_request("https://login.microsoftonline.com/common/oauth2/v2.0/token",
|
|
|
|
"grant_type=srv_challenge", &resp_code, &response, &response_length))
|
2023-03-08 18:33:49 +03:00
|
|
|
{
|
2023-07-02 19:16:01 +03:00
|
|
|
WLog_Print(aad->log, WLOG_ERROR, "nonce request failed");
|
2023-03-08 18:33:49 +03:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2023-07-02 19:16:01 +03:00
|
|
|
if (resp_code != 200)
|
2023-03-08 18:33:49 +03:00
|
|
|
{
|
|
|
|
WLog_Print(aad->log, WLOG_ERROR,
|
2023-07-02 19:16:01 +03:00
|
|
|
"Server unwilling to provide nonce; returned status code %li", resp_code);
|
2023-03-08 18:33:49 +03:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2023-07-02 19:16:01 +03:00
|
|
|
json = cJSON_ParseWithLength((const char*)response, response_length);
|
2023-03-08 18:33:49 +03:00
|
|
|
if (!json)
|
|
|
|
{
|
2023-07-02 19:16:01 +03:00
|
|
|
WLog_Print(aad->log, WLOG_ERROR, "Failed to parse nonce response");
|
2023-03-08 18:33:49 +03:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!json_get_string_alloc(aad->log, json, "Nonce", &aad->nonce))
|
|
|
|
goto fail;
|
|
|
|
|
2023-07-02 19:16:01 +03:00
|
|
|
ret = TRUE;
|
2023-03-08 18:33:49 +03:00
|
|
|
|
|
|
|
fail:
|
2023-07-02 19:16:01 +03:00
|
|
|
free(response);
|
|
|
|
cJSON_Delete(json);
|
|
|
|
return ret;
|
2023-03-08 18:33:49 +03:00
|
|
|
}
|
|
|
|
|
2023-03-08 04:06:47 +03:00
|
|
|
int aad_client_begin(rdpAad* aad)
|
|
|
|
{
|
2023-07-02 19:16:01 +03:00
|
|
|
size_t size = 0;
|
2023-03-08 04:06:47 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(aad);
|
|
|
|
WINPR_ASSERT(aad->rdpcontext);
|
|
|
|
|
|
|
|
rdpSettings* settings = aad->rdpcontext->settings;
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
|
|
|
freerdp* instance = aad->rdpcontext->instance;
|
|
|
|
WINPR_ASSERT(instance);
|
|
|
|
|
|
|
|
/* Get the host part of the hostname */
|
2023-03-08 18:33:49 +03:00
|
|
|
const char* hostname = freerdp_settings_get_string(settings, FreeRDP_ServerHostname);
|
|
|
|
if (!hostname)
|
|
|
|
{
|
|
|
|
WLog_Print(aad->log, WLOG_ERROR, "FreeRDP_ServerHostname == NULL");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
aad->hostname = _strdup(hostname);
|
2023-03-09 23:13:51 +03:00
|
|
|
if (!aad->hostname)
|
2023-03-08 18:33:49 +03:00
|
|
|
{
|
|
|
|
WLog_Print(aad->log, WLOG_ERROR, "_strdup(FreeRDP_ServerHostname) == NULL");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
char* p = strchr(aad->hostname, '.');
|
|
|
|
if (p)
|
2023-03-08 04:06:47 +03:00
|
|
|
*p = '\0';
|
|
|
|
|
2023-07-02 19:16:01 +03:00
|
|
|
if (winpr_asprintf(&aad->scope, &size,
|
|
|
|
"ms-device-service%%3A%%2F%%2Ftermsrv.wvd.microsoft.com%%2Fname%%2F%s%%"
|
|
|
|
"2Fuser_impersonation",
|
|
|
|
aad->hostname) <= 0)
|
|
|
|
return -1;
|
|
|
|
|
2023-03-08 04:06:47 +03:00
|
|
|
if (!generate_pop_key(aad))
|
2023-07-02 19:16:01 +03:00
|
|
|
return -1;
|
2023-03-08 04:06:47 +03:00
|
|
|
|
|
|
|
/* Obtain an oauth authorization code */
|
2023-07-20 09:35:55 +03:00
|
|
|
if (!instance->GetAccessToken)
|
2023-03-08 18:33:49 +03:00
|
|
|
{
|
2023-07-20 09:35:55 +03:00
|
|
|
WLog_Print(aad->log, WLOG_ERROR, "instance->GetAccessToken == NULL");
|
2023-07-02 19:16:01 +03:00
|
|
|
return -1;
|
2023-03-08 18:33:49 +03:00
|
|
|
}
|
2023-07-20 09:35:55 +03:00
|
|
|
const BOOL arc = instance->GetAccessToken(instance, ACCESS_TOKEN_TYPE_AAD, &aad->access_token,
|
|
|
|
2, aad->scope, aad->kid);
|
2023-03-08 18:33:49 +03:00
|
|
|
if (!arc)
|
2023-03-08 04:06:47 +03:00
|
|
|
{
|
2023-07-02 19:16:01 +03:00
|
|
|
WLog_Print(aad->log, WLOG_ERROR, "Unable to obtain access token");
|
|
|
|
return -1;
|
2023-03-08 04:06:47 +03:00
|
|
|
}
|
|
|
|
|
2023-07-02 19:16:01 +03:00
|
|
|
/* Send the nonce request message */
|
|
|
|
if (!aad_get_nonce(aad))
|
2023-03-08 04:06:47 +03:00
|
|
|
{
|
2023-07-02 19:16:01 +03:00
|
|
|
WLog_Print(aad->log, WLOG_ERROR, "Unable to obtain nonce");
|
|
|
|
return -1;
|
2023-03-08 04:06:47 +03:00
|
|
|
}
|
|
|
|
|
2023-07-02 19:16:01 +03:00
|
|
|
return 1;
|
2023-03-08 04:06:47 +03:00
|
|
|
}
|
|
|
|
|
2023-03-08 18:33:49 +03:00
|
|
|
static char* aad_create_jws_header(rdpAad* aad)
|
2023-03-08 04:06:47 +03:00
|
|
|
{
|
|
|
|
WINPR_ASSERT(aad);
|
|
|
|
|
|
|
|
/* Construct the base64url encoded JWS header */
|
2023-03-08 18:33:49 +03:00
|
|
|
char* buffer = NULL;
|
|
|
|
size_t bufferlen = 0;
|
|
|
|
const int length =
|
2023-05-17 20:17:59 +03:00
|
|
|
winpr_asprintf(&buffer, &bufferlen, "{\"alg\":\"RS256\",\"kid\":\"%s\"}", aad->kid);
|
2023-03-08 18:33:49 +03:00
|
|
|
if (length < 0)
|
|
|
|
return NULL;
|
|
|
|
|
2023-03-08 22:26:33 +03:00
|
|
|
char* jws_header = crypto_base64url_encode((const BYTE*)buffer, bufferlen);
|
2023-03-08 18:33:49 +03:00
|
|
|
free(buffer);
|
|
|
|
return jws_header;
|
|
|
|
}
|
2023-03-08 04:06:47 +03:00
|
|
|
|
2023-03-08 18:33:49 +03:00
|
|
|
static char* aad_create_jws_payload(rdpAad* aad, const char* ts_nonce)
|
|
|
|
{
|
|
|
|
const time_t ts = time(NULL);
|
|
|
|
|
|
|
|
WINPR_ASSERT(aad);
|
|
|
|
|
|
|
|
char* e = NULL;
|
|
|
|
char* n = NULL;
|
2023-04-25 12:20:00 +03:00
|
|
|
if (!get_encoded_rsa_params(aad->log, aad->key, &e, &n))
|
2023-03-08 18:33:49 +03:00
|
|
|
return NULL;
|
2023-03-08 04:06:47 +03:00
|
|
|
|
|
|
|
/* Construct the base64url encoded JWS payload */
|
2023-03-08 18:33:49 +03:00
|
|
|
char* buffer = NULL;
|
|
|
|
size_t bufferlen = 0;
|
|
|
|
const int length =
|
2023-05-17 20:17:59 +03:00
|
|
|
winpr_asprintf(&buffer, &bufferlen,
|
2023-05-17 20:25:37 +03:00
|
|
|
"{"
|
|
|
|
"\"ts\":\"%li\","
|
|
|
|
"\"at\":\"%s\","
|
|
|
|
"\"u\":\"ms-device-service://termsrv.wvd.microsoft.com/name/%s\","
|
|
|
|
"\"nonce\":\"%s\","
|
|
|
|
"\"cnf\":{\"jwk\":{\"kty\":\"RSA\",\"e\":\"%s\",\"n\":\"%s\"}},"
|
|
|
|
"\"client_claims\":\"{\\\"aad_nonce\\\":\\\"%s\\\"}\""
|
|
|
|
"}",
|
|
|
|
ts, aad->access_token, aad->hostname, ts_nonce, e, n, aad->nonce);
|
2023-03-08 18:33:49 +03:00
|
|
|
free(e);
|
|
|
|
free(n);
|
|
|
|
|
2023-03-08 04:06:47 +03:00
|
|
|
if (length < 0)
|
2023-03-08 18:33:49 +03:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
char* jws_payload = crypto_base64url_encode((BYTE*)buffer, bufferlen);
|
|
|
|
free(buffer);
|
|
|
|
return jws_payload;
|
|
|
|
}
|
|
|
|
|
2023-04-25 12:20:00 +03:00
|
|
|
static BOOL aad_update_digest(rdpAad* aad, WINPR_DIGEST_CTX* ctx, const char* what)
|
2023-03-08 18:33:49 +03:00
|
|
|
{
|
|
|
|
WINPR_ASSERT(aad);
|
|
|
|
WINPR_ASSERT(ctx);
|
|
|
|
WINPR_ASSERT(what);
|
|
|
|
|
2023-04-25 12:20:00 +03:00
|
|
|
const BOOL dsu1 = winpr_DigestSign_Update(ctx, what, strlen(what));
|
|
|
|
if (!dsu1)
|
2023-03-08 18:33:49 +03:00
|
|
|
{
|
2023-04-25 12:20:00 +03:00
|
|
|
WLog_Print(aad->log, WLOG_ERROR, "winpr_DigestSign_Update [%s] failed", what);
|
2023-03-08 18:33:49 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-04-25 12:20:00 +03:00
|
|
|
static char* aad_final_digest(rdpAad* aad, WINPR_DIGEST_CTX* ctx)
|
2023-03-08 18:33:49 +03:00
|
|
|
{
|
|
|
|
char* jws_signature = NULL;
|
|
|
|
|
|
|
|
WINPR_ASSERT(aad);
|
|
|
|
WINPR_ASSERT(ctx);
|
|
|
|
|
|
|
|
size_t siglen = 0;
|
2023-04-25 12:20:00 +03:00
|
|
|
const int dsf = winpr_DigestSign_Final(ctx, NULL, &siglen);
|
2023-03-08 18:33:49 +03:00
|
|
|
if (dsf <= 0)
|
|
|
|
{
|
2023-04-25 12:20:00 +03:00
|
|
|
WLog_Print(aad->log, WLOG_ERROR, "winpr_DigestSign_Final failed with %d", dsf);
|
2023-03-08 18:33:49 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
char* buffer = calloc(siglen + 1, sizeof(char));
|
|
|
|
if (!buffer)
|
|
|
|
{
|
|
|
|
WLog_Print(aad->log, WLOG_ERROR, "calloc %" PRIuz " bytes failed", siglen + 1);
|
2023-03-08 04:06:47 +03:00
|
|
|
goto fail;
|
2023-03-08 18:33:49 +03:00
|
|
|
}
|
|
|
|
|
2023-03-09 23:13:51 +03:00
|
|
|
size_t fsiglen = siglen;
|
2023-04-25 12:20:00 +03:00
|
|
|
const int dsf2 = winpr_DigestSign_Final(ctx, (BYTE*)buffer, &fsiglen);
|
2023-03-08 18:33:49 +03:00
|
|
|
if (dsf2 <= 0)
|
|
|
|
{
|
2023-04-25 12:20:00 +03:00
|
|
|
WLog_Print(aad->log, WLOG_ERROR, "winpr_DigestSign_Final failed with %d", dsf2);
|
2023-03-08 04:06:47 +03:00
|
|
|
goto fail;
|
2023-03-08 18:33:49 +03:00
|
|
|
}
|
2023-03-08 04:06:47 +03:00
|
|
|
|
2023-03-08 18:33:49 +03:00
|
|
|
if (siglen != fsiglen)
|
|
|
|
{
|
|
|
|
WLog_Print(aad->log, WLOG_ERROR,
|
2023-04-25 12:20:00 +03:00
|
|
|
"winpr_DigestSignFinal returned different sizes, first %" PRIuz " then %" PRIuz,
|
2023-03-08 18:33:49 +03:00
|
|
|
siglen, fsiglen);
|
2023-03-08 04:06:47 +03:00
|
|
|
goto fail;
|
2023-03-08 18:33:49 +03:00
|
|
|
}
|
2023-03-08 22:26:33 +03:00
|
|
|
jws_signature = crypto_base64url_encode((const BYTE*)buffer, fsiglen);
|
2023-03-08 18:33:49 +03:00
|
|
|
fail:
|
|
|
|
free(buffer);
|
|
|
|
return jws_signature;
|
|
|
|
}
|
2023-03-08 04:06:47 +03:00
|
|
|
|
2023-03-08 18:33:49 +03:00
|
|
|
static char* aad_create_jws_signature(rdpAad* aad, const char* jws_header, const char* jws_payload)
|
|
|
|
{
|
|
|
|
char* jws_signature = NULL;
|
2023-03-08 04:06:47 +03:00
|
|
|
|
2023-03-08 18:33:49 +03:00
|
|
|
WINPR_ASSERT(aad);
|
2023-03-08 04:06:47 +03:00
|
|
|
|
2023-04-25 12:20:00 +03:00
|
|
|
WINPR_DIGEST_CTX* md_ctx = freerdp_key_digest_sign(aad->key, WINPR_MD_SHA256);
|
2023-03-08 18:33:49 +03:00
|
|
|
if (!md_ctx)
|
|
|
|
{
|
2023-04-25 12:20:00 +03:00
|
|
|
WLog_Print(aad->log, WLOG_ERROR, "winpr_Digest_New failed");
|
2023-03-08 04:06:47 +03:00
|
|
|
goto fail;
|
2023-03-08 18:33:49 +03:00
|
|
|
}
|
2023-03-08 04:06:47 +03:00
|
|
|
|
2023-03-08 18:33:49 +03:00
|
|
|
if (!aad_update_digest(aad, md_ctx, jws_header))
|
|
|
|
goto fail;
|
|
|
|
if (!aad_update_digest(aad, md_ctx, "."))
|
|
|
|
goto fail;
|
|
|
|
if (!aad_update_digest(aad, md_ctx, jws_payload))
|
2023-03-08 04:06:47 +03:00
|
|
|
goto fail;
|
|
|
|
|
2023-03-08 18:33:49 +03:00
|
|
|
jws_signature = aad_final_digest(aad, md_ctx);
|
|
|
|
fail:
|
2023-04-25 12:20:00 +03:00
|
|
|
winpr_Digest_Free(md_ctx);
|
2023-03-08 18:33:49 +03:00
|
|
|
return jws_signature;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int aad_send_auth_request(rdpAad* aad, const char* ts_nonce)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
2023-03-08 22:26:33 +03:00
|
|
|
char* jws_header = NULL;
|
2023-03-08 18:33:49 +03:00
|
|
|
char* jws_payload = NULL;
|
|
|
|
char* jws_signature = NULL;
|
|
|
|
|
|
|
|
WINPR_ASSERT(aad);
|
|
|
|
WINPR_ASSERT(ts_nonce);
|
|
|
|
|
|
|
|
wStream* s = Stream_New(NULL, 1024);
|
|
|
|
if (!s)
|
2023-03-08 04:06:47 +03:00
|
|
|
goto fail;
|
|
|
|
|
2023-03-08 18:33:49 +03:00
|
|
|
/* Construct the base64url encoded JWS header */
|
2023-03-08 22:26:33 +03:00
|
|
|
jws_header = aad_create_jws_header(aad);
|
2023-03-08 18:33:49 +03:00
|
|
|
if (!jws_header)
|
2023-03-08 04:06:47 +03:00
|
|
|
goto fail;
|
|
|
|
|
2023-03-08 18:33:49 +03:00
|
|
|
/* Construct the base64url encoded JWS payload */
|
|
|
|
jws_payload = aad_create_jws_payload(aad, ts_nonce);
|
|
|
|
if (!jws_payload)
|
|
|
|
goto fail;
|
2023-03-08 04:06:47 +03:00
|
|
|
|
2023-03-08 18:33:49 +03:00
|
|
|
/* Sign the JWS with the pop key */
|
|
|
|
jws_signature = aad_create_jws_signature(aad, jws_header, jws_payload);
|
|
|
|
if (!jws_signature)
|
|
|
|
goto fail;
|
2023-03-08 04:06:47 +03:00
|
|
|
|
2023-03-08 18:33:49 +03:00
|
|
|
/* Construct the Authentication Request PDU with the JWS as the RDP Assertion */
|
|
|
|
if (stream_sprintf(s, "{\"rdp_assertion\":\"%s.%s.%s\"}", jws_header, jws_payload,
|
|
|
|
jws_signature) < 0)
|
|
|
|
goto fail;
|
|
|
|
Stream_SealLength(s);
|
|
|
|
|
|
|
|
if (transport_write(aad->transport, s) < 0)
|
|
|
|
{
|
|
|
|
WLog_Print(aad->log, WLOG_ERROR, "transport_write [%" PRIdz " bytes] failed",
|
|
|
|
Stream_Length(s));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = 1;
|
|
|
|
aad->state = AAD_STATE_AUTH;
|
|
|
|
}
|
2023-03-08 04:06:47 +03:00
|
|
|
fail:
|
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
free(jws_header);
|
|
|
|
free(jws_payload);
|
|
|
|
free(jws_signature);
|
2023-03-08 18:33:49 +03:00
|
|
|
|
2023-03-08 04:06:47 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-03-08 17:18:00 +03:00
|
|
|
static int aad_parse_state_initial(rdpAad* aad, wStream* s)
|
2023-03-08 04:06:47 +03:00
|
|
|
{
|
2023-03-08 17:18:00 +03:00
|
|
|
const char* jstr = Stream_PointerAs(s, char);
|
|
|
|
const size_t jlen = Stream_GetRemainingLength(s);
|
|
|
|
const char* ts_nonce = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
cJSON* json = NULL;
|
2023-03-08 04:06:47 +03:00
|
|
|
|
2023-03-08 17:18:00 +03:00
|
|
|
if (!Stream_SafeSeek(s, jlen))
|
|
|
|
goto fail;
|
2023-03-08 04:06:47 +03:00
|
|
|
|
2023-07-20 12:46:03 +03:00
|
|
|
json = cJSON_ParseWithLength(jstr, jlen);
|
2023-03-08 17:18:00 +03:00
|
|
|
if (!json)
|
|
|
|
goto fail;
|
2023-03-08 04:06:47 +03:00
|
|
|
|
2023-03-08 18:14:43 +03:00
|
|
|
if (!json_get_const_string(aad->log, json, "ts_nonce", &ts_nonce))
|
2023-03-08 17:18:00 +03:00
|
|
|
goto fail;
|
2023-03-08 04:06:47 +03:00
|
|
|
|
2023-03-08 17:18:00 +03:00
|
|
|
ret = aad_send_auth_request(aad, ts_nonce);
|
|
|
|
fail:
|
2023-03-09 23:13:51 +03:00
|
|
|
cJSON_Delete(json);
|
2023-03-08 17:18:00 +03:00
|
|
|
return ret;
|
|
|
|
}
|
2023-03-08 04:06:47 +03:00
|
|
|
|
2023-03-08 17:18:00 +03:00
|
|
|
static int aad_parse_state_auth(rdpAad* aad, wStream* s)
|
|
|
|
{
|
|
|
|
int rc = -1;
|
|
|
|
double result = 0;
|
|
|
|
cJSON* json = NULL;
|
|
|
|
const char* jstr = Stream_PointerAs(s, char);
|
|
|
|
const size_t jlength = Stream_GetRemainingLength(s);
|
2023-03-08 04:06:47 +03:00
|
|
|
|
2023-03-08 17:18:00 +03:00
|
|
|
if (!Stream_SafeSeek(s, jlength))
|
|
|
|
goto fail;
|
2023-03-08 04:06:47 +03:00
|
|
|
|
2023-07-20 12:46:03 +03:00
|
|
|
json = cJSON_ParseWithLength(jstr, jlength);
|
2023-03-08 17:18:00 +03:00
|
|
|
if (!json)
|
|
|
|
goto fail;
|
2023-03-08 04:06:47 +03:00
|
|
|
|
2023-03-08 18:14:43 +03:00
|
|
|
if (!json_get_number(aad->log, json, "authentication_result", &result))
|
2023-03-08 17:18:00 +03:00
|
|
|
goto fail;
|
2023-03-08 04:06:47 +03:00
|
|
|
|
2023-03-08 18:33:49 +03:00
|
|
|
if (result != 0.0)
|
|
|
|
{
|
|
|
|
WLog_Print(aad->log, WLOG_ERROR, "Authentication result: %lf", result);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
aad->state = AAD_STATE_FINAL;
|
2023-03-08 17:18:00 +03:00
|
|
|
rc = 1;
|
|
|
|
fail:
|
2023-03-09 23:13:51 +03:00
|
|
|
cJSON_Delete(json);
|
2023-03-08 17:18:00 +03:00
|
|
|
return rc;
|
|
|
|
}
|
2023-03-08 18:33:49 +03:00
|
|
|
|
2023-03-08 17:18:00 +03:00
|
|
|
int aad_recv(rdpAad* aad, wStream* s)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(aad);
|
|
|
|
WINPR_ASSERT(s);
|
|
|
|
|
2023-03-08 18:33:49 +03:00
|
|
|
switch (aad->state)
|
|
|
|
{
|
|
|
|
case AAD_STATE_INITIAL:
|
|
|
|
return aad_parse_state_initial(aad, s);
|
|
|
|
case AAD_STATE_AUTH:
|
|
|
|
return aad_parse_state_auth(aad, s);
|
2023-03-08 22:26:33 +03:00
|
|
|
case AAD_STATE_FINAL:
|
2023-03-08 18:33:49 +03:00
|
|
|
default:
|
|
|
|
WLog_Print(aad->log, WLOG_ERROR, "Invalid AAD_STATE %d", aad->state);
|
|
|
|
return -1;
|
|
|
|
}
|
2023-03-08 04:06:47 +03:00
|
|
|
}
|
|
|
|
|
2023-03-08 18:33:49 +03:00
|
|
|
static BOOL generate_rsa_2048(rdpAad* aad)
|
2023-03-08 04:06:47 +03:00
|
|
|
{
|
|
|
|
WINPR_ASSERT(aad);
|
2023-04-25 12:20:00 +03:00
|
|
|
return freerdp_key_generate(aad->key, 2048);
|
2023-03-08 18:33:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static char* generate_rsa_digest_base64_str(rdpAad* aad, const char* input, size_t ilen)
|
|
|
|
{
|
|
|
|
char* b64 = NULL;
|
|
|
|
WINPR_DIGEST_CTX* digest = winpr_Digest_New();
|
|
|
|
if (!digest)
|
|
|
|
{
|
|
|
|
WLog_Print(aad->log, WLOG_ERROR, "winpr_Digest_New failed");
|
2023-03-08 04:06:47 +03:00
|
|
|
goto fail;
|
2023-03-08 18:33:49 +03:00
|
|
|
}
|
2023-03-08 04:06:47 +03:00
|
|
|
|
|
|
|
if (!winpr_Digest_Init(digest, WINPR_MD_SHA256))
|
2023-03-08 18:33:49 +03:00
|
|
|
{
|
|
|
|
WLog_Print(aad->log, WLOG_ERROR, "winpr_Digest_Init(WINPR_MD_SHA256) failed");
|
|
|
|
goto fail;
|
|
|
|
}
|
2023-03-08 04:06:47 +03:00
|
|
|
|
2023-03-08 18:33:49 +03:00
|
|
|
if (!winpr_Digest_Update(digest, (const BYTE*)input, ilen))
|
|
|
|
{
|
|
|
|
WLog_Print(aad->log, WLOG_ERROR, "winpr_Digest_Update(%" PRIuz ") failed", ilen);
|
2023-03-08 04:06:47 +03:00
|
|
|
goto fail;
|
2023-03-08 18:33:49 +03:00
|
|
|
}
|
2023-03-08 04:06:47 +03:00
|
|
|
|
2023-03-08 18:33:49 +03:00
|
|
|
BYTE hash[WINPR_SHA256_DIGEST_LENGTH] = { 0 };
|
|
|
|
if (!winpr_Digest_Final(digest, hash, sizeof(hash)))
|
2023-03-08 04:06:47 +03:00
|
|
|
{
|
2023-03-08 18:33:49 +03:00
|
|
|
WLog_Print(aad->log, WLOG_ERROR, "winpr_Digest_Final(%" PRIuz ") failed", sizeof(hash));
|
|
|
|
goto fail;
|
2023-03-08 04:06:47 +03:00
|
|
|
}
|
|
|
|
|
2023-03-08 18:33:49 +03:00
|
|
|
/* Base64url encode the hash */
|
|
|
|
b64 = crypto_base64url_encode(hash, sizeof(hash));
|
|
|
|
|
|
|
|
fail:
|
|
|
|
winpr_Digest_Free(digest);
|
|
|
|
return b64;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL generate_json_base64_str(rdpAad* aad, const char* b64_hash)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(aad);
|
|
|
|
|
|
|
|
char* buffer = NULL;
|
|
|
|
size_t blen = 0;
|
2023-05-17 20:17:59 +03:00
|
|
|
const int length = winpr_asprintf(&buffer, &blen, "{\"kid\":\"%s\"}", b64_hash);
|
2023-03-08 18:33:49 +03:00
|
|
|
if (length < 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2023-03-08 04:06:47 +03:00
|
|
|
/* Finally, base64url encode the JSON text to form the kid */
|
2023-03-08 18:33:49 +03:00
|
|
|
free(aad->kid);
|
2023-03-08 22:26:33 +03:00
|
|
|
aad->kid = crypto_base64url_encode((const BYTE*)buffer, (size_t)length);
|
2023-03-08 18:33:49 +03:00
|
|
|
free(buffer);
|
|
|
|
|
|
|
|
if (!aad->kid)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL generate_pop_key(rdpAad* aad)
|
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
char* buffer = NULL;
|
|
|
|
char* b64_hash = NULL;
|
|
|
|
char *e = NULL, *n = NULL;
|
|
|
|
|
|
|
|
WINPR_ASSERT(aad);
|
|
|
|
|
|
|
|
/* Generate a 2048-bit RSA key pair */
|
|
|
|
if (!generate_rsa_2048(aad))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* Encode the public key as a JWK */
|
2023-04-25 12:20:00 +03:00
|
|
|
if (!get_encoded_rsa_params(aad->log, aad->key, &e, &n))
|
2023-03-08 18:33:49 +03:00
|
|
|
goto fail;
|
2023-03-08 04:06:47 +03:00
|
|
|
|
2023-03-08 18:33:49 +03:00
|
|
|
size_t blen = 0;
|
|
|
|
const int alen =
|
2023-05-17 20:17:59 +03:00
|
|
|
winpr_asprintf(&buffer, &blen, "{\"e\":\"%s\",\"kty\":\"RSA\",\"n\":\"%s\"}", e, n);
|
2023-03-08 18:33:49 +03:00
|
|
|
if (alen < 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* Hash the encoded public key */
|
|
|
|
b64_hash = generate_rsa_digest_base64_str(aad, buffer, blen);
|
|
|
|
if (!b64_hash)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* Encode a JSON object with a single property "kid" whose value is the encoded hash */
|
|
|
|
ret = generate_json_base64_str(aad, b64_hash);
|
2023-03-08 04:06:47 +03:00
|
|
|
|
|
|
|
fail:
|
2023-03-08 18:33:49 +03:00
|
|
|
free(b64_hash);
|
2023-03-08 04:06:47 +03:00
|
|
|
free(buffer);
|
|
|
|
free(e);
|
|
|
|
free(n);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-04-25 12:20:00 +03:00
|
|
|
static char* bn_to_base64_url(wLog* wlog, rdpPrivateKey* key, enum FREERDP_KEY_PARAM param)
|
2023-03-08 18:33:49 +03:00
|
|
|
{
|
|
|
|
WINPR_ASSERT(wlog);
|
2023-04-25 12:20:00 +03:00
|
|
|
WINPR_ASSERT(key);
|
2023-03-08 18:33:49 +03:00
|
|
|
|
2023-04-25 12:20:00 +03:00
|
|
|
size_t len = 0;
|
|
|
|
char* bn = freerdp_key_get_param(key, param, &len);
|
|
|
|
if (!bn)
|
2023-03-08 18:33:49 +03:00
|
|
|
return NULL;
|
|
|
|
|
2023-04-25 12:20:00 +03:00
|
|
|
char* b64 = crypto_base64url_encode(bn, len);
|
|
|
|
free(bn);
|
2023-03-08 18:33:49 +03:00
|
|
|
|
|
|
|
if (!b64)
|
|
|
|
WLog_Print(wlog, WLOG_ERROR, "failed base64 url encode BIGNUM");
|
|
|
|
|
|
|
|
return b64;
|
|
|
|
}
|
|
|
|
|
2023-04-25 12:20:00 +03:00
|
|
|
BOOL get_encoded_rsa_params(wLog* wlog, rdpPrivateKey* key, char** pe, char** pn)
|
2023-03-08 04:06:47 +03:00
|
|
|
{
|
2023-03-08 18:33:49 +03:00
|
|
|
BOOL rc = FALSE;
|
|
|
|
char* e = NULL;
|
|
|
|
char* n = NULL;
|
2023-03-08 04:06:47 +03:00
|
|
|
|
2023-03-08 18:33:49 +03:00
|
|
|
WINPR_ASSERT(wlog);
|
2023-04-25 12:20:00 +03:00
|
|
|
WINPR_ASSERT(key);
|
2023-03-08 18:33:49 +03:00
|
|
|
WINPR_ASSERT(pe);
|
|
|
|
WINPR_ASSERT(pn);
|
2023-03-08 18:14:43 +03:00
|
|
|
|
2023-03-08 18:33:49 +03:00
|
|
|
*pe = NULL;
|
|
|
|
*pn = NULL;
|
2023-03-08 04:06:47 +03:00
|
|
|
|
2023-04-25 12:20:00 +03:00
|
|
|
e = bn_to_base64_url(wlog, key, FREERDP_KEY_PARAM_RSA_E);
|
2023-03-08 18:33:49 +03:00
|
|
|
if (!e)
|
|
|
|
{
|
|
|
|
WLog_Print(wlog, WLOG_ERROR, "failed base64 url encode RSA E");
|
2023-03-08 04:06:47 +03:00
|
|
|
goto fail;
|
2023-03-08 18:33:49 +03:00
|
|
|
}
|
2023-03-08 04:06:47 +03:00
|
|
|
|
2023-04-25 12:20:00 +03:00
|
|
|
n = bn_to_base64_url(wlog, key, FREERDP_KEY_PARAM_RSA_N);
|
2023-03-08 18:33:49 +03:00
|
|
|
if (!n)
|
|
|
|
{
|
|
|
|
WLog_Print(wlog, WLOG_ERROR, "failed base64 url encode RSA N");
|
2023-03-08 04:06:47 +03:00
|
|
|
goto fail;
|
2023-03-08 18:33:49 +03:00
|
|
|
}
|
2023-03-08 04:06:47 +03:00
|
|
|
|
2023-03-08 18:33:49 +03:00
|
|
|
rc = TRUE;
|
2023-03-08 04:06:47 +03:00
|
|
|
fail:
|
2023-03-08 18:33:49 +03:00
|
|
|
if (!rc)
|
2023-03-08 04:06:47 +03:00
|
|
|
{
|
2023-03-08 18:33:49 +03:00
|
|
|
free(e);
|
|
|
|
free(n);
|
2023-03-08 04:06:47 +03:00
|
|
|
}
|
2023-03-08 18:33:49 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
*pe = e;
|
|
|
|
*pn = n;
|
|
|
|
}
|
|
|
|
return rc;
|
2023-03-08 04:06:47 +03:00
|
|
|
}
|
2023-03-10 13:54:16 +03:00
|
|
|
#else
|
|
|
|
int aad_client_begin(rdpAad* aad)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(aad);
|
|
|
|
WLog_Print(aad->log, WLOG_ERROR, "AAD security not compiled in, aborting!");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
int aad_recv(rdpAad* aad, wStream* s)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(aad);
|
|
|
|
WLog_Print(aad->log, WLOG_ERROR, "AAD security not compiled in, aborting!");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
rdpAad* aad_new(rdpContext* context, rdpTransport* transport)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(transport);
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
|
|
|
|
rdpAad* aad = (rdpAad*)calloc(1, sizeof(rdpAad));
|
|
|
|
|
|
|
|
if (!aad)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
aad->log = WLog_Get(FREERDP_TAG("aad"));
|
2023-04-25 12:20:00 +03:00
|
|
|
aad->key = freerdp_key_new();
|
|
|
|
if (!aad->key)
|
|
|
|
goto fail;
|
2023-03-10 13:54:16 +03:00
|
|
|
aad->rdpcontext = context;
|
|
|
|
aad->transport = transport;
|
|
|
|
|
|
|
|
return aad;
|
2023-04-25 12:20:00 +03:00
|
|
|
fail:
|
|
|
|
aad_free(aad);
|
|
|
|
return NULL;
|
2023-03-10 13:54:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void aad_free(rdpAad* aad)
|
|
|
|
{
|
|
|
|
if (!aad)
|
|
|
|
return;
|
|
|
|
|
|
|
|
free(aad->hostname);
|
2023-07-02 19:16:01 +03:00
|
|
|
free(aad->scope);
|
2023-03-10 13:54:16 +03:00
|
|
|
free(aad->nonce);
|
|
|
|
free(aad->access_token);
|
|
|
|
free(aad->kid);
|
2023-04-25 12:20:00 +03:00
|
|
|
freerdp_key_free(aad->key);
|
2023-03-10 13:54:16 +03:00
|
|
|
|
|
|
|
free(aad);
|
|
|
|
}
|
|
|
|
|
|
|
|
AAD_STATE aad_get_state(rdpAad* aad)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(aad);
|
|
|
|
return aad->state;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL aad_is_supported(void)
|
|
|
|
{
|
2023-07-02 19:16:01 +03:00
|
|
|
#ifdef WITH_AAD
|
2023-03-10 13:54:16 +03:00
|
|
|
return TRUE;
|
|
|
|
#else
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
|
|
|
}
|