Skip to content

Commit 619fc19

Browse files
author
Jesse Langford
committed
updated certificate configuration
1 parent 489e303 commit 619fc19

File tree

4 files changed

+33
-26
lines changed

4 files changed

+33
-26
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ You will need the following:
1212

1313
- A PassKit account (signup for free at https://app.passkit.com)
1414
- Your PassKit SDK Credentials (available from the https://app.passkit.com/app/account/developer-tools)
15-
- Nodejs 10 or above (https://nodejs.org/en/)
15+
- Nodejs 11.6.0 or above (https://nodejs.org/en/)
1616

1717
### Configuration
1818

@@ -24,7 +24,7 @@ You will need the following:
2424
- ca-chain.pem
2525
- key.pem
2626

27-
3. Run `npm run openssl` and provide your account password in the terminal prompt.
27+
3. Add your account password into the `src/config/config.js` PASSPHRASE variable
2828

2929
4. If you wish to receive enrolment emails, edit lines 281 and 307 of the QuickStartLoyalty class to provide an address where you can receive mail.
3030

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
"author": "",
66
"license": "ISC",
77
"scripts": {
8-
"test": "jest",
9-
"openssl": "cd src/certs && openssl ec -in key.pem -out key.pem"
8+
"test": "jest"
109
},
1110
"jest": {
1211
"verbose": true

src/config/config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
ROOT_CERT: "./src/certs/ca-chain.pem",
3+
PRIVATE_KEY: "./src/certs/key.pem",
4+
CERTIFICATE: "./src/certs/certificate.pem",
5+
ADDRESS: "grpc.pub1.passkit.io",
6+
PORT: 443,
7+
PASSPHRASE: "",
8+
};

src/lib/client.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,37 @@ const grpc = require("grpc");
1010
const {
1111
UsersClient,
1212
} = require("passkit-node-sdk/io/core/a_rpc_others_grpc_pb");
13-
14-
const ROOT_CERT = "./src/certs/ca-chain.pem";
15-
const PRIVATE_KEY = "./src/certs/key.pem";
16-
const CERTIFICATE = "./src/certs/certificate.pem";
17-
const ADDRESS = "grpc.pub1.passkit.io";
18-
const PORT = 443;
13+
const crypto = require("crypto");
14+
const config = require("../config/config");
1915

2016
class PassKitClient {
2117
constructor() {
18+
const privateKeyEncBytes = fs.readFileSync(config.PRIVATE_KEY);
19+
const privateKey = crypto.createPrivateKey({
20+
cypher: "aes-256-cbc",
21+
format: "pem",
22+
key: privateKeyEncBytes,
23+
passphrase: config.PASSPHRASE,
24+
type: "pkcs8",
25+
});
26+
2227
const channelCredential = grpc.credentials.createSsl(
23-
fs.readFileSync(ROOT_CERT),
24-
fs.readFileSync(PRIVATE_KEY),
25-
fs.readFileSync(CERTIFICATE)
28+
fs.readFileSync(config.ROOT_CERT),
29+
Buffer.from(
30+
privateKey.export({ format: "pem", type: "pkcs8" }).toString()
31+
),
32+
fs.readFileSync(config.CERTIFICATE)
2633
);
2734

28-
this.userClient = new UsersClient(`${ADDRESS}:${PORT}`, channelCredential);
35+
const grpcAddress = `${config.ADDRESS}:${config.PORT}`;
2936

30-
this.templateClient = new TemplatesClient(
31-
`${ADDRESS}:${PORT}`,
32-
channelCredential
33-
);
37+
this.userClient = new UsersClient(grpcAddress, channelCredential);
3438

35-
this.membersClient = new MembersClient(
36-
`${ADDRESS}:${PORT}`,
37-
channelCredential
38-
);
39+
this.templateClient = new TemplatesClient(grpcAddress, channelCredential);
3940

40-
this.imageClient = new ImagesClient(
41-
`${ADDRESS}:${PORT}`,
42-
channelCredential
43-
);
41+
this.membersClient = new MembersClient(grpcAddress, channelCredential);
42+
43+
this.imageClient = new ImagesClient(grpcAddress, channelCredential);
4444
}
4545

4646
getTemplateClient() {

0 commit comments

Comments
 (0)