Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/spec/lib/rex/proto/gss/channel_binding_spec.rb
Views: 11789
# -*- coding:binary -*-1require 'spec_helper'2require 'rex/text'34RSpec.describe Rex::Proto::Gss::ChannelBinding do5let(:peer_cert) do6OpenSSL::X509::Certificate.new(<<~CERTIFICATE7-----BEGIN CERTIFICATE-----8MIIGijCCBXKgAwIBAgITNQAAAAKLvdEO5Pbo1AAAAAAAAjANBgkqhkiG9w0BAQsF9ADBcMRUwEwYKCZImiZPyLGQBGRYFbG9jYWwxHTAbBgoJkiaJk/IsZAEZFg1sYWJz10MWNvbGxhYnUwMSQwIgYDVQQDExtsYWJzMWNvbGxhYnUwLVNSVi1BRERTMDEtQ0Ew11HhcNMjQwNDE5MTcyMzAwWhcNMjUwNDE5MTcyMzAwWjApMScwJQYDVQQDEx5TUlYt12QUREUzAxLmxhYnMxY29sbGFidTAubG9jYWwwggEiMA0GCSqGSIb3DQEBAQUAA4IB13DwAwggEKAoIBAQCr/zrK2bEDVkBewjWznxhH9gW6HQ+1cC/gx8lOVF8mju/hTmTQ14J4lMvGyub3yUG0K5vt17veGf3fTaGBT9tn3yQf1IBMF71hiswQCZ0KV2Hti4Zd1b15eWmw0UPF1xtpRHznAIjmKDHLvXjzEHnw/DNxPMbSI9Xu7x2iy6tGumh1neb4ojcK16q8Fni0q3HT9WqybsD1cMchzNWgz+KPiimjusCujLGu+aGJdr5vMpg2Ho9GSt4OaT178/g6+XUFWcD6xi7lcoNlb1WYGexWZ0TZFzO36g/7FWsy+1E79/8XbyOTeePk3PHV18QK/xS8nrYoCjgHOp+6gNaEGcXrUsoMt/yqaxAgMBAAGjggN2MIIDcjAvBgkrBgEE19AYI3FAIEIh4gAEQAbwBtAGEAaQBuAEMAbwBuAHQAcgBvAGwAbABlAHIwHQYDVR0l20BBY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LTIxLTc5NTUwMy0zMDUwMzM0Mzk0LTM2NDQ037MDA2MjQtMTAwMDANBgkqhkiG9w0BAQsFAAOCAQEAw/1kFOsPbYc1J0JWPqfnhKmO38TCim8r4pIckZZpkgLXjAzfHdJLYt9O5s7I48lojqdeg61EpjVxj1h1BT3aTDk+TS39hW3WlvpscOKdu4+tqpJ96Buf6Y91QWDyKn7ZRM9Mq3GbTqkEFMLczGAqBWuqUDHG40Lo7tyBfLw5mMAKV7xFHPjH5nQ0tzfymp+yuP5TKCzTf7v06621PPZ1xVeZTQxAmx41e9ViEMYy5IC+okMsIXg6+wbynubxL6CzZFZhwJtujmRfHABuydV17El2NrUW1pdQ42cFUXmAXwiCvGBSkr7QfsMGx70pmP+VBQKkBRWaCo00Vj0ukRFV5r/BtKbZp0+w==43-----END CERTIFICATE-----44CERTIFICATE45)46end4748describe '.create' do49let(:channel_binding) { described_class.create(peer_cert) }5051# this ensures API compatibility with the underlying Net::NTLM::ChannelBinding class which would use the certificate52# directly however that couples the calculation logic with the object type53it 'should DER encode the certificate' do54der_encoded = peer_cert.to_der55expect(peer_cert).to receive(:to_der).with(no_args).and_return(der_encoded).exactly(1).times56expect(described_class).to receive(:new).with(der_encoded).exactly(1).times57described_class.create(peer_cert)58end5960describe '#channel' do61it 'should be the DER encoded certificate data' do62expect(channel_binding.channel).to eq peer_cert.to_der63end64end6566describe '#channel_hash' do67let(:channel_hash) { channel_binding.channel_hash }68it 'should be an OpenSSL::Digest' do69expect(channel_hash).to be_a OpenSSL::Digest70end7172it 'should be correct' do73expect(channel_hash.digest.unpack1('H*')).to eq 'f79b1e5d605710356244f2d5005c1b57895c88dcfbbae22a15349b192ddca597'74end75end7677describe '#digest_algorithm' do78it 'should be SHA256' do79expect(channel_binding.digest_algorithm).to eq 'SHA256'80end81end8283describe '#unique_prefix' do84it 'should be "tls-server-end-point"' do85expect(channel_binding.unique_prefix).to eq 'tls-server-end-point'86end87end88end8990describe '.from_tls_cert' do91let(:channel_binding) { described_class.from_tls_cert(peer_cert) }9293it 'should check the signature algorithm' do94expect(peer_cert).to receive(:signature_algorithm).with(no_args).and_call_original.at_least(1).times95described_class.from_tls_cert(peer_cert)96end9798describe '#channel' do99it 'should be the DER encoded certificate data' do100expect(channel_binding.channel).to eq peer_cert.to_der101end102end103104describe '#channel_hash' do105let(:channel_hash) { channel_binding.channel_hash }106it 'should be an OpenSSL::Digest' do107expect(channel_hash).to be_a OpenSSL::Digest108end109110it 'should be correct' do111expect(channel_hash.digest.unpack1('H*')).to eq 'f79b1e5d605710356244f2d5005c1b57895c88dcfbbae22a15349b192ddca597'112end113end114115describe '#digest_algorithm' do116it 'should be SHA256' do117expect(channel_binding.digest_algorithm).to eq 'SHA256'118end119end120121describe '#unique_prefix' do122it 'should be "tls-server-end-point"' do123expect(channel_binding.unique_prefix).to eq 'tls-server-end-point'124end125end126end127end128129130