Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

OpenSSL::SSL::SSLContext#groups=

ctx.groups = groups_list
ctx.ecdh_curves = groups_list

Sets the list of supported groups for key agreement for this context.

For a TLS client, the list is directly used in the “supported_groups” extension. For a server, the list is used by OpenSSL to determine the set of shared supported groups. OpenSSL will pick the most appropriate one from it.

ecdh_curves= is a deprecated alias for groups=.

See also the man page SSL_CTX_set1_groups_list(3).

Example

Example
ctx1 = OpenSSL::SSL::SSLContext.new
ctx1.groups = "X25519:P-256"
Thread.new {
  ssl = OpenSSL::SSL::SSLSocket.new(tcp_svr.accept, ctx1)
  ssl.accept
}

ctx2 = OpenSSL::SSL::SSLContext.new
ctx2.groups = "P-256"
cli = OpenSSL::SSL::SSLSocket.new(tcp_sock, ctx2)
cli.connect

p cli.tmp_key.group.curve_name
# => "prime256v1" (is an alias for NIST P-256)