Skip to content

Commit ba9ef6e

Browse files
authored
(xmlsec-core) Added max key length limit for PBKDF2 and updated comments (#1391)
1 parent f72ba71 commit ba9ef6e

5 files changed

Lines changed: 29 additions & 15 deletions

File tree

‎scripts/build_coverity.sh‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,17 @@ srcdir=$(cd "$script_pwd/.." && pwd)
1818
today=`date +%F-%H-%M-%S`
1919
tar_file="xmlsec1-$version-$today.tar.gz"
2020

21-
# Restore the caller's working directory on any exit (including 'set -e'
22-
# failures), since the script builds in the source tree.
23-
trap 'cd "$cur_pwd"' EXIT
24-
25-
echo "============== Building xmlsec"
26-
cd "$srcdir"
21+
echo "============== Building xmlsec: $PWD =============="
2722
# Regenerate the build system so that configure always matches the current
2823
# configure.ac, even if a stale configure was left over from a previous run.
29-
autoreconf -i -f
30-
./configure --enable-legacy-features --enable-ftp --enable-http --with-gcrypt
24+
autoreconf -i -f "$srcdir"
25+
"$srcdir/configure" --enable-legacy-features --enable-ftp --enable-http --with-gcrypt
3126
make clean
3227
rm -rf cov-int/
3328
cov-build --dir cov-int make -j4
3429
tar czvf "$tar_file" cov-int
3530

36-
echo "============== Uploading to Coverity"
31+
echo "============== Uploading to Coverity =============="
3732
curl \
3833
--form token="$cov_token" \
3934
--form email="$cov_email" \

‎src/gcrypt/ciphers.c‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,13 +307,14 @@ xmlSecGCryptBlockCipherCtxFinal(xmlSecGCryptBlockCipherCtxPtr ctx,
307307
if(encrypt == 0) {
308308
xmlSecSize padding;
309309

310-
/* check padding.
310+
/* Check padding:
311311
*
312-
* Only the padding length carried in the last byte is validated (it must be
313-
* non-zero and not exceed the block size); the remaining padding bytes are not
314-
* checked for equality and the check is not constant-time. This simplified
315-
* validation is a deliberate project-wide design choice, matching the OpenSSL
316-
* backend. See XML Encryption specification for details. */
312+
* XML Encryption (W3C) uses PKCS#5-style padding: a full block is appended
313+
* whose last octet holds the padding length, while the remaining padding octets
314+
* are filled with random bytes (see the encrypt branch above). This is NOT strict
315+
* PKCS#7 (where every padding octet equals the length), so the other octets are
316+
* deliberately not validated for equality See the XML Encryption specification
317+
* for details. */
317318
padding = (xmlSecSize)outBuf[blockLen - 1];
318319
if((padding == 0) || (inSize < padding)) {
319320
xmlSecInvalidSizeLessThanError("Input data padding",

‎src/gnutls/signatures.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,9 @@ xmlSecGnuTLSSignatureInitialize(xmlSecTransformPtr transform) {
382382
ctx->keyId = xmlSecGnuTLSKeyDataGost2001Id;
383383
ctx->dgstAlgo = GNUTLS_DIG_GOSTR_94;
384384
ctx->signAlgo = GNUTLS_SIGN_GOST_94;
385+
/* GOST R 34.10-94 (GOST_01) is a legacy algorithm that GnuTLS classifies as
386+
* "insufficient security" under the default security profile. Without the
387+
* GNUTLS_VERIFY_ALLOW_BROKEN flag, the signature verification would fail. */
385388
ctx->verifyFlags = GNUTLS_VERIFY_ALLOW_BROKEN;
386389
ctx->getPubKey = xmlSecGnuTLSKeyDataGost2001GetPublicKey;
387390
ctx->getPrivKey = xmlSecGnuTLSKeyDataGost2001GetPrivateKey;

‎src/transform_helpers.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,6 +1431,10 @@ xmlSecTransformPbkdf2ParamsRead(xmlSecTransformPbkdf2ParamsPtr params, xmlNodePt
14311431
xmlSecInternalError("xmlSecGetNodeContentAsSize(keyLength)", NULL);
14321432
return(-1);
14331433
}
1434+
if(params->keyLength > XMLSEC_PBKDF2_MAX_KEY_LENGTH) {
1435+
xmlSecInvalidSizeDataError("keyLength", params->keyLength, "too big", NULL);
1436+
return(-1);
1437+
}
14341438

14351439
/* next is required PRF */
14361440
cur = xmlSecGetNextElementNode(cur->next);

‎src/transform_helpers.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,17 @@ XMLSEC_EXPORT int xmlSecTransformEdDSAReadContextString(xmlNodePtr node,
204204
#define XMLSEC_PBKDF2_MAX_ITERATIONS ((xmlSecSize)1000000)
205205
#endif /* !defined(XMLSEC_PBKDF2_MAX_ITERATIONS) */
206206

207+
/*
208+
* The maximum derived key length (in bytes) accepted by
209+
* xmlSecTransformPbkdf2ParamsRead(). Key lengths above this
210+
* limit are rejected to protect against oversized derived-key
211+
* buffer allocations (denial of service) when processing
212+
* untrusted documents.
213+
*/
214+
#if !defined(XMLSEC_PBKDF2_MAX_KEY_LENGTH)
215+
#define XMLSEC_PBKDF2_MAX_KEY_LENGTH ((xmlSecSize)4096)
216+
#endif /* !defined(XMLSEC_PBKDF2_MAX_KEY_LENGTH) */
217+
207218
struct _xmlSecTransformPbkdf2Params {
208219
xmlSecBuffer salt;
209220
xmlSecSize iterationCount;

0 commit comments

Comments
 (0)