mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2025-11-12 19:38:26 -06:00
EMV keyfile support: Overall code improvements and bug fixes
This commit is contained in:
@@ -17,62 +17,94 @@
|
||||
|
||||
#include "SecurityToken.h"
|
||||
#include "EMVToken.h"
|
||||
#include "PCSCException.h"
|
||||
#include "iostream"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace VeraCrypt
|
||||
{
|
||||
vector<shared_ptr<TokenKeyfile>> Token::GetAvailableKeyfiles(bool EMVOption) {
|
||||
vector<shared_ptr<TokenKeyfile>> Token::GetAvailableKeyfiles(bool isEMVSupportEnabled)
|
||||
{
|
||||
vector<shared_ptr<TokenKeyfile>> availableKeyfiles;
|
||||
bool securityTokenLibraryInitialized = true;
|
||||
bool scardLibraryInitialized = true;
|
||||
|
||||
try{
|
||||
foreach (SecurityTokenKeyfile k, SecurityToken::GetAvailableKeyfiles()) {
|
||||
try
|
||||
{
|
||||
foreach (SecurityTokenKeyfile k, SecurityToken::GetAvailableKeyfiles())
|
||||
{
|
||||
availableKeyfiles.push_back(shared_ptr<TokenKeyfile>(new SecurityTokenKeyfile(k)));
|
||||
}
|
||||
} catch (SecurityTokenLibraryNotInitialized){
|
||||
}
|
||||
catch (SecurityTokenLibraryNotInitialized&)
|
||||
{
|
||||
securityTokenLibraryInitialized = false;
|
||||
}
|
||||
|
||||
if (isEMVSupportEnabled)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (EMVTokenKeyfile k, EMVToken::GetAvailableKeyfiles())
|
||||
{
|
||||
availableKeyfiles.push_back(shared_ptr<TokenKeyfile>(new EMVTokenKeyfile(k)));
|
||||
}
|
||||
}
|
||||
catch (ScardLibraryInitializationFailed&)
|
||||
{
|
||||
scardLibraryInitialized = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(EMVOption){
|
||||
foreach (EMVTokenKeyfile k, EMVToken::GetAvailableKeyfiles()) {
|
||||
availableKeyfiles.push_back(shared_ptr<TokenKeyfile>(new EMVTokenKeyfile(k)));
|
||||
}
|
||||
}
|
||||
|
||||
if(availableKeyfiles.size() == 0 && ! securityTokenLibraryInitialized){
|
||||
throw SecurityTokenLibraryNotInitialized();
|
||||
if (availableKeyfiles.size() == 0)
|
||||
{
|
||||
if (!securityTokenLibraryInitialized)
|
||||
{
|
||||
throw SecurityTokenLibraryNotInitialized();
|
||||
}
|
||||
else if (!scardLibraryInitialized)
|
||||
{
|
||||
throw ScardLibraryInitializationFailed();
|
||||
}
|
||||
}
|
||||
|
||||
return availableKeyfiles;
|
||||
}
|
||||
|
||||
bool Token::IsKeyfilePathValid(const wstring& tokenKeyfilePath, bool EMVOption)
|
||||
bool Token::IsKeyfilePathValid(const wstring& tokenKeyfilePath, bool isEMVSupportEnabled)
|
||||
{
|
||||
if(EMVOption){
|
||||
return SecurityToken::IsKeyfilePathValid(tokenKeyfilePath) || EMVToken::IsKeyfilePathValid(tokenKeyfilePath);
|
||||
}
|
||||
if (isEMVSupportEnabled)
|
||||
{
|
||||
return SecurityToken::IsKeyfilePathValid(tokenKeyfilePath) || EMVToken::IsKeyfilePathValid(tokenKeyfilePath);
|
||||
}
|
||||
return SecurityToken::IsKeyfilePathValid(tokenKeyfilePath);
|
||||
}
|
||||
|
||||
list <shared_ptr<TokenInfo>> Token::GetAvailableTokens()
|
||||
{
|
||||
list <shared_ptr<TokenInfo>> availableTokens;
|
||||
foreach(SecurityTokenInfo securityToken, SecurityToken::GetAvailableTokens()){
|
||||
|
||||
foreach(SecurityTokenInfo securityToken, SecurityToken::GetAvailableTokens())
|
||||
{
|
||||
availableTokens.push_back(shared_ptr<TokenInfo>(new SecurityTokenInfo(std::move(securityToken))));
|
||||
}
|
||||
|
||||
return availableTokens ;
|
||||
}
|
||||
|
||||
shared_ptr<TokenKeyfile> Token::getTokenKeyfile(const TokenKeyfilePath path){
|
||||
shared_ptr<TokenKeyfile> Token::getTokenKeyfile(const TokenKeyfilePath& path)
|
||||
{
|
||||
shared_ptr<TokenKeyfile> tokenKeyfile;
|
||||
|
||||
if(SecurityToken::IsKeyfilePathValid(path)){
|
||||
if (SecurityToken::IsKeyfilePathValid(path))
|
||||
{
|
||||
tokenKeyfile = shared_ptr<TokenKeyfile>(new SecurityTokenKeyfile(path));
|
||||
} else {
|
||||
if(EMVToken::IsKeyfilePathValid(path)){
|
||||
}
|
||||
else
|
||||
{
|
||||
if (EMVToken::IsKeyfilePathValid(path))
|
||||
{
|
||||
tokenKeyfile = shared_ptr<TokenKeyfile>(new EMVTokenKeyfile(path));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user