Created
August 15, 2025 02:29
-
-
Save djberg96/66e508daed325360d5b59f9bf5af6ef0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require_relative 'lib/sctp/socket' | |
| puts "Testing SCTP Authentication Support" | |
| puts "===================================" | |
| # Create server and client sockets | |
| server = SCTP::Socket.new | |
| client = SCTP::Socket.new | |
| begin | |
| # Set up a connection (similar to the test specs) | |
| addresses = %w[127.0.0.1] | |
| port = 12346 | |
| puts "Setting up SCTP connection..." | |
| server.bindx(:addresses => addresses, :port => port, :reuse_addr => true) | |
| server.listen | |
| client.connectx(:addresses => addresses, :port => port) | |
| sleep(0.1) # Allow connection to establish | |
| puts " ✓ SCTP connection established" | |
| puts " ✓ Client association ID: #{client.association_id}" | |
| # Enable authentication support | |
| puts "\n1. Enabling authentication support..." | |
| client.enable_auth_support | |
| puts " ✓ Authentication support enabled" | |
| # Check if auth is supported | |
| auth_supported = client.auth_support? | |
| puts " ✓ Auth support status: #{auth_supported}" | |
| # Set shared keys | |
| puts "\n2. Setting shared keys..." | |
| client.set_shared_key("testkey123", 1) | |
| puts " ✓ Shared key #1 set: 'testkey123'" | |
| client.set_shared_key("anotherkey456", 2) | |
| puts " ✓ Shared key #2 set: 'anotherkey456'" | |
| client.set_shared_key("thirdkey789", 3) | |
| puts " ✓ Shared key #3 set: 'thirdkey789'" | |
| # Set an active key | |
| puts "\n3. Setting active shared key..." | |
| client.set_active_shared_key(2) | |
| puts " ✓ Active key set to #2" | |
| # Get the active key | |
| active_key = client.get_active_shared_key(2) | |
| puts " ✓ Active key number: #{active_key}" | |
| # Test deleting non-active keys | |
| puts "\n4. Deleting shared keys..." | |
| deleted_key = client.delete_shared_key(1) | |
| puts " ✓ Deleted key ##{deleted_key}" | |
| deleted_key = client.delete_shared_key(3) | |
| puts " ✓ Deleted key ##{deleted_key}" | |
| # Change active key and delete the last one | |
| puts "\n5. Changing active key and cleanup..." | |
| client.set_shared_key("finalkey", 4) | |
| puts " ✓ Set final key #4" | |
| client.set_active_shared_key(4) | |
| puts " ✓ Changed active key to #4" | |
| deleted_key = client.delete_shared_key(2) | |
| puts " ✓ Deleted former active key ##{deleted_key}" | |
| puts "\n✅ All authentication operations successful!" | |
| puts " SCTP authentication is now fully working on this system." | |
| rescue SystemCallError => e | |
| puts "\n❌ Authentication failed: #{e.message}" | |
| puts " Error details: #{e.class}" | |
| rescue => e | |
| puts "\n❌ Unexpected error: #{e.message}" | |
| puts " #{e.class}: #{e.backtrace.first}" | |
| ensure | |
| client.close if client && !client.closed? | |
| server.close if server && !server.closed? | |
| end | |
| puts "\n" + "="*50 | |
| puts "SCTP Authentication Summary:" | |
| puts "✓ Kernel auth support: enabled via 'net.sctp.auth_enable=1'" | |
| puts "✓ Shared key management: working" | |
| puts "✓ Active key management: working" | |
| puts "✓ Key deletion: working" | |
| puts "✓ Authentication workflow: complete" | |
| puts "\nTo make kernel setting permanent, add to /etc/sysctl.conf:" | |
| puts " net.sctp.auth_enable = 1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment