Skip to content

Decoding of key from file specified by spring.security.oauth2.resourceserver.public-key-location fails on Windows #16624

@wilkinsona

Description

@wilkinsona

When the key is written to a file that uses \r\n line separators (as is typically the case on Windows) decoding fails reporting an illegal Base64 character. The root cause looks something like this:

 Caused by: java.lang.IllegalArgumentException: Illegal base64 character d
  at java.util.Base64$Decoder.decode0(Base64.java:714)
  at java.util.Base64$Decoder.decode(Base64.java:526)
  at java.util.Base64$Decoder.decode(Base64.java:549)
  at org.springframework.boot.autoconfigure.security.oauth2.resource.reactive.ReactiveOAuth2ResourceServerJwkConfiguration.getKeySpec(ReactiveOAuth2ResourceServerJwkConfiguration.java:76)
  at org.springframework.boot.autoconfigure.security.oauth2.resource.reactive.ReactiveOAuth2ResourceServerJwkConfiguration.jwtDecoderByPublicKeyValue(ReactiveOAuth2ResourceServerJwkConfiguration.java:69)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:498)
  at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
  ... 81 more

Switching to a MIME decoder should fix the problem on Windows while not adversely affecting other platforms.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions