Commit Graph

3397 Commits

Author SHA1 Message Date
Benjamin Dauvergne 16148102e5 In lasso_saml20_login_process_response_status_and_assertion does not overwirte signature_status with rc which is always at 0 (#54689)
We are losing information in this case, like if the response was not
signed.
2022-11-23 09:40:28 +01:00
Jakub Hrozek 2d78634827 In lasso_saml20_login_process_response_status_and_assertion remove dead switch (#54689)
In case VERIFY_HINT was set to IGNORE and the login signature was
incorrect, lasso_saml20_login_process_response_status_and_assertion
would have jumped straight to the cleanup label which just returns the
return code.

Related: https://dev.entrouvert.org/issues/54689
License: MIT
2022-11-23 09:40:28 +01:00
Benjamin Dauvergne d10c0f6693 Fix unused parameters warnings (#71400) 2022-11-21 13:28:10 +01:00
Benjamin Dauvergne 72b778e47e Fix all cast-function-type warnings (#71400) 2022-11-21 13:28:08 +01:00
Benjamin Dauvergne 69b1ea1c2f Fix warning about enum conversion (#71400) 2022-11-21 13:28:06 +01:00
Benjamin Dauvergne 0c4d3014a4 Fix use of wrong enumeration NULL value (#71400)
It produced a cast warning.
2022-11-21 13:27:53 +01:00
Benjamin Dauvergne 6389b2ca48 Fix warnings about type casts (#71400) 2022-11-21 13:27:47 +01:00
Benjamin Dauvergne 8a588a8acb Replace all use of xmlSecBase64Decode by lasso_base64_decode (#71399) 2022-11-21 13:27:15 +01:00
Benjamin Dauvergne 1aa6271f93 Adapt lasso_base64_decode to the deprecation of xmlSecBase64Decode (#71399)
We now use the non-deprecated new API (since xmlsec 1.2.35) xmlSecBase64Decode_ex.
2022-11-21 13:27:15 +01:00
Benjamin Dauvergne 228ac9470f Make lasso_inflate output the inflated buffer size (#71399) 2022-11-21 13:27:12 +01:00
Benjamin Dauvergne 66ebd11166 Use OpenSSL EVP API to work around deprecation of low level APIs in OpenSSL 3 (#71313)
OpenSSL API is used to sign query-string values in the SAML 2.0 Redirect binding.
Other binding only need the libxmlsec API as signature are XML DSIG signatures.
2022-11-21 13:22:04 +01:00
Benjamin Dauvergne 3a7ad3610f Fix parsing of Count attribute of saml:ProxyRestriction (#69673) 2022-09-28 18:18:36 +02:00
Benjamin Dauvergne d80357e226 Keep ABI stability (#56883)
The following functions where part of the experimental ID-WSF support
recently removed but where incorrectly included in the official ABI, so we
restore dummy versions of them (they do nothing or return NULL):
- lasso_get_prefix_for_dst_service_href
- lasso_get_prefix_for_idwsf2_dst_service_href
- lasso_register_dst_service
- lasso_register_idwsf2_dst_service
2021-09-13 12:13:11 +02:00
Benjamin Dauvergne 53b0bd3569 Change default key encryption padding algorithm to RSA-OAEP (#56023)
The key encryption padding algorithm is now configurable, the default
being changed to OAEP. It's possible to set the default through
./configure with:

    --with-default-key-encryption-method=[rsa-pkcs1|rsa-oaep]

at initialization time with an environment variable:

    LASSO_DEFAULT_KEY_ENCRYPTION_METHOD=[rsa-pkcs1|rsa-oaep]

or at runtime for a service provider:

    lasso_provider_set_key_encryption_method(LassoProvider *provider,
        LassoKeyEncryptionMethod key_encryption_method)

The setting is global for all encrypted nodes (Assertion or NameID).
2021-09-11 19:20:04 +02:00
Benjamin Dauvergne 4a880977d1 Remove ID-WSF 1.0, 2.0 and WS-* support (#56644)
It has been deprecated for a long time.
2021-09-11 18:54:41 +02:00
Benjamin Dauvergne d4ccf15902 Fix warning about int conversion
saml2_authn_context.c:77:3: warning: initialization of ‘unsigned int’ from ‘void *’
    makes integer from pointer without a cast [-Wint-conversion]
2021-09-03 10:14:24 +02:00
Benjamin Dauvergne 663c094ec7 Prevent multiple OneTimeUse elements (#52961)
"A SAML authority MUST NOT include more than one <OneTimeUse> element within a
<Conditions>element of an assertion"
2021-07-16 14:36:32 +02:00
Jakub Hrozek f9a3aca0cb Check if the signature method is allowed in addition to being valid (#54037)
Adds a new utility function lasso_allowed_signature_method() that checks
if the signature method is allowed. Previously, the code would only
check if the method was valid.

This new function is used whenever lasso_validate_signature_method was
previously used through lasso_ok_signature_method() which wraps both
validate and allowed.

lasso_allowed_signature_method() is also used on a couple of places,
notably lasso_query_verify_helper().

Related:
https://dev.entrouvert.org/issues/54037
2021-06-24 02:15:17 +02:00
Jakub Hrozek 0d34c97be1 Mass-replace LASSO_SIGNATURE_METHOD_RSA_SHA1 with lasso_get_default_signature_method() (#54037)
This should be backwards-compatible but at the same time use the
selected default instead of RSA-SHA1.

Related:
https://dev.entrouvert.org/issues/54037
2021-06-23 23:32:33 +02:00
Jakub Hrozek f095ac8f57 Make the default signature method and the minimal hash strength configurable (#54037)
Adds two new configure options:
    --with-default-sign-algo
    --min-hash-algo

--with-default-sign-algo sets the default signing algorithm and defaults
to rsa-sha1. At the moment, two algorithms are supported: rsa-sha1 and
rsa-sha256.

--min-hash-algo sets the minimum hash algorithm to be accepted. The
default is sha1 for backwards compatibility as well.

Related:
https://dev.entrouvert.org/issues/54037
2021-06-23 23:32:29 +02:00
Jakub Hrozek 8b8fd22a16 Fix lasso_query_sign HMAC other than SHA1 (#54037)
The switch clause was using SHA1 digests for all digest types when
signing. This obviously breaks verifying the signatures if HMAC-SHAXXX
is used and XXX is something else than 1.
2021-06-23 23:32:12 +02:00
Benjamin Dauvergne ea7e5efe97 Fix signature checking on unsigned response with multiple assertions
CVE-2021-28091 : when AuthnResponse messages are not signed (which is
permitted by the specifiation), all assertion's signatures should be
checked, but currently after the first signed assertion is checked all
following assertions are accepted without checking their signature, and
the last one is considered the main assertion.

This patch :
* check signatures from all assertions if the message is not signed,
* refuse messages with assertion from different issuers than the one on
  the message, to prevent assertion bundling event if they are signed.
2021-06-01 11:50:53 +02:00
Benjamin Dauvergne f912e8d1ef replace deprecated index() by strchr() (#51385) 2021-02-26 16:31:53 +01:00
Benjamin Dauvergne cbbea83e3f Fix: new provider reference count is incremented one time too many (#51420) 2021-02-25 10:10:03 +01:00
Benjamin Dauvergne 0b742b1f6d tools: reimplement xmlURIEscapeStr to respect RFC3986 (#45581)
Bugfix by Emmanuel Dreyfus.

License: MIT
2020-08-14 10:58:06 +02:00
Benjamin Dauvergne 4bae1c8b7c Release 2.6.1 2020-04-22 15:04:46 +02:00
Benjamin Dauvergne 92d12b9954 Keep order of SessionIndexes 2020-04-22 04:45:52 +02:00
Benjamin Dauvergne 55feba5762 Clear SessionIndex when private SessionIndexes is empty (#41950) 2020-04-22 04:30:27 +02:00
Benjamin Dauvergne e5ad4b1702 misc: clear warnings about class_init signature using coccinelle
$ spatch --in-place --sp-file add-second-arg-to-class-init.cocci `git grep -l -C1 ^class_init \*.c`
	$ sed -i 's/\*unused\>/*unused G_GNUC_UNUSED/' `git grep -l 'void \*unused'`
2020-03-26 22:52:49 +01:00
Bernhard M. Wiedemann 1b51873ccf Sort input file lists (#40454)
so that lasso.py, lasso/types.c and liblasso.so.3.13.0
build reproducibly
in spite of indeterministic filesystem readdir order.
For some reason, lasso/extract_sections.py lasso/extract_symbols.py
do not need such patches to get a reproducible openSUSE package.

See https://reproducible-builds.org/ for why this is good.

This patch was done while working on reproducible builds for openSUSE.

License: MIT
Signed-off-by: Bernhard M. Wiedemann <bwiedemann@suse.de>
2020-03-05 12:51:17 +01:00
Benjamin Dauvergne db7e25287a Improve error logging during node parsing (#12829) 2019-09-06 15:32:51 +02:00
Benjamin Dauvergne 84bc5b48d3 Improve compatibility with Solaris (#32425) 2019-09-06 14:42:44 +02:00
Benjamin Dauvergne 6c852f8c0b Fix reference count in lasso_server_add_provider2 (fixes #35061)
As implemented lasso_server_add_provider2 could not be used as a publik
API as it dit not increase the reference count of the LassoProvider
object before adding it to the providers hashtable.

lasso_server_add_provider_helper had to be modified to decrement the
reference count of the new LassoProvider object after using
lasso_server_add_provider2.
2019-09-05 12:42:01 +02:00
Dmitrii Shcherbakov 1e85f1b2bd PAOS: Do not populate "Destination" attribute
When ECP profile (saml-ecp-v2.0-cs01) is used with PAOS binding Lasso
populates an AuthnRequest with the "Destination" attribute set to
AssertionConsumerURL of an SP - this leads to IdP-side errors because
the destination attribute in the request does not match the IdP URL.

The "Destination" attribute is mandatory only for HTTP Redirect and HTTP
Post bindings when AuthRequests are signed per saml-bindings-2.0-os
(sections 3.4.5.2 and 3.5.5.2). Specifically for PAOS it makes sense to
avoid setting that optional attribute because an ECP decides which IdP
to use, not the SP.

Fixes Bug: 34409
License: MIT
Signed-off-by: Dmitrii Shcherbakov <dmitrii.shcherbakov@canonical.com>
2019-07-03 23:54:57 +02:00
Benjamin Dauvergne 5853fbc150 export symbol lasso_log (#33784)
The symbol lasso_log has to be exported, otherwise Solaris run-time linker
fails due to an unresolved symbol dependency.
2019-07-02 11:57:08 +02:00
Benjamin Dauvergne b0fb24c951 Do not ignore WantAuthnRequestSigned value with hint MAYBE (fixes #33354)
Bug introduced in commit 394680712.
2019-05-23 10:11:09 +02:00
Benjamin Dauvergne 16aa8a7413 Use io.open(encoding=utf8) in extract_symbols/sections.py (fixes #33360) 2019-05-23 10:07:31 +02:00
Benjamin Dauvergne 151ad17e04 xml: adapt schema in saml2:AuthnContext (#29340)
saml2:AuthnContext XML schema indicate that AuthenticatingAuthority is
an optional unbounded list of nodes, but the current Lasso schema only
handle an unique element. To prevent Lasso from refusing perfectly legal
messages, we add a rule to the Lasso ignoring other nodes after the
first one.
2019-01-19 12:11:33 +01:00
John Dennis 642182bdf4 Fix ECP signature not found error when only assertion is signed (#26828)
With a SAML Authn Response either the message or the assertion
contained in the response message or both can be signed. Most IdP's
sign the message. This fixes a bug when processing an ECP authn
response when only the assertion is signed.

lasso_saml20_profile_process_soap_response_with_headers() performs a
signature check on the SAML message. A signature can also appear on
the assertion which is checked by
lasso_saml20_login_process_response_status_and_assertion() The problem
occurred when the message was not signed and
lasso_saml20_profile_process_soap_response_with_headers() returned
LASSO_DS_ERROR_SIGNATURE_NOT_FOUND as an error code which is not
actually an error because we haven't checked the signature on the
assertion yet. We were returning the first
LASSO_DS_ERROR_SIGNATURE_NOT_FOUND error when in fact the subsequent
signature check in
lasso_saml20_login_process_response_status_and_assertion() succeeded.

The ECP unit tests were enhanced to cover these cases.

The enhanced unit test revealed a problem in two switch statements
operating on the return value of
lasso_profile_get_signature_verify_hint() which were missing a case
statement for LASSO_PROFILE_SIGNATURE_VERIFY_HINT_FORCE which caused
an abort due to an unknown enumeration value.

Fixes Bug: 26828
License: MIT
Signed-off-by: John Dennis <jdennis@redhat.com>
2019-01-11 16:11:31 +01:00
Benjamin Dauvergne 580aca65b1 extract_types.py: force io to use UTF-8 encoding (fixes #27332) 2018-10-15 11:27:09 +02:00
Benjamin Dauvergne 5070a06a9a xml: fix parsing of saml:AuthnContext (fixes #25640)
Decl/DeclRef are alternatives, when matching a Decl we should jump over
the DeclRef.
2018-10-14 20:35:45 +02:00
John Dennis 3d9d58d52c Make more Python scripts compatible with both Py2 and Py3
While porting other Python code in the repo to run under Py3 (as well
as Py2) it was discovered there were a number of other Python scripts
which also needed porting. However these scripts are never invoked
during a build so there was no easy way to test the porting work. I
assume these scripts are for developers only and/or are
historical. Because there was no way for me to test the porting
changes on these scripts I did not want to include the changes in the
patch for the Py3 porting which fixed scripts that are invoked during
the build (the former patch is mandatory, this patch is optional at
the moment). I did verify the scripts compile cleanly under both Py2
and Py3, however it's possible I missed porting something or the error
does not show up until run-time.

Examples of the required changes are:

* Replace use of the built-in function file() with open().  file()
  does not exist in Py3, open works in both Py2 and Py3.  The code was
  also modified to use a file context manager (e.g. with open(xxx) as
  f:). This assures open files are properly closed when the code block
  using the file goes out of scope. This is a standard modern Python
  idiom.

* Replace all use of the print keyword with the six.print_()
  function, which itself is an emulation of Py3's print function. Py3
  no longer has a print keyword, only a print() function.

* The dict methods .keys(), .values(), .items() no longer return a
  list in Py3, instead they return a "view" object which is an
  iterator whose result is an unordered set. The most notable
  consequence is you cannot index the result of these functions like
  your could in Py2 (e.g. dict.keys()[0] will raise a run time
  exception).

* Replace use of StringIO.StringIO and cStringIO with
  six.StringIO. Py3 no longer has cStringIO and the six variant
  handles the correct import.

* Py3 no longer allows the "except xxx, variable" syntax, where
  variable appering after the comma is assigned the exception object,
  you must use the "as" keyword to perform the variable assignment
  (e.g. execpt xxx as variable)

* Python PEP 3113 removed tuple parameter unpacking. Therefore you can
  no longer define a formal parameter list that contains tuple
  notation representing a single parameter that is unpacked into
  multiple arguments.

License: MIT
Signed-off-by: John Dennis <jdennis@redhat.com>
2018-07-24 11:03:09 +02:00
John Dennis 17c39c3990 Make Python scripts compatible with both Py2 and Py3
During the build if the Python3 interpreter is used a number of
scripts will fail because they were never ported from Py2 to Py3. In
general we want Python code to be compatible with both Py2 and
Py3. This patch brings the scripts up to date with Py3 but retains
backwards compatibility with Py2 (specifically Py 2.7, the last Py2
release).

Examples of the required changes are:

* Replace use of the built-in function file() with open().  file()
  does not exist in Py3, open works in both Py2 and Py3.  The code was
  also modified to use a file context manager (e.g. with open(xxx) as
  f:). This assures open files are properly closed when the code block
  using the file goes out of scope. This is a standard modern Python
  idiom.

* Replace all use of the print keyword with the six.print_()
  function, which itself is an emulation of Py3's print function. Py3
  no longer has a print keyword, only a print() function.

* The dict methods .keys(), .values(), .items() no longer return a
  list in Py3, instead they return a "view" object which is an
  iterator whose result is an unordered set. The most notable
  consequence is you cannot index the result of these functions like
  your could in Py2 (e.g. dict.keys()[0] will raise a run time
  exception).

* Replace use of StringIO.StringIO and cStringIO with
  six.StringIO. Py3 no longer has cStringIO and the six variant
  handles the correct import.

* Py3 no longer allows the "except xxx, variable" syntax, where
  variable appering after the comma is assigned the exception object,
  you must use the "as" keyword to perform the variable assignment
  (e.g. execpt xxx as variable)

Note: the modifications in this patch are the minimum necessary to get
the build to run with the Py3 interpreter. There are numerous other
Python scripts in the repo which need Py3 porting as well but because
they are not invoked during a build they will be updated in a
subsequent patch.

License: MIT
Signed-off-by: John Dennis <jdennis@redhat.com>
2018-07-24 11:03:09 +02:00
John Dennis 87040110ed Use python interpreter specified configure script
The configure script allows you to specify the python interpreter to
use via the --with-python option. There were several places where the
python interpreter was implicity invoked without using the specified
version. This can create a number of problems in an environment with
multiple python versions as is the case during the transition from
Python 2 to Python 3. Python 2 is not compatible with Python
3. Lasso's Python code is supposed to be compatible with both
versions. But during the build and when running the unit tests it is
essential the same interpreter be used consistently otherwise you can
have problems.

This patch assures whenever python is invoked it does so via the
$(PYTHON) configuration variable.

What about shebang lines (e.g #/usr/bin/python) at the top of scripts?
Python PEP 394 (https://www.python.org/dev/peps/pep-0394/) covers
this. Basically it says if a script is compatible only with Py2 the
shebang should be #/usr/bin/python2, if only compatible with Py3 the
shebang should be #/usr/bin/python3. However, if the script is
compatible with both versions it can continue to use the
compatible with both Py2 and Py3.

License: MIT
Signed-off-by: John Dennis <jdennis@redhat.com>
2018-07-24 11:03:09 +02:00
Benjamin Dauvergne f33d51db53 tools: set output buffer size in lasso_inflate to 20 times the input size (fixes #24853) 2018-06-28 23:16:18 +02:00
Benjamin Dauvergne e29de3160d tools: fix segfault in lasso_get_saml_message (fixes #24830)
We reuse the "message" local variable but we should not.
Also fix a segfault in lasso_xmltextreader_from_message() when getting
the length of "message" before checking if it is NULL or not.
2018-06-28 10:30:53 +02:00
Benjamin Dauvergne 877f9e7888 deprecate loading PEM formatted public keys in lasso_xmlsec_load_key_info
Also ensure work-around bug[1] in libxmlsec 1.2.24 and 1.2.25.

[1]: https://github.com/lsh123/xmlsec/issues/164
2018-05-01 12:06:15 +02:00
Benjamin Dauvergne 81a628202d add a pem-public-key runtime flag
We want to deprecate support for loading PEM formatted key
from ds:KeyValue nodes, before final removal it will have to be activated
through a runtime flag (using LASSO_FLAG environment variable).
2018-05-01 11:13:08 +02:00
John Dennis 760eb947ab Replace xmlSecSoap functions with lasso implementations
xmlsec has removed support for SOAP. The missing xmlSecSoap* functions
and their dependent utiliity functions were added to Lasso following
the model of the existing xmlSec implmentations.

Note: Lasso tried to accommodate both SOAP 1.1 and SOAP 1.2 but SAML2
*only* uses SOAP 1.1 thus the SOAP 1.2 support was superfluous and
confused matters. Therefire the SOAP 1.2 support was removed.

The following new functions were added to Lasso to support SOAP:

* lasso_xml_next_element_node
* lasso_xml_get_node_ns_href
* lasso_xml_is_element_node
* lasso_xml_soap11_get_header
* lasso_xml_soap11_get_body

The following is the mapping from the deprecated xmlSecSoap symbols
to the new Lasso symbols:

xmlSecSoap11Ns -> LASSO_SOAP_ENV_HREF
xmlSecGetNextElementNode -> lasso_xml_next_element_node
xmlSecGetNodeNsHref -> lasso_xml_get_node_ns_href
xmlSecCheckNodeName -> lasso_xml_is_element_node
xmlSecSoap11GetHeader -> lasso_xml_soap11_get_header
xmlSecSoap11GetBody -> lasso_xml_soap11_get_body

This patch also extends the automake version support in autogen.sh to the
current 1.16 version.

License: MIT
Signed-off-by: John Dennis <jdennis@redhat.com>
2018-04-30 18:06:55 +02:00
Benjamin Dauvergne a354701fae add xmlsec_soap.h to Makefile 2018-04-06 22:39:54 +02:00