CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/proto/kerberos/model/ap_req.rb
Views: 11766
1
# -*- coding: binary -*-
2
3
module Rex
4
module Proto
5
module Kerberos
6
module Model
7
# This class provides a representation of a KRB_AP_REQ definition, containing the Kerberos protocol version number,
8
# the message type KRB_AP_REQ, an options field to indicate any options in use, and the ticket and authenticator
9
# themselves
10
class ApReq < Element
11
# @!attribute pvno
12
# @return [Integer] The protocol version number
13
attr_accessor :pvno
14
# @!attribute msg_type
15
# @return [Integer] The type of the protocol message
16
attr_accessor :msg_type
17
# @!attribute options
18
# @return [Integer] request options, affects processing
19
attr_accessor :options
20
# @!attribute ticket
21
# @return [Rex::Proto::Kerberos::Model::Ticket] The ticket authenticating the client to the server
22
attr_accessor :ticket
23
# @!attribute authenticator
24
# @return [Rex::Proto::Kerberos::Model::EncryptedData] This contains the authenticator, which includes the
25
# client's choice of a subkey
26
attr_accessor :authenticator
27
28
# Rex::Proto::Kerberos::Model::ApReq decoding isn't supported
29
#
30
# @raise [NotImplementedError]
31
def decode(input)
32
raise ::NotImplementedError, 'AP-REQ decoding not supported'
33
end
34
35
# Encodes the Rex::Proto::Kerberos::Model::ApReq into an ASN.1 String
36
#
37
# @return [String]
38
def encode
39
to_asn1.to_der
40
end
41
42
# @return [OpenSSL::ASN1::ASN1Data] The ap_req ASN1Data
43
def to_asn1
44
elems = []
45
46
elems << OpenSSL::ASN1::ASN1Data.new([encode_pvno], 0, :CONTEXT_SPECIFIC)
47
elems << OpenSSL::ASN1::ASN1Data.new([encode_msg_type], 1, :CONTEXT_SPECIFIC)
48
elems << OpenSSL::ASN1::ASN1Data.new([encode_options], 2, :CONTEXT_SPECIFIC)
49
elems << OpenSSL::ASN1::ASN1Data.new([encode_ticket], 3, :CONTEXT_SPECIFIC)
50
elems << OpenSSL::ASN1::ASN1Data.new([encode_authenticator], 4, :CONTEXT_SPECIFIC)
51
52
seq = OpenSSL::ASN1::Sequence.new(elems)
53
54
seq_asn1 = OpenSSL::ASN1::ASN1Data.new([seq], AP_REQ, :APPLICATION)
55
seq_asn1
56
end
57
58
private
59
60
# Encodes the pvno field
61
#
62
# @return [OpenSSL::ASN1::Integer]
63
def encode_pvno
64
bn = OpenSSL::BN.new(pvno.to_s)
65
int = OpenSSL::ASN1::Integer.new(bn)
66
67
int
68
end
69
70
# Encodes the msg_type field
71
#
72
# @return [OpenSSL::ASN1::Integer]
73
def encode_msg_type
74
bn = OpenSSL::BN.new(msg_type.to_s)
75
int = OpenSSL::ASN1::Integer.new(bn)
76
77
int
78
end
79
80
# Encodes the options field
81
#
82
# @return [OpenSSL::ASN1::BitString]
83
def encode_options
84
OpenSSL::ASN1::BitString.new([options].pack('N'))
85
end
86
87
# Encodes the ticket field
88
#
89
# @return [String]
90
def encode_ticket
91
ticket.encode
92
end
93
94
# Encodes the authenticator field
95
#
96
# @return [String]
97
def encode_authenticator
98
authenticator.encode
99
end
100
end
101
end
102
end
103
end
104
end
105
106