Commit 7fac593e authored by Guus der Kinderen's avatar Guus der Kinderen

OF-1011: Trim each line of a PEM representation

parent a9815e8a
......@@ -705,8 +705,12 @@ public class CertificateManager {
throw new IllegalArgumentException( "Argument 'pemRepresentation' cannot be null or an empty String.");
}
final Collection<X509Certificate> certificates;
try ( InputStream inputStream = new ByteArrayInputStream( pemRepresentation.trim().getBytes() ) )
// The parser is very picky. We should trim each line of the input string.
final String pem = pemRepresentation
.replaceAll( "(?m) +$", "" ) // remove trailing whitespace
.replaceAll( "(?m)^ +", "" ); // remove leading whitespace
try ( InputStream inputStream = new ByteArrayInputStream( pem.getBytes() ) )
{
final CertificateFactory certificateFactory = CertificateFactory.getInstance( "X509" );
return (Collection<X509Certificate>) certificateFactory.generateCertificates( inputStream );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment