mirror of
https://github.com/gnif/LookingGlass.git
synced 2026-11-14 07:47:19 +00:00
[client] network: add QUIC transport foundation
This commit is contained in:
40
client/transports/Network/platform/linux/fingerprint.c
Normal file
40
client/transports/Network/platform/linux/fingerprint.c
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Looking Glass
|
||||
* Copyright © 2017-2026 The Looking Glass Authors
|
||||
* https://looking-glass.io
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., 59
|
||||
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "../../fingerprint.h"
|
||||
|
||||
#include <openssl/evp.h>
|
||||
|
||||
bool networkFingerprintSHA256(const uint8_t * data, size_t size,
|
||||
uint8_t fingerprint[NETWORK_FINGERPRINT_SIZE])
|
||||
{
|
||||
EVP_MD_CTX * context = EVP_MD_CTX_new();
|
||||
if (!context)
|
||||
return false;
|
||||
|
||||
unsigned int outputSize = 0;
|
||||
const bool result =
|
||||
EVP_DigestInit_ex(context, EVP_sha256(), NULL) == 1 &&
|
||||
EVP_DigestUpdate(context, data, size) == 1 &&
|
||||
EVP_DigestFinal_ex(context, fingerprint, &outputSize) == 1 &&
|
||||
outputSize == NETWORK_FINGERPRINT_SIZE;
|
||||
EVP_MD_CTX_free(context);
|
||||
return result;
|
||||
}
|
||||
28
client/transports/Network/platform/linux/platform.c
Normal file
28
client/transports/Network/platform/linux/platform.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Looking Glass
|
||||
* Copyright © 2017-2026 The Looking Glass Authors
|
||||
* https://looking-glass.io
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., 59
|
||||
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "../../platform.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
bool networkPlatformReplaceFile(const char * source, const char * target)
|
||||
{
|
||||
return rename(source, target) == 0;
|
||||
}
|
||||
39
client/transports/Network/platform/windows/fingerprint.c
Normal file
39
client/transports/Network/platform/windows/fingerprint.c
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Looking Glass
|
||||
* Copyright © 2017-2026 The Looking Glass Authors
|
||||
* https://looking-glass.io
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., 59
|
||||
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "../../fingerprint.h"
|
||||
|
||||
#include <windows.h>
|
||||
#include <bcrypt.h>
|
||||
#include <wincrypt.h>
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
bool networkFingerprintSHA256(const uint8_t * data, size_t size,
|
||||
uint8_t fingerprint[NETWORK_FINGERPRINT_SIZE])
|
||||
{
|
||||
if (size > ULONG_MAX)
|
||||
return false;
|
||||
|
||||
DWORD outputSize = NETWORK_FINGERPRINT_SIZE;
|
||||
return CryptHashCertificate2(BCRYPT_SHA256_ALGORITHM, 0, NULL,
|
||||
data, (DWORD)size, fingerprint, &outputSize) &&
|
||||
outputSize == NETWORK_FINGERPRINT_SIZE;
|
||||
}
|
||||
44
client/transports/Network/platform/windows/platform.c
Normal file
44
client/transports/Network/platform/windows/platform.c
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Looking Glass
|
||||
* Copyright © 2017-2026 The Looking Glass Authors
|
||||
* https://looking-glass.io
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., 59
|
||||
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "../../platform.h"
|
||||
|
||||
#include "common/win32.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
|
||||
bool networkPlatformReplaceFile(const char * source, const char * target)
|
||||
{
|
||||
wchar_t * sourceWide = lgUtf8ToWide(source);
|
||||
wchar_t * targetWide = lgUtf8ToWide(target);
|
||||
if (!sourceWide || !targetWide)
|
||||
{
|
||||
free(targetWide);
|
||||
free(sourceWide);
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool result = MoveFileExW(sourceWide, targetWide,
|
||||
MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH);
|
||||
free(targetWide);
|
||||
free(sourceWide);
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user