Class: KRB5::Keytab

Inherits:
Object
  • Object
show all
Includes:
Mixin::Packer
Defined in:
lib/krb5/keytab.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixin::Packer

#pack_bytes, #pack_int16, #pack_int32, #pack_int8

Constructor Details

#initializeKeytab

Returns a new instance of Keytab.



24
25
26
# File 'lib/krb5/keytab.rb', line 24

def initialize
  @entries = []
end

Instance Attribute Details

#bytesSting?

Place to store byte array for #to_bytes

Returns:

  • (Sting, nil)


22
23
24
# File 'lib/krb5/keytab.rb', line 22

def bytes
  @bytes
end

#entriesArray<KRB5::Entry>

Keytab entries

Returns:



14
15
16
# File 'lib/krb5/keytab.rb', line 14

def entries
  @entries
end

#source_bytesString?

If parsed, contains source bytes

Returns:

  • (String, nil)


18
19
20
# File 'lib/krb5/keytab.rb', line 18

def source_bytes
  @source_bytes
end

#versionInteger

Keytab version

Returns:

  • (Integer)


10
11
12
# File 'lib/krb5/keytab.rb', line 10

def version
  @version
end

Class Method Details

.load(filename) ⇒ Object



28
29
30
31
# File 'lib/krb5/keytab.rb', line 28

def self.load(filename)
  keytab_data = File.binread(filename)
  KRB5::KeytabParser.parse(keytab_data)
end

Instance Method Details

#==(other) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/krb5/keytab.rb', line 80

def ==(other)
  i[version entries].each do |state|
    return false unless other.send(state) == self.send(state)
  end

  true
end

#save(filename) ⇒ Object



33
34
35
# File 'lib/krb5/keytab.rb', line 33

def save(filename)
  File.binwrite(filename, to_bytes)
end

#to_bytesObject

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)


66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/krb5/keytab.rb', line 66

def to_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