Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registration failed: premature end of stream (expected to read 1 bytes, got 0 instead) #107

Open
alizarei95 opened this issue Oct 18, 2023 · 9 comments

Comments

@alizarei95
Copy link

Hi there,
I'm developing an authenticator. When I generate create credential response, I get this error in webauthn.io :
Registration failed: premature end of stream (expected to read 1 bytes, got 0 instead)

But, when I'm testing with https://webauthnsample.azurewebsites.net/ or https://webauthntest.identitystandards.io/ everything work well.
What is exact problem?

@MasterKale
Copy link
Collaborator

What is exact problem?

Help me help you. Please provide any details, there's nothing here for me to begin debugging.

@alizarei95
Copy link
Author

Here is full response which webauthn gets:

REGISTRATION RESPONSE 20:10:54.611 (index):508 { "id": "6MpN9tzIRZGkout3Roum5Q", "rawId": "6MpN9tzIRZGkout3Roum5Q", "response": { "attestationObject": "o2NmbXRmcGFja2VkaGF1dGhEYXRhWJR0puqSE8mcL3SyJJKzIM9AJiqUwalQoDl_KSULYIQe8MUAAAAROaVkfhhTRGyh9qebrp9bxwAQ6MpN9tzIRZGkout3Roum5aUBAgMmIAEhWCBjfryIzwhCLOZ6AkIcU_5kHzblft9yFn0AtKB3NiqqOyJYIGZqt2I3Sd6JmXsC76BBgWKN_5_3K8BhThW7crlFe1NQZ2F0dFN0bXSjY2FsZyZjc2lnWEYwRAIgXBHqbGYvMjS0UxcB0c_2X3E7jX-GHgIlQ_syxg59iXYCIHEG1jeNFZGrsA-2Vt0KAUJYCCyUlezAuHZXnKvMBeioY3g1Y4FZAfIwggHuMIIBlKADAgECAgkA5pSqn2hxl74wCgYIKoZIzj0EAwIwQTEkMCIGA1UECgwbVmFuY29zeXMgRGF0YSBTZWN1cml0eSBJbmMuMRkwFwYDVQQDDBBWYW5jb3N5cyBSb290IENBMCAXDTE4MTIyMjE3MTQzNloYDzIwNjgxMjA5MTcxNDM2WjCBgDELMAkGA1UEBhMCQ0ExJDAiBgNVBAoMG1ZhbmNvc3lzIERhdGEgU2VjdXJpdHkgSW5jLjEiMCAGA1UECwwZQXV0aGVudGljYXRvciBBdHRlc3RhdGlvbjEnMCUGA1UEAwweVmFuY29zeXMgQW5kcm9pZCBBdXRoZW50aWNhdG9yMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEf-qpRvI9l6DkSl0VUwaRnggahsN8QWm2C9x7K5sJmHo2qZyYS-pMJjeJM-fnMF3f2nMlosITZJhC83uDt-8pkqMzMDEwDAYDVR0TAQH_BAIwADAhBgsrBgEEAYLlHAEBBAQSBBA5pWR-GFNEbKH2p5uun1vHMAoGCCqGSM49BAMCA0gAMEUCIQDzjysauABP9632mu8CJ_7TwPBb2YhDYoHOClsGPaHbMgIgFDVHo8TeC2Lrp_wObk62e6CEd-vb-QHgbqNCa49nCFo", "clientDataJSON": "eyJ0eXBlIjoid2ViYXV0aG4uY3JlYXRlIiwiY2hhbGxlbmdlIjoiaTQwTHdoc2h5MHhyTjhDakY4N2U3d1RHdWljR2ZERG5yZ19nWnlOOU1zZ0M4YkRBZEdlVHdqUGpfRTlUb1JNNDhoY0pJdHg1b0I4RnhVSm9DU0c3elEiLCJvcmlnaW4iOiJodHRwczovL3dlYmF1dGhuLmlvIn0", "transports": [ "internal", "hybrid" ], "publicKeyAlgorithm": -7, "publicKey": "BGN-vIjPCEIs5noCQhxT_mQfNuV-33IWfQC0oHc2Kqo7Zmq3YjdJ3omZewLvoEGBYo3_n_crwGFOFbtyuUV7U1A", "authenticatorData": "dKbqkhPJnC90siSSsyDPQCYqlMGpUKA5fyklC2CEHvDFAAAAETmlZH4YU0Rsofanm66fW8cAEOjKTfbcyEWRpKLrd0aLpuWlAQIDJiABIVggY368iM8IQizmegJCHFP-ZB825X7fchZ9ALSgdzYqqjsiWCBmardiN0neiZl7Au-gQYFijf-f9yvAYU4Vu3K5RXtTUA" }, "type": "public-key", "clientExtensionResults": {} }

@MasterKale
Copy link
Collaborator

Thank you, we're almost there.

Registration failed: premature end of stream (expected to read 1 bytes, got 0 instead)

The full stack trace you're seeing from Python will be helpful as well, try to include the Python code that causes this too if you can.

@alizarei95
Copy link
Author

Currently I can't run repo locally, can you debug without it?

@MasterKale
Copy link
Collaborator

Oh, I see, this is an issue you're having with the live website. Aright, I'll see if this is enough to work with.

@alizarei95
Copy link
Author

Is there any update here?
@MasterKale

@MasterKale
Copy link
Collaborator

Is there any update here?

I was at a conference all week so I didn't have a chance to dig into this. I'll let you know how things go when I can.

@alizarei95
Copy link
Author

Any update? @MasterKale

@MasterKale
Copy link
Collaborator

Okay, I recreated in a simple call to verify_registration_response():

from webauthn import verify_registration_response
from webauthn.helpers import base64url_to_bytes

def verify():
    resp = verify_registration_response(
        credential="""{
            "id": "6MpN9tzIRZGkout3Roum5Q",
            "rawId": "6MpN9tzIRZGkout3Roum5Q",
            "response": {
                "attestationObject": "o2NmbXRmcGFja2VkaGF1dGhEYXRhWJR0puqSE8mcL3SyJJKzIM9AJiqUwalQoDl_KSULYIQe8MUAAAAROaVkfhhTRGyh9qebrp9bxwAQ6MpN9tzIRZGkout3Roum5aUBAgMmIAEhWCBjfryIzwhCLOZ6AkIcU_5kHzblft9yFn0AtKB3NiqqOyJYIGZqt2I3Sd6JmXsC76BBgWKN_5_3K8BhThW7crlFe1NQZ2F0dFN0bXSjY2FsZyZjc2lnWEYwRAIgXBHqbGYvMjS0UxcB0c_2X3E7jX-GHgIlQ_syxg59iXYCIHEG1jeNFZGrsA-2Vt0KAUJYCCyUlezAuHZXnKvMBeioY3g1Y4FZAfIwggHuMIIBlKADAgECAgkA5pSqn2hxl74wCgYIKoZIzj0EAwIwQTEkMCIGA1UECgwbVmFuY29zeXMgRGF0YSBTZWN1cml0eSBJbmMuMRkwFwYDVQQDDBBWYW5jb3N5cyBSb290IENBMCAXDTE4MTIyMjE3MTQzNloYDzIwNjgxMjA5MTcxNDM2WjCBgDELMAkGA1UEBhMCQ0ExJDAiBgNVBAoMG1ZhbmNvc3lzIERhdGEgU2VjdXJpdHkgSW5jLjEiMCAGA1UECwwZQXV0aGVudGljYXRvciBBdHRlc3RhdGlvbjEnMCUGA1UEAwweVmFuY29zeXMgQW5kcm9pZCBBdXRoZW50aWNhdG9yMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEf-qpRvI9l6DkSl0VUwaRnggahsN8QWm2C9x7K5sJmHo2qZyYS-pMJjeJM-fnMF3f2nMlosITZJhC83uDt-8pkqMzMDEwDAYDVR0TAQH_BAIwADAhBgsrBgEEAYLlHAEBBAQSBBA5pWR-GFNEbKH2p5uun1vHMAoGCCqGSM49BAMCA0gAMEUCIQDzjysauABP9632mu8CJ_7TwPBb2YhDYoHOClsGPaHbMgIgFDVHo8TeC2Lrp_wObk62e6CEd-vb-QHgbqNCa49nCFo",
                "clientDataJSON": "eyJ0eXBlIjoid2ViYXV0aG4uY3JlYXRlIiwiY2hhbGxlbmdlIjoiaTQwTHdoc2h5MHhyTjhDakY4N2U3d1RHdWljR2ZERG5yZ19nWnlOOU1zZ0M4YkRBZEdlVHdqUGpfRTlUb1JNNDhoY0pJdHg1b0I4RnhVSm9DU0c3elEiLCJvcmlnaW4iOiJodHRwczovL3dlYmF1dGhuLmlvIn0",
                "transports": [
                "internal",
                "hybrid"
                ],
                "publicKeyAlgorithm": -7,
                "publicKey": "BGN-vIjPCEIs5noCQhxT_mQfNuV-33IWfQC0oHc2Kqo7Zmq3YjdJ3omZewLvoEGBYo3_n_crwGFOFbtyuUV7U1A",
                "authenticatorData": "dKbqkhPJnC90siSSsyDPQCYqlMGpUKA5fyklC2CEHvDFAAAAETmlZH4YU0Rsofanm66fW8cAEOjKTfbcyEWRpKLrd0aLpuWlAQIDJiABIVggY368iM8IQizmegJCHFP-ZB825X7fchZ9ALSgdzYqqjsiWCBmardiN0neiZl7Au-gQYFijf-f9yvAYU4Vu3K5RXtTUA"
            },
            "type": "public-key",
            "clientExtensionResults": {}
        }""",
        expected_challenge=base64url_to_bytes("i40Lwhshy0xrN8CjF87e7wTGuicGfDDnrg_gZyN9MsgC8bDAdGeTwjPj_E9ToRM48hcJItx5oB8FxUJoCSG7zQ"),
        expected_origin="https://webauthn.io",
        expected_rp_id="webauthn.io",
    )

    print(resp)

verify()

The error happens when attempting to read extensions in authenticator data:

Traceback (most recent call last):
  File "/Users/matt/Developer/py_webauthn/webauthn/helpers/parse_cbor.py", line 16, in parse_cbor
    to_return = cbor2.loads(data)
                ^^^^^^^^^^^^^^^^^
_cbor2.CBORDecodeEOF: premature end of stream (expected to read 1 bytes, got 0 instead)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/matt/Developer/py_webauthn/./107-end-of-stream.py", line 30, in <module>
    verify()
  File "/Users/matt/Developer/py_webauthn/./107-end-of-stream.py", line 5, in verify
    resp = verify_registration_response(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/matt/Developer/py_webauthn/webauthn/registration/verify_registration_response.py", line 153, in verify_registration_response
    attestation_object = parse_attestation_object(response.attestation_object)  # TODO: Issue #173
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/matt/Developer/py_webauthn/webauthn/helpers/parse_attestation_object.py", line 16, in parse_attestation_object
    auth_data=parse_authenticator_data(attestation_dict["authData"]),
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/matt/Developer/py_webauthn/webauthn/helpers/parse_authenticator_data.py", line 91, in parse_authenticator_data
    extension_object = parse_cbor(val[pointer:])
                       ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/matt/Developer/py_webauthn/webauthn/helpers/parse_cbor.py", line 18, in parse_cbor
    raise InvalidCBORData(
webauthn.helpers.exceptions.InvalidCBORData: Could not decode CBOR data

Investigating...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants