Skip to content

[v12] Fix SAML certificate decoding when data is padded#30451

Merged
tigrato merged 1 commit intobranch/v12from
bot/backport-30372-branch/v12
Aug 14, 2023
Merged

[v12] Fix SAML certificate decoding when data is padded#30451
tigrato merged 1 commit intobranch/v12from
bot/backport-30372-branch/v12

Conversation

@tigrato
Copy link
Copy Markdown
Contributor

@tigrato tigrato commented Aug 14, 2023

Backport #30372 to branch/v12

This PR fixes an issue when the SAML connector's certificate contains
spaces or tabs in every line.
Spaces and tabs do not belong to base64 dictionary and the decoding
operation fails.
An example of a certificate that we failed to parse:

```xml
<ds:X509Certificate>
    MIIDpDCCAoygAwIBAgIGAVvvlUB6MA0GCSqGSIb3DQEBCwUAMIGSMQswCQYDVQQGEwJVUzETMBEG
    A1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNU2FuIEZyYW5jaXNjbzENMAsGA1UECgwET2t0YTEU
    MBIGA1UECwwLU1NPUHJvdmlkZXIxEzARBgNVBAMMCmRldi04MTMzNTQxHDAaBgkqhkiG9w0BCQEW
    DWluZm9Ab2t0YS5jb20wHhcNMTcwNTA5MjMzODQ3WhcNMjcwNTA5MjMzOTQ3WjCBkjELMAkGA1UE
    BhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcMDVNhbiBGcmFuY2lzY28xDTALBgNV
    BAoMBE9rdGExFDASBgNVBAsMC1NTT1Byb3ZpZGVyMRMwEQYDVQQDDApkZXYtODEzMzU0MRwwGgYJ
    KoZIhvcNAQkBFg1pbmZvQG9rdGEuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA
    ltQB+ZTGKoaNiWQRZ/bzl9oNmbjFyLiVlDASaYnuv1yBx70/Tzr9VXn0gWkl5yH0zIpzREvR5qM1
    VAaH3dgNbxTg15f0e5xDk7r5ggS11mX5p8S1Ca9UQmqhRRv7jhMJxHbCy4rFV5jO/uyNQDaMZLPd
    zFuzpwKaWhy/UCQ3lDmNzxp3Q6T3FULV+fvs7tJp+8p6qfpoGkANGVfs/Jx/kgbbk0JZG2wk4VVl
    b1rZTZJWQ6hCLwTAsD/WixcUx1BFTXmqoZTYNETATVJQ+bEMCVf8K4hxbH6hEgjoL//AE9zgpa1m
    uvKwevYBvYZ/+VRy+It3d9mq73AdrG9vchE3qQIDAQABMA0GCSqGSIb3DQEBCwUAA4IBAQASANAj
    8JQdBdKIrrbU6n1egwETwkOUwWyUja/5t+C/RIZPuKP5XmsUhFecbCrML2+M7HG0l5leqyD3u5pS
    yhyBz99QWZegoRJy05tciuQUCyPrp6zDzl5De3byq5WQ6Ke+uiRb2GFdDNDhLuMlE48aLWyjm4qh
    31Q0/wAWJ1zwmrYxu4p/OhZemU7myuSF5tp35rzV3CPRN31d2UcZAwzMUgwKkCE3yT1o+lLskg/k
    C7yZIZM0DuazwkaenExrncvPtF6KL7eccudcknNjhRjFD3Yx1nNXgbVRHvVaElm0YxLiLcl8l0Rn
    pHM7WKwFyW1dvEDax3BGj9/cbKvpvcwR
</ds:X509Certificate>
```

This PR replaces the old `strings.TrimSpace` - this function only trims
the spaces leading and trailing spaces - with `strings.Fields` that
splits the string per `unicode.IsSpace` and returns a list of strings
without spaces and without new lines.

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
@tigrato tigrato enabled auto-merge August 14, 2023 17:31
@tigrato tigrato added this pull request to the merge queue Aug 14, 2023
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 14, 2023
@tigrato tigrato added this pull request to the merge queue Aug 14, 2023
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 14, 2023
@tigrato tigrato added this pull request to the merge queue Aug 14, 2023
Merged via the queue into branch/v12 with commit 7d4b760 Aug 14, 2023
@tigrato tigrato deleted the bot/backport-30372-branch/v12 branch August 14, 2023 19:26
@camscale camscale mentioned this pull request Aug 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants