Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FIT-Connect-SDK - .NET
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container 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
FIT-Connect
FIT-Connect-SDK - .NET
Commits
b8112bb2
Commit
b8112bb2
authored
2 years ago
by
Klaus Fischer
Browse files
Options
Downloads
Patches
Plain Diff
Getting destination ID missing
parent
cdbbba50
No related branches found
No related tags found
1 merge request
!9
.NET-SDK: SET-Empfang inkl. Signaturprüfung - Ticket 562
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
FitConnect/Services/SubmissionService.cs
+49
-14
49 additions, 14 deletions
FitConnect/Services/SubmissionService.cs
with
49 additions
and
14 deletions
FitConnect/Services/SubmissionService.cs
+
49
−
14
View file @
b8112bb2
...
@@ -155,7 +155,7 @@ internal class SubmissionService : RestCallService, ISubmissionService {
...
@@ -155,7 +155,7 @@ internal class SubmissionService : RestCallService, ISubmissionService {
// Download well known keys
// Download well known keys
var
valid
=
await
ValidateSignature
(
events
);
var
valid
=
await
ValidateSignature
(
events
);
// TODO: Check JSON Schema
// TODO: Check JSON Schema
valid
&=
await
ValidateSchema
(
events
,
false
);
//
valid &= await ValidateSchema(events, false);
if
(!
valid
)
{
if
(!
valid
)
{
_logger
?.
LogError
(
"Invalid SET, signature can not be verified"
);
_logger
?.
LogError
(
"Invalid SET, signature can not be verified"
);
...
@@ -226,18 +226,12 @@ internal class SubmissionService : RestCallService, ISubmissionService {
...
@@ -226,18 +226,12 @@ internal class SubmissionService : RestCallService, ISubmissionService {
return
valid
;
return
valid
;
}
}
private
async
Task
<
bool
>
ValidateSignature
(
EventLogDto
?
events
)
{
private
async
Task
<
bool
>
ValidateSignature
(
EventLogDto
events
)
{
// Load Key from GET {{submission_api_url}}/v1/destinations/{{destinationId}}/keys/{{keyId}}
var
keys
=
await
GetJsonWebKeysForEvent
(
events
);
var
keyIds
=
GetKeyIdsFromEvent
(
events
);
var
keySet
=
new
JsonWebKeySet
(
await
Router
.
GetSubmissionServiceValidationJwk
(
_baseUrl
));
var
valid
=
events
.
EventLog
?.
Aggregate
(
true
,
var
keys
=
_signatureValidationKey
==
null
(
current
,
eventJson
)
=>
?
keySet
.
Keys
current
&
FitEncryption
.
VerifyJwt
(
eventJson
,
keys
,
logger
:
_logger
))
??
true
;
:
keySet
.
Keys
.
Append
(
_signatureValidationKey
);
var
valid
=
true
;
foreach
(
var
eventJson
in
events
.
EventLog
)
{
valid
&=
FitEncryption
.
VerifyJwt
(
eventJson
,
keys
,
logger
:
_logger
);
}
if
(!
valid
)
{
if
(!
valid
)
{
_logger
?.
LogDebug
(
"Signature is invalid"
);
_logger
?.
LogDebug
(
"Signature is invalid"
);
...
@@ -248,8 +242,49 @@ internal class SubmissionService : RestCallService, ISubmissionService {
...
@@ -248,8 +242,49 @@ internal class SubmissionService : RestCallService, ISubmissionService {
return
valid
;
return
valid
;
}
}
private
IEnumerable
<
JsonWebKey
>
GetKeyIdsFromEvent
(
EventLogDto
events
)
{
private
async
Task
<
IEnumerable
<
JsonWebKey
>>
GetJsonWebKeysForEvent
(
EventLogDto
events
)
{
return
new
List
<
JsonWebKey
>();
var
keySet
=
new
JsonWebKeySet
(
await
Router
.
GetSubmissionServiceValidationJwk
(
_baseUrl
));
var
keys
=
_signatureValidationKey
==
null
?
keySet
.
Keys
:
keySet
.
Keys
.
Append
(
_signatureValidationKey
);
return
(
await
GetKeyIdsFromEvent
(
events
)).
Union
(
keys
);
}
private
async
Task
<
IEnumerable
<
JsonWebKey
>>
GetKeyIdsFromEvent
(
EventLogDto
events
)
{
if
(
events
.
EventLog
==
null
)
return
new
List
<
JsonWebKey
>();
// Load Key from GET {{submission_api_url}}/v1/destinations/{{destinationId}}/keys/{{keyId}}
var
keyIds
=
events
.
EventLog
.
Select
(
ExtractSubmissionIdFromEvent
).
ToList
();
var
result
=
new
List
<
JsonWebKey
>();
foreach
(
var
(
submission
,
keyId
)
in
keyIds
)
{
try
{
// TODO Get destinationId from submission
var
destinationId
=
"aa3704d6-8bd7-4d40-a8af-501851f93934"
;
var
keyJson
=
await
RestCallForString
(
$"/destinations/
{
destinationId
}
/keys/
{
keyId
}
"
,
HttpMethod
.
Get
);
result
.
Add
(
new
JsonWebKey
(
keyJson
));
}
catch
(
Exception
e
)
{
_logger
?.
LogWarning
(
e
,
"Error loading key {KeyId}"
,
keyId
);
}
}
return
result
;
}
private
(
string
submissionId
,
string
keyId
)
ExtractSubmissionIdFromEvent
(
string
events
)
{
var
jwtParts
=
events
.
Split
(
'.'
).
Select
(
Base64UrlEncoder
.
Decode
).
ToList
();
var
header
=
JsonConvert
.
DeserializeObject
<
Dictionary
<
string
,
object
>>(
jwtParts
[
0
]);
var
payload
=
JsonConvert
.
DeserializeObject
<
Dictionary
<
string
,
object
>>(
jwtParts
[
1
]);
var
keyId
=
(
string
)
header
[
"kid"
];
var
submissionId
=
((
string
)
payload
[
"sub"
]).
Split
(
':'
)[
1
];
return
(
submissionId
,
keyId
);
}
}
public
async
Task
GetValidationJwk
()
{
public
async
Task
GetValidationJwk
()
{
...
...
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