Skip to content
This repository has been archived by the owner on May 9, 2022. It is now read-only.

TypeError: argument should be a bytes-like object or ASCII string, not 'NoneType' #295

Open
gozus19p opened this issue Sep 10, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@gozus19p
Copy link

Buongiorno a tutti,

apro questa issue in quanto sto riscontrando un problema in fase di trasmissione della SAMLRequest a idptest.spid.gov.it.
L'errore che viene evidenziato è il seguente:

TypeError: argument should be a bytes-like object or ASCII string, not 'NoneType'
qui la trace trace.txt completa

Non sto riuscendo ad interpretare la problematica, purtroppo non conosco nel dettaglio Python.
La soluzione software a cui sto lavorando è sviluppata in Java 8, tramite Spring; lato SAML si è scelto di procedere sfruttando il binding HTTP-POST.
La request generata è quindi codificata in Base64 (tramite API org.opensaml.xml.util.Base64 - metodo org.opensaml.xml.util.Base64.encodeBytes(requestMessage.getBytes(), Base64.DONT_BREAK_LINES); ), non si utilizza il deflate.

Di seguito condivido la request in Base64 e il nostro metadata: test-files.zip.

A corredo aggiungo che inizialmente l'ambiente di test SPID ha generato errori puntuali in merito alla struttura del file (problemi sulla costruzione dell'Issuer e tag analoghi); risolti questi mi sono bloccato qui.

Ringrazio in anticipo e saluto,
Manuel

@ioggstream
Copy link
Contributor

A naso signature_value.text è None

raw_signature = b64decode(signature_value.text)

Puoi verificare i dati corrispondenti nella firma e/o controllare se è codificata correttamente?

@bfabio
Copy link
Member

bfabio commented Sep 11, 2020

Ciao @gozus19p, ti confermo che la firma è vuota. In ogni caso il server non dovrebbe sollevare un'eccezione, ma gestirla.

<samlp:AuthnRequest xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
    AssertionConsumerServiceURL="https://test-peppol-smpw.regione.emilia-romagna.it/rest/spid/send-login-response"
    AttributeConsumingServiceIndex="1"
    Destination="https://idptest.spid.gov.it/sso"
    ID="_abdd8d0-370e-4f76-b281-8eebb276faef"
    IssueInstant="2020-09-10T08:06:31.617Z"
    ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
    Version="2.0">
    <saml2:Issuer xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion"
        Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity"
        NameQualifier="https://test-peppol-smpw.regione.emilia-romagna.it">
        https://test-peppol-smpw.regione.emilia-romagna.it</saml2:Issuer>
    <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
        <ds:SignedInfo>
            <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
            <ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" />
            <ds:Reference URI="#_abdd8d0-370e-4f76-b281-8eebb276faef">
                <ds:Transforms>
                    <ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
                    <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
                </ds:Transforms>
                <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
                <ds:DigestValue />
            </ds:Reference>
        </ds:SignedInfo>
        <ds:SignatureValue />    <============== QUI
        <ds:KeyInfo>
            <ds:KeyValue>
                <ds:RSAKeyValue>
                    <ds:Modulus>
                        tCxAiKg2Tsv/h4nY3knopphr2yK86otp3NotHk0cq10fwmG4pSlm8X+/8+Rb2OeiwwiqFguJt9ou
                        5geHvsS37jUzVLuKwb/n6BXqFazrxgqtlxgNsvmgxUlSHqO1jg5KoKME1aK6qqMMuzJBOrM0df8r
                        2nh3vwALBffixhdW8xkSAn0/p0IMzGYmDJk+wF0Hm3yzLnIz/I7BoNSFZtRMlu4PjZ7JWrtfITsx
                        j11ouyvljc2kFuat+KB8qVJrwExGhhtga/WU2a/zapa60rllMfk7X87JxWBjsYYMO7ZSr6DfcbDu
                        U+Ck4nM9Klxvi4u1p9wVnbEg2Z3LCEI/EHRRIw==</ds:Modulus>
                    <ds:Exponent>AQAB</ds:Exponent>
                </ds:RSAKeyValue>
            </ds:KeyValue>
            <ds:X509Data>
                <ds:X509Certificate>
                    MIIEeTCCA2GgAwIBAgIUPagXUGCKeCQzCN+EkmLqNNO3kPkwDQYJKoZIhvcNAQELBQAwgcsxCzAJ
                    BgNVBAYTAklUMRcwFQYDVQQIDA5FbWlsaWEtUm9tYWduYTEQMA4GA1UEBwwHQm9sb2duYTEhMB8G
                    A1UECgwYUEVQUE9MIFNNUCBDZW50cmFsaXp6YXRvMRUwEwYDVQQLDAxJbnRlcmNlbnQtRVIxMzAx
                    BgNVBAMMKnRlc3QtcGVwcG9sLXNtcHcucmVnaW9uZS5lbWlsaWEtcm9tYWduYS5pdDEiMCAGCSqG
                    SIb3DQEJARYTbWFudWVsLmdvenppQGVuZy5pdDAeFw0yMDA4MzEwOTE0MTZaFw0yMTA4MzEwOTE0
                    MTZaMIHLMQswCQYDVQQGEwJJVDEXMBUGA1UECAwORW1pbGlhLVJvbWFnbmExEDAOBgNVBAcMB0Jv
                    bG9nbmExITAfBgNVBAoMGFBFUFBPTCBTTVAgQ2VudHJhbGl6emF0bzEVMBMGA1UECwwMSW50ZXJj
                    ZW50LUVSMTMwMQYDVQQDDCp0ZXN0LXBlcHBvbC1zbXB3LnJlZ2lvbmUuZW1pbGlhLXJvbWFnbmEu
                    aXQxIjAgBgkqhkiG9w0BCQEWE21hbnVlbC5nb3p6aUBlbmcuaXQwggEiMA0GCSqGSIb3DQEBAQUA
                    A4IBDwAwggEKAoIBAQC0LECIqDZOy/+HidjeSeimmGvbIrzqi2nc2i0eTRyrXR/CYbilKWbxf7/z
                    5FvY56LDCKoWC4m32i7mB4e+xLfuNTNUu4rBv+foFeoVrOvGCq2XGA2y+aDFSVIeo7WODkqgowTV
                    orqqowy7MkE6szR1/yvaeHe/AAsF9+LGF1bzGRICfT+nQgzMZiYMmT7AXQebfLMucjP8jsGg1IVm
                    1EyW7g+Nnslau18hOzGPXWi7K+WNzaQW5q34oHypUmvATEaGG2Br9ZTZr/NqlrrSuWUx+TtfzsnF
                    YGOxhgw7tlKvoN9xsO5T4KTicz0qXG+Li7Wn3BWdsSDZncsIQj8QdFEjAgMBAAGjUzBRMB0GA1Ud
                    DgQWBBT2IJywqgFAM5HHmf2Ga9R5UYX0DjAfBgNVHSMEGDAWgBT2IJywqgFAM5HHmf2Ga9R5UYX0
                    DjAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQB/PM9J52U56JW9zAMhV9IMRwN1
                    ATBDWZMnaZH0IXybN3rYYDLWah5oTpV1LMlaZyW/pimdtROR0WXgfrP+C4zganddC3PxLW0k6ZyC
                    Yz+aT/EkYShu2YFQ79IQz9pXiJgLY3T+2OWN55mE8E+8FU3nlPEWHer7MvTl8vbBpQjSf9w9GGt3
                    DziXdHy+eP4Nn2GIlLfWbXrhvtPiJ8jMHWYXbepnK9CZbBQS4DhaQC+ba3+ZP2BnaG9dPuaxF5VI
                    RvvUq/LX+mps9cMHxdpXFucmrnd7IsPg23aqqlQaBKzYN8HHiXId5CLfgLaqBulrmALTPVjZxapQ
                    aNWxOcGCes+H</ds:X509Certificate>
            </ds:X509Data>
        </ds:KeyInfo>
    </ds:Signature>
    <saml2p:NameIDPolicy xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol"
        Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient" />
        <saml2p:RequestedAuthnContext xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol"
            Comparison="exact">
            <saml:AuthnContextClassRef xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">
                https://www.spid.gov.it/SpidL2</saml:AuthnContextClassRef>
        </saml2p:RequestedAuthnContext>
    </samlp:AuthnRequest>

@gozus19p
Copy link
Author

Ciao a tutti. Ho fixato l'apposizione della firma e ora non riscontro più il problema sopra citato.
Vi ringrazio per il riscontro.

@ioggstream
Copy link
Contributor

@bfabio il validatore xml dovrebbe ritornare un errore prima di processare il payload, ti torna? Magari modifichiamo l'issue e riapriamolo. Mi pare abbastanza semplice per finire nell'Hacktoberfest 👍

@bfabio bfabio reopened this Dec 31, 2020
@peppelinux peppelinux added the bug Something isn't working label Feb 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants