Skip to content

Commit

Permalink
chore: lib: apply compilation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
M0Rf30 committed Sep 15, 2024
1 parent ee5b0ac commit b601b02
Show file tree
Hide file tree
Showing 30 changed files with 110 additions and 91 deletions.
10 changes: 6 additions & 4 deletions libs/pkcs11/src/CSP/FirmaConCIE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ CK_RV CK_ENTRY firmaConCIE(const char* inFilePath, const char* type,

progressCallBack(20, "Getting certificate from CIE...");

IAS* ias =
new IAS((CToken::TokenTransmitCallback)TokenTransmitCallback, atrBa);
IAS* ias = (IAS*)malloc(sizeof(IAS));
new (ias)
IAS((CToken::TokenTransmitCallback)TokenTransmitCallback, atrBa);
ias->SetCardContext(&conn);

foundCIE = false;
Expand Down Expand Up @@ -133,7 +134,8 @@ CK_RV CK_ENTRY firmaConCIE(const char* inFilePath, const char* type,
memcpy(fullPinCStr, FullPIN.data(), 8);
fullPinCStr[8] = 0;

CIESign* cieSign = new CIESign(ias);
CIESign* cieSign = (CIESign*)malloc(sizeof(CIESign));
new (cieSign) CIESign(ias);

uint16_t ret = cieSign->sign(inFilePath, type, fullPinCStr, page, x, y, w,
h, imagePathFile, outFilePath);
Expand Down Expand Up @@ -172,4 +174,4 @@ CK_RV CK_ENTRY firmaConCIE(const char* inFilePath, const char* type,

free(readers);
return SCARD_S_SUCCESS;
}
}
17 changes: 8 additions & 9 deletions libs/pkcs11/src/CSP/IAS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,18 +676,17 @@ ByteDynArray IAS::SM(ByteArray &keyEnc, ByteArray &keySig, ByteArray &apdu,
auto calcMac = ISOPad(ByteDynArray(seq).append(smHead));

ByteDynArray iv(8);
iv.fill(0); // IV for APDU encryption and signature should be 0. Please refer
// to IAS specification §7.1.9 Secure messaging – Command APDU
// protection
iv.fill(0); // IV for APDU encryption and signature should be 0.

CDES3 encDes(keyEnc, iv);

CMAC sigMac(keySig, iv);

uint8_t Val01 = 1;

ByteDynArray datafield, doob;
if (apdu[4] != 0 && apdu.size() > 5) {
size_t apduSize = apdu.size();

if (apdu[4] != 0 && apduSize > 5) {
ByteDynArray enc = encDes.RawEncode(ISOPad(apdu.mid(5, apdu[4])));

if ((apdu[1] & 1) == 0)
Expand All @@ -698,7 +697,7 @@ ByteDynArray IAS::SM(ByteArray &keyEnc, ByteArray &keySig, ByteArray &apdu,
calcMac.append(doob);
datafield.append(doob);
}
if (apdu[4] == 0 && apdu.size() > 7) {
if (apdu[4] == 0 && apduSize > 7) {
ByteDynArray enc =
encDes.RawEncode(ISOPad(apdu.mid(7, (apdu[5] << 8) | apdu[6])));
if ((apdu[1] & 1) == 0)
Expand All @@ -709,8 +708,8 @@ ByteDynArray IAS::SM(ByteArray &keyEnc, ByteArray &keySig, ByteArray &apdu,
calcMac.append(doob);
datafield.append(doob);
}
if (apdu.size() == 5 || apdu.size() == (apdu[4] + 6)) {
uint8_t le = apdu[apdu.size() - 1];
if (apduSize == 5 || apduSize == static_cast<size_t>(apdu[4] + 6)) {
uint8_t le = apdu[apduSize - 1];
ByteArray leBa = VarToByteArray(le);
doob.setASN1Tag(0x97, leBa);
calcMac.append(doob);
Expand Down Expand Up @@ -1551,4 +1550,4 @@ void IAS::VerificaSOD(ByteArray &SOD, std::map<BYTE, ByteDynArray> &hashSet) {
exit_func
}

#define DWL_MSGRESULT 0
#define DWL_MSGRESULT 0
15 changes: 7 additions & 8 deletions libs/pkcs11/src/CSP/VerificaConCIE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include <sys/types.h>

#include "LOGGER/Logger.h"
#include "PKCS11/PKCS11Functions.h"

using namespace CieIDLogger;
Expand All @@ -21,7 +20,7 @@ extern "C" {
CK_RV CK_ENTRY verificaConCIE(const char* inFilePath, const char* proxyAddress,
int proxyPort, const char* usrPass);
CK_RV CK_ENTRY getNumberOfSign(void);
CK_RV CK_ENTRY getVerifyInfo(u_int64_t index, struct verifyInfo_t* vInfos);
CK_RV CK_ENTRY getVerifyInfo(int index, struct verifyInfo_t* vInfos);
CK_RV CK_ENTRY estraiP7m(const char* inFilePath, const char* outFilePath);
}

Expand All @@ -33,10 +32,10 @@ CK_RV CK_ENTRY verificaConCIE(const char* inFilePath, const char* proxyAddress,
proxyPort, usrPass);

if (verifyResult.nErrorCode == 0) {
return 0;
printf("verificaConCIE OK");
return (CK_RV)verifyResult.verifyInfo.pSignerInfos->nCount;
} else {
LOG_ERROR("verificaConCIE - Errore nella verifica: %lu\n",
verifyResult.nErrorCode);
printf("Errore nella verifica: %lu\n", verifyResult.nErrorCode);
return verifyResult.nErrorCode;
}
}
Expand All @@ -45,8 +44,8 @@ CK_RV CK_ENTRY getNumberOfSign(void) {
return (CK_RV)verifyResult.verifyInfo.pSignerInfos->nCount;
}

CK_RV CK_ENTRY getVerifyInfo(u_int64_t index, struct verifyInfo_t* vInfos) {
if (index >= 0 && index < getNumberOfSign()) {
CK_RV CK_ENTRY getVerifyInfo(int index, struct verifyInfo_t* vInfos) {
if (index >= 0 && (CK_RV)index < getNumberOfSign()) {
SIGNER_INFO tmpSignerInfo =
(verifyResult.verifyInfo.pSignerInfos->pSignerInfo)[index];
strcpy(vInfos->name, tmpSignerInfo.szGIVENNAME);
Expand All @@ -70,4 +69,4 @@ CK_RV CK_ENTRY estraiP7m(const char* inFilePath, const char* outFilePath) {
long res = verifier->get_file_from_p7m(inFilePath, outFilePath);

return res;
}
}
5 changes: 2 additions & 3 deletions libs/pkcs11/src/CSP/VerificaConCIE.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
#define LIBS_PKCS11_SRC_CSP_VERIFICACONCIE_H_

#include <stdio.h>
#include <sys/types.h>

#include "CSP/AbilitaCIE.h"
#include "AbilitaCIE.h"
#include "Sign/CIEVerify.h"

typedef CK_RV (*verificaConCIEfn)(const char* inFilePath);
typedef CK_RV (*getNumberOfSignfn)(void);
typedef CK_RV (*getVerifyInfofn)(u_int64_t index, struct verifyInfo_t* vInfos);
typedef CK_RV (*getVerifyInfofn)(int index, struct verifyInfo_t* vInfos);
typedef CK_RV (*estraiP7mfn)(const char* inFilePath, const char* outFilePath);
#endif // LIBS_PKCS11_SRC_CSP_VERIFICACONCIE_H_
22 changes: 13 additions & 9 deletions libs/pkcs11/src/LOGGER/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <sys/time.h>
#include <unistd.h>

#include <chrono>
#include <cstdlib>
#include <cstring>
#include <ctime>
Expand Down Expand Up @@ -191,18 +192,21 @@ void Logger::logOnConsole(string& data) {
cout << getCurrentTime() << " " << data << endl;
}

string Logger::getCurrentTime() {
char pbtDate[256];
timeval curTime;
gettimeofday(&curTime, NULL);
int milli = curTime.tv_usec / 1000;
std::string Logger::getCurrentTime() {
// Get the current time as a time_point
auto now = std::chrono::system_clock::now();

// Convert to time_t for formatting
std::time_t now_c = std::chrono::system_clock::to_time_t(now);

strftime(pbtDate, sizeof(pbtDate), "%Y-%m-%d %H:%M:%S",
gmtime(&curTime.tv_sec));
// Convert to local time
std::tm local_tm = *std::localtime(&now_c);

sprintf(pbtDate, "%s:%03d", pbtDate, milli);
// Format the time as a string
std::ostringstream oss;
oss << std::put_time(&local_tm, "%Y-%m-%d %H:%M:%S");

return pbtDate;
return oss.str();
}

void Logger::log_log(ostream& out, LogLevel level, const char* text) throw() {
Expand Down
5 changes: 3 additions & 2 deletions libs/pkcs11/src/PKCS11/Slot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,12 @@ void CSlot::Final() {
std::shared_ptr<CP11Object> CSlot::FindP11Object(CK_OBJECT_CLASS objClass,
CK_ATTRIBUTE_TYPE attr,
CK_BYTE *val, int valLen) {
init_func for (DWORD i = 0; i < P11Objects.size(); i++) {
for (size_t i = 0; i < P11Objects.size(); i++) {
auto obj = P11Objects[i];
if (obj->ObjClass == objClass) {
ByteArray *attrVal = obj->getAttribute(attr);
if (attrVal && attrVal->size() == valLen) {
if (attrVal && attrVal->size() == static_cast<size_t>(
valLen)) { // Cast valLen to size_t
if (memcmp(attrVal->data(), val, valLen) == 0) {
return obj;
}
Expand Down
5 changes: 3 additions & 2 deletions libs/pkcs11/src/Sign/CIEVerify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ long CIEVerify::verify(const char* input_file, VERIFY_RESULT* verifyResult,
LOG_ERROR("CIEVerify::invalid proxy port");
return DISIGON_ERROR_INVALID_SIGOPT;
} else {
ret =
disigon_verify_set(ctx, DISIGON_OPT_PROXY_PORT, (void*)proxy_port);
ret = disigon_verify_set(ctx, DISIGON_OPT_PROXY_PORT, &proxy_port);
if (ret != 0) {
throw ret;
}
Expand Down Expand Up @@ -79,6 +78,8 @@ long CIEVerify::verify(const char* input_file, VERIFY_RESULT* verifyResult,
} catch (long err) {
LOG_ERROR("CIEVerify::verify error: %lx", err);
}

return 0;
}

long CIEVerify::get_file_from_p7m(const char* input_file,
Expand Down
4 changes: 3 additions & 1 deletion libs/pkcs11/src/Util/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ std::string dumpHexDataLowerCase(ByteArray data, std::string &dump) {
void PutPaddingBT0(ByteArray &ba, long dwLen) {
init_func

if (dwLen > ba.size()) throw logged_error("Lunghezza del padding errata");
if (dwLen > static_cast<long>(ba.size())) {
throw logged_error("Lunghezza del padding errata");
}

ba.left(ba.size() - dwLen).fill(0);
exit_func
Expand Down
2 changes: 0 additions & 2 deletions libs/shared/src/Util/SyncroMutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ class CSyncroMutex {
};

class CSyncroLocker {
CSyncroMutex *pMutex;

public:
CSyncroLocker(CSyncroMutex &mutex);
~CSyncroLocker();
Expand Down
8 changes: 4 additions & 4 deletions libs/shared/src/Util/UUCByteArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,11 @@ const char* UUCByteArray::toHexString() { return toHexString(0); }

const char* UUCByteArray::toHexString(int nSize) {
if (m_szHex) {
delete m_szHex;
delete[] m_szHex;
m_szHex = NULL;
}

if (nSize == 0 || nSize > m_unLen) {
if (nSize <= 0 || nSize > static_cast<int>(m_unLen)) {
nSize = (int)m_unLen;
}

Expand All @@ -253,14 +253,14 @@ const char* UUCByteArray::toHexString(int nSize) {
try {
char szDigit[3];
memset(m_szHex, 0, (nSize + 1) * 2);
for (unsigned int i = 0; i < nSize; i++) {
for (unsigned int i = 0; i < static_cast<unsigned int>(nSize); i++) {
snprintf(szDigit, 3, "%02X", m_pbtContent[i]);
strncat(m_szHex, szDigit, 2);
}

return m_szHex;
} catch (...) {
delete m_szHex;
delete[] m_szHex;
m_szHex = NULL;
throw -3L;
}
Expand Down
4 changes: 2 additions & 2 deletions libs/sign-sdk/include/PdfVerifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ class PDFVerifier {

int GetNumberOfSignatures();

int VerifySignature(int index, const char* szDate, char* signatureType,
int VerifySignature(size_t index, const char* szDate, char* signatureType,
REVOCATION_INFO* pRevocationInfo);

int GetSignature(int index, UUCByteArray& signedDocument,
int GetSignature(size_t index, UUCByteArray& signedDocument,
SignatureAppearanceInfo& appearanceInfo);

static int GetNumberOfSignatures(PdfMemDocument* pPdfDocument);
Expand Down
6 changes: 3 additions & 3 deletions libs/sign-sdk/src/ASN1/ASN1GenericSequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void CASN1GenericSequence::addElementAt(const CASN1Object& obj, int nPos) {
}

CASN1Object CASN1GenericSequence::elementAt(int nPos) {
if (this->size() > nPos) {
if (this->size() > static_cast<unsigned int>(nPos)) {
int offset = m_pnOffsets[nPos];
UUCByteArray curObj(getValue()->getContent() + offset,
getLength() - offset + 1);
Expand Down Expand Up @@ -241,7 +241,7 @@ int CASN1GenericSequence::makeOffset() {

unsigned int offset = 0;
UUCByteArray objVal;
int i = 0;
unsigned int i = 0;
while (offset < len) {
if (i == m_nOffsetsMax) {
m_nOffsetsMax += 1000;
Expand All @@ -257,7 +257,7 @@ int CASN1GenericSequence::makeOffset() {
int iLen = currentObj.getOrigLenLen() + currentObj.getLength() + 2;
offset += iLen;
i++;
} catch (CASN1ParsingException e) {
} catch (const CASN1ParsingException& e) {
break;
}
}
Expand Down
3 changes: 3 additions & 0 deletions libs/sign-sdk/src/ASN1/ContentType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ CContentType::CContentType(const CASN1ObjectIdentifier& algoId)

CContentType::CContentType(char* lpszOId) : CASN1ObjectIdentifier(lpszOId) {}

CContentType::CContentType(const char* timeStampDataOID)
: CASN1ObjectIdentifier(timeStampDataOID) {}

CContentType::CContentType(UUCBufferedReader& reader)
: CASN1ObjectIdentifier(reader) {}

Expand Down
1 change: 1 addition & 0 deletions libs/sign-sdk/src/ASN1/ContentType.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class CContentType : public CASN1ObjectIdentifier {
CContentType(const CASN1Object& contentType);

CContentType(char* lpszOId);
CContentType(const char* timeStampDataOID);

CContentType(const CASN1ObjectIdentifier& algoId);

Expand Down
6 changes: 3 additions & 3 deletions libs/sign-sdk/src/ASN1/Name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ CName::CName(UUCBufferedReader& reader) : CASN1Sequence(reader) {}

CName::CName(const CASN1Object& name) : CASN1Sequence(name) {}

string CName::getField(const char* fieldOID) {
string strname = "";
std::string CName::getField(const char* fieldOID) {
std::string strname = "";

for (int i = 0; i < size(); i++) {
for (size_t i = 0; i < size(); i++) {
CASN1SetOf element = elementAt(i);
CASN1Sequence value = element.elementAt(0);

Expand Down
2 changes: 1 addition & 1 deletion libs/sign-sdk/src/ASN1/SignerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ CCertificate CSignerInfo::getSignatureCertificate(CSignerInfo& signature,
CIssuerAndSerialNumber issuerAndSerialNumber =
signature.getIssuerAndSerialNumber();

for (int i = 0; i < certificates.size(); i++) {
for (size_t i = 0; i < certificates.size(); i++) {
CCertificate cert = certificates.elementAt(i);
CName issuer = cert.getIssuer();
CASN1Integer serialNumber = cert.getSerialNumber();
Expand Down
2 changes: 1 addition & 1 deletion libs/sign-sdk/src/ASN1/UUCBufferedReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void UUCBufferedReader::releaseMark() {
}

void UUCBufferedReader::reset() {
if (m_nTop > -1) {
if (static_cast<int>(m_nTop) > -1) {
m_nIndex = m_pnStack[m_nTop];
m_nTop--;
}
Expand Down
2 changes: 1 addition & 1 deletion libs/sign-sdk/src/ASN1/UUCBufferedReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ class UUCBufferedReader {

unsigned int* m_pnStack;
unsigned int m_nStackSize;
int m_nTop;
unsigned int m_nTop;
};
2 changes: 1 addition & 1 deletion libs/sign-sdk/src/Base64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ int base64_decoded_size(int len) { return ((len / 4) * 3); }
*/
void base64_encode_binary(char *out, const unsigned char *in, int len) {
int size;
size_t i = 0;
int i = 0;

while (i < len) {
size = (len - i < 4) ? len - i : 4;
Expand Down
Loading

0 comments on commit b601b02

Please sign in to comment.