class KRB5::Keytab

Attributes

bytes[RW]

Place to store byte array for to_bytes @return [Sting, nil]

entries[RW]

Keytab entries @return [Array<KRB5::Entry>]

source_bytes[RW]

If parsed, contains source bytes @return [String, nil]

version[RW]

Keytab version @return [Integer]

Public Class Methods

load(filename) click to toggle source
# File lib/krb5/keytab.rb, line 28
def self.load(filename)
  keytab_data = File.binread(filename)
  KRB5::KeytabParser.parse(keytab_data)
end
new() click to toggle source
# File lib/krb5/keytab.rb, line 24
def initialize
  @entries = []
end

Public Instance Methods

==(other) click to toggle source
# File lib/krb5/keytab.rb, line 82
def ==(other)
  %i[version entries].each do |state|
    return false unless other.send(state) == self.send(state)
  end

  true
end
save(filename) click to toggle source
# File lib/krb5/keytab.rb, line 33
def save(filename)
  File.binwrite(filename, to_bytes)
end
to_bytes() click to toggle source

keytab ::=

5 (8 bits)
version (8 bits)
entry1 length (32 bits)
entry1 (entry)
entry2 length (32 bits)
entry2 (entry)
...

entry ::=

principal
timestamp (32 bits)
key version (8 bits)
enctype (16 bits)
key length (16 bits)
key contents
key version (32 bits) [in release 1.14 and later]

principal ::=

count of components (16 bits) [includes realm in version 1]
realm (data)
component1 (data)
component2 (data)
...
name type (32 bits) [omitted in version 1]

data ::=

length (16 bits)
value (length bytes)
# File lib/krb5/keytab.rb, line 66
def to_bytes
  @bytes = []

  # First byte is always a 5
  pack_int8(5)
  pack_int8(version)

  entries.each do |entry|
    entry_bytes = entry.to_bytes
    pack_int32(entry_bytes.length)
    pack_bytes(entry_bytes)
  end

  @bytes.join
end