Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ xmlSecAppCmdLineParamsListParse(xmlSecAppCmdLineParamPtr* params,

/* check that all parameters at the end are filenames */
for(ii = pos; (ii < argc); ++ii) {
if((argv[ii][0] == '-') && (strcmp(argv[pos], XMLSEC_STDOUT_FILENAME) != 0)) {
if((argv[ii][0] == '-') && (strcmp(argv[ii], XMLSEC_STDOUT_FILENAME) != 0)) {
fprintf(stderr, "Error: filename is expected instead of parameter \"%s\".\n", argv[ii]);
return(-1);
}
Expand Down
26 changes: 16 additions & 10 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ dnl seamonkey-nspr and seamonkey-nss
dnl mozilla-nspr and mozilla-nss
dnl xulrunner-nspr and xulrunner-nss
dnl nspr and nss
if test "z$NSPR_FOUND" = "zno" -a "z$PKGCONFIG_FOUND" = "zyes" -a "z$with_mozilla_ver" = "z" -a "z$with_seamonkey_ver" ; then
if test "z$NSPR_FOUND" = "zno" -a "z$PKGCONFIG_FOUND" = "zyes" -a "z$with_mozilla_ver" = "z" ; then
if test "z$NSPR_FOUND" = "zno" ; then
PKG_CHECK_MODULES(NSPR, seamonkey-nspr >= $NSPR_MIN_VERSION,
[NSPR_FOUND=yes NSPR_PACKAGE=seamonkey-nspr],
Expand All @@ -1046,7 +1046,7 @@ if test "z$NSPR_FOUND" = "zno" -a "z$PKGCONFIG_FOUND" = "zyes" -a "z$with_mozill
[NSPR_FOUND=no])
fi
fi
if test "z$NSS_FOUND" = "zno" -a "z$PKGCONFIG_FOUND" = "zyes" -a "z$with_mozilla_ver" = "z" -a "z$with_seamonkey_ver" ; then
if test "z$NSS_FOUND" = "zno" -a "z$PKGCONFIG_FOUND" = "zyes" -a "z$with_mozilla_ver" = "z" ; then
if test "z$NSS_FOUND" = "zno" ; then
PKG_CHECK_MODULES(NSS, seamonkey-nss >= $SEAMONKEY_MIN_VERSION,
[NSS_FOUND=yes NSS_PACKAGE=seamonkey-nss],
Expand Down Expand Up @@ -1263,6 +1263,7 @@ GCRYPT_INCLUDE_MARKER="gcrypt.h"
GCRYPT_LIB_MARKER="libgcrypt$shrext"
GCRYPT_CRYPTO_LIB="$XMLSEC_PACKAGE-gcrypt"
GCRYPT_LIBS_LIST="-lgcrypt"
GCRYPT_PACKAGE=libgcrypt

XMLSEC_NO_GCRYPT="1"
GCRYPT_VERSION=
Expand Down Expand Up @@ -1302,22 +1303,22 @@ dnl Priority 3: Guess with pkg_config
if test "z$GCRYPT_FOUND" = "zno" -a "z$PKGCONFIG_FOUND" = "zyes" ; then
if test "z$GCRYPT_FOUND" = "zno" ; then
PKG_CHECK_MODULES(GCRYPT, gcrypt >= $GCRYPT_MIN_VERSION,
[GCRYPT_FOUND=yes],
[GCRYPT_FOUND=yes GCRYPT_PACKAGE=gcrypt],
[GCRYPT_FOUND=no])
fi
if test "z$GCRYPT_FOUND" = "zno" ; then
PKG_CHECK_MODULES(GCRYPT, libgcrypt20 >= $GCRYPT_MIN_VERSION,
[GCRYPT_FOUND=yes],
[GCRYPT_FOUND=yes GCRYPT_PACKAGE=libgcrypt20],
[GCRYPT_FOUND=no])
fi
if test "z$GCRYPT_FOUND" = "zno" ; then
PKG_CHECK_MODULES(GCRYPT, libgcrypt11 >= $GCRYPT_MIN_VERSION,
[GCRYPT_FOUND=yes],
[GCRYPT_FOUND=yes GCRYPT_PACKAGE=libgcrypt11],
[GCRYPT_FOUND=no])
fi
if test "z$GCRYPT_FOUND" = "zno" ; then
PKG_CHECK_MODULES(GCRYPT, libgcrypt >= $GCRYPT_MIN_VERSION,
[GCRYPT_FOUND=yes],
[GCRYPT_FOUND=yes GCRYPT_PACKAGE=libgcrypt],
[GCRYPT_FOUND=no])
fi
fi
Expand Down Expand Up @@ -1434,6 +1435,7 @@ AC_SUBST(GCRYPT_CFLAGS)
AC_SUBST(GCRYPT_LIBS)
AC_SUBST(GCRYPT_CRYPTO_LIB)
AC_SUBST(GCRYPT_MIN_VERSION)
AC_SUBST(GCRYPT_PACKAGE)

dnl ==========================================================================
dnl See if we can find GnuTLS
Expand All @@ -1445,6 +1447,7 @@ GNUTLS_INCLUDE_MARKER="gnutls/gnutls.h"
GNUTLS_LIB_MARKER="libgnutls$shrext"
GNUTLS_CRYPTO_LIB="$XMLSEC_PACKAGE-gnutls"
GNUTLS_LIBS_LIST="-lgnutls"
GNUTLS_PACKAGE=gnutls

XMLSEC_NO_GNUTLS="1"
GNUTLS_INCLUDE_PATH=
Expand Down Expand Up @@ -1479,12 +1482,12 @@ dnl Priority 3: Guess with pkg_config
if test "z$GNUTLS_FOUND" = "zno" -a "z$PKGCONFIG_FOUND" = "zyes" ; then
if test "z$GNUTLS_FOUND" = "zno" ; then
PKG_CHECK_MODULES(GNUTLS, gnutls >= $GNUTLS_MIN_VERSION,
[GNUTLS_FOUND=yes],
[GNUTLS_FOUND=yes GNUTLS_PACKAGE=gnutls],
[GNUTLS_FOUND=no])
fi
if test "z$GNUTLS_FOUND" = "zno" ; then
PKG_CHECK_MODULES(GNUTLS, libgnutls >= $GNUTLS_MIN_VERSION,
[GNUTLS_FOUND=yes],
[GNUTLS_FOUND=yes GNUTLS_PACKAGE=libgnutls],
[GNUTLS_FOUND=no])
fi
fi
Expand Down Expand Up @@ -1587,6 +1590,7 @@ AC_SUBST(GNUTLS_CFLAGS)
AC_SUBST(GNUTLS_LIBS)
AC_SUBST(GNUTLS_CRYPTO_LIB)
AC_SUBST(GNUTLS_MIN_VERSION)
AC_SUBST(GNUTLS_PACKAGE)


dnl ==========================================================================
Expand Down Expand Up @@ -2396,8 +2400,10 @@ dnl ==========================================================================
dnl See do we need templates tests
dnl ==========================================================================
AC_MSG_CHECKING(for templates testing)
AC_ARG_ENABLE([tmpl_tests], [AS_HELP_STRING([--enable-tmpl-tests],[enable templates testing in xmlsec utility (yes)])])
if test "z$enable_tmpl_tests" = "zyes" ; then
AC_ARG_ENABLE([tmpl_tests], [AS_HELP_STRING([--enable-tmpl-tests],[enable templates testing in xmlsec utility (yes)]),
[enable_tmpl_tests=$enableval],
[enable_tmpl_tests=yes]])
if test "z$enable_tmpl_tests" = "zno" ; then
XMLSEC_DEFINES="$XMLSEC_DEFINES -DXMLSEC_NO_TMPL_TEST=1"
AC_MSG_RESULT([disabled])
else
Expand Down
122 changes: 102 additions & 20 deletions src/gnutls/x509vfy.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,49 @@ xmlSecGnuTLSX509CheckTime(const gnutls_x509_crt_t * cert_list,
return(1);
}

/* For custom verification time, check only trusted certs that could act as
* issuer for @p cert. This avoids rejecting valid chains because of unrelated
* expired certs in the trust store. */
static int
xmlSecGnuTLSX509StoreCheckTrustedAnchorTime(xmlSecGnuTLSX509StoreCtxPtr ctx,
gnutls_x509_crt_t cert,
time_t verification_time) {
xmlSecSize ca_list_size, ii;

xmlSecAssert2(ctx != NULL, -1);
xmlSecAssert2(cert != NULL, -1);

ca_list_size = xmlSecPtrListGetSize(&(ctx->certsTrusted));
for(ii = 0; ii < ca_list_size; ++ii) {
gnutls_x509_crt_t trusted_cert;
unsigned int is_issuer;
int ret;

trusted_cert = xmlSecPtrListGetItem(&(ctx->certsTrusted), ii);
if(trusted_cert == NULL) {
xmlSecInternalError("xmlSecPtrListGetItem(certsTrusted)", NULL);
return(-1);
}

is_issuer = gnutls_x509_crt_check_issuer(cert, trusted_cert);
if(is_issuer == 0) {
continue;
}

ret = xmlSecGnuTLSX509CheckTime(&trusted_cert, 1, verification_time);
if(ret < 0) {
xmlSecInternalError("xmlSecGnuTLSX509CheckTime(trusted_cert)", NULL);
return(-1);
} else if(ret == 1) {
/* found a matching trusted cert that is valid at the requested time */
return(1);
}
}

/* no valid matching trusted cert found at the requested verification time */
return(0);
}

static int
xmlSecGnuTLSX509GetVerificationFlags(const xmlSecKeyInfoCtx* keyInfoCtx,
unsigned int* flags) {
Expand All @@ -258,8 +301,13 @@ xmlSecGnuTLSX509GetVerificationFlags(const xmlSecKeyInfoCtx* keyInfoCtx,
(*flags) = 0;

/* gnutls doesn't allow to specify "verification" timestamp so
we have to do it ourselves */
(*flags) |= GNUTLS_VERIFY_DISABLE_TIME_CHECKS;
we have to do it ourselves; disable the gnutls time checks only
in this case, otherwise gnutls checks the validity periods of
all certificates (including the trusted ones) against the
current time */
if(keyInfoCtx->certsVerificationTime > 0) {
(*flags) |= GNUTLS_VERIFY_DISABLE_TIME_CHECKS;
}

if((keyInfoCtx->flags & XMLSEC_KEYINFO_FLAGS_X509DATA_SKIP_STRICT_CHECKS) != 0) {
(*flags) |= GNUTLS_VERIFY_ALLOW_SIGN_RSA_MD2;
Expand Down Expand Up @@ -471,12 +519,32 @@ xmlSecGnuTLSX509StoreVerify(xmlSecKeyDataStorePtr store,
}

/* gnutls doesn't allow to specify "verification" timestamp so
we have to do it ourselves */
ret = xmlSecGnuTLSX509CheckTime(cert_list, cert_list_cur_size, verification_time);
if(ret != 1) {
xmlSecInternalError("xmlSecGnuTLSX509CheckTime", NULL);
/* ignore error, don't stop, continue! */
continue;
we have to do it ourselves (gnutls only checks the time against
the current time, which is not the custom verification time) */
if(keyInfoCtx->certsVerificationTime > 0) {
ret = xmlSecGnuTLSX509CheckTime(cert_list, cert_list_cur_size, verification_time);
if(ret < 0) {
xmlSecInternalError("xmlSecGnuTLSX509CheckTime", NULL);
/* ignore error, don't stop, continue! */
continue;
} else if(ret != 1) {
/* cert in the candidate chain is not valid at verification time */
continue;
}

/* GNUTLS_VERIFY_DISABLE_TIME_CHECKS disables time checks for trusted
certs too, so check only the trust anchor candidates for this
chain instead of all trusted certs in the store. */
ret = xmlSecGnuTLSX509StoreCheckTrustedAnchorTime(ctx,
cert_list[cert_list_cur_size - 1], verification_time);
if(ret < 0) {
xmlSecInternalError("xmlSecGnuTLSX509StoreCheckTrustedAnchorTime", NULL);
/* ignore error, don't stop, continue! */
continue;
} else if(ret != 1) {
/* trusted cert candidate not valid at the verification time */
continue;
}
}

/* DONE! */
Expand Down Expand Up @@ -598,18 +666,32 @@ xmlSecGnuTLSX509StoreVerifyIssuerCert(xmlSecGnuTLSX509StoreCtxPtr ctx,
}

/* gnutls doesn't allow to specify "verification" timestamp so
we have to do it ourselves */
verification_time = (keyInfoCtx->certsVerificationTime > 0) ?
keyInfoCtx->certsVerificationTime :
time(0);
ret = xmlSecGnuTLSX509CheckTime(chain, chain_cur_size, verification_time);
if(ret < 0) {
xmlSecInternalError("xmlSecGnuTLSX509CheckTime", NULL);
goto done;
} else if(ret != 1) {
/* issuer cert not valid at the verification time */
res = 0;
goto done;
we have to do it ourselves; GNUTLS_VERIFY_DISABLE_TIME_CHECKS makes
gnutls skip the time checks for the trusted certs as well, so they
have to be checked here too */
if(keyInfoCtx->certsVerificationTime > 0) {
verification_time = keyInfoCtx->certsVerificationTime;

ret = xmlSecGnuTLSX509CheckTime(chain, chain_cur_size, verification_time);
if(ret < 0) {
xmlSecInternalError("xmlSecGnuTLSX509CheckTime", NULL);
goto done;
} else if(ret != 1) {
/* issuer cert not valid at the verification time */
res = 0;
goto done;
}

ret = xmlSecGnuTLSX509StoreCheckTrustedAnchorTime(ctx,
chain[chain_cur_size - 1], verification_time);
if(ret < 0) {
xmlSecInternalError("xmlSecGnuTLSX509StoreCheckTrustedAnchorTime", NULL);
goto done;
} else if(ret != 1) {
/* trusted cert candidate not valid at the verification time */
res = 0;
goto done;
}
}

/* done! */
Expand Down
4 changes: 4 additions & 0 deletions src/keyinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,10 @@ xmlSecKeyDataEncryptedKeyXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNodeP
}
xmlSecAssert2(keyInfoCtx->encCtx != NULL, -1);

/* setup current recursion levels for the write context */
keyInfoCtx->encCtx->keyInfoWriteCtx.curRetrievalMethodLevel = keyInfoCtx->curRetrievalMethodLevel;
keyInfoCtx->encCtx->keyInfoWriteCtx.curEncryptedKeyLevel = keyInfoCtx->curEncryptedKeyLevel + 1;

/* encrypt */
ret = xmlSecEncCtxBinaryEncrypt(keyInfoCtx->encCtx, node, keyBuf, keySize);
if(ret < 0) {
Expand Down
30 changes: 27 additions & 3 deletions src/kw_aes_des.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "globals.h"

#include <stdint.h>
#include <stdlib.h>
#include <string.h>

Expand Down Expand Up @@ -763,6 +764,21 @@ static const xmlSecByte xmlSecKWAesMagicBlock[XMLSEC_KW_AES_MAGIC_BLOCK_SIZE] =
0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6
};

/* XORs the full 64-bit counter @p counter into the 8-byte A register @p block
* (big-endian), as required by RFC 3394. Only the low byte is not enough: for
* N >= 43 the counter t exceeds 255 and the high bytes must be mixed in too. */
static void
xmlSecKWAesXorCounter(xmlSecByte* block, uint64_t counter) {
xmlSecSize ii;

xmlSecAssert(block != NULL);

for(ii = 0; ii < XMLSEC_KW_AES_MAGIC_BLOCK_SIZE; ++ii) {
/* the shift (up to 56) is well-defined */
block[ii] ^= (xmlSecByte)(counter >> (8 * (XMLSEC_KW_AES_MAGIC_BLOCK_SIZE - 1 - ii)));
}
}

int
xmlSecKWAesEncode(xmlSecKWAesId kwAesId, xmlSecTransformPtr transform,
const xmlSecByte *in, xmlSecSize inSize,
Expand Down Expand Up @@ -818,7 +834,7 @@ xmlSecKWAesEncode(xmlSecKWAesId kwAesId, xmlSecTransformPtr transform,
"outWritten2=" XMLSEC_SIZE_FMT, outWritten2);
return(-1);
}
block[7] ^= (xmlSecByte)tt;
xmlSecKWAesXorCounter(block, tt);
memcpy(out, block, 8);
memcpy(p, block + 8, 8);
}
Expand All @@ -844,11 +860,19 @@ xmlSecKWAesDecode(xmlSecKWAesId kwAesId, xmlSecTransformPtr transform,
xmlSecAssert2(kwAesId->decrypt != NULL, -1);
xmlSecAssert2(transform != NULL, -1);
xmlSecAssert2(in != NULL, -1);
xmlSecAssert2(inSize >= XMLSEC_KW_AES_MAGIC_BLOCK_SIZE, -1);
xmlSecAssert2(out != NULL, -1);
xmlSecAssert2(outSize >= inSize, -1);
xmlSecAssert2(outWritten != NULL, -1);

/* a valid wrapped key is at least the magic block plus one data block;
* reject a bare magic block (NN == 0) which would otherwise "unwrap" to a
* zero-length key without any decryption or integrity check */
if(inSize < 2 * XMLSEC_KW_AES_MAGIC_BLOCK_SIZE) {
xmlSecInvalidSizeLessThanError("Input data", inSize,
2 * XMLSEC_KW_AES_MAGIC_BLOCK_SIZE, NULL);
return(-1);
}

/* copy input */
if(in != out) {
memcpy(out, in, inSize);
Expand All @@ -872,7 +896,7 @@ xmlSecKWAesDecode(xmlSecKWAesId kwAesId, xmlSecTransformPtr transform,

memcpy(block, out, 8);
memcpy(block + 8, p, 8);
block[7] ^= (xmlSecByte)tt;
xmlSecKWAesXorCounter(block, tt);

outWritten2 = 0;
ret = kwAesId->decrypt(transform, block, sizeof(block),
Expand Down
5 changes: 2 additions & 3 deletions src/nss/ciphers.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,15 @@ xmlSecNssBlockCipherCtxInit(xmlSecNssBlockCipherCtxPtr ctx,
}

symKey = PK11_ImportSymKey(slot, ctx->cipher, PK11_OriginDerive,
CKA_ENCRYPT, &keyItem, NULL);
(encrypt) ? CKA_ENCRYPT : CKA_DECRYPT, &keyItem, NULL);
if(symKey == NULL) {
xmlSecNssError("PK11_ImportSymKey", cipherName);
PK11_FreeSlot(slot);
return(-1);
}

ctx->cipherCtx = PK11_CreateContextBySymKey(ctx->cipher,
(encrypt) ? CKA_ENCRYPT : CKA_DECRYPT,
symKey, &ivItem);
(encrypt) ? CKA_ENCRYPT : CKA_DECRYPT, symKey, &ivItem);
if(ctx->cipherCtx == NULL) {
xmlSecNssError("PK11_CreateContextBySymKey", cipherName);
PK11_FreeSymKey(symKey);
Expand Down
6 changes: 5 additions & 1 deletion src/nss/keytrans.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,11 @@ xmlSecNssKeyTransportCtxFinal(xmlSecNssKeyTransportCtxPtr ctx, xmlSecBufferPtr i
SECItem* keyItem;

/* pay attention to mechanism */
symKey = PK11_PubUnwrapSymKey(ctx->prikey, &oriskv, ctx->cipher, CKA_UNWRAP, 0);
/* target is the mechanism of the unwrapped symmetric key, which is
* unknown here (passing ctx->cipher, e.g. CKM_RSA_PKCS, would make
* NSS mark the unwrapped session key as CKK_RSA), so pass
* CKM_GENERIC_SECRET_KEY_GEN */
symKey = PK11_PubUnwrapSymKey(ctx->prikey, &oriskv, CKM_GENERIC_SECRET_KEY_GEN, CKA_UNWRAP, 0);
if(symKey == NULL) {
xmlSecNssError("PK11_PubUnwrapSymKey", NULL);
xmlSecBufferDestroy(result);
Expand Down
Loading
Loading