Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MetaGer Keymanager
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open-source
MetaGer Keymanager
Commits
68f97d91
Commit
68f97d91
authored
2 years ago
by
Dominik Hebeler
Browse files
Options
Downloads
Patches
Plain Diff
added first redeem checks
parent
ea23cc7e
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
pass/app.js
+2
-2
2 additions, 2 deletions
pass/app.js
pass/app/Crypto.js
+40
-0
40 additions, 0 deletions
pass/app/Crypto.js
pass/resources/js/checkout.js
+17
-4
17 additions, 4 deletions
pass/resources/js/checkout.js
pass/routes/redeem.js
+16
-6
16 additions, 6 deletions
pass/routes/redeem.js
with
75 additions
and
12 deletions
pass/app.js
+
2
−
2
View file @
68f97d91
...
@@ -8,7 +8,7 @@ var logger = require("morgan");
...
@@ -8,7 +8,7 @@ var logger = require("morgan");
var
indexRouter
=
require
(
"
./routes/index
"
);
var
indexRouter
=
require
(
"
./routes/index
"
);
var
checkoutRouter
=
require
(
"
./routes/checkout/checkout
"
);
var
checkoutRouter
=
require
(
"
./routes/checkout/checkout
"
);
var
capture
Router
=
require
(
"
./routes/
capture
.js
"
);
var
redeem
Router
=
require
(
"
./routes/
redeem
.js
"
);
var
app
=
express
();
var
app
=
express
();
...
@@ -25,7 +25,7 @@ app.use(express.static(path.join(__dirname, "public")));
...
@@ -25,7 +25,7 @@ app.use(express.static(path.join(__dirname, "public")));
app
.
use
(
"
/
"
,
indexRouter
);
app
.
use
(
"
/
"
,
indexRouter
);
app
.
use
(
"
/checkout
"
,
checkoutRouter
);
app
.
use
(
"
/checkout
"
,
checkoutRouter
);
app
.
use
(
"
/
capture
"
,
capture
Router
);
app
.
use
(
"
/
redeem
"
,
redeem
Router
);
// Browserified Javascript files
// Browserified Javascript files
app
.
get
(
app
.
get
(
...
...
This diff is collapsed.
Click to expand it.
pass/app/Crypto.js
+
40
−
0
View file @
68f97d91
...
@@ -70,6 +70,46 @@ class Crypto {
...
@@ -70,6 +70,46 @@ class Crypto {
return
private_key
;
return
private_key
;
}
}
async
validateMetaGerPassCode
(
expiration_month
,
metager_pass_codes
)
{
expiration_month
=
this
.
#dayjs
(
expiration_month
);
// Check if codes are expired
if
(
!
this
.
#dayjs
().
isBefore
(
expiration_month
,
"
month
"
))
{
return
Promise
.
reject
(
"
Redeem Codes are expired.
"
);
}
let
private_key
=
await
this
.
#private_key_get
(
expiration_month
);
let
uuid_regexExp
=
/^
[
0-9a-fA-F
]{8}\b
-
[
0-9a-fA-F
]{4}\b
-
[
0-9a-fA-F
]{4}\b
-
[
0-9a-fA-F
]{4}\b
-
[
0-9a-fA-F
]{12}
$/gi
;
for
(
let
i
=
0
;
i
<
metager_pass_codes
.
length
;
i
++
)
{
// Check if code iss in correct format
let
metager_pass_code
=
metager_pass_codes
[
i
];
if
(
!
metager_pass_code
.
hasOwnProperty
(
"
code
"
)
||
!
metager_pass_code
.
code
.
match
(
uuid_regexExp
)
)
{
return
Promise
.
reject
(
metager_pass_code
.
code
+
"
is not a valid UUID
"
);
}
// Check if signature is in correct format
if
(
!
metager_pass_code
.
hasOwnProperty
(
"
signature
"
)
||
!
metager_pass_code
.
signature
.
match
(
/^
\d
+$/gi
)
)
{
return
Promise
.
reject
(
i
+
1
+
"
. signature has not a valid format
"
);
}
let
verification_result
=
BlindSignature
.
verify2
({
unblinded
:
metager_pass_code
.
signature
,
key
:
private_key
,
message
:
metager_pass_code
.
code
,
});
if
(
!
verification_result
)
{
console
.
log
(
i
);
return
Promise
.
reject
(
"
One or more signatures could not be verified
"
);
}
}
}
async
sign
(
encrypted_sales_receipts
,
order_date
)
{
async
sign
(
encrypted_sales_receipts
,
order_date
)
{
let
private_key
=
await
this
.
#private_key_get
(
order_date
);
let
private_key
=
await
this
.
#private_key_get
(
order_date
);
let
signed_encrypted_sales_receipts
=
[];
let
signed_encrypted_sales_receipts
=
[];
...
...
This diff is collapsed.
Click to expand it.
pass/resources/js/checkout.js
+
17
−
4
View file @
68f97d91
...
@@ -138,15 +138,28 @@ function four_finish_purchase() {
...
@@ -138,15 +138,28 @@ function four_finish_purchase() {
// Make Create Key button work
// Make Create Key button work
let
create_key_button
=
document
.
getElementById
(
"
create-key-button
"
);
let
create_key_button
=
document
.
getElementById
(
"
create-key-button
"
);
let
order_month
=
require
(
"
dayjs
"
)
.
unix
(
metager_pass_order_id
.
substr
(
0
,
10
))
.
format
(
"
YYYY-MM-01
"
);
create_key_button
.
addEventListener
(
"
pointerdown
"
,
()
=>
{
create_key_button
.
addEventListener
(
"
pointerdown
"
,
()
=>
{
fetch
(
"
/capture/create
"
,
{
let
redeem_data
=
{
expiration_month
:
metager_pass_expires_at
,
generation_month
:
order_month
,
metager_pass_codes
:
[],
};
for
(
let
i
=
0
;
i
<
metager_pass_sales_receipts
.
length
;
i
++
)
{
redeem_data
.
metager_pass_codes
.
push
({
code
:
metager_pass_sales_receipts
[
i
],
signature
:
metager_pass_signatures
[
i
],
});
}
fetch
(
"
/redeem/create
"
,
{
method
:
"
POST
"
,
method
:
"
POST
"
,
headers
:
{
headers
:
{
"
Content-Type
"
:
"
application/json;charset=utf-8
"
,
"
Content-Type
"
:
"
application/json;charset=utf-8
"
,
},
},
body
:
JSON
.
stringify
({
body
:
JSON
.
stringify
(
redeem_data
),
expiration_month
:
metager_pass_expires_at
,
}),
});
});
});
});
}
}
This diff is collapsed.
Click to expand it.
pass/routes/
capture
.js
→
pass/routes/
redeem
.js
+
16
−
6
View file @
68f97d91
...
@@ -3,6 +3,7 @@ var router = express.Router();
...
@@ -3,6 +3,7 @@ var router = express.Router();
const
{
query
,
body
,
validationResult
}
=
require
(
"
express-validator
"
);
const
{
query
,
body
,
validationResult
}
=
require
(
"
express-validator
"
);
const
dayjs
=
require
(
"
dayjs
"
);
const
dayjs
=
require
(
"
dayjs
"
);
const
Crypto
=
require
(
"
../app/Crypto
"
);
var
customParseFormat
=
require
(
"
dayjs/plugin/customParseFormat
"
);
var
customParseFormat
=
require
(
"
dayjs/plugin/customParseFormat
"
);
dayjs
.
extend
(
customParseFormat
);
dayjs
.
extend
(
customParseFormat
);
...
@@ -18,12 +19,21 @@ router.use(
...
@@ -18,12 +19,21 @@ router.use(
.
isDate
()
.
isDate
()
.
matches
(
/^
\d{4}
-
\d{2}
-
\d{2}
$/
)
.
matches
(
/^
\d{4}
-
\d{2}
-
\d{2}
$/
)
.
withMessage
(
"
Invalid Purchase Date supplied
"
),
.
withMessage
(
"
Invalid Purchase Date supplied
"
),
body
(
"
receipts
"
)
body
(
"
receipts
"
).
custom
(
async
(
receipts
,
{
req
})
=>
{
.
custom
((
receipts
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
let
expiration_month
=
dayjs
(
req
.
body
.
expiration_month
);
new
Crypto
()
return
true
;
.
validateMetaGerPassCode
(
})
req
.
body
.
expiration_month
,
.
withMessage
(
"
Supplied Receipts are invalid
"
),
req
.
body
.
metager_pass_codes
)
.
then
(()
=>
{
resolve
(
true
);
})
.
catch
((
reason
)
=>
{
reject
(
reason
);
});
});
}),
(
req
,
res
,
next
)
=>
{
(
req
,
res
,
next
)
=>
{
const
errors
=
validationResult
(
req
);
const
errors
=
validationResult
(
req
);
if
(
!
errors
.
isEmpty
())
{
if
(
!
errors
.
isEmpty
())
{
...
...
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