Skip to content

Commit 4713557

Browse files
author
Adam Parkin
committed
INTERAC-9 update instructions for generating local cert
1 parent 909e4b0 commit 4713557

File tree

7 files changed

+99
-78
lines changed

7 files changed

+99
-78
lines changed

README.md

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,48 +18,56 @@ and then start up as follows.
1818
## Server Setup & Installation
1919

2020
* Execute a git clone command on this repo and in a terminal cd into the root project directory.
21+
2122
```bash
22-
$ git clone https://github.com/bambora/na-payment-apis-demo.git
23-
$ cd na-payment-apis-demo/server/app
23+
git clone https://github.com/bambora/na-payment-apis-demo.git
24+
cd na-payment-apis-demo/server/app
2425
```
2526

2627
* Install virtualenv (if not already available)
28+
2729
```bash
28-
$ [sudo] pip install virtualenv
30+
[sudo] pip install virtualenv
2931
```
3032

3133
* Create (if not already created) and/or Activate project environment
34+
3235
```bash
33-
$ virtualenv -p python3 venv
34-
$ source venv/bin/activate
36+
virtualenv -p python3 venv
37+
source venv/bin/activate
3538
```
3639

3740
* Install/update project dependencies
41+
3842
```bash
39-
(venv) app$ pip install -r requirements.txt
43+
cd server/app
44+
pip install -r requirements.txt
4045
```
4146

4247
## Execution (Development Only)
4348

4449
### Set up Environment Variables
45-
We are using 2 test accounts in this demo app. One is on Production, the other is on Sandbox. All services, except Visa Checkout can be tested on Production. Visa Checkout mist be tested on Sandbox.
50+
51+
We are using 2 test accounts in this demo app. One is on Production, the other is on Sandbox. All services,
52+
except Visa Checkout can be tested on Production. Visa Checkout mist be tested on Sandbox.
4653

4754
#### Mac/Linux
55+
4856
```bash
49-
(venv) app$ export SERVER_URL_BASE="https://api.na.bambora.com" # Defaults to this and can be omitted
50-
(venv) app$ export DATABASE_URL=sqlite:////tmp/mobilepay-demo.db # Defaults to this and can be omitted
51-
(venv) app$ export MERCHANT_ID=<your_bambora_merchant_id>
52-
(venv) app$ export API_PASSCODE=<your_payment_api_passcode>
53-
(venv) app$ export BATCH_PAYMENT_API_PASSCODE=<your_batch_payment_api_passcode>
54-
(venv) app$ export REPORT_API_PASSCODE=<report_api_passcode>
55-
(venv) app$ export SANDBOX_MERCHANT_ID=<your_bambora_sandbox_merchant_id>
56-
(venv) app$ export SANDBOX_API_PASSCODE=<your_sandbox_payment_api_passcode>
57-
(venv) app$ export SANDBOX_HASH_KEY=<your_sandbox_hash_key>
58-
(venv) app$ export SANDBOX_VISA_CHECKOUT_API_KEY=<your_sandbox_visa_checkout_api_key>
57+
export SERVER_URL_BASE="https://api.na.bambora.com" # Defaults to this and can be omitted
58+
export DATABASE_URL=sqlite:////tmp/mobilepay-demo.db # Defaults to this and can be omitted
59+
export MERCHANT_ID=<your_bambora_merchant_id>
60+
export API_PASSCODE=<your_payment_api_passcode>
61+
export BATCH_PAYMENT_API_PASSCODE=<your_batch_payment_api_passcode>
62+
export REPORT_API_PASSCODE=<report_api_passcode>
63+
export SANDBOX_MERCHANT_ID=<your_bambora_sandbox_merchant_id>
64+
export SANDBOX_API_PASSCODE=<your_sandbox_payment_api_passcode>
65+
export SANDBOX_HASH_KEY=<your_sandbox_hash_key>
66+
export SANDBOX_VISA_CHECKOUT_API_KEY=<your_sandbox_visa_checkout_api_key>
5967
```
6068

61-
6269
#### Windows
70+
6371
```bash
6472
(venv) app$ $env:SERVER_URL_BASE ="https://api.na.bambora.com" # Defaults to this and can be omitted
6573
(venv) app$ $env:DATABASE_URL = "sqlite:////users/<your_user>/appdata/local/temp/mobilepay-demo.db"
@@ -71,10 +79,31 @@ We are using 2 test accounts in this demo app. One is on Production, the other i
7179
```
7280

7381
### Run
82+
83+
From within the server/app directory:
84+
7485
```bash
75-
(venv) app$ python server.py
86+
python server.py
7687
```
7788

89+
## Local Dev SSL Setup
90+
91+
If you require HTTPS, then you'll need to create a local CA authority, trust it, and then generate certs to use.
92+
93+
### Generate the Root cert & App Cert
94+
95+
Run the supplied `gen-cert.sh` script. This creates the root CA & cert for the app.
96+
97+
### Trust the Cert
98+
99+
#### Mac
100+
101+
```bash
102+
sudo security add-trusted-cert -d -r trustAsRoot -k /Library/Keychains/System.keychain server/app/domain.crt
103+
```
104+
105+
Once this is done, going to https://0.0.0.0:5000 should resolve without error.
106+
78107
# Mobile Payment Clients
79108

80109
Apple Pay or Android Pay payment requests are initiated from mobile clients and then, if successful, an Apple Pay or

gen-cert.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
set -e
3+
4+
cd server/app
5+
6+
openssl genrsa -out server_rootCA.key 2048
7+
openssl req -x509 -new -nodes -key server_rootCA.key -sha256 -days 730 -out server_rootCA.pem -config ../conf/openssl.conf
8+
openssl req -new -nodes -newkey rsa:2048 -sha256 -out domain.csr -keyout domain.key -config ../conf/openssl.conf
9+
openssl x509 -req -in domain.csr -CA server_rootCA.pem -CAkey server_rootCA.key -CAcreateserial -sha256 -days 365 -out domain.crt -extfile ../conf/openssl.ext.conf

server/app/domain.crt

Lines changed: 0 additions & 28 deletions
This file was deleted.

server/app/domain.key

Lines changed: 0 additions & 27 deletions
This file was deleted.

server/app/server.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,12 @@ def route(path):
104104
# needs to use an IP address or name and not 0.0.0.0 or else
105105
# browser side security checks will likely fail.
106106
if __name__ == '__main__':
107-
context = (os.path.join(app.root_path, 'domain.crt'),
108-
os.path.join(app.root_path, 'domain.key'))
109-
app.run(debug=True, host='0.0.0.0', ssl_context=context)
110-
#app.run(debug=True, host='0.0.0.0')
107+
# if cert exists, use it for SSL, else just run plain HTTP
108+
cert_file = os.path.join(app.root_path, 'domain.crt')
109+
key_file = os.path.join(app.root_path, 'domain.key')
110+
if os.path.exists(cert_file) and os.path.exists(key_file):
111+
context = (os.path.join(app.root_path, 'domain.crt'),
112+
os.path.join(app.root_path, 'domain.key'))
113+
app.run(debug=True, host='0.0.0.0', ssl_context=context)
114+
else:
115+
app.run(debug=True, host='0.0.0.0')

server/conf/openssl.conf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# openssl.conf
2+
[ req ]
3+
default_bits = 2048
4+
default_keyfile = server.key
5+
default_md = sha256
6+
distinguished_name = req_distinguished_name
7+
prompt = no
8+
req_extensions = v3_req
9+
10+
[ req_distinguished_name ]
11+
C=CA
12+
ST=BC
13+
L=Victoria
14+
O=Bambora
15+
OU=local_RootCA
16+
17+
CN = 0.0.0.0
18+
19+
[ v3_req ]
20+
basicConstraints = CA:FALSE
21+
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
22+
subjectAltName = @alt_names
23+
24+
[alt_names]
25+
IP.1 = 0.0.0.0

server/conf/openssl.ext.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# openssl.ext.conf
2+
authorityKeyIdentifier=keyid,issuer
3+
basicConstraints=CA:FALSE
4+
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
5+
subjectAltName = @alt_names
6+
7+
[alt_names]
8+
IP.1 = 0.0.0.0

0 commit comments

Comments
 (0)