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/gss/asn1.rb
Views: 11704
1
module Rex::Proto::Gss::Asn1
2
#
3
# GSS has some "pseudo-asn1" to wrap up tokens. This function parses that wrapping, extracts
4
# the mechanism specified, and returns it and the token following it
5
def unwrap_pseudo_asn1(token)
6
start_of_token = nil
7
mech_id = nil
8
# This bit is pseudo-ASN1 - we parse up until the OID, then take note of where we got up
9
# to, and continue parsing from there.
10
OpenSSL::ASN1.traverse(token) do | depth, offset, header_len, length, constructed, tag_class, tag|
11
component = token[offset, header_len+length]
12
if depth == 1 && tag_class == :UNIVERSAL && tag == 6
13
mech_id = OpenSSL::ASN1.decode(component)
14
start_of_token = offset+header_len+length
15
break
16
end
17
end
18
19
[mech_id, token[start_of_token, token.length - start_of_token]]
20
end
21
22
def wrap_pseudo_asn1(mech_id, token)
23
OpenSSL::ASN1::ASN1Data.new(
24
[
25
mech_id,
26
token
27
],
28
0,
29
:APPLICATION
30
).to_der
31
end
32
end
33
34