Commit b7216469 authored by Dave Cridland's avatar Dave Cridland

Merge pull request #464 from guusdk/OF-1011

OF-1011: Trim each line of a PEM representation
parents 15c4b551 7fac593e
...@@ -705,8 +705,12 @@ public class CertificateManager { ...@@ -705,8 +705,12 @@ public class CertificateManager {
throw new IllegalArgumentException( "Argument 'pemRepresentation' cannot be null or an empty String."); throw new IllegalArgumentException( "Argument 'pemRepresentation' cannot be null or an empty String.");
} }
final Collection<X509Certificate> certificates; // The parser is very picky. We should trim each line of the input string.
try ( InputStream inputStream = new ByteArrayInputStream( pemRepresentation.trim().getBytes() ) ) 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" ); final CertificateFactory certificateFactory = CertificateFactory.getInstance( "X509" );
return (Collection<X509Certificate>) certificateFactory.generateCertificates( inputStream ); 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