Commit b9777ec6 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

keystore: Add a win32 crypt_file implementation

parent 8cbc5cae
......@@ -10,6 +10,10 @@ libfile_keystore_plugin_la_SOURCES = keystore/file.c \
if HAVE_ANDROID
libfile_keystore_plugin_la_SOURCES += keystore/file_crypt_android.c
endif
if HAVE_WIN32
libfile_keystore_plugin_la_SOURCES += keystore/file_crypt_win32.c
libfile_keystore_plugin_la_LIBADD = -lcrypt32
endif
keystore_LTLIBRARIES += libfile_keystore_plugin.la
libsecret_plugin_la_SOURCES = keystore/secret.c
......
......@@ -18,7 +18,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#if defined(__ANDROID__) /* TODO || defined(_WIN32) */
#if defined(__ANDROID__) || defined(_WIN32)
# define CRYPTFILE
struct crypt
......
/*****************************************************************************
* file_crypt_win32.c: Crypt using CryptProtectData
*****************************************************************************
* Copyright © 2016 VLC authors, VideoLAN and VideoLabs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <vlc_keystore.h>
#include "file_crypt.h"
#include <windows.h>
#include <wincrypt.h>
typedef WINBOOL WINAPI (*ProcessFunc)(DATA_BLOB*, LPCWSTR, DATA_BLOB*, PVOID, CRYPTPROTECT_PROMPTSTRUCT*,
DWORD, DATA_BLOB*);
static size_t Process(const uint8_t *p_src, size_t i_src_len, uint8_t **pp_dst, ProcessFunc pf_process)
{
DATA_BLOB input_blob =
{
.cbData = i_src_len,
.pbData = (BYTE*)p_src
};
DATA_BLOB output_blob;
if (pf_process( &input_blob, NULL, NULL, NULL, NULL, CRYPTPROTECT_UI_FORBIDDEN, &output_blob) == FALSE)
return 0;
*pp_dst = malloc(output_blob.cbData);
if( unlikely( *pp_dst == NULL ) )
{
LocalFree( output_blob.pbData );
return 0;
}
memcpy( *pp_dst, output_blob.pbData, output_blob.cbData );
LocalFree( output_blob.pbData );
return output_blob.cbData;
}
static size_t Decrypt( vlc_keystore *p_keystore, void *p_ctx, const uint8_t *p_src,
size_t i_src_len, uint8_t ** pp_dst )
{
VLC_UNUSED( p_keystore );
VLC_UNUSED( p_ctx );
// Cast the function pointer to avoid an invalid parameter warning, regarding the "description"
// parameter. It's LPCWSTR in the case of CryptProtectData, and LPWSTR* in the case of CryptUnprotect
// Since we pass NULL anyway, we don't care
return Process( p_src, i_src_len, pp_dst, (ProcessFunc)&CryptUnprotectData );
}
static size_t Encrypt( vlc_keystore *p_keystore, void *p_ctx, const uint8_t *p_src,
size_t i_src_len, uint8_t ** pp_dst )
{
VLC_UNUSED( p_keystore );
VLC_UNUSED( p_ctx );
return Process( p_src, i_src_len, pp_dst, CryptProtectData );
}
int CryptInit(vlc_keystore *p_keystore, struct crypt *p_crypt)
{
VLC_UNUSED( p_keystore );
p_crypt->pf_decrypt = Decrypt;
p_crypt->pf_encrypt = Encrypt;
return VLC_SUCCESS;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment