-
Notifications
You must be signed in to change notification settings - Fork 41
Description
When initializing a PEMDocument
(or in my case really a swift-certificates Certificate
) via a pemString:
which comes from a Windows-world service, an error is thrown that it "could not find PEM start marker". The same string piped to openssl x509
is recognized successfully.
I believe the problem is that
swift-asn1/Sources/SwiftASN1/Basic ASN1 Types/PEMDocument.swift
Lines 232 to 239 in 60b2af8
let ( | |
beginDiscriminatorPrefix, | |
beginDiscriminatorInfix, | |
beginDiscriminatorSuffix | |
) = self.firstRangesOf( | |
prefix: "-----BEGIN ", | |
suffix: "-----\n" | |
) |
"-----\n"
and thus does not match on what in my case is "-----\r\n"
. (There may be more "\n"-dependent logic beyond that point but this is the source of the initial failure.)
The workaround I'm using is to pass in myPemString.replacingOccurences(of: "\r\n", with: "\n")
but it would be nice if these libraries could handle line breaks more generically. I'm not sure if this is the most relevant standard but RFC 1421 says:
To represent the encapsulated text of a PEM message, the encoding function's output is delimited into text lines (using local conventions) […]
which I suppose could be argued that the PEM document conventions could to be local to the receiver but in this case my PEM document is using the "local conventions" of the sender :-)