
클라이언트에 여러 키가 있는 mtls를 설정하려고 하는 상황이 있습니다. 어떤 별칭이 작동하는지 확인하는 방법을 찾을 수 없는 것 같으니 여기 어딘가에서 나를 안내할 수 있습니까?
Java는 키 저장소에 여러 개의 키가 있지만 그 중 하나만 서버 신뢰 저장소에 있는 경우 사용할 별칭을 어떻게 결정합니까?
업데이트
현재 다음 코드가 있습니다
public class ConfigurableAliasKeyManagerFactory extends KeyManagerFactory {
...
private static final class ConfigurableAliasKeyManagerFactorySpi extends KeyManagerFactorySpi {
...
@Override
protected KeyManager[] engineGetKeyManagers() {
return Arrays.stream(this.delegate.getKeyManagers())
.filter(X509ExtendedKeyManager.class::isInstance)
.map(X509ExtendedKeyManager.class::cast)
.map(this::wrap)
.toArray(KeyManager[]::new);
}
}
...
protected static final class ConfigurableAliasKeyManager extends X509ExtendedKeyManager {
@Getter
private final String alias;
public ConfigurableAliasKeyManager(X509ExtendedKeyManager keyManager, String alias) {
this.delegate = keyManager;
this.alias = alias;
}
@Override
public String chooseClientAlias(String[] keyType, Principal[] issuers, Socket socket) {
return (this.alias != null) ? this.alias : this.delegate.chooseClientAlias(keyType, issuers, socket);
}
...
}
}
하지만 중단점이 작동하지 않는 것 같아서 chooseClientAlias
호출되지 않는 것 같습니다.
답변1
많은 것들이 있지만 가장 쉬운 것은 예제를 게시하는 것입니다.
https://github.com/jrgleason/spring-boot-mtls
이것은 올바르게 작동하는 것 같습니다. 실패 사례를 테스트하려면 클라이언트 별칭을 client3과 같은 것으로 변경하세요.