<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
    version="1.1.2"
    xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
    targetNamespace="http://id.elegnamnden.se/csig/1.1/dss-ext/ns"
    xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:dss="urn:oasis:names:tc:dss:1.0:core:schema"
    xmlns:csig="http://id.elegnamnden.se/csig/1.1/dss-ext/ns">

  <xs:annotation>
    <xs:documentation>
      Version: 1.1.2
      Schema location URL: https://docs.swedenconnect.se/schemas/csig/1.1/EidCentralSigDssExt-1.1.2.xsd
    </xs:documentation>
  </xs:annotation>

  <xs:import namespace="urn:oasis:names:tc:SAML:2.0:assertion"
      schemaLocation="https://docs.oasis-open.org/security/saml/v2.0/saml-schema-assertion-2.0.xsd"/>

  <xs:element name="SignRequestExtension" type="csig:SignRequestExtensionType">
    <xs:annotation>
      <xs:documentation>
        Extension to an OASIS DSS SignRequest, providing additional 
        information about a sign request. This element extends the 
        dss:OptionalInputs element of a dss:SignRequest.
      </xs:documentation>
    </xs:annotation>
  </xs:element>

  <xs:element name="SignResponseExtension" type="csig:SignResponseExtensionType">
    <xs:annotation>
      <xs:documentation>
        Extension to an OASIS DSS SignResponse, providing additional information 
        about a sign response. This element extends the dss:OptionalOutput element 
        of a dss:SignResponse.
      </xs:documentation>
    </xs:annotation>
  </xs:element>

  <xs:element name="SignTasks" type="csig:SignTasksType" />

  <xs:element name="SignTaskData" type="csig:SignTaskDataType" />
    
  <xs:element name="RequestTime" type="xs:dateTime">
    <xs:annotation>
      <xs:documentation>
        Time when the request was created.
      </xs:documentation>
    </xs:annotation>
  </xs:element>

  <xs:element name="Signer" type="saml:AttributeStatementType">
    <xs:annotation>
      <xs:documentation>
        The identity of the signer expressed as a sequence of SAML attributes 
        using the AttributesType complex type.
      </xs:documentation>
    </xs:annotation>
  </xs:element>

  <xs:element name="IdentityProvider" type="saml:NameIDType">
    <xs:annotation>
      <xs:documentation>
        The SAML entityID of the Identity Provider that MUST be used to 
        authenticate the signer before signing. The EntitID value is specified 
        using the saml:NameIDType complex type and MUST include a Format 
        attribute with the value urn:oasis:names:tc:SAML:2.0:nameid-format:entity.
      </xs:documentation>
    </xs:annotation>
  </xs:element>
  
  <xs:element name="AuthnProfile" type="xs:string">
    <xs:annotation>
      <xs:documentation>
        An opaque string that can be used to inform the Signing Service about 
        specific requirements regarding the user authentication at the given 
        Identity Provider.
      </xs:documentation>
    </xs:annotation>
  </xs:element>

  <xs:element name="SignRequester" type="saml:NameIDType">
    <xs:annotation>
      <xs:documentation>
        The SAML entityID of the service that sends this request to the signing service. 
        The entityID value is specified using the saml:NameIDType complex type and MUST 
        include a Format attribute with the value 
        urn:oasis:names:tc:SAML:2.0:nameid-format:entity.
      </xs:documentation>
    </xs:annotation>
  </xs:element>

  <xs:element name="SignService" type="saml:NameIDType">
    <xs:annotation>
      <xs:documentation>
        The SAML entityID of the service to which this Sign Request is sent. 
        The entityID value is specified using the saml:NameIDType complex type 
        and MUST include a Format attribute with the value 
        urn:oasis:names:tc:SAML:2.0:nameid-format:entity.
      </xs:documentation>
    </xs:annotation>
  </xs:element>

  <xs:element name="RequestedSignatureAlgorithm" type="xs:anyURI">
    <xs:annotation>
      <xs:documentation>
        An identifier of the signature algorithm the requesting service prefers 
        when generating the requested signature.
      </xs:documentation>
    </xs:annotation>
  </xs:element>

  <xs:element name="CertRequestProperties" type="csig:CertRequestPropertiesType">
    <xs:annotation>
      <xs:documentation>
        The requested properties of the signature certificate being issued by the 
        signature service.
      </xs:documentation>
    </xs:annotation>
  </xs:element>

  <xs:element name="RequestedCertAttributes" type="csig:RequestedAttributesType">
    <xs:annotation>
      <xs:documentation>
        An optional set of requested attributes that the requesting service prefers 
        or requires in the subject name of the generated signing certificate.
      </xs:documentation>
    </xs:annotation>
  </xs:element>

  <xs:element name="OtherProperties" type="csig:AnyType" />

  <xs:element name="SignMessage" type="csig:SignMessageType">
    <xs:annotation>
      <xs:documentation>
        Sign message included as a choice of a Base64 encoded string or 
        an encrypted sign message.
      </xs:documentation>
    </xs:annotation>
  </xs:element>

  <xs:element name="Message" type="xs:base64Binary" />
  
  <xs:element name="EncryptedMessage" type="saml:EncryptedElementType" />

  <xs:element name="OtherRequestInfo" type="csig:AnyType">
    <xs:annotation>
      <xs:documentation>
        Any additional inputs to the request extension.
      </xs:documentation>
    </xs:annotation>
  </xs:element>

  <xs:element name="ResponseTime" type="xs:dateTime">
    <xs:annotation>
      <xs:documentation>
        The time when the sign response was created.
      </xs:documentation>
    </xs:annotation>
  </xs:element>

  <xs:element name="Request" type="xs:base64Binary">
    <xs:annotation>
      <xs:documentation>
        An element of type EncodedRequestType with base64Binary base type, holding 
        a representation of a complete and signed dss:SignRequest element that is 
        related to this sign response. This element MUST be present if signing was 
        successful.
      </xs:documentation>
    </xs:annotation>
  </xs:element>

  <xs:element name="SignerAssertionInfo" type="csig:SignerAssertionInfoType">
    <xs:annotation>
      <xs:documentation>
        An element of type SignerAssertionInfoType holding information about how 
        the signer was authenticated by the sign service as well as information 
        about subject attribute values present in the SAML assertion authenticating 
        the signer, which was incorporated into the signer certificate. This element 
        MUST be present if signing was successful.
      </xs:documentation>
    </xs:annotation>
  </xs:element>
  
  <xs:element name="ContextInfo" type="csig:ContextInfoType" />

  <xs:element name="SamlAssertions" type="csig:SAMLAssertionsType" />

  <xs:element name="SignatureCertificateChain" type="csig:CertificateChainType">
    <xs:annotation>
      <xs:documentation>
        An element of type CertificateChainType holding the signer certificate as 
        well as other certificates that may be used to validate the signature. This 
        element MUST be present if signing was successful and MUST contain all 
        certificate that are necessary to compile a complete and functional signed 
        document.
      </xs:documentation>
    </xs:annotation>
  </xs:element>

  <xs:element name="OtherResponseInfo" type="csig:AnyType">
    <xs:annotation>
      <xs:documentation>
        Optional sign response elements of type AnyType.
      </xs:documentation>
    </xs:annotation>
  </xs:element>
  
  <xs:element name="ToBeSignedBytes" type="xs:base64Binary">
    <xs:annotation>
      <xs:documentation>
        The octets that are hashed and signed when generating the signture. For 
        PDF and common modes of CMS this is the DER encoded SignedAttributess field. 
        For XML this is the canonicalized SignedInfo octets.
      </xs:documentation>
    </xs:annotation>
  </xs:element>
  
  <xs:element name="AdESObject" type="csig:AdESObjectType">
    <xs:annotation>
      <xs:documentation>
        Information in support of AdES signature creation.
      </xs:documentation>
    </xs:annotation>
  </xs:element>

  <xs:element name="Base64Signature" type="csig:Base64SignatureType">
    <xs:annotation>
      <xs:documentation>Result signature bytes</xs:documentation>
    </xs:annotation>
  </xs:element>

  <xs:element name="OtherSignTaskData" type="csig:AnyType" />

  <xs:complexType name="SignRequestExtensionType">
    <xs:sequence>
      <xs:element ref="csig:RequestTime" />
      <xs:element ref="saml:Conditions">
        <xs:annotation>
          <xs:documentation>
            Conditions that MUST be evaluated when assessing the validity of and/or 
            when using the Sign Request. See Section 2.5 of SAML2.0 for additional 
            information on how to evaluate conditions.

            This element MUST include the attributes NotBefore and NotOnOrAfter and 
            MUST include the element saml:AudienceRestriction which in turn MUST 
            contain one saml:Audience element, specifying the return URL for any 
            resulting Sign Response message.
          </xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element ref="csig:Signer" minOccurs="0" />
      <xs:element ref="csig:IdentityProvider" />
      <xs:element ref="csig:AuthnProfile" minOccurs="0">
        <xs:annotation>
          <xs:documentation>
            If set, the Version attribute MUST be 1.4 or higher.
          </xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element ref="csig:SignRequester" />      
      <xs:element ref="csig:SignService" />
      <xs:element ref="csig:RequestedSignatureAlgorithm" minOccurs="0" />
      <xs:element ref="csig:CertRequestProperties" minOccurs="0" />
      <xs:element ref="csig:SignMessage" minOccurs="0" maxOccurs="1" />
      <xs:element ref="csig:OtherRequestInfo" minOccurs="0" />
    </xs:sequence>
    <xs:attribute name="Version" type="xs:string" use="optional" default="1.1">
      <xs:annotation>
        <xs:documentation>
          The version of the DSS extensions specification. If absent, the version value defaults to "1.1". 
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>
  
  <xs:complexType name="SignResponseExtensionType">
    <xs:sequence>
      <xs:element ref="csig:ResponseTime"/>
      <xs:element ref="csig:Request" minOccurs="0" />
      <xs:element ref="csig:SignerAssertionInfo" minOccurs="0" maxOccurs="1" />
      <xs:element ref="csig:SignatureCertificateChain" minOccurs="0" />
      <xs:element ref="csig:OtherResponseInfo" minOccurs="0" />
    </xs:sequence>
    <xs:attribute name="Version" type="xs:string" default="1.1">
      <xs:annotation>
        <xs:documentation>
          The version of the DSS specification. If absent, the version value defaults to "1.1". 
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>

  <xs:complexType name="CertificateChainType">
    <xs:sequence>
      <xs:element name="X509Certificate" type="xs:base64Binary" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="MappedAttributeType">
    <xs:sequence>
      <xs:element name="AttributeAuthority" type="saml:NameIDType" 
                  minOccurs="0" maxOccurs="unbounded" />
      <xs:element name="SamlAttributeName" type="csig:PreferredSAMLAttributeNameType"
                  minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
    <xs:attribute name="CertAttributeRef" type="xs:string" use="optional" />
    <xs:attribute name="CertNameType" default="rdn" use="optional">
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:enumeration value="rdn" />
          <xs:enumeration value="san" />
          <xs:enumeration value="sda" />
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="FriendlyName" type="xs:string" />
    <xs:attribute name="DefaultValue" type="xs:string" />
    <xs:attribute name="Required" type="xs:boolean" default="false" />
  </xs:complexType>

  <xs:complexType name="RequestedAttributesType">
    <xs:sequence>
      <xs:element name="RequestedCertAttribute" type="csig:MappedAttributeType"
                  minOccurs="1" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="AnyType">
    <xs:sequence>
      <xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="SAMLAssertionsType">
    <xs:sequence>
      <xs:element name="Assertion" type="xs:base64Binary" maxOccurs="unbounded" />
    </xs:sequence>    
  </xs:complexType>

  <xs:complexType name="PreferredSAMLAttributeNameType">
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="Order" type="xs:int" default="0" />
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>

  <xs:complexType name="SignTasksType">
    <xs:sequence>
      <xs:element maxOccurs="unbounded" ref="csig:SignTaskData"/>
    </xs:sequence>
  </xs:complexType>
  
  <xs:complexType name="SignTaskDataType">
    <xs:sequence>
      <xs:element ref="csig:ToBeSignedBytes" />
      <xs:element ref="csig:AdESObject" minOccurs="0" maxOccurs="1" />
      <xs:element ref="csig:Base64Signature" minOccurs="0" />
      <xs:element ref="csig:OtherSignTaskData" minOccurs="0" />
    </xs:sequence>
    <xs:attribute name="SignTaskId" type="xs:string">
      <xs:annotation>
        <xs:documentation>
          A distinguishing id of this sign task which is used to distinguish between 
          multiple sign tasks in the same request.
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="SigType" use="required">
      <xs:annotation>
        <xs:documentation>
          Enumeration of the type of signature the canonical signed information is
          associated with.
        </xs:documentation>
      </xs:annotation>
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:enumeration value="XML" />
          <xs:enumeration value="PDF" />
          <xs:enumeration value="CMS" />
          <xs:enumeration value="ASiC" />
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="AdESType" default="None">
      <xs:annotation>
        <xs:documentation>
          Specifies the type of AdES signature. BES means that the signing certificate
          hash must be covered by the signature. EPES means that the signing 
          certificate hash and a signature policy identifier must be covered by 
          the signature.
        </xs:documentation>
      </xs:annotation>
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:enumeration value="None" />
          <xs:enumeration value="BES" />
          <xs:enumeration value="EPES" />
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="ProcessingRules" type="xs:anyURI" use="optional">
      <xs:annotation>
        <xs:documentation>
          An identifier for processing rules that must be executed by the signature 
          service when processing data in this element.
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>

  <xs:complexType name="AdESObjectType">
    <xs:sequence>
      <xs:element name="SignatureId" type="xs:string" minOccurs="0" />
      <xs:element name="AdESObjectBytes" type="xs:base64Binary" minOccurs="0" />
      <xs:element name="OtherAdESData" type="csig:AnyType" minOccurs="0" />
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="CertRequestPropertiesType">
    <xs:sequence>
      <xs:element ref="saml:AuthnContextClassRef" minOccurs="0" maxOccurs="unbounded">
        <xs:annotation>
          <xs:documentation>
            The URI reference(s) to the requested level of assurance with which the 
            certificate subject should be authenticated.
          </xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element ref="csig:RequestedCertAttributes" minOccurs="0" />
      <xs:element ref="csig:OtherProperties" minOccurs="0" />
    </xs:sequence>
    <xs:attribute default="PKC" name="CertType">
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:enumeration value="PKC" />
          <xs:enumeration value="QC" />
          <xs:enumeration value="QC/SSCD" />
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
  </xs:complexType>

  <xs:complexType name="SignerAssertionInfoType">
    <xs:sequence>
      <xs:element ref="csig:ContextInfo" />
      <xs:element ref="saml:AttributeStatement" />
      <xs:element ref="csig:SamlAssertions" minOccurs="0" />
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="ContextInfoType">
    <xs:sequence minOccurs="0" maxOccurs="1">
      <xs:element name="IdentityProvider" type="saml:NameIDType" />
      <xs:element name="AuthenticationInstant" type="xs:dateTime" />
      <xs:element ref="saml:AuthnContextClassRef" />
      <xs:element name="ServiceID" type="xs:string" minOccurs="0" />
      <xs:element name="AuthType" type="xs:string" minOccurs="0" />
      <xs:element name="AssertionRef" type="xs:string" minOccurs="0" />
    </xs:sequence>
  </xs:complexType>
  
  <xs:complexType name="Base64SignatureType">
    <xs:simpleContent>
      <xs:extension base="xs:base64Binary">
        <xs:attribute name="Type" type="xs:anyURI" />
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>

  <xs:complexType name="SignMessageType">
    <xs:choice>
      <xs:element ref="csig:Message" />
      <xs:element ref="csig:EncryptedMessage" />
    </xs:choice>
    <xs:attribute name="MustShow" type="xs:boolean" default="false" />
    <xs:attribute name="DisplayEntity" type="xs:anyURI" />
    <xs:attribute name="MimeType" default="text">
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:enumeration value="text/html" />
          <xs:enumeration value="text" />
          <xs:enumeration value="text/markdown" />
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
    <xs:anyAttribute namespace="##other" processContents="lax" />
  </xs:complexType>

</xs:schema>
