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

Throw Leading or trailing line missing PEM discriminator #148

Open
MohammadTaghiAhadi opened this issue Oct 12, 2023 · 5 comments
Open

Throw Leading or trailing line missing PEM discriminator #148

MohammadTaghiAhadi opened this issue Oct 12, 2023 · 5 comments

Comments

@MohammadTaghiAhadi
Copy link

Hi,
I am using this dependency in my project
but when i want to create cms using CMS.sign() throw Leading or trailing line missing PEM discriminator.

please help me

let data: [UInt8] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
let signatureBytes = try CMS.sign(
data ,
signatureAlgorithm: .ecdsaWithSHA256,
certificate: Certificate.init(pemEncoded: self.globalCertificate),
privateKey: Certificate.PrivateKey(pemEncoded: privateKey.debugDescription)
)

certificate value is

-----BEGIN CERTIFICATE-----
MIIF4DCCBMigAwIBAgIIOrB4pCYzhncwDQYJKoZIhvcNAQELBQAwgakxCzAJBgNV
BAYTAklSMQ8wDQYDVQQIEwZUZWhyYW4xGTAXBgNVBAoTEE5vbi1Hb3Zlcm5tZW50
YWwxEDAOBgNVBAsTB1RlY3Zlc3QxJDAiBgNVBAsTG1NtYXJ0IFRydXN0IEludGVy
bWVkaWF0ZSBDQTE2MDQGA1UEAxMtU21hcnQgdHJ1c3QgcHJpdmF0ZSBpbnRlcm1l
ZGlhdGUgYnJvbnplIENBLUczMB4XDTIzMTAxMjA4NTA0NloXDTI0MTAxMjA4NTA0
NlowdzELMAkGA1UEBhMCSVIxFTATBgNVBAoMDFVuYWZmaWxpYXRlZDERMA8GA1UE
BAwI2KfYrdiv24wxDzANBgNVBCoMBti52YTbjDETMBEGA1UEBRMKMTUyMDI3MDEx
OTEYMBYGA1UEAwwPYWxpIG51bGwgW3NpZ25dMIIBIjANBgkqhkiG9w0BAQEFAAOC
AQ8AMIIBCgKCAQEAp2BLSuEGr47tcrpq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DgQWBBQr8T/7
o/6tUB3Xk88KGvRc+seZJjAOBgNVHQ8BAf8EBAMCBsAwDQYJKoZIhvcNAQELBQAD
ggEBAKe3l+nQ2PuJRuSkiO2d8YxPV0+eAMKvI5fUYwNTrReeIo/kWLtV2p76yAli
l/zOrfeO9PokVXZlbWRxXljVvOkI7oRazzdgcks3vAfU4FFgHdPXGE3LiLNFfd68
SL9l5JdSUxfhR5kDem3A8Agz5OCafbVnE7nS6rkAXy3hcx19W3bPrraKtAkFKPGb
QPwLJfmGF6bNqTgBk7/SIRCsPmuyr7NIGGttQkOBuWcdsapIedQRzhISS1jX7ipO
Tc7v828JeZOT6rlvB/heTXmuwvjxNNmX2e0FPSHHFejqsPN1rsYLYlgJwD6jzv9Z
Jac355Gk2fAfvyfNsS3Q3JUJX5c=
-----END CERTIFICATE-----

@Lukasa
Copy link
Collaborator

Lukasa commented Oct 12, 2023

Can you provide the version of swift-certificates you're using?

@MohammadTaghiAhadi
Copy link
Author

Can you provide the version of swift-certificates you're using?

0.6.0

@dnadoba
Copy link
Member

dnadoba commented Oct 12, 2023

The certificate parses just fine with 0.6.0 and 1.0.1. Instead, the parsing error is very likely coming from the private key:

Certificate.PrivateKey(pemEncoded: privateKey.debugDescription)

.debugDescription doesn't look right. What's the type of privateKey?

@MohammadTaghiAhadi
Copy link
Author

The certificate parses just fine with 0.6.0 and 1.0.1. Instead, the parsing error is very likely coming from the private key:

Certificate.PrivateKey(pemEncoded: privateKey.debugDescription)

.debugDescription doesn't look right. What's the type of privateKey?
type of privateKey is SecKey

@Lukasa
Copy link
Collaborator

Lukasa commented Aug 16, 2024

Sorry this went quiet. The debug description of a SecKey is unlikely to be right. You probably need to use SecKeyCopyExternalRepresentation

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

3 participants