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/crypto_asn/x509_spec.rb
Views: 11789
# -*- coding:binary -*-1require 'spec_helper'23RSpec.describe Rex::Proto::CryptoAsn1::X509::OtherName do4let(:encoded) do5"\xa0\x2e\x06\x0a\x2b\x06\x01\x04\x01\x82\x37\x14\x02\x03\xa0\x20" +6"\x0c\x1e\x44\x45\x53\x4b\x54\x4f\x50\x2d\x4d\x57\x4a\x39\x4d\x4f\x45" +7"\x43\x24\x40\x6d\x73\x66\x6c\x61\x62\x2e\x6c\x6f\x63\x61\x6c"8end910describe '.parse' do11let(:decoded) { described_class.parse(encoded) }1213it 'decodes otherName correctly' do14expect(decoded[:type_id].value?).to be_truthy15expect(decoded[:type_id]).to be_a RASN1::Types::ObjectId16expect(decoded[:value].value?).to be_truthy17expect(decoded[:value]).to be_a RASN1::Types::Any18end19end2021describe '#to_der' do22it 'encodes correctly' do23instance = described_class.new(24type_id: '1.3.6.1.4.1.311.20.2.3',25value: "\xA0 \f\[email protected]".b26)27expect(instance.to_der).to eq encoded28end29end30end3132RSpec.describe Rex::Proto::CryptoAsn1::X509::GeneralName do33context 'when otherName is chosen' do34let(:encoded) do35"\xa0\x2e\x06\x0a\x2b\x06\x01\x04\x01\x82\x37\x14\x02\x03\xa0\x20\x0c" +36"\x1e\x44\x45\x53\x4b\x54\x4f\x50\x2d\x4d\x57\x4a\x39\x4d\x4f\x45\x43" +37"\x24\x40\x6d\x73\x66\x6c\x61\x62\x2e\x6c\x6f\x63\x61\x6c"38end3940describe '.parse' do41let(:decoded) { described_class.parse(encoded) }4243it 'decodes otherName correctly' do44expect(decoded[:otherName].value?).to be_truthy45expect(decoded[:otherName]).to be_a Rex::Proto::CryptoAsn1::X509::OtherName46end47end4849describe '#to_der' do50it 'encodes correctly' do51instance = described_class.new(52otherName: {53type_id: '1.3.6.1.4.1.311.20.2.3',54value: "\xA0 \f\[email protected]".b55}56).tap { |gn| gn.chosen = 0 }57expect(instance.to_der).to eq encoded58end59end60end6162context 'when rfc822Name is chosen' do63let(:encoded) do64"\x81\x14\x73\x70\x65\x6e\x63\x65\x72\x40\x6d\x73\x66\x6c\x61\x62\x2e" +65"\x6c\x6f\x63\x61\x6c".b66end6768describe '.parse' do69let(:decoded) { described_class.parse(encoded) }7071it 'decodes rfc822Name correctly' do72expect(decoded[:rfc822Name].value?).to be_truthy73expect(decoded[:rfc822Name]).to be_a RASN1::Types::IA5String74expect(decoded[:rfc822Name].value).to eq '[email protected]'75end76end7778describe '#to_der' do79it 'encodes correctly' do80instance = described_class.new(81rfc822Name: '[email protected]'82).tap { |gn| gn.chosen = 1 }83expect(instance.to_der).to eq encoded84end85end86end8788context 'when dNSName is chosen' do89let(:encoded) do90"\x82\x1d\x44\x45\x53\x4b\x54\x4f\x50\x2d\x4d\x57\x4a\x39\x4d\x4f\x45" +91"\x43\x2e\x6d\x73\x66\x6c\x61\x62\x2e\x6c\x6f\x63\x61\x6c".b92end9394describe '.parse' do95let(:decoded) { described_class.parse(encoded) }9697it 'decodes dNSName correctly' do98expect(decoded[:dNSName].value?).to be_truthy99expect(decoded[:dNSName]).to be_a RASN1::Types::IA5String100expect(decoded[:dNSName].value).to eq 'DESKTOP-MWJ9MOEC.msflab.local'101end102end103104describe '#to_der' do105it 'encodes correctly' do106instance = described_class.new(107dNSName: 'DESKTOP-MWJ9MOEC.msflab.local'108).tap { |gn| gn.chosen = 2 }109expect(instance.to_der).to eq encoded110end111end112end113end114115RSpec.describe Rex::Proto::CryptoAsn1::X509::SubjectAltName do116let(:encoded) do117"\x30\x30\xa0\x2e\x06\x0a\x2b\x06\x01\x04\x01\x82\x37\x14\x02\x03\xa0\x20" +118"\x0c\x1e\x44\x45\x53\x4b\x54\x4f\x50\x2d\x4d\x57\x4a\x39\x4d\x4f\x45" +119"\x43\x24\x40\x6d\x73\x66\x6c\x61\x62\x2e\x6c\x6f\x63\x61\x6c"120end121122describe '.parse' do123let(:decoded) { described_class.parse(encoded) }124125it 'decodes GeneralNames correctly' do126expect(decoded[:GeneralNames]).to be_a RASN1::Types::SequenceOf127expect(decoded[:GeneralNames].length).to eq 1128expect(decoded[:GeneralNames].value.first).to be_a Rex::Proto::CryptoAsn1::X509::GeneralName129end130end131132describe '#to_der' do133it 'encodes correctly' do134instance = described_class.new(GeneralNames: [{135otherName: {136type_id: '1.3.6.1.4.1.311.20.2.3',137value: "\xA0 \f\[email protected]".b138}139}]).tap { |san| san[:GeneralNames][0].chosen = 0 }140expect(instance.to_der).to eq encoded141end142end143end144145146