Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
Signing verification utilities
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
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
Seal
Building blocks
Signing verification utilities
Commits
11bae20d
Commit
11bae20d
authored
4 years ago
by
Zdravko Iliev
Browse files
Options
Downloads
Patches
Plain Diff
add compute,sign and verify qr code
parent
f29c2cbf
No related branches found
No related tags found
1 merge request
!39
Resolve "QR Code Data Signing & Verification flow"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/services/QrCodeDataService.ts
+68
-0
68 additions, 0 deletions
src/services/QrCodeDataService.ts
with
68 additions
and
0 deletions
src/services/QrCodeDataService.ts
+
68
−
0
View file @
11bae20d
...
@@ -13,6 +13,7 @@ import {
...
@@ -13,6 +13,7 @@ import {
import
CloudflareService
from
"
./CloudflareService
"
;
import
CloudflareService
from
"
./CloudflareService
"
;
import
CryptoServiceDefault
from
"
./CryptoService
"
;
import
CryptoServiceDefault
from
"
./CryptoService
"
;
import
{
ICryptoService
}
from
"
./CryptoService/ICryptoService
"
;
import
{
ICryptoService
}
from
"
./CryptoService/ICryptoService
"
;
import
{
CryptoService
}
from
"
../index
"
;
const
EmailDataMessageV1
=
vereign
.
protobuf
.
qrcode_data
.
EmailData_V1
;
const
EmailDataMessageV1
=
vereign
.
protobuf
.
qrcode_data
.
EmailData_V1
;
const
KeyDataMessageV1
=
vereign
.
protobuf
.
qrcode_data
.
KeyData_V1
;
const
KeyDataMessageV1
=
vereign
.
protobuf
.
qrcode_data
.
KeyData_V1
;
...
@@ -109,6 +110,70 @@ const assembleQrCodeData = (
...
@@ -109,6 +110,70 @@ const assembleQrCodeData = (
return
Buffer
.
concat
([
Buffer
.
from
(
head
),
Buffer
.
from
(
tail
)]);
return
Buffer
.
concat
([
Buffer
.
from
(
head
),
Buffer
.
from
(
tail
)]);
};
};
const
computeQrCodeHash
=
async
(
emailData
:
MessageData
):
Promise
<
string
>
=>
{
const
attachments
=
emailData
.
attachments
.
map
((
attachment
)
=>
{
//TODO: check if we can use attachment hash, attachment hashAlg
if
(
attachment
.
url
)
{
return
{
name
:
attachment
.
name
,
size
:
attachment
.
size
,
url
:
attachment
.
url
,
};
}
return
{
name
:
attachment
.
name
,
size
:
attachment
.
size
,
};
});
const
dataForHashing
=
{
statusId
:
emailData
.
statusId
,
sender
:
emailData
.
sender
,
subject
:
emailData
.
subject
,
date
:
emailData
.
date
,
recipients
:
emailData
.
recipients
,
attachments
,
};
const
promises
=
Object
.
values
(
dataForHashing
).
map
(
async
(
value
)
=>
{
const
base64
=
Buffer
.
from
(
JSON
.
stringify
(
value
)).
toString
(
"
base64
"
);
return
CryptoService
.
SHA256
(
base64
);
});
const
hashArray
=
await
Promise
.
all
(
promises
);
return
hashArray
.
sort
().
join
(
"
\n
"
);
};
const
calculateQRCodeSignature
=
async
(
accountPrivateKey
:
string
,
qrCodeHash
:
string
):
Promise
<
string
>
=>
{
const
signature
=
await
CryptoService
.
signRSA
(
accountPrivateKey
,
Buffer
.
from
(
qrCodeHash
)
);
return
arrayBufferToBase64
(
signature
);
};
const
verifyQrCodeSignature
=
async
(
publicKey
:
string
,
qrCodeSignature
:
string
,
recipientQRCodeHash
:
string
):
Promise
<
boolean
>
=>
{
const
qrCodeSignatureAsBuffer
=
base64ToArrayBuffer
(
qrCodeSignature
);
const
recipientQRCodeHashAsBuffer
=
Buffer
.
from
(
recipientQRCodeHash
);
const
result
=
await
CryptoService
.
verifyRSASignature
(
publicKey
,
recipientQRCodeHashAsBuffer
,
qrCodeSignatureAsBuffer
);
return
result
;
};
interface
WithServices
{
interface
WithServices
{
getMessageDataFromBase64
:
(
base64
:
string
)
=>
Promise
<
MessageData
>
;
getMessageDataFromBase64
:
(
base64
:
string
)
=>
Promise
<
MessageData
>
;
}
}
...
@@ -198,5 +263,8 @@ export default {
...
@@ -198,5 +263,8 @@ export default {
decodeKeyDataPair
,
decodeKeyDataPair
,
breakQrCodeData
,
breakQrCodeData
,
assembleQrCodeData
,
assembleQrCodeData
,
computeQrCodeHash
,
calculateQRCodeSignature
,
verifyQrCodeSignature
,
withServices
,
withServices
,
};
};
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