@@ -41,8 +41,6 @@ const QString CDoc1::AES128GCM_MTH = QStringLiteral("http://www.w3.org/2009/xmle
4141const QString CDoc1::AES192GCM_MTH = QStringLiteral(" http://www.w3.org/2009/xmlenc11#aes192-gcm" );
4242const QString CDoc1::AES256GCM_MTH = QStringLiteral(" http://www.w3.org/2009/xmlenc11#aes256-gcm" );
4343const QString CDoc1::RSA_MTH = QStringLiteral(" http://www.w3.org/2001/04/xmlenc#rsa-1_5" );
44- const QString CDoc1::KWAES128_MTH = QStringLiteral(" http://www.w3.org/2001/04/xmlenc#kw-aes128" );
45- const QString CDoc1::KWAES192_MTH = QStringLiteral(" http://www.w3.org/2001/04/xmlenc#kw-aes192" );
4644const QString CDoc1::KWAES256_MTH = QStringLiteral(" http://www.w3.org/2001/04/xmlenc#kw-aes256" );
4745const QString CDoc1::CONCATKDF_MTH = QStringLiteral(" http://www.w3.org/2009/xmlenc11#ConcatKDF" );
4846const QString CDoc1::AGREEMENT_MTH = QStringLiteral(" http://www.w3.org/2009/xmlenc11#ECDH-ES" );
@@ -66,7 +64,6 @@ const QHash<QString, const EVP_CIPHER*> CDoc1::ENC_MTH{
6664const QHash<QString, QCryptographicHash::Algorithm> CDoc1::SHA_MTH{
6765 {SHA256_MTH, QCryptographicHash::Sha256}, {SHA384_MTH, QCryptographicHash::Sha384}, {SHA512_MTH, QCryptographicHash::Sha512}
6866};
69- const QHash<QString, quint32> CDoc1::KWAES_SIZE{{KWAES128_MTH, 16 }, {KWAES192_MTH, 24 }, {KWAES256_MTH, 32 }};
7067
7168CDoc1::CDoc1 (const QString &path)
7269 : QFile(path)
@@ -108,7 +105,6 @@ CDoc1::CDoc1(const QString &path)
108105 return ;
109106
110107 CKey key;
111- key.id = xml.attributes ().value (QLatin1String (" Id" )).toString ();
112108 key.recipient = xml.attributes ().value (QLatin1String (" Recipient" )).toString ();
113109 while (!xml.atEnd ())
114110 {
@@ -117,18 +113,17 @@ CDoc1::CDoc1(const QString &path)
117113 break ;
118114 if (!xml.isStartElement ())
119115 continue ;
120- // EncryptedData/KeyInfo/KeyName
121- if (xml.name () == QLatin1String (" KeyName" ))
122- key.name = xml.readElementText ();
123- // EncryptedData/KeyInfo/EncryptedKey/EncryptionMethod
124- else if (xml.name () == QLatin1String (" EncryptionMethod" ))
125- key.method = xml.attributes ().value (QLatin1String (" Algorithm" )).toString ();
116+ if (xml.name () == QLatin1String (" EncryptionMethod" ))
117+ {
118+ auto method = xml.attributes ().value (QLatin1String (" Algorithm" ));
119+ key.unsupported = std::max (key.unsupported , method != KWAES256_MTH && method != RSA_MTH);
120+ }
126121 // EncryptedData/KeyInfo/EncryptedKey/KeyInfo/AgreementMethod
127122 else if (xml.name () == QLatin1String (" AgreementMethod" ))
128- key.agreement = xml.attributes ().value (QLatin1String (" Algorithm" )). toString ( );
123+ key.unsupported = std::max (key. unsupported , xml.attributes ().value (QLatin1String (" Algorithm" )) != AGREEMENT_MTH );
129124 // EncryptedData/KeyInfo/EncryptedKey/KeyInfo/AgreementMethod/KeyDerivationMethod
130125 else if (xml.name () == QLatin1String (" KeyDerivationMethod" ))
131- key.derive = xml.attributes ().value (QLatin1String (" Algorithm" )). toString ( );
126+ key.unsupported = std::max (key. unsupported , xml.attributes ().value (QLatin1String (" Algorithm" )) != CONCATKDF_MTH );
132127 // EncryptedData/KeyInfo/EncryptedKey/KeyInfo/AgreementMethod/KeyDerivationMethod/ConcatKDFParams
133128 else if (xml.name () == QLatin1String (" ConcatKDFParams" ))
134129 {
@@ -273,16 +268,13 @@ CKey CDoc1::canDecrypt(const QSslCertificate &cert) const
273268 {
274269 if (!ENC_MTH.contains (method) ||
275270 k.cert != cert ||
276- k.cipher .isEmpty ())
271+ k.cipher .isEmpty () ||
272+ k.unsupported )
277273 continue ;
278- if (cert.publicKey ().algorithm () == QSsl::Rsa &&
279- k.method == RSA_MTH)
274+ if (cert.publicKey ().algorithm () == QSsl::Rsa)
280275 return k;
281276 if (cert.publicKey ().algorithm () == QSsl::Ec &&
282- !k.publicKey .isEmpty () &&
283- KWAES_SIZE.contains (k.method ) &&
284- k.derive == CONCATKDF_MTH &&
285- k.agreement == AGREEMENT_MTH)
277+ !k.publicKey .isEmpty ())
286278 return k;
287279 }
288280 return {};
@@ -432,8 +424,6 @@ bool CDoc1::save(const QString &path)
432424 for (const CKey &k: qAsConst (keys))
433425 {
434426 writeElement (w, DENC, QStringLiteral (" EncryptedKey" ), [&]{
435- if (!k.id .isEmpty ())
436- w.writeAttribute (QStringLiteral (" Id" ), k.id );
437427 if (!k.recipient .isEmpty ())
438428 w.writeAttribute (QStringLiteral (" Recipient" ), k.recipient );
439429 QByteArray cipher;
@@ -446,8 +436,6 @@ bool CDoc1::save(const QString &path)
446436 {QStringLiteral (" Algorithm" ), RSA_MTH},
447437 });
448438 writeElement (w, DS, QStringLiteral (" KeyInfo" ), [&]{
449- if (!k.name .isEmpty ())
450- w.writeTextElement (DS, QStringLiteral (" KeyName" ), k.name );
451439 writeElement (w, DS, QStringLiteral (" X509Data" ), [&]{
452440 writeBase64Element (w, DS, QStringLiteral (" X509Certificate" ), k.cert .toDer ());
453441 });
@@ -464,14 +452,13 @@ bool CDoc1::save(const QString &path)
464452 QByteArray oid = Crypto::curve_oid (peerPKey);
465453 QByteArray SsDer = Crypto::toPublicKeyDer (priv.get ());
466454
467- const QString encryptionMethod = KWAES256_MTH;
468455 QString concatDigest = SHA384_MTH;
469456 switch ((SsDer.size () - 1 ) / 2 ) {
470457 case 32 : concatDigest = SHA256_MTH; break ;
471458 case 48 : concatDigest = SHA384_MTH; break ;
472459 default : concatDigest = SHA512_MTH; break ;
473460 }
474- QByteArray encryptionKey = Crypto::concatKDF (SHA_MTH[concatDigest], KWAES_SIZE[encryptionMethod],
461+ QByteArray encryptionKey = Crypto::concatKDF (SHA_MTH[concatDigest],
475462 sharedSecret, props.value (QStringLiteral (" DocumentFormat" )).toUtf8 () + SsDer + k.cert .toDer ());
476463#ifndef NDEBUG
477464 qDebug () << " ENC Ss" << SsDer.toHex ();
@@ -484,7 +471,7 @@ bool CDoc1::save(const QString &path)
484471 return ;
485472
486473 writeElement (w, DENC, QStringLiteral (" EncryptionMethod" ), {
487- {QStringLiteral (" Algorithm" ), encryptionMethod },
474+ {QStringLiteral (" Algorithm" ), KWAES256_MTH },
488475 });
489476 writeElement (w, DS, QStringLiteral (" KeyInfo" ), [&]{
490477 writeElement (w, DENC, QStringLiteral (" AgreementMethod" ), {
@@ -553,7 +540,7 @@ QByteArray CDoc1::transportKey(const CKey &key)
553540 if (key.isRSA )
554541 return backend->decrypt (key.cipher , false );
555542 return backend->deriveConcatKDF (key.publicKey , SHA_MTH[key.concatDigest ],
556- int (KWAES_SIZE[key. method ]), key.AlgorithmID , key.PartyUInfo , key.PartyVInfo );
543+ key.AlgorithmID , key.PartyUInfo , key.PartyVInfo );
557544 });
558545 if (decryptedKey.isEmpty ())
559546 {
0 commit comments