This is a gem wrapping the SIP v2 protocol.
http://multimedia.3m.com/mws/media/355361O/sip2-protocol.pdf
Add this line to your application's Gemfile:
gem'sip2'And then execute:
$ bundleSo far only login (code 93) and patron_information (code 63) are supported
client=Sip2::Client.new(host: 'my.sip2.host.net',port: 6001)patron=client.connectdo |connection|
ifconnection.login'sip_username','sip_password'connection.patron_information'patron_username','patron_password'endendputs'Valid patron'ifpatron && patron.authenticated?The Sip2::Client will use TLS if a
SSLContext
is passed in the ssl_context parameter. There are quite a few ways this can be configured, but that will
depend on how the server being connected to is configured. A basic example is:
# Setup a cert store using the system certificates/trust chaincert_store=OpenSSL::X509::Store.newcert_store.set_default_paths# Setup the SSL contextssl_context=OpenSSL::SSL::SSLContext.newssl_context.verify_mode=OpenSSL::SSL::VERIFY_PEER# This is important. We want to verify the certificate is legitimate ssl_context.min_version=OpenSSL::SSL::TLS1_2_VERSION# Generally good practice to enforce the most recent TLS versionssl_context.cert_store=cert_store# Use the certificate store we configured above# Raise an exception if the certificate doesn't check outssl_context.verify_callback=procdo |preverify_ok,context|
raiseOpenSSL::SSL::SSLError,<<~ERROR.stripifpreverify_ok != true || context.error != 0 SSL Verification failed -- Preverify: #{preverify_ok}, Error: #{context.error_string} (#{context.error}) ERRORtrueendclient=Sip2::Client.new(host: 'my.sip2.host.net',port: 6001,ssl_context: ssl_context)If you needed to explicitly specify the certificate to be used there are a few options available to use instead of cert_store (see the documentation for full details and other options):
- ca_file - path to a file containing a CA certificate
- ca_path - path to a directory containing CA certificates
- client_ca - a certificate or array of certificates
- client_cert_cb - callback where an array containing an X509 certificate and key are returned
Be sure to validate that your setup behaves the way you expect it to. Pass in an invalid certificate and see it fails. Pass a mismatching hostname and see it fails. etc.
Bug reports and pull requests are welcome on GitHub at https://github.com/Studiosity/sip2-ruby.
Note that spec tests are appreciated to minimise regressions. Before submitting a PR, please ensure that:
$ rspecand
$ rubocopboth succeed
The gem is available as open source under the terms of the MIT License.