Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-App-Kort
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Onboarding
AlekSIS-App-Kort
Commits
f00e832d
Verified
Commit
f00e832d
authored
1 year ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Fix bugs in SDM implementation
parent
8f6471ac
No related branches found
Branches containing commit
No related tags found
1 merge request
!14
Draft: Resolve "Object / Person identification using SDM NFC cards"
Pipeline
#132172
failed
1 year ago
Stage: prepare
Stage: test
Stage: build
Stage: publish
Stage: docker
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
aleksis/apps/kort/models/sdm.py
+12
-7
12 additions, 7 deletions
aleksis/apps/kort/models/sdm.py
with
12 additions
and
7 deletions
aleksis/apps/kort/models/sdm.py
+
12
−
7
View file @
f00e832d
from
binascii
import
unhexlify
from
django.core.exceptions
import
BadRequest
from
django.
core.
http
import
Request
from
django.http
import
Http
Request
from
libsdm
import
EncMode
,
InvalidMessage
,
decrypt_sun_message
from
libsdm.derive
import
derive_
undiversified_key
,
derive_tag
_key
from
libsdm.derive
import
derive_
tag_key
,
derive_undiversified
_key
from
libsdm.util
import
parse_parameters
from
aleksis.core.mixins
import
ExtensibleModel
,
ObjectAuthenticator
...
...
@@ -15,13 +15,18 @@ from .cards import Card
class
NfcSdmAuthenticator
(
ObjectAuthenticator
):
"""
Object authenticator using NFC SDM.
"""
name
=
"
nfc_sdm
"
require_lrp
=
False
def
authenticate
(
self
,
request
:
Request
,
obj
:
ExtensibleModel
):
def
authenticate
(
self
,
request
:
Http
Request
,
obj
:
ExtensibleModel
):
"""
SUN decrypting authenticator
"""
master_key
=
unhexlify
(
get_site_preferences
()[
"
nfc__sdm_master_key
"
])
param_mode
,
picc_enc_data
,
enc_file_data
,
sdmmac
=
parse_parameters
(
request
.
GET
)
master_key
=
unhexlify
(
get_site_preferences
()[
"
kort__sdm_master_key
"
])
try
:
param_mode
,
picc_enc_data
,
enc_file_data
,
sdmmac
=
parse_parameters
(
request
.
GET
)
except
ValueError
as
e
:
raise
BadRequest
(
**
e
.
args
)
try
:
res
=
decrypt_sun_message
(
param_mode
=
param_mode
,
...
...
@@ -40,13 +45,13 @@ class NfcSdmAuthenticator(ObjectAuthenticator):
try
:
card
=
Card
.
objects
.
get
(
chip_number__iexact
=
res
[
"
uid
"
].
hex
())
except
Card
.
DoesNotEx
ac
t
:
except
Card
.
DoesNotEx
is
t
:
return
False
if
card
.
person
!=
obj
:
raise
BadRequest
(
"
Card is not linked to identified object
"
)
if
card
.
last_read_counter
<
=
res
[
"
read_ctr
"
]:
if
card
.
last_read_counter
>
=
res
[
"
read_ctr
"
]:
raise
BadRequest
(
"
Read counter went backwards, possible replay attack
"
)
card
.
last_read_counter
=
res
[
"
read_ctr
"
]
card
.
save
()
...
...
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