Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scapy
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CodeLinaro
public-release-test-restored
platform
external
scapy
Commits
9888e6c4
Commit
9888e6c4
authored
8 years ago
by
mtu
Browse files
Options
Downloads
Patches
Plain Diff
Fix complex ASN1 fields randval()
parent
b2884fde
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
scapy/asn1fields.py
+13
-2
13 additions, 2 deletions
scapy/asn1fields.py
test/x509.uts
+14
-0
14 additions, 0 deletions
test/x509.uts
with
27 additions
and
2 deletions
scapy/asn1fields.py
+
13
−
2
View file @
9888e6c4
...
...
@@ -367,7 +367,7 @@ class ASN1F_SEQUENCE_OF(ASN1F_field):
return
self
.
i2m
(
pkt
,
s
)
def
randval
(
self
):
return
packet
.
fuzz
(
self
.
asn1pkt
())
return
packet
.
fuzz
(
self
.
cls
())
def
__repr__
(
self
):
return
"
<%s %s>
"
%
(
self
.
__class__
.
__name__
,
self
.
name
)
...
...
@@ -488,7 +488,16 @@ class ASN1F_CHOICE(ASN1F_field):
explicit_tag
=
exp
)
return
BER_tagging_enc
(
s
,
explicit_tag
=
self
.
explicit_tag
)
def
randval
(
self
):
return
RandChoice
(
*
(
packet
.
fuzz
(
x
())
for
x
in
self
.
choices
.
itervalues
()))
randchoices
=
[]
for
p
in
self
.
choices
.
itervalues
():
if
hasattr
(
p
,
"
ASN1_root
"
):
# should be ASN1_Packet class
randchoices
.
append
(
packet
.
fuzz
(
p
()))
elif
hasattr
(
p
,
"
ASN1_tag
"
):
if
type
(
p
)
is
type
:
# should be (basic) ASN1F_field class
randchoices
.
append
(
p
(
"
dummy
"
,
None
).
randval
())
else
:
# should be ASN1F_PACKET instance
randchoices
.
append
(
p
.
randval
())
return
RandChoice
(
*
randchoices
)
class
ASN1F_PACKET
(
ASN1F_field
):
holds_packets
=
1
...
...
@@ -520,6 +529,8 @@ class ASN1F_PACKET(ASN1F_field):
s
=
str
(
x
)
return
BER_tagging_enc
(
s
,
implicit_tag
=
self
.
implicit_tag
,
explicit_tag
=
self
.
explicit_tag
)
def
randval
(
self
):
return
packet
.
fuzz
(
self
.
cls
())
class
ASN1F_BIT_STRING_ENCAPS
(
ASN1F_BIT_STRING
):
"""
...
...
This diff is collapsed.
Click to expand it.
test/x509.uts
+
14
−
0
View file @
9888e6c4
...
...
@@ -190,3 +190,17 @@ s = str(X509_CRL())
str(X509_CRL(s)) == s
############ Randval tests ###############################################
= Randval tests : ASN1F_SEQUENCE_OF
random.seed(42)
r = ASN1F_SEQUENCE_OF("test", [], ASN1P_INTEGER).randval().number
assert(isinstance(r, RandNum))
int(r) == -16393048219351680611L
= Randval tests : ASN1F_PACKET
random.seed(0xcafecafe)
r = ASN1F_PACKET("otherName", None, X509_OtherName).randval()
assert(isinstance(r, X509_OtherName))
str(r.type_id) == '171.184.10.271'
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment