@@ -67,7 +67,7 @@ def extract_user_and_realm(certificate, username, realm)
67
67
certificate . extensions . select { |ext | ext . oid == 'subjectAltName' } . each do |san_extension |
68
68
begin
69
69
asn_san = OpenSSL ::ASN1 . decode ( san_extension )
70
- asn_san_value = asn_san . value . find { |value | value . is_a? OpenSSL ::ASN1 ::OctetString }
70
+ asn_san_value = asn_san . value . find { |value | value . is_a? OpenSSL ::ASN1 ::OctetString }
71
71
72
72
if asn_san_value . nil?
73
73
raise ArgumentError , 'Invalid certificate provided: unable to decode SAN'
@@ -95,7 +95,7 @@ def extract_user_and_realm(certificate, username, realm)
95
95
elsif san_entry . tag == 2 # dNSName
96
96
parts = san_entry . value . split ( '.' )
97
97
if parts . length == 1
98
- user = san_entry
98
+ user = san_entry . value # Corrected to extract string value
99
99
domain = ''
100
100
else
101
101
user = parts [ 0 ] + '$'
@@ -110,15 +110,26 @@ def extract_user_and_realm(certificate, username, realm)
110
110
end
111
111
112
112
unless realm . nil? # and also username, since it's both or neither
113
- unless results . map { |x | x . map ( &:downcase ) } . include? ( [ username . downcase , realm . downcase ] )
114
- # If we've been provided an override but can't find them in a SAN, give a warning
113
+ normalized_results = results . map do |pair |
114
+ pair . map do |value |
115
+ if value . is_a? ( String )
116
+ value . downcase
117
+ elsif value . is_a? ( OpenSSL ::ASN1 ::ASN1Data ) && value . respond_to? ( :value )
118
+ val = value . value
119
+ val . is_a? ( String ) ? val . downcase : val . to_s . downcase
120
+ else
121
+ value . to_s . downcase
122
+ end
123
+ end
124
+ end
125
+
126
+ unless normalized_results . include? ( [ username . downcase , realm . downcase ] )
115
127
print_warning ( "Warning: Provided principal and realm (#{ username } @#{ realm } ) do not match entries in certificate:" )
116
128
results . each do |cert_username , cert_realm |
117
129
print_warning ( " * #{ cert_username } @#{ cert_realm } " )
118
130
end
119
131
end
120
132
121
- # But hey, they've overridden it, so off we go
122
133
return [ username , realm ]
123
134
end
124
135
@@ -220,16 +231,21 @@ def build_pa_pk_as_req(pfx, dh, dh_nonce, request_body, opts)
220
231
client_dh_nonce : RASN1 ::Types ::OctetString . new ( value : dh_nonce )
221
232
)
222
233
234
+
223
235
auth_pack [ :client_public_value ] [ :subject_public_key ] . bit_length = pub_key_encoded . length * 8
224
236
237
+
225
238
signed_auth_pack = sign_auth_pack ( auth_pack , pfx . key , certificate )
226
239
240
+
227
241
pa_as_req = Rex ::Proto ::Kerberos ::Model ::PreAuthPkAsReq . new
228
242
243
+
229
244
pa_as_req . signed_auth_pack = signed_auth_pack
230
245
246
+
231
247
Rex ::Proto ::Kerberos ::Model ::PreAuthDataEntry . new ( type : Rex ::Proto ::Kerberos ::Model ::PreAuthType ::PA_PK_AS_REQ ,
232
- value : pa_as_req . to_der )
248
+ value : pa_as_req . to_der )
233
249
end
234
250
235
251
# Calculate the cryptographic signatures over the AuthPack, and create the appropriate
0 commit comments