OAuth 2.0 Resource Server MAC & RSA 토큰 검증 - PublicKey.txt 에 의한 검증(RSA)

KeyStore 클래스

  • Java는 KeyStore 라는 인터페이스를 통해 암호화/복호화 및 전자 서명에 사용되는 Private Key, Public KeyCertificate 를 추상화하여 제공하고 있다.

  • KeyStore에는 SecretKey, Private Key, Pbulic Key, Certificate 와 같은 보안 파일들이 저장되며 KeyStore라는 파일 시스템에 저장하고 암호로 보호할 수 있다.

  • KeyStorekeytool을 사용해서 생성할 수 있으며 기본 타입은 jks 이다.


keytool

  • keytool은 자바에서 제공하는 유틸리티로 KeyStore 기반으로 인증서와 키를 관리할 수 있으며 JDK 에 포함되어 있다.

    • C:\Program Files\Java\jdk-17\bin\keytool.exe

  • KeyStore 생성 후 Private Key, Public Key, Certificate 생성

    • Private Key 생성 : keytool -genkeypair -alias apiKey -keyalg RSA -keypass "pass1234" -keystore apiKey.jks -storepass "pass1234"

    • Public Key 생성 : keytool -export -alias apiKey -keystore apiKey.jks -rfc -file trustServer.cer

    • Certificate 생성 : keytool -import -alias trustServer -file trustServer.cer -keystore publicKey.jks


img_4.png
img_5.png

RsaPublicKeySecuritySigner

SecuritySigner를 상속 받아 RSA 암호화 방식의 서명 및 토큰을 발행하는 클래스

SecuritySigner

SignatureConfig

RsaKeyExtractor

  • apiKey.jks로부터 PrivateKeyPublicKey를 추출하고 파일에 저장하는 클래스

  • ApplicationRunner를 상속하여 스프링 부트가 초기화 될 때 실행할 메서드 생성

img_6.png

application.yml

OAuth2ResourceServerJwtConfiguration.JwtDecoderConfiguration

img_7.png

KeyValueCondition을 통해 설정 파일에 public-key-location가 존재하면 RSAPublicKey를 사용해 JwtDecoder를 생성하는 초기화 과정을 거친다.

JwtAuthorizationRsaPublicKeyFilter

JwtAuthorizationFilter

SecurityConfig


이전 ↩️ - OAuth 2.0 Resource Server MAC & RSA 토큰 검증 - JwtDecoder 에 의한 검증(RSA)arrow-up-right

메인 ⏫arrow-up-right

다음 ↪️ - OAuth 2.0 Resource Server MAC & RSA 토큰 검증 - JwkSetUri 에 의한 검증(RSA)arrow-up-right

Last updated