diff --git a/.gitignore b/.gitignore index fc5ac1eb..589735fb 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ *.o *.orig *.so +.cache/ .idea/ .trunk .vscode diff --git a/libs/pkcs11/src/CSP/AbilitaCIE.cpp b/libs/pkcs11/src/CSP/AbilitaCIE.cpp index 54e95e8d..651e3035 100644 --- a/libs/pkcs11/src/CSP/AbilitaCIE.cpp +++ b/libs/pkcs11/src/CSP/AbilitaCIE.cpp @@ -27,6 +27,7 @@ #include #include +#include "CSP/IAS.h" #include "Crypto/AES.h" #include "Crypto/ASNParser.h" #include "Crypto/CryptoUtil.h" @@ -35,12 +36,11 @@ #include "LOGGER/Logger.h" #include "PKCS11/PKCS11Functions.h" #include "PKCS11/Slot.h" -#include "Sign/definitions.h" #include "Sign/CIESign.h" #include "Sign/CIEVerify.h" +#include "Sign/definitions.h" #include "Util/CryptoppUtils.h" #include "Util/ModuleInfo.h" -#include "CSP/IAS.h" using namespace CieIDLogger; diff --git a/libs/pkcs11/src/CSP/AbilitaCIE.h b/libs/pkcs11/src/CSP/AbilitaCIE.h index 44abe72f..60ec1bb1 100644 --- a/libs/pkcs11/src/CSP/AbilitaCIE.h +++ b/libs/pkcs11/src/CSP/AbilitaCIE.h @@ -5,7 +5,6 @@ // Created by ugo chirico on 02/09/18. http://www.ugochirico.com // Copyright © 2018 IPZS. All rights reserved. // -#include #include "PCSC/PCSC.h" #include "PKCS11/cryptoki.h" diff --git a/libs/pkcs11/src/CSP/FirmaConCIE.cpp b/libs/pkcs11/src/CSP/FirmaConCIE.cpp index 271b9e99..31e2cfde 100644 --- a/libs/pkcs11/src/CSP/FirmaConCIE.cpp +++ b/libs/pkcs11/src/CSP/FirmaConCIE.cpp @@ -6,16 +6,13 @@ #include "CSP/FirmaConCIE.h" -#include "Crypto/ASNParser.h" +#include "CSP/AbilitaCIE.h" +#include "CSP/IAS.h" #include "LOGGER/Logger.h" #include "PCSC/PCSC.h" #include "PKCS11/PKCS11Functions.h" -#include "PKCS11/Slot.h" -#include "Sign/definitions.h" #include "Sign/CIESign.h" #include "Util/ModuleInfo.h" -#include "CSP/AbilitaCIE.h" -#include "CSP/IAS.h" using namespace CieIDLogger; diff --git a/libs/pkcs11/src/CSP/FirmaConCIE.h b/libs/pkcs11/src/CSP/FirmaConCIE.h index a480696a..c2a98d50 100644 --- a/libs/pkcs11/src/CSP/FirmaConCIE.h +++ b/libs/pkcs11/src/CSP/FirmaConCIE.h @@ -8,13 +8,8 @@ #ifndef FirmaConCIE_h #define FirmaConCIE_h -#include - -#include - -#include "PKCS11/cryptoki.h" -#include "Sign/CIESign.h" #include "CSP/AbilitaCIE.h" +#include "PKCS11/cryptoki.h" typedef CK_CALLBACK_FUNCTION(CK_RV, SIGN_COMPLETED_CALLBACK)(const int ret); diff --git a/libs/pkcs11/src/CSP/IAS.cpp b/libs/pkcs11/src/CSP/IAS.cpp index df703138..390e97c9 100644 --- a/libs/pkcs11/src/CSP/IAS.cpp +++ b/libs/pkcs11/src/CSP/IAS.cpp @@ -13,10 +13,9 @@ #include "Crypto/SHA1.h" #include "Crypto/sha256.h" #include "Crypto/sha512.h" -#include "Util/ModuleInfo.h" - -#include "Util/CacheLib.h" #include "LOGGER/Logger.h" +#include "Util/CacheLib.h" +#include "Util/ModuleInfo.h" using namespace CieIDLogger; @@ -393,8 +392,8 @@ void IAS::SelectAID_IAS(bool SM) { throw scard_error(sw); } } else if (type == CIE_Type::CIE_Gemalto || type == CIE_Type::CIE_STM || - CIE_Type::CIE_STM2 || CIE_Type::CIE_STM3 || - CIE_Type::CIE_ACTALIS || CIE_Type::CIE_BIT4ID) { + type == CIE_Type::CIE_STM2 || type == CIE_Type::CIE_STM3 || + type == CIE_Type::CIE_ACTALIS || type == CIE_Type::CIE_BIT4ID) { uint8_t selectIAS[] = {0x00, 0xa4, 0x04, 0x0c}; if (SM) { if ((sw = SendAPDU_SM(VarToByteArray(selectIAS), IAS_AID, resp)) != diff --git a/libs/pkcs11/src/CSP/PINManager.cpp b/libs/pkcs11/src/CSP/PINManager.cpp index ec975599..469d6d2c 100644 --- a/libs/pkcs11/src/CSP/PINManager.cpp +++ b/libs/pkcs11/src/CSP/PINManager.cpp @@ -10,19 +10,14 @@ #include -#include #include -#include "Crypto/ASNParser.h" -#include "Crypto/sha256.h" +#include "CSP/AbilitaCIE.h" +#include "CSP/IAS.h" #include "LOGGER/Logger.h" #include "PCSC/PCSC.h" #include "PKCS11/PKCS11Functions.h" -#include "PKCS11/Slot.h" -#include "Sign/definitions.h" #include "Util/ModuleInfo.h" -#include "CSP/AbilitaCIE.h" -#include "CSP/IAS.h" using namespace CieIDLogger; diff --git a/libs/pkcs11/src/CSP/VerificaConCIE.cpp b/libs/pkcs11/src/CSP/VerificaConCIE.cpp index affc2eab..7fd320ad 100644 --- a/libs/pkcs11/src/CSP/VerificaConCIE.cpp +++ b/libs/pkcs11/src/CSP/VerificaConCIE.cpp @@ -7,6 +7,7 @@ // #include "CSP/VerificaConCIE.h" + #include #include "LOGGER/Logger.h" diff --git a/libs/pkcs11/src/LOGGER/Logger.cpp b/libs/pkcs11/src/LOGGER/Logger.cpp index 93695aaa..588980fe 100644 --- a/libs/pkcs11/src/LOGGER/Logger.cpp +++ b/libs/pkcs11/src/LOGGER/Logger.cpp @@ -11,7 +11,6 @@ #include #include #include -#include using namespace std; using namespace CieIDLogger; diff --git a/libs/pkcs11/src/LOGGER/Logger.h b/libs/pkcs11/src/LOGGER/Logger.h index a4f30254..0b0a5533 100644 --- a/libs/pkcs11/src/LOGGER/Logger.h +++ b/libs/pkcs11/src/LOGGER/Logger.h @@ -2,7 +2,6 @@ #define _LOGGER_H_ // C++ Header File(s) -#include #include #include @@ -103,7 +102,6 @@ class Logger { std::ofstream m_File; std::fstream m_ConfigFile; char pbLog[MAX_PATH]; - char pbConfig[MAX_PATH]; time_t t_configTime; pthread_mutexattr_t m_Attr; pthread_mutex_t m_Mutex; diff --git a/libs/pkcs11/src/PKCS11/CIEP11Template.cpp b/libs/pkcs11/src/PKCS11/CIEP11Template.cpp index f32f7d2a..fe211e2d 100644 --- a/libs/pkcs11/src/PKCS11/CIEP11Template.cpp +++ b/libs/pkcs11/src/PKCS11/CIEP11Template.cpp @@ -101,8 +101,8 @@ class CIEData { CToken token; bool init; CIEData(CSlot *slot, ByteArray atr) - : ias((CToken::TokenTransmitCallback)TokenTransmitCallback, atr), - slot(*slot) { + : slot(*slot), + ias((CToken::TokenTransmitCallback)TokenTransmitCallback, atr) { ByteDynArray key(32); ByteDynArray iv(16); aesKey.Init(key.random(), iv.random()); diff --git a/libs/pkcs11/src/PKCS11/CardContext.cpp b/libs/pkcs11/src/PKCS11/CardContext.cpp index a7c9c9fa..0e012ca9 100644 --- a/libs/pkcs11/src/PKCS11/CardContext.cpp +++ b/libs/pkcs11/src/PKCS11/CardContext.cpp @@ -1,8 +1,9 @@ #include "PKCS11/CardContext.h" -#include "Util/util.h" #include +#include "Util/util.h" + extern CLog Log; void CCardContext::getContext() { diff --git a/libs/pkcs11/src/PKCS11/CardTemplate.cpp b/libs/pkcs11/src/PKCS11/CardTemplate.cpp index fb3c5686..de024266 100644 --- a/libs/pkcs11/src/PKCS11/CardTemplate.cpp +++ b/libs/pkcs11/src/PKCS11/CardTemplate.cpp @@ -2,8 +2,8 @@ #include -#include "Util/ModuleInfo.h" #include "PKCS11/CIEP11Template.h" +#include "Util/ModuleInfo.h" extern CLog Log; diff --git a/libs/pkcs11/src/PKCS11/CardTemplate.h b/libs/pkcs11/src/PKCS11/CardTemplate.h index 7db7beb3..e79b955e 100644 --- a/libs/pkcs11/src/PKCS11/CardTemplate.h +++ b/libs/pkcs11/src/PKCS11/CardTemplate.h @@ -3,10 +3,8 @@ #include #include -#include "PCSC/Token.h" #include "PKCS11/session.h" - namespace p11 { class CCardTemplate; diff --git a/libs/pkcs11/src/PKCS11/Mechanism.cpp b/libs/pkcs11/src/PKCS11/Mechanism.cpp index 136374fc..e7c6d0da 100644 --- a/libs/pkcs11/src/PKCS11/Mechanism.cpp +++ b/libs/pkcs11/src/PKCS11/Mechanism.cpp @@ -1,8 +1,9 @@ #include "PKCS11/Mechanism.h" #include "Crypto/RSA.h" -#include "Util/util.h" #include "PKCS11/P11Object.h" +#include "PKCS11/session.h" +#include "Util/util.h" extern CLog Log; @@ -425,7 +426,7 @@ ByteDynArray CRSA_PKCS1::SignRecover(ByteArray &Data) { CSignRSAwithDigest::CSignRSAwithDigest(CK_MECHANISM_TYPE type, std::shared_ptr Session, CDigest *Digest) - : pDigest(Digest), CSignRSA(type, std::move(Session)) {} + : CSignRSA(type, std::move(Session)), pDigest(Digest) {} CSignRSAwithDigest::~CSignRSAwithDigest() {} bool CSignRSAwithDigest::SignSupportMultipart() { init_func return true; } @@ -467,7 +468,7 @@ void CSignRSAwithDigest::SignSetOperationState(ByteArray &OperationState) { CVerifyRSAwithDigest::CVerifyRSAwithDigest(CK_MECHANISM_TYPE type, std::shared_ptr Session, CDigest *Digest) - : pDigest(Digest), CVerifyRSA(type, std::move(Session)) {} + : CVerifyRSA(type, std::move(Session)), pDigest(Digest) {} CVerifyRSAwithDigest::~CVerifyRSAwithDigest() {} bool CVerifyRSAwithDigest::VerifySupportMultipart() { init_func return true; } diff --git a/libs/pkcs11/src/PKCS11/P11Object.cpp b/libs/pkcs11/src/PKCS11/P11Object.cpp index c7e69802..7f75a144 100644 --- a/libs/pkcs11/src/PKCS11/P11Object.cpp +++ b/libs/pkcs11/src/PKCS11/P11Object.cpp @@ -1,163 +1,164 @@ #include "PKCS11/P11Object.h" + #include "PKCS11/CardTemplate.h" extern CLog Log; - namespace p11 { -CP11Object::CP11Object(CK_OBJECT_CLASS objClass,void *TemplateData) { - ObjClass=objClass; - pTemplateData=TemplateData; - addAttribute(CKA_CLASS,ByteArray((BYTE*)&ObjClass,sizeof(CK_OBJECT_CLASS))); +CP11Object::CP11Object(CK_OBJECT_CLASS objClass, void* TemplateData) { + ObjClass = objClass; + pTemplateData = TemplateData; + addAttribute(CKA_CLASS, ByteArray((BYTE*)&ObjClass, sizeof(CK_OBJECT_CLASS))); } -void CP11Object::addAttribute(CK_ATTRIBUTE_TYPE type,ByteArray data) { - init_func - attributes[type] = data; +void CP11Object::addAttribute(CK_ATTRIBUTE_TYPE type, ByteArray data) { + init_func attributes[type] = data; } ByteArray* CP11Object::getAttribute(CK_ATTRIBUTE_TYPE type) { - init_func - AttributeMap::const_iterator pPair; - pPair=attributes.find(type); - if (pPair==attributes.end()) { - return nullptr; - } - return (ByteArray*)&pPair->second; -} - -CK_ULONG CP11Object::GetAttributeValue(CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount) { - init_func - - bool attribInvalid = false; - - for (unsigned int i=0; isize(); - } else { - if (attr->size() > ulValLen) - throw p11_error(CKR_BUFFER_TOO_SMALL); - - ByteArray((uint8_t*)pTemplate[i].pValue, attr->size()).copy(*attr); - pTemplate[i].ulValueLen = (CK_ULONG)attr->size(); - } - } else { - pTemplate[i].ulValueLen = -1; - attribInvalid = true; - } + init_func AttributeMap::const_iterator pPair; + pPair = attributes.find(type); + if (pPair == attributes.end()) { + return nullptr; + } + return (ByteArray*)&pPair->second; +} + +CK_ULONG CP11Object::GetAttributeValue(CK_ATTRIBUTE_PTR pTemplate, + CK_ULONG ulCount) { + init_func + + bool attribInvalid = false; + + for (unsigned int i = 0; i < ulCount; i++) { + CK_ULONG ulValLen = pTemplate[i].ulValueLen; + + ByteArray* attr = getAttribute(pTemplate[i].type); + if (attr != nullptr) { + if (pTemplate[i].pValue == NULL) { + pTemplate[i].ulValueLen = (CK_ULONG)attr->size(); + } else { + if (attr->size() > ulValLen) throw p11_error(CKR_BUFFER_TOO_SMALL); + + ByteArray((uint8_t*)pTemplate[i].pValue, attr->size()).copy(*attr); + pTemplate[i].ulValueLen = (CK_ULONG)attr->size(); + } + } else { + pTemplate[i].ulValueLen = -1; + attribInvalid = true; } + } - return attribInvalid ? CKR_ATTRIBUTE_TYPE_INVALID : CKR_OK; + return attribInvalid ? CKR_ATTRIBUTE_TYPE_INVALID : CKR_OK; } CK_ULONG CP11Object::GetObjectSize() { - init_func - // devo almeno leggerlo dalla carta per sapere che dimensioni ha - if (!bReadValue) { - pSlot->pTemplate->FunctionList.templateReadObjectAttributes(pSlot->pTemplateData, this); - } - return pSlot->pTemplate->FunctionList.templateGetObjectSize(pSlot->pTemplateData,this); + init_func + // devo almeno leggerlo dalla carta per sapere che dimensioni ha + if (!bReadValue) { + pSlot->pTemplate->FunctionList.templateReadObjectAttributes( + pSlot->pTemplateData, this); + } + return pSlot->pTemplate->FunctionList.templateGetObjectSize( + pSlot->pTemplateData, this); } void CP11Object::SetAttributes(CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount) { - init_func - for (DWORD i=0; ipTemplate->FunctionList.templateReadObjectAttributes(pSlot->pTemplateData, this); - } + AttributeMap::iterator it = attributes.find(type); + if (it == attributes.end() && !bReadValue) { + pSlot->pTemplate->FunctionList.templateReadObjectAttributes( + pSlot->pTemplateData, this); + } - return CP11Object::getAttribute(type); + return CP11Object::getAttribute(type); } -CP11Data::CP11Data(void *TemplateData) : CP11Object(CKO_DATA,TemplateData) { - bReadValue=false; +CP11Data::CP11Data(void* TemplateData) : CP11Object(CKO_DATA, TemplateData) { + bReadValue = false; } ByteArray* CP11Data::getAttribute(CK_ATTRIBUTE_TYPE type) { - init_func - AttributeMap::iterator it=attributes.find(type); - if (it==attributes.end() && !bReadValue) { - pSlot->pTemplate->FunctionList.templateReadObjectAttributes(pSlot->pTemplateData, this); - } + init_func AttributeMap::iterator it = attributes.find(type); + if (it == attributes.end() && !bReadValue) { + pSlot->pTemplate->FunctionList.templateReadObjectAttributes( + pSlot->pTemplateData, this); + } - return CP11Object::getAttribute(type); + return CP11Object::getAttribute(type); } void CP11Data::SetAttributes(CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount) { - init_func - CP11Object::SetAttributes(pTemplate, ulCount); - bReadValue = true; + init_func CP11Object::SetAttributes(pTemplate, ulCount); + bReadValue = true; } bool CP11Object::IsPrivate() { - init_func - ByteArray* baVal = getAttribute(CKA_PRIVATE); + init_func ByteArray* baVal = getAttribute(CKA_PRIVATE); - if (baVal==nullptr) - return false; - else - return (ByteArrayToVar(*baVal, CK_BBOOL) == TRUE); + if (baVal == nullptr) + return false; + else + return (ByteArrayToVar(*baVal, CK_BBOOL) == TRUE); } -CP11PrivateKey::CP11PrivateKey(void *TemplateData) : CP11Object(CKO_PRIVATE_KEY,TemplateData) { - bReadValue=false; +CP11PrivateKey::CP11PrivateKey(void* TemplateData) + : CP11Object(CKO_PRIVATE_KEY, TemplateData) { + bReadValue = false; } ByteArray* CP11PrivateKey::getAttribute(CK_ATTRIBUTE_TYPE type) { - init_func - - if (type==CKA_PRIME_1 || - type==CKA_PRIME_2 || - type==CKA_EXPONENT_1 || - type==CKA_EXPONENT_2 || - type==CKA_COEFFICIENT || - type==CKA_PRIME_1) - throw p11_error(CKR_ATTRIBUTE_SENSITIVE); - - AttributeMap::iterator it=attributes.find(type); - if (it==attributes.end() && !bReadValue) { - pSlot->pTemplate->FunctionList.templateReadObjectAttributes(pSlot->pTemplateData, this); - } + init_func - return CP11Object::getAttribute(type); + if (type == CKA_PRIME_1 || type == CKA_PRIME_2 || + type == CKA_EXPONENT_1 || type == CKA_EXPONENT_2 || + type == CKA_COEFFICIENT || + type == CKA_PRIME_1) throw p11_error(CKR_ATTRIBUTE_SENSITIVE); + + AttributeMap::iterator it = attributes.find(type); + if (it == attributes.end() && !bReadValue) { + pSlot->pTemplate->FunctionList.templateReadObjectAttributes( + pSlot->pTemplateData, this); + } + + return CP11Object::getAttribute(type); } -CP11PublicKey::CP11PublicKey(void *TemplateData) : CP11Object(CKO_PUBLIC_KEY,TemplateData) { - bReadValue=false; +CP11PublicKey::CP11PublicKey(void* TemplateData) + : CP11Object(CKO_PUBLIC_KEY, TemplateData) { + bReadValue = false; } ByteArray* CP11PublicKey::getAttribute(CK_ATTRIBUTE_TYPE type) { - init_func + init_func - AttributeMap::iterator it=attributes.find(type); - if (it==attributes.end() && !bReadValue) { - pSlot->pTemplate->FunctionList.templateReadObjectAttributes(pSlot->pTemplateData, this); - } + AttributeMap::iterator it = attributes.find(type); + if (it == attributes.end() && !bReadValue) { + pSlot->pTemplate->FunctionList.templateReadObjectAttributes( + pSlot->pTemplateData, this); + } - return CP11Object::getAttribute(type); + return CP11Object::getAttribute(type); } -} +} // namespace p11 diff --git a/libs/pkcs11/src/PKCS11/P11Object.h b/libs/pkcs11/src/PKCS11/P11Object.h index 6f415bdc..23c27348 100644 --- a/libs/pkcs11/src/PKCS11/P11Object.h +++ b/libs/pkcs11/src/PKCS11/P11Object.h @@ -1,63 +1,64 @@ #pragma once -#include "PKCS11/session.h" #include -#include "PKCS11/cryptoki.h" +#include "PKCS11/Slot.h" namespace p11 { -typedef std::map AttributeMap; +typedef std::map AttributeMap; class CSession; class CP11Object { - public: - bool bReadValue; - static size_t P11ObjectCnt; - - CSlot *pSlot; - void *pTemplateData; //dati specifici per il template della carta - - CP11Object(CK_OBJECT_CLASS objClass, void *TemplateData); - CK_OBJECT_CLASS ObjClass; - AttributeMap attributes; - void addAttribute(CK_ATTRIBUTE_TYPE type, ByteArray data); - - /// nullptr come valore di ritorno sognifica che l'attibuto non fa parte della mappa di attributi dell'oggetto - virtual ByteArray* getAttribute(CK_ATTRIBUTE_TYPE type); - - virtual CK_ULONG GetAttributeValue(CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount); - virtual void SetAttributes(CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount); - virtual CK_ULONG GetObjectSize(); - virtual ~CP11Object() = default; - bool IsPrivate(); + public: + bool bReadValue; + static size_t P11ObjectCnt; + + CSlot *pSlot; + void *pTemplateData; // dati specifici per il template della carta + + CP11Object(CK_OBJECT_CLASS objClass, void *TemplateData); + CK_OBJECT_CLASS ObjClass; + AttributeMap attributes; + void addAttribute(CK_ATTRIBUTE_TYPE type, ByteArray data); + + /// nullptr come valore di ritorno sognifica che l'attibuto non fa parte della + /// mappa di attributi dell'oggetto + virtual ByteArray *getAttribute(CK_ATTRIBUTE_TYPE type); + + virtual CK_ULONG GetAttributeValue(CK_ATTRIBUTE_PTR pTemplate, + CK_ULONG ulCount); + virtual void SetAttributes(CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount); + virtual CK_ULONG GetObjectSize(); + virtual ~CP11Object() = default; + bool IsPrivate(); }; class CP11Certificate : public CP11Object { - public: - CP11Certificate(void *TemplateData); - virtual ByteArray* getAttribute(CK_ATTRIBUTE_TYPE type); - virtual void SetAttributes(CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount); + public: + CP11Certificate(void *TemplateData); + virtual ByteArray *getAttribute(CK_ATTRIBUTE_TYPE type); + virtual void SetAttributes(CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount); }; class CP11Data : public CP11Object { - public: - CP11Data(void *TemplateData); - virtual ByteArray* getAttribute(CK_ATTRIBUTE_TYPE type); - virtual void SetAttributes(CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount); + public: + CP11Data(void *TemplateData); + virtual ByteArray *getAttribute(CK_ATTRIBUTE_TYPE type); + virtual void SetAttributes(CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount); }; class CP11PublicKey : public CP11Object { - public: - CP11PublicKey(void *TemplateData); - virtual ByteArray* getAttribute(CK_ATTRIBUTE_TYPE type); + public: + CP11PublicKey(void *TemplateData); + virtual ByteArray *getAttribute(CK_ATTRIBUTE_TYPE type); }; class CP11PrivateKey : public CP11Object { - public: - CP11PrivateKey(void *TemplateData); - virtual ByteArray* getAttribute(CK_ATTRIBUTE_TYPE type); + public: + CP11PrivateKey(void *TemplateData); + virtual ByteArray *getAttribute(CK_ATTRIBUTE_TYPE type); }; -} +} // namespace p11 diff --git a/libs/pkcs11/src/PKCS11/PKCS11Functions.cpp b/libs/pkcs11/src/PKCS11/PKCS11Functions.cpp index 8287235b..4a637e03 100644 --- a/libs/pkcs11/src/PKCS11/PKCS11Functions.cpp +++ b/libs/pkcs11/src/PKCS11/PKCS11Functions.cpp @@ -17,7 +17,6 @@ #include "Util/ModuleInfo.h" #include "Util/SyncroEvent.h" #include "Util/UUCByteArray.h" -#include "Util/util.h" using namespace CieIDLogger; diff --git a/libs/pkcs11/src/PKCS11/Slot.cpp b/libs/pkcs11/src/PKCS11/Slot.cpp index 428ff96b..e298231b 100644 --- a/libs/pkcs11/src/PKCS11/Slot.cpp +++ b/libs/pkcs11/src/PKCS11/Slot.cpp @@ -6,7 +6,6 @@ #include "CSP/ATR.h" #include "LOGGER/Logger.h" -#include "PCSC/Token.h" #include "PKCS11/CardTemplate.h" #include "PKCS11Functions.h" #include "Util/SyncroEvent.h" diff --git a/libs/pkcs11/src/PKCS11/session.cpp b/libs/pkcs11/src/PKCS11/session.cpp index 4346dde5..5d9af2fb 100644 --- a/libs/pkcs11/src/PKCS11/session.cpp +++ b/libs/pkcs11/src/PKCS11/session.cpp @@ -1,9 +1,9 @@ #include "PKCS11/session.h" #include "Crypto/RSA.h" +#include "PKCS11/CardTemplate.h" #include "Util/TLV.h" #include "Util/util.h" -#include "PKCS11/CardTemplate.h" extern CLog Log; diff --git a/libs/pkcs11/src/PKCS11/session.h b/libs/pkcs11/src/PKCS11/session.h index bea44617..d1931127 100644 --- a/libs/pkcs11/src/PKCS11/session.h +++ b/libs/pkcs11/src/PKCS11/session.h @@ -1,15 +1,13 @@ #pragma once -#include "PKCS11/cryptoki.h" +#include +#include -#include "PKCS11/Mechanism.h" -#include "PKCS11/Slot.h" -#include "PCSC/Token.h" +#include -#include -#include +#include "PKCS11/Mechanism.h" #include "PKCS11/P11Object.h" -#include +#include "PKCS11/Slot.h" namespace p11 { @@ -18,7 +16,7 @@ class p11_error : public logged_error { public: p11_error(CK_RV p11ErrorCode, const char *message) - : p11ErrorCode(p11ErrorCode), logged_error(message) {} + : logged_error(message), p11ErrorCode(p11ErrorCode) {} p11_error(CK_RV p11ErrorCode) : p11_error(p11ErrorCode, stdPrintf("%s:%08x", "Errore PKCS11", p11ErrorCode).c_str()) { diff --git a/libs/pkcs11/src/UI/AbilitaCIE.mm b/libs/pkcs11/src/UI/AbilitaCIE.mm deleted file mode 100644 index 00199a4c..00000000 --- a/libs/pkcs11/src/UI/AbilitaCIE.mm +++ /dev/null @@ -1,103 +0,0 @@ -// -// AbilitaCIE.cpp -// cie-pkcs11 -// -// Created by ugo chirico on 02/09/18. -// Copyright © 2018 IPZS. All rights reserved. -// - -#include -#include - -#include //inet_addr -#include //printf -#include //strlen -#include //socket - -#include "Crypto/CryptoUtil.h" - -#include - -using namespace CryptoPP; - -void showUI(const char *szPAN) { - NSTask *task = [[NSTask alloc] init]; - - task.launchPath = @"/usr/bin/open"; - task.arguments = @[ - @"-n", @"/Applications/CIE ID.app" - ]; //, [NSString stringWithUTF8String:szPAN]]; - - [task launch]; -} - -int sendMessage(const char *szCommand, const char *szParam) { - int sock; - struct sockaddr_in server; - char szMessage[100], szServerReply[1000]; - - // Create socket - sock = socket(AF_INET, SOCK_STREAM, 0); - if (sock == -1) { - printf("Could not create socket"); - } - puts("Socket created"); - - server.sin_addr.s_addr = inet_addr("127.0.0.1"); - server.sin_family = AF_INET; - server.sin_port = htons(88888); - - // Connect to remote server - if (connect(sock, (struct sockaddr *)&server, sizeof(server)) < 0) { - perror("connect failed. Error"); - return 1; - } - - puts("Connected\n"); - - if (szParam) - sprintf(szMessage, "%s:%s", szCommand, szParam); - else - sprintf(szMessage, "%s", szCommand); - - std::string sMessage = szMessage; - std::string sCipherText; - - encrypt(sMessage, sCipherText); - - int messagelen = (int)sCipherText.size(); - std::string sHeader((char *)&messagelen, sizeof(messagelen)); - - sMessage = sHeader.append(sCipherText); - - // Send some data - if (send(sock, sMessage.c_str(), (size_t)sMessage.length(), 0) < 0) { - puts("Send failed"); - return 2; - } - - // Receive a reply from the server - if (recv(sock, szServerReply, 100, 0) < 0) { - puts("recv failed"); - return 3; - } - - puts("Server reply :"); - puts(szServerReply); - - close(sock); - return 0; -} - -void notifyPINLocked() { sendMessage("pinlocked", NULL); } - -void notifyPINWrong(int trials) { - char szParam[100]; - sprintf(szParam, "%d", trials); - - sendMessage("pinwrong", szParam); -} - -void notifyCardNotRegistered(const char *szPAN) { - sendMessage("cardnotregistered", szPAN); -} diff --git a/libs/pkcs11/src/Util/UtilException.cpp b/libs/pkcs11/src/Util/UtilException.cpp index 8fca77f6..f81f4e39 100644 --- a/libs/pkcs11/src/Util/UtilException.cpp +++ b/libs/pkcs11/src/Util/UtilException.cpp @@ -1,8 +1,6 @@ #include "Util/UtilException.h" -#include - #include "LOGGER/Logger.h" #include "Util/util.h" diff --git a/libs/shared/src/Crypto/CryptoUtil.h b/libs/shared/src/Crypto/CryptoUtil.h index e22e0025..c1ad0b4a 100644 --- a/libs/shared/src/Crypto/CryptoUtil.h +++ b/libs/shared/src/Crypto/CryptoUtil.h @@ -9,58 +9,72 @@ #ifndef CryptoUtil_h #define CryptoUtil_h -#include #include #include -#include "keys.h" +#include #include + #include +#include "keys.h" + using namespace CryptoPP; int encrypt(std::string& message, std::string& ciphertext) { - byte key[ CryptoPP::AES::DEFAULT_KEYLENGTH ], iv[ CryptoPP::AES::BLOCKSIZE ]; - memset( key, 0x00, CryptoPP::AES::DEFAULT_KEYLENGTH ); - memset( iv, 0x00, CryptoPP::AES::BLOCKSIZE ); - - std::string enckey = ENCRYPTION_KEY; - - byte digest[SHA1::DIGESTSIZE]; - CryptoPP::SHA1().CalculateDigest(digest, (byte*)enckey.c_str(), enckey.length()); - memcpy(key, digest, CryptoPP::AES::DEFAULT_KEYLENGTH ); - // - // Create Cipher Text - // - CryptoPP::AES::Encryption aesEncryption(key, CryptoPP::AES::DEFAULT_KEYLENGTH); - CryptoPP::CBC_Mode_ExternalCipher::Encryption cbcEncryption( aesEncryption, iv ); - - CryptoPP::StreamTransformationFilter stfEncryptor(cbcEncryption, new CryptoPP::StringSink( ciphertext ) ); - stfEncryptor.Put( reinterpret_cast( message.c_str() ), message.length() + 1 ); - stfEncryptor.MessageEnd(); - - return 0; + CryptoPP::byte key[CryptoPP::AES::DEFAULT_KEYLENGTH], + iv[CryptoPP::AES::BLOCKSIZE]; + memset(key, 0x00, CryptoPP::AES::DEFAULT_KEYLENGTH); + memset(iv, 0x00, CryptoPP::AES::BLOCKSIZE); + + std::string enckey = ENCRYPTION_KEY; + + CryptoPP::byte digest[SHA1::DIGESTSIZE]; + CryptoPP::SHA1().CalculateDigest(digest, (CryptoPP::byte*)enckey.c_str(), + enckey.length()); + memcpy(key, digest, CryptoPP::AES::DEFAULT_KEYLENGTH); + // + // Create Cipher Text + // + CryptoPP::AES::Encryption aesEncryption(key, + CryptoPP::AES::DEFAULT_KEYLENGTH); + CryptoPP::CBC_Mode_ExternalCipher::Encryption cbcEncryption(aesEncryption, + iv); + + CryptoPP::StreamTransformationFilter stfEncryptor( + cbcEncryption, new CryptoPP::StringSink(ciphertext)); + stfEncryptor.Put(reinterpret_cast(message.c_str()), + message.length() + 1); + stfEncryptor.MessageEnd(); + + return 0; }; int decrypt(std::string& ciphertext, std::string& message) { - byte key[ CryptoPP::AES::DEFAULT_KEYLENGTH ], iv[ CryptoPP::AES::BLOCKSIZE ]; - memset( key, 0x00, CryptoPP::AES::DEFAULT_KEYLENGTH ); - memset( iv, 0x00, CryptoPP::AES::BLOCKSIZE ); + CryptoPP::byte key[CryptoPP::AES::DEFAULT_KEYLENGTH], + iv[CryptoPP::AES::BLOCKSIZE]; + memset(key, 0x00, CryptoPP::AES::DEFAULT_KEYLENGTH); + memset(iv, 0x00, CryptoPP::AES::BLOCKSIZE); - std::string enckey = ENCRYPTION_KEY; + std::string enckey = ENCRYPTION_KEY; - byte digest[SHA1::DIGESTSIZE]; - CryptoPP::SHA1().CalculateDigest(digest, (byte*)enckey.c_str(), enckey.length()); - memcpy(key, digest, CryptoPP::AES::DEFAULT_KEYLENGTH ); + CryptoPP::byte digest[SHA1::DIGESTSIZE]; + CryptoPP::SHA1().CalculateDigest(digest, (CryptoPP::byte*)enckey.c_str(), + enckey.length()); + memcpy(key, digest, CryptoPP::AES::DEFAULT_KEYLENGTH); - // Decrypt - CryptoPP::AES::Decryption aesDecryption(key, CryptoPP::AES::DEFAULT_KEYLENGTH); - CryptoPP::CBC_Mode_ExternalCipher::Decryption cbcDecryption( aesDecryption, iv ); + // Decrypt + CryptoPP::AES::Decryption aesDecryption(key, + CryptoPP::AES::DEFAULT_KEYLENGTH); + CryptoPP::CBC_Mode_ExternalCipher::Decryption cbcDecryption(aesDecryption, + iv); - CryptoPP::StreamTransformationFilter stfDecryptor(cbcDecryption, new CryptoPP::StringSink( message ) ); - stfDecryptor.Put( reinterpret_cast( ciphertext.c_str() ), ciphertext.size() ); - stfDecryptor.MessageEnd(); + CryptoPP::StreamTransformationFilter stfDecryptor( + cbcDecryption, new CryptoPP::StringSink(message)); + stfDecryptor.Put(reinterpret_cast(ciphertext.c_str()), + ciphertext.size()); + stfDecryptor.MessageEnd(); - return 0; + return 0; }; #endif /* CryptoUtil_h */ diff --git a/libs/shared/src/Crypto/RSA.cpp b/libs/shared/src/Crypto/RSA.cpp index bde94712..9418d271 100644 --- a/libs/shared/src/Crypto/RSA.cpp +++ b/libs/shared/src/Crypto/RSA.cpp @@ -2,7 +2,8 @@ #include -#include "Util/util.h" +#include "Util/funccallinfo.h" +#include "Util/log.h" extern CLog Log; #if (CRYPTOPP_VERSION >= 600) && (__cplusplus >= 201103L) @@ -15,10 +16,7 @@ typedef unsigned char byte; #include #include -using CryptoPP::DecodingResult; -using CryptoPP::InvertibleRSAFunction; using CryptoPP::PSS; -using CryptoPP::RSA; using CryptoPP::RSASS; using CryptoPP::SecByteBlock; using CryptoPP::SHA512; diff --git a/libs/shared/src/Crypto/SHA1.cpp b/libs/shared/src/Crypto/SHA1.cpp index e556cae8..aedd0346 100644 --- a/libs/shared/src/Crypto/SHA1.cpp +++ b/libs/shared/src/Crypto/SHA1.cpp @@ -1,21 +1,24 @@ #include "Crypto/SHA1.h" +#include + CSHA1::CSHA1() : isInit(false) {} CSHA1::~CSHA1() {} void CSHA1::Init() { - SHA1_Init(&ctx); + EVP_MD_CTX* ctx = EVP_MD_CTX_new(); + EVP_DigestInit_ex(ctx, EVP_sha1(), NULL); isInit = true; } void CSHA1::Update(ByteArray data) { if (!isInit) throw logged_error("Hash non inizializzato"); - SHA1_Update(&ctx, data.data(), data.size()); + EVP_DigestUpdate(ctx, data.data(), data.size()); } ByteDynArray CSHA1::Final() { if (!isInit) throw logged_error("Hash non inizializzato"); ByteDynArray resp(SHA_DIGEST_LENGTH); - SHA1_Final(resp.data(), &ctx); + EVP_DigestFinal_ex(ctx, resp.data(), NULL); isInit = false; return resp; diff --git a/libs/shared/src/Crypto/SHA1.h b/libs/shared/src/Crypto/SHA1.h index ae8e486e..8322321a 100644 --- a/libs/shared/src/Crypto/SHA1.h +++ b/libs/shared/src/Crypto/SHA1.h @@ -1,5 +1,5 @@ #pragma once - +#include #include #include "Util/UtilException.h" @@ -7,7 +7,7 @@ class CSHA1 { bool isInit; - SHA_CTX ctx; + EVP_MD_CTX* ctx; public: CSHA1(); diff --git a/libs/shared/src/Crypto/SHA256.cpp b/libs/shared/src/Crypto/SHA256.cpp index 5b1980be..94de0928 100644 --- a/libs/shared/src/Crypto/SHA256.cpp +++ b/libs/shared/src/Crypto/SHA256.cpp @@ -3,19 +3,21 @@ #include #include #include +#include void CSHA256::Init() { - SHA256_Init(&ctx); + EVP_MD_CTX* ctx = EVP_MD_CTX_new(); + EVP_DigestInit_ex(ctx, EVP_sha256(), NULL); isInit = true; } void CSHA256::Update(ByteArray data) { if (!isInit) throw logged_error("Hash non inizializzato"); - SHA256_Update(&ctx, data.data(), data.size()); + EVP_DigestUpdate(ctx, data.data(), data.size()); } ByteDynArray CSHA256::Final() { if (!isInit) throw logged_error("Hash non inizializzato"); ByteDynArray resp(SHA_DIGEST_LENGTH); - SHA256_Final(resp.data(), &ctx); + EVP_DigestFinal_ex(ctx, resp.data(), NULL); isInit = false; return resp; diff --git a/libs/shared/src/Crypto/sha256.h b/libs/shared/src/Crypto/sha256.h index 5d58f4b4..87a4459b 100644 --- a/libs/shared/src/Crypto/sha256.h +++ b/libs/shared/src/Crypto/sha256.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include "Util/Array.h" @@ -8,11 +9,11 @@ class CSHA256 { public: - ByteDynArray Digest(ByteArray &data); + ByteDynArray Digest(ByteArray& data); void Init(); void Update(ByteArray data); ByteDynArray Final(); bool isInit; - SHA256_CTX ctx; + EVP_MD_CTX* ctx; }; diff --git a/libs/shared/src/PCSC/PCSC.cpp b/libs/shared/src/PCSC/PCSC.cpp index 5177b2dc..22f6d475 100644 --- a/libs/shared/src/PCSC/PCSC.cpp +++ b/libs/shared/src/PCSC/PCSC.cpp @@ -82,8 +82,12 @@ readerMonitor::readerMonitor(void (*eventHandler)(std::string &reader, auto loadReaderList = [&]() -> void { char *readers = nullptr; - unsigned long int len = 0; +#ifdef __APPLE__ + DWORD len = 0; +#else + unsigned long int len = 0; +#endif if (SCardListReaders(rm->hContext, NULL, NULL, &len)) throw logged_error("Nessun lettore installato"); diff --git a/libs/sign-sdk/src/ASN1/ASN1GenericSequence.cpp b/libs/sign-sdk/src/ASN1/ASN1GenericSequence.cpp index 6680281e..8f2b416a 100644 --- a/libs/sign-sdk/src/ASN1/ASN1GenericSequence.cpp +++ b/libs/sign-sdk/src/ASN1/ASN1GenericSequence.cpp @@ -5,7 +5,7 @@ #include "ASN1Exception.h" CASN1GenericSequence::CASN1GenericSequence(BYTE btTag) - : m_nSize(0), m_nOffsetsMax(MAXSIZE), m_pnOffsets(NULL) { + : m_pnOffsets(NULL), m_nOffsetsMax(MAXSIZE), m_nSize(0) { m_pnOffsets = (unsigned int*)calloc(m_nOffsetsMax + 2, sizeof(m_pnOffsets[0])); setTag(btTag); @@ -13,9 +13,9 @@ CASN1GenericSequence::CASN1GenericSequence(BYTE btTag) CASN1GenericSequence::CASN1GenericSequence(UUCBufferedReader& reader) : CASN1Object(reader), - m_nSize(0), + m_pnOffsets(NULL), m_nOffsetsMax(MAXSIZE), - m_pnOffsets(NULL) { + m_nSize(0) { m_pnOffsets = (unsigned int*)calloc(m_nOffsetsMax + 2, sizeof(m_pnOffsets[0])); m_nSize = makeOffset(); @@ -23,23 +23,23 @@ CASN1GenericSequence::CASN1GenericSequence(UUCBufferedReader& reader) CASN1GenericSequence::CASN1GenericSequence(const UUCByteArray& content) : CASN1Object(content), - m_nSize(0), + m_pnOffsets(NULL), m_nOffsetsMax(MAXSIZE), - m_pnOffsets(NULL) { + m_nSize(0) { m_pnOffsets = (unsigned int*)calloc(m_nOffsetsMax + 2, sizeof(m_pnOffsets[0])); m_nSize = makeOffset(); } CASN1GenericSequence::CASN1GenericSequence(const CASN1Object& obj) - : CASN1Object(obj), m_nSize(0), m_nOffsetsMax(MAXSIZE), m_pnOffsets(NULL) { + : CASN1Object(obj), m_pnOffsets(NULL), m_nOffsetsMax(MAXSIZE), m_nSize(0) { m_pnOffsets = (unsigned int*)calloc(m_nOffsetsMax + 2, sizeof(m_pnOffsets[0])); m_nSize = makeOffset(); } CASN1GenericSequence::CASN1GenericSequence(const CASN1GenericSequence& obj) - : CASN1Object(obj), m_nSize(0), m_nOffsetsMax(MAXSIZE), m_pnOffsets(NULL) { + : CASN1Object(obj), m_pnOffsets(NULL), m_nOffsetsMax(MAXSIZE), m_nSize(0) { m_pnOffsets = (unsigned int*)calloc(m_nOffsetsMax + 2, sizeof(m_pnOffsets[0])); m_nSize = makeOffset(); @@ -47,9 +47,9 @@ CASN1GenericSequence::CASN1GenericSequence(const CASN1GenericSequence& obj) CASN1GenericSequence::CASN1GenericSequence(const BYTE* value, long len) : CASN1Object(value, len), - m_nSize(0), + m_pnOffsets(NULL), m_nOffsetsMax(MAXSIZE), - m_pnOffsets(NULL) { + m_nSize(0) { m_pnOffsets = (unsigned int*)calloc(m_nOffsetsMax + 2, sizeof(m_pnOffsets[0])); m_nSize = makeOffset(); @@ -187,8 +187,7 @@ void CASN1GenericSequence::setElementAt(const CASN1Object& obj, int nPos) { } void CASN1GenericSequence::removeElementAt(int nPos) { - if (nPos < 0 || (unsigned int)nPos > size()) - throw -1; + if (nPos < 0 || (unsigned int)nPos > size()) throw -1; UUCByteArray oldVal(*(getValue())); diff --git a/libs/sign-sdk/src/Base64.cpp b/libs/sign-sdk/src/Base64.cpp index 580529de..b6bceefa 100644 --- a/libs/sign-sdk/src/Base64.cpp +++ b/libs/sign-sdk/src/Base64.cpp @@ -35,8 +35,6 @@ #include #include -#include "Sign/disigonsdk.h" - #define XX 100 /** @var base64_list diff --git a/libs/sign-sdk/src/CIEEngine.c b/libs/sign-sdk/src/CIEEngine.c index e33911d5..f90140cd 100644 --- a/libs/sign-sdk/src/CIEEngine.c +++ b/libs/sign-sdk/src/CIEEngine.c @@ -422,7 +422,7 @@ static EVP_PKEY *cie_load_pubkey(ENGINE *engine, const char *s_key_id, UI_METHOD *ui_method, void *callback_data) { printf("call cie_load_pubkey\n"); - return 1; + return NULL; } static EVP_PKEY_METHOD *cie_pkey_method_rsa() { diff --git a/libs/sign-sdk/src/CIESigner.cpp b/libs/sign-sdk/src/CIESigner.cpp index aaccddb0..8dc9cc3b 100644 --- a/libs/sign-sdk/src/CIESigner.cpp +++ b/libs/sign-sdk/src/CIESigner.cpp @@ -5,8 +5,6 @@ #include #include "PKCS11/cryptoki.h" - - #include "UUCLogger.h" USE_LOG; #include diff --git a/libs/sign-sdk/src/CSP/IAS.cpp b/libs/sign-sdk/src/CSP/IAS.cpp index 2af72e52..7584c20a 100644 --- a/libs/sign-sdk/src/CSP/IAS.cpp +++ b/libs/sign-sdk/src/CSP/IAS.cpp @@ -344,8 +344,8 @@ void IAS::SelectAID_IAS(bool SM) { throw scard_error(sw); } } else if (type == CIE_Type::CIE_Gemalto || type == CIE_Type::CIE_STM || - CIE_Type::CIE_STM2 || CIE_Type::CIE_STM3 || - CIE_Type::CIE_ACTALIS || CIE_Type::CIE_BIT4ID) { + type == CIE_Type::CIE_STM2 || type == CIE_Type::CIE_STM3 || + type == CIE_Type::CIE_ACTALIS || type == CIE_Type::CIE_BIT4ID) { uint8_t selectIAS[] = {0x00, 0xa4, 0x04, 0x0c}; if (SM) { if ((sw = SendAPDU_SM(VarToByteArray(selectIAS), IAS_AID, resp)) != diff --git a/libs/sign-sdk/src/CounterSignatureGenerator.cpp b/libs/sign-sdk/src/CounterSignatureGenerator.cpp index 983ad66c..261996c7 100644 --- a/libs/sign-sdk/src/CounterSignatureGenerator.cpp +++ b/libs/sign-sdk/src/CounterSignatureGenerator.cpp @@ -12,8 +12,8 @@ CounterSignatureGenerator::CounterSignatureGenerator(CSignedDocument& signedDoc, int signerInfoIndex) : m_signedDoc(signedDoc), - m_signerInfoIndex(signerInfoIndex), - m_signerInfo(m_signedDoc.getSignerInfo(m_signerInfoIndex)) { + m_signerInfo(m_signedDoc.getSignerInfo(m_signerInfoIndex)), + m_signerInfoIndex(signerInfoIndex) { m_signerInfos = signedDoc.getSignerInfos(); m_certificates = signedDoc.getCertificates(); m_digestAlgos = signedDoc.getDigestAlgos(); diff --git a/libs/sign-sdk/src/PCSC.cpp b/libs/sign-sdk/src/PCSC.cpp index 6b93b94e..1e11552e 100644 --- a/libs/sign-sdk/src/PCSC.cpp +++ b/libs/sign-sdk/src/PCSC.cpp @@ -1,10 +1,6 @@ #include #include -#include - -#include "Util/UtilException.h" - struct transData { SCARDCONTEXT context; bool started; @@ -98,8 +94,8 @@ readerMonitor::readerMonitor(void (*eventHandler)(std::string &reader, auto loadReaderList = [&]() -> void { char *readers = nullptr; - if (SCardListReaders(rm->hContext, nullptr, (char *)&readers, SCARD_AUTOALLOCATE) != - SCARD_S_SUCCESS || + if (SCardListReaders(rm->hContext, nullptr, (char *)&readers, + SCARD_AUTOALLOCATE) != SCARD_S_SUCCESS || readers == nullptr) { throw logged_error("Nessun lettore installato"); } diff --git a/libs/sign-sdk/src/RSA/r_encode.c b/libs/sign-sdk/src/RSA/r_encode.c index d687dd2e..f4fb6f69 100644 --- a/libs/sign-sdk/src/RSA/r_encode.c +++ b/libs/sign-sdk/src/RSA/r_encode.c @@ -63,7 +63,7 @@ /* ENC is the basic 1 character encoding function to make a char printing */ -#define ENC(c) ((int)bintoasc[((c)&077)]) +#define ENC(c) ((int)bintoasc[((c) & 077)]) #define PAD '=' /* Index this array by a 6 bit value to get the character corresponding @@ -95,12 +95,8 @@ static void encode PROTO_LIST((unsigned char[4], unsigned char[3], int)); /* This will always returns 0. It is an int function for future compatibility, done to provide compatibility with RSAREF(tm). */ -int R_EncodePEMBlock(encodedBlock, encodedBlockLen, block, blockLen) -unsigned char *encodedBlock; /* encoded block */ -unsigned int *encodedBlockLen; /* length of encoded block */ -unsigned char *block; /* block */ -unsigned int blockLen; /* length of block */ -{ +int R_EncodePEMBlock(unsigned char *encodedBlock, unsigned int *encodedBlockLen, + unsigned char *block, unsigned int blockLen) { unsigned int i, lastLen; if (blockLen < 1) { @@ -120,12 +116,8 @@ unsigned int blockLen; /* length of block */ return (ID_OK); } -int R_DecodePEMBlock(outbuf, outlength, inbuf, inlength) -unsigned char *outbuf; /* block */ -unsigned int *outlength; /* length of block */ -unsigned char *inbuf; /* encoded block */ -unsigned int inlength; /* length of encoded block */ -{ +int R_DecodePEMBlock(unsigned char *outbuf, unsigned int *outlength, + unsigned char *inbuf, unsigned int inlength) { unsigned char *bp; int length; unsigned int c1, c2, c3, c4; @@ -181,10 +173,7 @@ unsigned int inlength; /* length of encoded block */ If fewer than 3 are present, the 1 or two extras must be zeros. */ -static void encode(f, p, count) unsigned char *f; /* output buffer */ -unsigned char *p; /* input buffer */ -int count; /* count */ -{ +static void encode(unsigned char *f, unsigned char *p, int count) { int c1, c2, c3, c4; c1 = *p >> 2; diff --git a/libs/sign-sdk/src/RSA/rsaeuro.h b/libs/sign-sdk/src/RSA/rsaeuro.h index c547d5be..ab7b6903 100644 --- a/libs/sign-sdk/src/RSA/rsaeuro.h +++ b/libs/sign-sdk/src/RSA/rsaeuro.h @@ -43,12 +43,12 @@ #include #include "global.h" -//#include "md2.h" /* allow access to others */ -//#include "md4.h" -//#include "md5.h" -//#include "shs.h" +// #include "md2.h" /* allow access to others */ +// #include "md4.h" +// #include "md5.h" +// #include "shs.h" #include "nn.h" -//#include "des.h" +// #include "des.h" #ifdef __cplusplus extern "C" { diff --git a/libs/sign-sdk/src/SignatureGenerator.cpp b/libs/sign-sdk/src/SignatureGenerator.cpp index 3805a990..8cc29b81 100644 --- a/libs/sign-sdk/src/SignatureGenerator.cpp +++ b/libs/sign-sdk/src/SignatureGenerator.cpp @@ -9,11 +9,9 @@ #include "ASN1/ASN1Octetstring.h" #include "ASN1/ASN1Sequence.h" #include "ASN1/ASN1Setof.h" -#include "ASN1/ASN1UTCTime.h" #include "ASN1/AlgorithmIdentifier.h" #include "ASN1/Certificate.h" #include "ASN1/DigestInfo.h" -#include "ASN1/IssuerAndSerialNumber.h" #include "CertStore.h" #include "RSA/sha1.h" #include "RSA/sha2.h" @@ -23,7 +21,7 @@ USE_LOG; using namespace std; CSignatureGeneratorBase::CSignatureGeneratorBase(CBaseSigner* pSigner) - : m_pSigner(pSigner), m_pTSAClient(NULL), m_nHashAlgo(CKM_SHA1_RSA_PKCS) { + : m_pSigner(pSigner), m_nHashAlgo(CKM_SHA1_RSA_PKCS), m_pTSAClient(NULL) { m_szAlias[0] = 0; } diff --git a/libs/sign-sdk/src/SignedDataGeneratorEx.cpp b/libs/sign-sdk/src/SignedDataGeneratorEx.cpp index fe6a13cc..647acf83 100644 --- a/libs/sign-sdk/src/SignedDataGeneratorEx.cpp +++ b/libs/sign-sdk/src/SignedDataGeneratorEx.cpp @@ -9,16 +9,9 @@ #include "SignedDataGeneratorEx.h" -#include - #include "ASN1/ASN1ObjectIdentifier.h" #include "ASN1/ASN1Octetstring.h" -#include "ASN1/ASN1Sequence.h" #include "ASN1/ASN1Setof.h" -#include "ASN1/ASN1UTCTime.h" -#include "ASN1/AlgorithmIdentifier.h" -#include "ASN1/IssuerAndSerialNumber.h" -#include "ASN1/Certificate.h" SignedDataGeneratorEx::SignedDataGeneratorEx(CSignedDocument& sd) { m_signerInfos = sd.getSignerInfos(); diff --git a/libs/sign-sdk/src/SignerInfoGenerator.cpp b/libs/sign-sdk/src/SignerInfoGenerator.cpp index 69cd3e7a..fcfc2467 100644 --- a/libs/sign-sdk/src/SignerInfoGenerator.cpp +++ b/libs/sign-sdk/src/SignerInfoGenerator.cpp @@ -17,9 +17,9 @@ #include "ASN1/ASN1Setof.h" #include "ASN1/ASN1UTCTime.h" #include "ASN1/AlgorithmIdentifier.h" +#include "ASN1/Certificate.h" #include "ASN1/IssuerAndSerialNumber.h" #include "ASN1/SignerInfo.h" -#include "ASN1/Certificate.h" CSignerInfoGenerator::CSignerInfoGenerator() : m_pIssuer(NULL), diff --git a/libs/sign-sdk/src/TSAClient.cpp b/libs/sign-sdk/src/TSAClient.cpp index e8880346..04e1ea5a 100644 --- a/libs/sign-sdk/src/TSAClient.cpp +++ b/libs/sign-sdk/src/TSAClient.cpp @@ -6,7 +6,6 @@ #include "ASN1/TimeStampRequest.h" #include "ASN1/TimeStampResponse.h" #include "ASN1/TimeStampToken.h" -#include "Base64.h" #include "UUCLogger.h" USE_LOG; diff --git a/libs/sign-sdk/src/Token.cpp b/libs/sign-sdk/src/Token.cpp index 9e577821..d0e532d6 100644 --- a/libs/sign-sdk/src/Token.cpp +++ b/libs/sign-sdk/src/Token.cpp @@ -2,9 +2,7 @@ #include -#include "util/tlv.h" #include "PCSC/APDU.h" -#include "stdafx.h" static char *szCompiledFile = __FILE__; diff --git a/libs/sign-sdk/src/UUCLogger.cpp b/libs/sign-sdk/src/UUCLogger.cpp index 897f4b7c..c939529e 100644 --- a/libs/sign-sdk/src/UUCLogger.cpp +++ b/libs/sign-sdk/src/UUCLogger.cpp @@ -3,8 +3,6 @@ #include #include -#include - logFunc pfnCrashliticsLog = NULL; UUCLogger::UUCLogger(void) : m_nLogLevel(1) {} diff --git a/libs/sign-sdk/src/UUCTextFileReader.cpp b/libs/sign-sdk/src/UUCTextFileReader.cpp index a195cdda..437a6930 100644 --- a/libs/sign-sdk/src/UUCTextFileReader.cpp +++ b/libs/sign-sdk/src/UUCTextFileReader.cpp @@ -8,7 +8,7 @@ USE_LOG; UUCTextFileReader::UUCTextFileReader(const char* szFilePath) { m_pf = fopen(szFilePath, "rt"); if (!m_pf) { - throw(long) ERROR_FILE_NOT_FOUND; + throw (long)ERROR_FILE_NOT_FOUND; } } @@ -37,7 +37,7 @@ long UUCTextFileReader::readLine(char* szLine, unsigned long nLen) { while ((fread(szLine + i, 1, 1, m_pf) > 0) && (szLine[i] != '\n')) { i++; if (i == nLen) { - throw(long) ERROR_MORE_DATA; + throw (long)ERROR_MORE_DATA; } } diff --git a/libs/sign-sdk/src/UUCTextFileWriter.cpp b/libs/sign-sdk/src/UUCTextFileWriter.cpp index e3a87d2b..862d5f5b 100644 --- a/libs/sign-sdk/src/UUCTextFileWriter.cpp +++ b/libs/sign-sdk/src/UUCTextFileWriter.cpp @@ -9,7 +9,7 @@ UUCTextFileWriter::UUCTextFileWriter(const char* szFilePath, else m_pf = fopen(szFilePath, "wt"); - if (!m_pf) throw(long) ERROR_FILE_NOT_FOUND; + if (!m_pf) throw (long)ERROR_FILE_NOT_FOUND; } UUCTextFileWriter::~UUCTextFileWriter() { fclose(m_pf); } diff --git a/libs/sign-sdk/src/Util/UtilException.cpp b/libs/sign-sdk/src/Util/UtilException.cpp index 5b3b54d9..d3ae17f5 100644 --- a/libs/sign-sdk/src/Util/UtilException.cpp +++ b/libs/sign-sdk/src/Util/UtilException.cpp @@ -1,8 +1,6 @@ #include "Util/UtilException.h" -#include - #include "Util/util.h" logged_error::logged_error(std::string message) diff --git a/libs/sign-sdk/src/definitions.cpp b/libs/sign-sdk/src/definitions.cpp index d90559c8..81d781f4 100644 --- a/libs/sign-sdk/src/definitions.cpp +++ b/libs/sign-sdk/src/definitions.cpp @@ -2,8 +2,6 @@ #include "Sign/definitions.h" // static unsigned long g_nErr; -#include - using namespace std; int atox(const char* szVal) { diff --git a/libs/sign-sdk/src/disigonsdk.cpp b/libs/sign-sdk/src/disigonsdk.cpp index c5b3dd0a..250c93f3 100644 --- a/libs/sign-sdk/src/disigonsdk.cpp +++ b/libs/sign-sdk/src/disigonsdk.cpp @@ -13,18 +13,16 @@ #include "ASN1/TimeStampResponse.h" #include "Base64.h" #include "CIESigner.h" -#include "CertStore.h" #include "CSP/IAS.h" +#include "CertStore.h" #include "M7MParser.h" #include "PdfSignatureGenerator.h" #include "PdfVerifier.h" -#include "RSA/sha2.h" #include "SignatureGenerator.h" #include "UUCLogger.h" #include "UUCProperties.h" #include "XAdESGenerator.h" #include "XAdESVerifier.h" -#include "podofo/podofo.h" DECLARE_LOG;