forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttps.py
More file actions
169 lines (136 loc) · 5.41 KB
/
https.py
File metadata and controls
169 lines (136 loc) · 5.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import graphene
from graphene_sqlalchemy import SQLAlchemyObjectType
from db import db_session
from models import Https_scans, Web_scans, Domains
from scalars.url import URL
class HTTPS(SQLAlchemyObjectType):
"""
Http Scan Object
"""
class Meta:
model = Https_scans
exclude_fields = ("id", "https_scan")
id = graphene.ID(description="The ID of the object")
domain = URL(description="The domain the scan was run on")
timestamp = graphene.DateTime(description="The time the scan was initiated")
implementation = graphene.String(
description="State of the HTTPS implementation on the server and any "
"issues therein"
)
enforced = graphene.String(
description="Degree to which HTTPS is enforced on the server based "
"on behaviour"
)
hsts = graphene.String(
description="Presence and completeness of HSTS implementation"
)
hsts_age = graphene.String(
description="Denotes how long the domain should only be accessed using " "HTTPS"
)
preloaded = graphene.String(
description="Denotes whether the domain has been submitted and "
"included within HSTS preload list"
)
https_guidance_tags = graphene.List(
lambda: graphene.String, description="Key tags found during scan"
)
def resolve_domain(self: Https_scans, info, **kwargs):
web_scan_domain_id = (
db_session.query(Web_scans)
.filter(Web_scans.id == self.id)
.first()
.domain_id
)
domain = (
db_session.query(Domains)
.filter(Domains.id == web_scan_domain_id)
.first()
.domain
)
return domain
def resolve_timestamp(self: Https_scans, info, **kwargs):
scan_date = (
db_session.query(Web_scans)
.filter(Web_scans.id == self.id)
.first()
.scan_date
)
return scan_date
def resolve_implementation(self: Https_scans, info, **kwargs):
implementation = self.https_scan.get("https", {}).get("implementation", None)
return implementation
def resolve_enforced(self: Https_scans, info, **kwargs):
enforced = self.https_scan.get("https", {}).get("enforced", None)
return enforced
def resolve_hsts(self: Https_scans, info, **kwargs):
hsts = self.https_scan.get("https", {}).get("hsts", None)
return hsts
def resolve_hsts_age(self: Https_scans, info, **kwargs):
hsts_age = self.https_scan.get("https", {}).get("hsts_age", None)
return hsts_age
def resolve_preloaded(self: Https_scans, info, **kwargs):
preloaded = self.https_scan.get("https", {}).get("preloaded", None)
return preloaded
def resolve_https_guidance_tags(self: Https_scans, info, **kwargs):
tags = []
if self.https_scan.get("https", {}).get("missing", None) is not None:
tags.append("https2")
return tags
# Implementation
implementation = self.https_scan.get("https", {}).get("implementation", None)
if implementation is not None:
if isinstance(implementation, str):
implementation = implementation.lower()
if implementation == "downgrades https":
tags.append("https3")
elif implementation == "bad chain":
tags.append("https4")
elif implementation == "bad hostname":
tags.append("https5")
# Enforced
enforced = self.https_scan.get("https", {}).get("enforced", None)
if enforced is not None:
if isinstance(enforced, str):
enforced = enforced.lower()
if enforced == "moderate":
tags.append("https8")
elif enforced == "weak":
tags.append("https7")
elif enforced == "not enforced":
tags.append("https6")
# HSTS
hsts = self.https_scan.get("https", {}).get("hsts", None)
if hsts is not None:
if isinstance(hsts, str):
hsts = hsts.lower()
if hsts == "hsts max age too short":
tags.append("https10")
elif hsts == "no hsts":
tags.append("https9")
# HSTS Age
hsts_age = self.https_scan.get("https", {}).get("hsts_age", None)
if hsts_age is not None:
if hsts_age < 31536000 and "https" not in tags:
tags.append("https10")
# Preload Status
preload_status = self.https_scan.get("https", {}).get("preload_status", None)
if preload_status is not None:
if isinstance(preload_status, str):
preload_status = preload_status.lower()
if preload_status == "hsts preload ready":
tags.append("https11")
elif preload_status == "hsts not preloaded":
tags.append("https12")
# Expired Cert
expired_cert = self.https_scan.get("https", {}).get("expired_cert", None)
if expired_cert is not None:
if expired_cert is True:
tags.append("https13")
# Self Signed Cert
self_signed_cert = self.https_scan.get("https", {}).get(
"self_signed_cert", None
)
if self_signed_cert is not None:
if self_signed_cert is True:
tags.append("https14")
return tags