Class: CryptoToolbox::Oracles::PaddingOracle::MemoryOracle

Inherits:
Object
  • Object
show all
Defined in:
lib/crypto-toolbox/oracles/padding_oracle/memory_oracle.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMemoryOracle

Returns a new instance of MemoryOracle.



29
30
31
32
33
# File 'lib/crypto-toolbox/oracles/padding_oracle/memory_oracle.rb', line 29

def initialize
  @key   = SecureRandom.random_bytes(16)
  @iv    = SecureRandom.random_bytes(16)
  @secret_plaintext = CryptBuffer.from_base64(PlaintextSelection::sample).str
end

Instance Attribute Details

#secret_plaintextObject (readonly)

for result validation only. I can trust myself



27
28
29
# File 'lib/crypto-toolbox/oracles/padding_oracle/memory_oracle.rb', line 27

def secret_plaintext
  @secret_plaintext
end

Instance Method Details

#connectObject



39
# File 'lib/crypto-toolbox/oracles/padding_oracle/memory_oracle.rb', line 39

def connect; end

#disconnectObject



40
# File 'lib/crypto-toolbox/oracles/padding_oracle/memory_oracle.rb', line 40

def disconnect; end

#sample_ciphertextObject



35
36
37
# File 'lib/crypto-toolbox/oracles/padding_oracle/memory_oracle.rb', line 35

def sample_ciphertext
  @ciphertext ||= generate_ciphertext
end

#valid_padding?(input, custom_block_amount = nil) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
51
# File 'lib/crypto-toolbox/oracles/padding_oracle/memory_oracle.rb', line 42

def valid_padding?(input,custom_block_amount=nil)
  # openssl will throw on invalid padding
  begin
    block  = CryptBuffer(input)
    result = CryptBuffer(decrypt(block))
    result.validate_padding!
  rescue CryptBufferConcern::Padding::InvalidPkcs7Padding => ex
    false
  end
end