@@ -92,9 +92,12 @@ const QByteArray Card::READBINARY = APDU("00B00000 00");
9292const QByteArray Card::REPLACE = APDU(" 002C0000 00" );
9393const QByteArray Card::VERIFY = APDU(" 00200000 00" );
9494
95- QPCSCReader::Result Card::transfer (QPCSCReader *reader, bool verify, const QByteArray &apdu,
95+ QPCSCReader::Result Card::transfer (QPCSCReader *reader, bool verify, QByteArray & &apdu,
9696 QSmartCardData::PinType type, quint8 newPINOffset, bool requestCurrentPIN)
9797{
98+ auto clean = qScopeGuard ([&apdu] {
99+ apdu.fill (' 0' );
100+ });
98101 if (!reader->isPinPad ())
99102 return reader->transfer (apdu);
100103 quint16 language = 0x0000 ;
@@ -191,11 +194,9 @@ const QByteArray IDEMIACard::AID_QSCD = APDU("00A4040C 10 51534344204170706C6963
191194const QByteArray IDEMIACard::ATR_COSMO8 = QByteArrayLiteral(" 3BDB960080B1FE451F830012233F536549440F9000F1" );
192195const QByteArray IDEMIACard::ATR_COSMOX = QByteArrayLiteral(" 3BDC960080B1FE451F830012233F54654944320F9000C3" );
193196
194- QPCSCReader::Result IDEMIACard::change (QPCSCReader *reader, QSmartCardData::PinType type, QByteArray && pin, QByteArray & &newpin) const
197+ QPCSCReader::Result IDEMIACard::change (QPCSCReader *reader, QSmartCardData::PinType type, const QByteArray &pin, const QByteArray &newpin) const
195198{
196199 QByteArray cmd = CHANGE;
197- newpin = pinTemplate (std::move (newpin));
198- pin = pinTemplate (std::move (pin));
199200 switch (type) {
200201 case QSmartCardData::Pin1Type:
201202 cmd[3 ] = 1 ;
@@ -291,19 +292,19 @@ bool IDEMIACard::loadPerso(QPCSCReader *reader, QSmartCardDataPrivate *d) const
291292 return updateCounters (reader, d);
292293}
293294
294- QByteArray IDEMIACard::pinTemplate (QByteArray &&pin)
295+ QByteArray IDEMIACard::pinTemplate (const QString &data) const
295296{
297+ QByteArray pin = data.toUtf8 ();
296298#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0)
297299 pin.resize (12 , char (0xFF ));
298300#else
299301 pin += QByteArray (12 - pin.size (), char (0xFF ));
300302#endif
301- return std::move ( pin) ;
303+ return pin;
302304}
303305
304- QPCSCReader::Result IDEMIACard::replace (QPCSCReader *reader, QSmartCardData::PinType type, QByteArray && puk, QByteArray & &pin) const
306+ QPCSCReader::Result IDEMIACard::replace (QPCSCReader *reader, QSmartCardData::PinType type, const QByteArray &puk, const QByteArray &pin) const
305307{
306- puk = pinTemplate (std::move (puk));
307308 QByteArray cmd = VERIFY;
308309 cmd[3 ] = 2 ;
309310 cmd[4 ] = char (puk.size ());
@@ -320,7 +321,6 @@ QPCSCReader::Result IDEMIACard::replace(QPCSCReader *reader, QSmartCardData::Pin
320321 }
321322 else
322323 cmd[3 ] = char (type);
323- pin = pinTemplate (std::move (pin));
324324 cmd[4 ] = char (pin.size ());
325325 return transfer (reader, false , cmd + pin, type, 0 , false );
326326}
@@ -351,11 +351,9 @@ bool IDEMIACard::updateCounters(QPCSCReader *reader, QSmartCardDataPrivate *d) c
351351
352352const QByteArray THALESCard::AID = APDU(" 00A4040C 0C A000000063504B43532D3135" );
353353
354- QPCSCReader::Result THALESCard::change (QPCSCReader *reader, QSmartCardData::PinType type, QByteArray && pin, QByteArray & &newpin) const
354+ QPCSCReader::Result THALESCard::change (QPCSCReader *reader, QSmartCardData::PinType type, const QByteArray &pin, const QByteArray &newpin) const
355355{
356356 QByteArray cmd = CHANGE;
357- newpin = pinTemplate (std::move (newpin));
358- pin = pinTemplate (std::move (pin));
359357 cmd[3 ] = char (0x80 | type);
360358 cmd[4 ] = char (pin.size () + newpin.size ());
361359 return transfer (reader, false , cmd + pin + newpin, type, quint8 (pin.size ()), true );
@@ -441,21 +439,19 @@ bool THALESCard::loadPerso(QPCSCReader *reader, QSmartCardDataPrivate *d) const
441439 return updateCounters (reader, d);
442440}
443441
444- QByteArray THALESCard::pinTemplate (const QString &pin)
442+ QByteArray THALESCard::pinTemplate (const QString &data) const
445443{
446- QByteArray result = pin .toUtf8 ();
444+ QByteArray pin = data .toUtf8 ();
447445#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0)
448- result .resize (12 , char (0x00 ));
446+ pin .resize (12 , char (0x00 ));
449447#else
450- result += QByteArray (12 - result.size (), char (0x00 ));
448+ pin += QByteArray (12 - result.size (), char (0x00 ));
451449#endif
452- return result ;
450+ return pin ;
453451}
454452
455- QPCSCReader::Result THALESCard::replace (QPCSCReader *reader, QSmartCardData::PinType type, QByteArray && puk, QByteArray & &pin) const
453+ QPCSCReader::Result THALESCard::replace (QPCSCReader *reader, QSmartCardData::PinType type, const QByteArray &puk, const QByteArray &pin) const
456454{
457- puk = pinTemplate (std::move (puk));
458- pin = pinTemplate (std::move (pin));
459455 QByteArray cmd = REPLACE;
460456 cmd[3 ] = char (0x80 | type);
461457 cmd[4 ] = char (puk.size () + pin.size ());
@@ -533,16 +529,31 @@ bool QSmartCard::pinChange(QSmartCardData::PinType type, QSmartCard::PinAction a
533529 }
534530 popup.reset (new PinPopup (src, flags, d->t .authCert (), parent, bodyText));
535531 popup->open ();
532+ oldPin = d->card ->pinTemplate ({});
533+ newPin = d->card ->pinTemplate ({});
536534 }
537535 else
538536 {
539537 PinUnblock p (type, action, d->t .retryCount (src), d->t .data (QSmartCardData::BirthDate).toDate (),
540538 d->t .data (QSmartCardData::Id).toString (), d->t .isPUKReplacable (), parent);
541539 if (!p.exec ())
542540 return false ;
543- oldPin = p.firstCodeText ().toUtf8 ();
544- newPin = p.newCodeText ().toUtf8 ();
541+ QString oldPinString = p.firstCodeText ();
542+ QString newPinString = p.newCodeText ();
543+ oldPin = d->card ->pinTemplate (oldPinString);
544+ newPin = d->card ->pinTemplate (newPinString);
545+ // Try to clean QLineEdit internal PIN copy using constData that does not detach memory
546+ auto chars = const_cast <QChar*>(oldPinString.constData ());
547+ for (int i = 0 ; i < oldPinString.length (); ++i)
548+ chars[i] = ' \0 ' ;
549+ chars = const_cast <QChar*>(newPinString.constData ());
550+ for (int i = 0 ; i < newPinString.length (); ++i)
551+ chars[i] = ' \0 ' ;
545552 }
553+ auto clean = qScopeGuard ([&oldPin, &newPin] {
554+ oldPin.fill (' \0 ' );
555+ newPin.fill (' \0 ' );
556+ });
546557
547558 QPCSCReader reader (d->t .reader (), &QPCSC::instance ());
548559 if (!reader.connect ())
@@ -551,8 +562,8 @@ bool QSmartCard::pinChange(QSmartCardData::PinType type, QSmartCard::PinAction a
551562 return false ;
552563 }
553564 auto response = action == QSmartCard::ChangeWithPin || action == QSmartCard::ActivateWithPin ?
554- d->card ->change (&reader, type, std::move ( oldPin), std::move ( newPin) ) :
555- d->card ->replace (&reader, type, std::move ( oldPin), std::move ( newPin) );
565+ d->card ->change (&reader, type, oldPin, newPin) :
566+ d->card ->replace (&reader, type, oldPin, newPin);
556567 switch (response.SW )
557568 {
558569 case 0x9000 :
0 commit comments