concept symmetric key in category spring

appears as: symmetric key, symmetric keys, symmetric key, A symmetric key
Spring Security in Action

This is an excerpt from Manning's book Spring Security in Action.

A better approach to test the authenticity of the communication is the use of cryptographic signatures (Figure 1.14). With this approach, a key is used to sign the request and the response. You don’t need to send the key on the wire, which is an advantage over static authorization values. The parties can use their key to validate the signature. The implementation can be done using two asymmetric key pairs. This approach assumes that we never exchange the private key. You can also find a simpler version in which we use a symmetric key, which requires a first-time exchange for configuration. The disadvantage is that the computation of a signature consumes more resources.

In this example, we’ll implement signing with a symmetric key. This approach implies that both the Authorization Server and the Resource Server know and use the same key. The Authorization Server signs the token with the key, and the Resource Server validates the signature using the same key (figure 15.3).

Figure 15.3 Using symmetric keys: Both the Authorization Server and the Resource Server share the same key. The Authorization Server uses the key to sign the issues tokens, and the Resource Server uses the key to validate the signature.

We configure a JwtTokenStore in the same way we did in chapter 14 for the JdbcTokenStore. Additionally, we’ll have to define an object of type JwtAccessTokenConverter. With the JwtAccessTokenConverter, we configure how the Authorization Server validates the token—in our case, using a symmetric key. Listing 15.1 shows you how to configure the JwtTokenStore in the configuration class.

Listing 15.1 Configuring the JwtTokenStore
@Configuration
@EnableAuthorizationServer
public class AuthServerConfig
  extends AuthorizationServerConfigurerAdapter {
 
  @Value("${jwt.key}")
  private String jwtKey;    #A
 
  @Autowired
  private AuthenticationManager authenticationManager;
 
  @Override
  public void configure(
    ClientDetailsServiceConfigurer clients)
    throws Exception {
      clients.inMemory()
             .withClient("client")
             .secret("secret")
             .authorizedGrantTypes("password", "refresh_token")
             .scopes("read");
    }
 
  @Override
  public void configure(
    AuthorizationServerEndpointsConfigurer endpoints) {
      endpoints
        .authenticationManager(authenticationManager)
        .tokenStore(tokenStore())    #B
        .accessTokenConverter(    #B
           jwtAccessTokenConverter());    #B
  }
 
  @Bean
  public TokenStore tokenStore() {
    return new JwtTokenStore(    #C
      jwtAccessTokenConverter());    #C
  }
 
  @Bean
  public JwtAccessTokenConverter jwtAccessTokenConverter() {
    var converter = new JwtAccessTokenConverter();
    converter.setSigningKey(jwtKey);    #D
    return converter;
 }
}

#A We get the value of the symmetric key from the application.properties file.

While working as a consultant for different projects, I’ve seen cases in which symmetric keys were exchanged by mail or other unsecured channels. Never do this! A symmetric key is a private key. One having such a key can use it to access the system. My rule of thumb is: “If you need to share the key outside your system, it shouldn’t be symmetric.”