GithubHelp home page GithubHelp logo

swedenconnect / signservice Goto Github PK

View Code? Open in Web Editor NEW
3.0 9.0 1.0 8.68 MB

A signature service according to the Swedish eID Framework specifications

License: Apache License 2.0

Java 95.73% CSS 1.68% JavaScript 0.07% HTML 2.46% Shell 0.06%

signservice's Introduction

Logo

Signature Service according to the Swedish eID Framework

License

This repository comprises of source code for building a Signature Service according to the Swedish eID Framework specifications - https://docs.swedenconnect.se/technical-framework.


Documentation

Go to https://docs.swedenconnect.se/signservice for documentation of how to understand and use this repository.

Java API documentation: https://docs.swedenconnect.se/signservice/apidocs

Modules

This repository comprises of the following modules:

  • core - Core API:s and classes.

  • authn - Support for user authentication.

  • protocol - Protocol support.

  • signhandler - Implementation of a Signature Handler, responsible of creating signatures.

  • keycert - Modules for generating signature keys and certificates.

  • signhandler - Module for creating signatures.

  • audit - Audit logging support.

  • engine - Signature Service processing logic engine.

  • config - Application configuration support.

  • spring-boot-starter - A Spring Boot Starter module that is useful when building a Signature Service application using Spring Boot.

  • demo-apps - Sample SignService applications.

  • bom - A Maven Bill-of-Materials POM that is useful when building SignService applications.


Copyright © 2022-2023, Myndigheten för digital förvaltning - Swedish Agency for Digital Government (DIGG). Licensed under version 2.0 of the Apache License.

signservice's People

Contributors

martin-lindstrom avatar razumain avatar magnushoflin avatar hnrcnrlndr avatar dagosec avatar

Stargazers

Stefan Nilsson avatar  avatar Evgeny Lukashevich avatar

Watchers

Leif Johansson avatar Mattias Kesti avatar  avatar  avatar Björn Molin avatar  avatar Felix Hellman avatar  avatar Josef Andersson avatar

Forkers

janderssonse

signservice's Issues

Make a configuration module

Currently we have a Spring Boot starter module that handles configuration of an application. For those deployments that do not use Spring this is of little help. We should make a framework-independent configuration module (and let the Spring Boot starter use that).

This activity also helps in documentation of the configuration settings.

Add audit logging events

We should add audit logging events to the engine implementation.

  • Completed (successful) operation
  • Errors

Also, we should make it configurable what is actually included in an audit event. Some users of the service may want to limit what is logged. For example don't include any personal data.

Wrong signing time in TBS data is not checked properly

When signing time is provided in the input To Be Signed data, different rules apply depending on the signature format.

If the signing time is provided in an XML Object as a signed signature property, then the signature service is allowed to update this time to current time and to process the signature.

However, if the document is a PDF, the signature process MUST be aborted. The reason for this is that PDF has multiple places to store signing time. Both as signed attribute, but also as a parameter in the signature dictionary. Since the sign service has no access to the signature dictionary, it must assume that there is a high risk that this dictionary contains false time information if the signed attributes holds a bad time.

Current implementation of sign service accepts sign request for PDF documents even if the signing time has substantial deviation from current time. This is in error.

For XML the sign service has a choice to either reject the request or to update the time. Sign service updates the time and process the request. We may want to consider rejecting such request in order to align XML and PDF document processing.
After all, a sign request with a signing time that is out of date is an indication that something is not quite right.

Too long request validity is ignored

If a Sign Request has a validity period that is too long (i.e. 1 hour), the sign request is processed as long as current time is within the validity period.

The risk here is that the validity period exceeds the replay checker retention period and opens for successful replay attacks.

Update the process used to add Certificates to PkiCredentials

When a certificate is generated, it is added to the signer's PkiCredential object.

Adding this certificate is not supported on the generic interface level, but only on the abstract class implementing the interface.

In theory there could be an implementation outside of this abstract class. The implementation of this is not straightforward using any function on the main interface but requires a test if the credential object is a subclass of the abstract implementation before calling the method in the abstract class. Once this has been added to the main interface, the implementation can be simplified.

SADValidator as interface?

SwedenConnectSamlAuthenticationHandler has a setter for SADValidator that allows setting a custom SADValidator.

If no one is set, the SADValidator of se.swedenconnect.opensaml.sweid.saml2.signservice.SADParser.SADValidator is set.

The problem here is that SADValidator is not an interface, but rather a static sub-class of SADParser, making it very hard to provide a custom implementation of it as intended by SwedenConnectSamlAuthenticationHandler

This seems to be a logical mismatch.

Add configurable support for PKCS10 request format

Current implementation only utilise the CRMF request format which provides less substantial Proof Of Possession (POP) to the issuing CA that the requestor has access to the corresponding private key.

PKCS10 request format requires access to the private key as the PKCS10 request is signed with the private key of the public key in the requested certificate.

Since signservice has access to the signer private key, there should be an option to use PKCS10 request format, which also allows greater flexibility of choice of compatible CA:s

Metadata cache directory must exists before start

When configuring the metadata provider bean it is possible to configure the backup-file. If this path points to a directory that does not exist, no cache will be written.

Solution: Make sure that the configuration process ensures that the directory exists, and if not, tries to create all intermediate directories.

Attribute mapping on default values

Attribute mapping data is placed in AuthnContextExtension even when the attribute and its data is provided by the SP as a default value. This is an error since there is no source attribute and the result is a XML Schema violation.

Fix URL comparisons

The internals use HttpServletRequest.getRequestURI that returns everything following the protocol. This makes it tricky to configure since the logic shouldn't be aware of the context path.

Add language tag to Logo in SAML metadata

The class MetadataConfiguration.UIInfoConfig.UIInfoLogo should be extended with a lang-tag so that we can publish logotypes for different languages (required by Swamid).

Certificate error - bad attribute name on default attribute values

The AuthContextExtension specifies the SAML source for every attribute in the certificate subject name.
However if that attribute is set by a default value, then no SAML name is specified.

This is a violation of the XML Schema of the SAMLAuthContext xml content.

In the reference signature service, the proper SAML attribute name is set. If none is set in the sign request, we should have a name for "default". It could be argued that the value "default" is more accurate as it does not imply that the IdP was the source of the value in the cert.

Fix Snyk-reports

We have some vulnerabilities concerning webjars reported by Snyk. Let's fix those ...

Use a catch-all in engine implementation

Currently, the engine implementation catches all "expected" exceptions and translates them into an error response message (when possible). However, unexpected exceptions (such as NPE) are not handled until we reach the catch-all where we display an error page.

This is on purpose, but after testing and before the first release we should catch all exceptions and try to send back an "internal error" response message (and audit log).

Allow external URL for CRLDP in simple CA

When simple CA is run locally, the CRL is not available and signed documents can't be validated. To allow tests where the document is validated, the CRL can be posted to a public location.

To support this, it must be possible to specify an external CRLDP location, and not just a path under localhost

Revert possibility to use default signature algorithm

The current feature to allow default value for signature algorithm should be reverted and always require signature algorithm to be specified in the request.

The main reason for this is that the tbs-data that is provided in the sign request must be prepared for a specific signature algorithm and in some cases that algorithm is not specified (like in PDF message digest attribute).

If signature algorithm is not specified in the sign request, this will create ambiguity in how to understand the tbs data.

Make SamlAuthenticationHandlerFactory easier to extend

As it is now the implementation uses getSamlType in too many places and we are ending up having to extend too many methods if we introduce a new SAML type.

Solution: Introduce an assertSamlType() method first in the flow (that can be extended). Then always have a default choice and don't fail on "unrecognized saml type".

Wrong handling of old or not yet valid requests

Requests with a request time set in the past or in the future results in a sign response to the requesting Service Provider.

No Sign Response should be returned unless the date and replay checks pass.

SAD issue time check lacks time skew tolerance configuration

The SADValidator at se.swedenconnect.opensaml.sweid.saml2.signservice.SADParser.SADValidator has a problem in the check of issue time at row 200

The current check: (long)sad.getIssuedAt() > now

This check does not allow any time skew. If the sign server clock is behind the IdP clock by just a few seconds, this check will fail. In test environments this will fail if time skew is a fraction of a second.

This check should have a configurable time skew margin.

Sign service provides error UI even when the user cold be returned to the requesting service

A fundamental requirement for sign services has always been the principle that the Sign Service has no UI for the user unless the request can't be returned to the requesting service for one of the following reasons:

  • The real requestor can't be safely identified
  • The return address to the requesting service is unknown
  • The request is a replay attempt
  • The request is not received within its validity period.

In all other instances, the user MUST be returned to the requesting service with an appropriate status indication in order to allow that application to get the user back and to handle the user in an appropriate manner.

Sign service currently does not meet this requirement. One case is there a request is made for an unsupported certificate type (QC, PKC, QC/SSSCD). If the requested certificate type is not supported, the user is presented by an error page claiming "internal error". In this case the user should be returned to the requesting service with an appropriate error response.

Allow multiple CA scopes in key and certificate handler

Current CMC key and certificate handler can only support one certificate type.

This is too restrictive and makes it very hard to setup the signservice in various test configurations. Configuration should decide if the CA supports one or more certificate types, not just a single type.

Consider using default bean if nothing is given

When configuring clients (engines) we need to point out an external bean even if we don't want to make any changes to the definition. Example:

    protocol:
      external:
        bean-name: signservice.DssProtocolHandler

We should make a change so that if there is only one bean of a particular type defined, we should default to that bean if nothing is set in the engine configuration. This makes configuration easier.

Configurable inclusion of SAD request

The inclusion of a SAD request is currently not configurable, but rather controlled by the status of the IdP and the sign request.

The following parts of the code is involved:

DefaultSignServiceEngine has a //TODO at row 513 stating:

      // Note: The authentication requirements may also be controlled by a policy ...
      // TODO: We need to extend the input to authenticate with a listing of all attributes
      // required. We get those from the signing certificate requirements ...
      final AuthnRequirements reqs = signRequest.getAuthnRequirements();

This is a place where it could be possible to influence the authentication requirements. AuthenticationRequirements has a parameter of type SignatureActivationRequestData. If set to null, it will not send a SAD request.

The SignatureActivationRequestData is set by parsing the SignRequest in row 536 of DssSignRequestMessage

    authnRequirements.setSignatureActivationRequestData(
        new DefaultSignatureActivationRequestData(
            this.signRequest.getRequestID(), docCount, certType == CertificateType.QC_SSCD));

Using this code, it will never be null.

Finally the decision to include SAD request is mad by SwedenConnectSamlAuthenticationHandler at row 126

    // Should we send a SAD request?
    //
    final SADRequest sadRequest = authnRequirements.getSignatureActivationRequestData() != null
        && signMessage != null
        && this.isSignatureActivationProtocolSupported(idpMetadata)
            ? (SADRequest) XMLObjectSupport.buildXMLObject(SADRequest.DEFAULT_ELEMENT_NAME)
            : null;
    if (sadRequest != null) {

I think this is the appropriate place to have a configurable option to not send a SAD request.

Given that the SignatureActivationRequestData is never null. The current logic is:

If signMessage is present and IdP supports SAD, then send SAD request.

This should be replaced by the following logic:

boolean SADREQ_ALWAYS_IF_SUPPORTED = true;
boolean sendSad = false;

  1. If qualified certificate is requested: sendSad = true
  2. If IdP supports SAD && SADREQ_ALWAYS_IF_SUPPORTED: sendSad = true
  3. If IdP does not support SAD && sendSad: Error
  4. if (sendSad) send SAD request

Signservice ID is not checked

If a Sign Request is received with a wrong SignService identifier, the sign service accepts the request and process the signature.

Order of checks - Signature validation before simpler validity checks

Signature validation is performed before simpler checks such as checks if the request is too old to be processed.

It is a good principle to do easier and less costly checks first, such as simple date checks before doing costly checks such as signature validation in order to reduce the attack surface for DOS attacks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.