Application
continuous-integration/drone/push Build encountered an error
Details
continuous-integration/drone/push Build encountered an error
Details
parent
31d1863914
commit
ef008c7a08
|
@ -8,6 +8,7 @@ module Cryptcheck::Engine
|
|||
Dir[fixtures].each { |f| load f }
|
||||
|
||||
autoload :Builder, 'cryptcheck/engine/builder'
|
||||
autoload :Buildable, 'cryptcheck/engine/buildable'
|
||||
autoload :Error, 'cryptcheck/engine/error'
|
||||
autoload :DoubleHash, 'cryptcheck/engine/double_hash'
|
||||
autoload :IdClasses, 'cryptcheck/engine/id_classes'
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
module Cryptcheck::Engine
|
||||
module Buildable
|
||||
def self.included(klass)
|
||||
klass.extend ClassMethod
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
module ClassMethod
|
||||
def buildable(&block)
|
||||
@@builder = Class.new do
|
||||
include Builder
|
||||
end
|
||||
@@builder.instance_eval &block if block_given?
|
||||
end
|
||||
|
||||
def build(&block)
|
||||
builder = @@builder.new
|
||||
builder.instance_eval &block if block_given?
|
||||
builder.resolve
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -582,7 +582,8 @@ module Cryptcheck::Engine
|
|||
raise ProtocolError, 'Unknown curve type %s' % type unless id
|
||||
io.write_uint8 id
|
||||
end
|
||||
|
||||
|
||||
autoload :Context, 'cryptcheck/engine/tls/context'
|
||||
autoload :RecordHeader, 'cryptcheck/engine/tls/record_header'
|
||||
autoload :Handshake, 'cryptcheck/engine/tls/handshake'
|
||||
autoload :ChangeCipherSpec, 'cryptcheck/engine/tls/change_cipher_spec'
|
||||
|
@ -591,15 +592,9 @@ module Cryptcheck::Engine
|
|||
autoload :Application, 'cryptcheck/engine/tls/application'
|
||||
|
||||
def self.read(context, io)
|
||||
header = RecordHeader.read context, io
|
||||
header = RecordHeader.read context, io
|
||||
record_type = header.type
|
||||
record =
|
||||
case (record_type)
|
||||
when Application
|
||||
record_type.read context, io, header.length
|
||||
else
|
||||
record_type.read context, io
|
||||
end
|
||||
record = record_type.read context, io, header.length
|
||||
raise AlertError, record if record.is_a? Alert
|
||||
[header, record]
|
||||
end
|
||||
|
|
|
@ -42,7 +42,7 @@ module Cryptcheck::Engine
|
|||
@description = description
|
||||
end
|
||||
|
||||
def self.read(_, io)
|
||||
def self.read(_, io, _)
|
||||
tmp = io.read_uint8
|
||||
level = LEVELS[tmp]
|
||||
raise ProtocolError, 'Unknown alert level 0x%02X' % tmp unless level
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
module Cryptcheck::Engine
|
||||
module Tls
|
||||
class Application
|
||||
ID = 0x17
|
||||
|
||||
attr_reader :data
|
||||
|
||||
def initialize(data)
|
||||
@data = data
|
||||
end
|
||||
|
||||
def self.read(_, io, length)
|
||||
data = io.read length
|
||||
self.new data
|
||||
end
|
||||
|
||||
def write(_, io)
|
||||
io.write self.data
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -4,7 +4,7 @@ module Cryptcheck::Engine
|
|||
ID = 0x14
|
||||
PAYLOAD = 0x01
|
||||
|
||||
def self.read(_, io)
|
||||
def self.read(_, io, _)
|
||||
payload = io.read_uint8
|
||||
raise ProtocolError, 'Expect change cipher spec payload to be 0x%02X, got 0x%02X' % [PAYLOAD, payload] unless payload == PAYLOAD
|
||||
self.new
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
module Cryptcheck::Engine
|
||||
module Tls
|
||||
class Context
|
||||
include Buildable
|
||||
buildable do
|
||||
attributes :ip, :port, :hostname, :version
|
||||
lists :compression, :cipher
|
||||
build do
|
||||
client = Client.new @ip, @port, @hostname, @version, @compressions, @cipher
|
||||
Context.new client
|
||||
end
|
||||
end
|
||||
|
||||
attr_reader :server, :client
|
||||
|
||||
private
|
||||
|
||||
def initialize(client)
|
||||
@client = client
|
||||
@server = Server.new
|
||||
end
|
||||
|
||||
class Client
|
||||
attr_accessor :random
|
||||
|
||||
def initialize(ip, port, hostname, version, compressions, ciphers)
|
||||
@ip = ip
|
||||
@port = port
|
||||
@hostname = hostname
|
||||
@version = version
|
||||
@compressions = compressions
|
||||
@ciphers = ciphers
|
||||
end
|
||||
end
|
||||
|
||||
class Server
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -27,7 +27,7 @@ module Cryptcheck::Engine
|
|||
ClientKeyExchange, # 0x10
|
||||
).freeze
|
||||
|
||||
def self.read(context, io)
|
||||
def self.read(context, io, _)
|
||||
tmp = io.read_uint8
|
||||
type = TYPES[tmp]
|
||||
raise ProtocolError, 'Unknown handshake type 0x%02X' % tmp unless type
|
||||
|
|
|
@ -7,6 +7,7 @@ module Cryptcheck::Engine
|
|||
Handshake, # 0x16
|
||||
ChangeCipherSpec, # 0x14
|
||||
Alert, # 0x15
|
||||
Application, # 0x17
|
||||
).freeze
|
||||
|
||||
def self.read(_, io)
|
||||
|
|
|
@ -6,7 +6,7 @@ module Cryptcheck::Engine
|
|||
describe '::read' do
|
||||
it 'must read record' do
|
||||
io.init '01 0A'
|
||||
alert = klass.read nil, io
|
||||
alert = klass.read nil, io, nil
|
||||
expect(io).to be_read 2
|
||||
expect(alert).to be_a Alert
|
||||
expect(alert.level).to eq :warning
|
||||
|
@ -15,12 +15,12 @@ module Cryptcheck::Engine
|
|||
|
||||
it 'must reject unknown level' do
|
||||
io.init 'FF 0A'
|
||||
expect { klass.read nil, io }.to raise_error ProtocolError, 'Unknown alert level 0xFF'
|
||||
expect { klass.read nil, io, nil }.to raise_error ProtocolError, 'Unknown alert level 0xFF'
|
||||
end
|
||||
|
||||
it 'must reject unknown description' do
|
||||
io.init '01 FF'
|
||||
expect { klass.read nil, io }.to raise_error ProtocolError, 'Unknown alert description 0xFF'
|
||||
expect { klass.read nil, io, nil }.to raise_error ProtocolError, 'Unknown alert description 0xFF'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -6,14 +6,14 @@ module Cryptcheck::Engine
|
|||
describe '::read' do
|
||||
it 'must read record' do
|
||||
io.init '01'
|
||||
change_cipher_spec = klass.read nil, io
|
||||
change_cipher_spec = klass.read nil, io, nil
|
||||
expect(io).to be_read 1
|
||||
expect(change_cipher_spec).to be_a ChangeCipherSpec
|
||||
end
|
||||
|
||||
it 'must reject unexpected payload' do
|
||||
io.init '02'
|
||||
expect { klass.read nil, io }.to raise_error ProtocolError, 'Expect change cipher spec payload to be 0x01, got 0x02'
|
||||
expect { klass.read nil, io, nil }.to raise_error ProtocolError, 'Expect change cipher spec payload to be 0x01, got 0x02'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ module Cryptcheck::Engine
|
|||
describe '::read' do
|
||||
it 'must read record' do
|
||||
io.init '00 000000'
|
||||
handshake = klass.read nil, io
|
||||
handshake = klass.read nil, io, nil
|
||||
expect(io).to be_read 4
|
||||
expect(handshake).to be_a Handshake
|
||||
expect(handshake.record).to be_a klass::HelloRequest
|
||||
|
@ -14,7 +14,7 @@ module Cryptcheck::Engine
|
|||
|
||||
it 'must reject unknown record' do
|
||||
io.init 'FF 000000'
|
||||
expect { klass.read nil, io }.to raise_error ProtocolError, 'Unknown handshake type 0xFF'
|
||||
expect { klass.read nil, io, nil }.to raise_error ProtocolError, 'Unknown handshake type 0xFF'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue