Skip to content

Commit

Permalink
Dockerize and add lots of scripts to make it easier to use.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyssmith2nd committed May 29, 2019
1 parent b333b84 commit 1fa429a
Show file tree
Hide file tree
Showing 15 changed files with 182 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
@@ -0,0 +1,3 @@
node_modules/

external/eosjs/node_modules/
6 changes: 6 additions & 0 deletions .gitignore
Expand Up @@ -3,3 +3,9 @@ dist
*.log
*.out
keys.json

*.crt
*.key
*.pem

webauthn-nodeos-data/
48 changes: 48 additions & 0 deletions docker/Dockerfile-eosio
@@ -0,0 +1,48 @@
FROM ubuntu:18.04

# Make sure the image is updated, install some prerequisites,
# Download the latest version of Clang (official binary) for Ubuntu
# Extract the archive and add Clang to the PATH
RUN apt-get update && apt-get install -y \
xz-utils \
build-essential \
curl \
&& rm -rf /var/lib/apt/lists/* \
&& curl -SL http://releases.llvm.org/8.0.0/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz \
| tar -xJC . && \
mv clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04 clang_8.0.0

RUN echo 'export PATH=/clang_8.0.0/bin:$PATH' >> ~/.bashrc
RUN echo 'export LD_LIBRARY_PATH=/clang_8.0.0/lib:LD_LIBRARY_PATH' >> ~/.bashrc

RUN apt-get update && apt-get install -y libudev-dev cmake \
git build-essential jq \
sudo autoconf libtool \
pkg-config libusb-1.0 wget

RUN git clone https://github.com/EOSIO/eos.git /app/eos

WORKDIR /app/eos

RUN git checkout webauthn && git submodule update --init --recursive
ENV PATH=/clang_8.0.0/bin:$PATH
ENV LD_LIBRARY_PATH=/clang_8.0.0/lib:LD_LIBRARY_PATH
RUN CC=clang CXX=clang++ ./scripts/eosio_build.sh -y

WORKDIR /app

RUN wget https://github.com/EOSIO/eosio.cdt/releases/download/v1.6.1/eosio.cdt_1.6.1-1_amd64.deb -O eosio.cdt.deb
RUN apt-get install ./eosio.cdt.deb
RUN git clone https://github.com/EOSIO/eosio.contracts.git /app/eosio.contracts

WORKDIR /app/eosio.contracts

RUN git checkout v1.7.0-rc1
RUN mkdir build && cd build && cmake .. && make contracts_project

WORKDIR /app/eos

RUN echo 'export PATH=/app/eos/build/bin:$PATH' >> ~/.bashrc
ENV PATH=/app/eos/build/bin:$PATH

COPY ./scripts /app/scripts
21 changes: 21 additions & 0 deletions docker/scripts/chain-setup.sh
@@ -0,0 +1,21 @@
#!/bin/bash
# Create wallet
cleos wallet create --file /app/.wallet-password
cleos wallet import --private-key 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3

# Enable webauthn feature of nodeos
curl -X POST http://127.0.0.1:8888/v1/producer/schedule_protocol_feature_activations -d '{"protocol_features_to_activate": ["0ec7e080177b2c02b278d5088611686b49d739925a92d9bfcacd7fc6b74053bd"]}' | jq

# Create token account
cleos create account eosio eosio.token EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV

sleep 1s # Sleep because there seems to be a race condition of trying to deploy the contract too quickly

# Deploy contracts
cleos set contract eosio /app/eosio.contracts/build/contracts/eosio.bios -p eosio
cleos set contract eosio.token /app/eosio.contracts/build/contracts/eosio.token -p eosio.token

# Initialize accounts
cleos push action eosio activate '["4fca8bd82bbd181e714e283f83e1b45d95ca5af40fb89ad3977b653c448f78c2"]' -p eosio
cleos push action eosio.token create '["eosio","10000000.0000 SYS"]' -p eosio.token
cleos push action eosio.token issue '["eosio","10000000.0000 SYS",""]' -p eosio
11 changes: 11 additions & 0 deletions haproxy-webauthn.cfg
@@ -0,0 +1,11 @@
defaults
timeout connect 10000ms
timeout client 50000ms
timeout server 50000ms

frontend https-in
bind *:7000 ssl crt ./localhostca.pem
use_backend http_backend

backend http_backend
server server1 localhost:8000
4 changes: 4 additions & 0 deletions scripts/build-docker.sh
@@ -0,0 +1,4 @@
#!/bin/bash
pushd docker
docker build . -t eosio/eos-webauthn:latest -f Dockerfile-eosio
popd
5 changes: 5 additions & 0 deletions scripts/chain-setup.sh
@@ -0,0 +1,5 @@
#!/bin/bash
./scripts/start.sh
sleep 5s # Give nodeos time to startup
docker exec -it webauthn-nodeos /app/scripts/chain-setup.sh
./scripts/stop.sh
5 changes: 5 additions & 0 deletions scripts/clean.sh
@@ -0,0 +1,5 @@
#!/bin/bash
docker stop webauthn-nodeos
docker rm webauthn-nodeos

rm -rf webauthn-nodeos-data
8 changes: 8 additions & 0 deletions scripts/frontend-setup.sh
@@ -0,0 +1,8 @@
#!/bin/bash
# Setup JS App
yarn
rm -rf node_modules/eosjs
(
cd external/eosjs && yarn
)
yarn add file:external/eosjs
39 changes: 39 additions & 0 deletions scripts/generate-cert.sh
@@ -0,0 +1,39 @@
#!/bin/bash
openssl req \
-x509 \
-nodes \
-new \
-newkey rsa:4096 \
-keyout localhostca.key \
-out localhostca.crt \
-sha256 \
-days 3650 \
-config <(cat <<EOF
[ req ]
prompt = no
distinguished_name = subject
x509_extensions = x509_ext
[ subject ]
commonName = localhost
[ x509_ext ]
subjectAltName = @alternate_names
basicConstraints=CA:TRUE,pathlen:0
[ alternate_names ]
DNS.1 = localhost
EOF
)

cat localhostca.crt localhostca.key > localhostca.pem

cp localhostca.pem docker/haproxy

CLEAR="\033[0m"
GREEN="\033[32m"
YELLOW="\033[33m"
echo -e "${GREEN}Certificate generated, remember to import into your browser!${CLEAR}"
echo -e "${YELLOW}For security, it is recommended you remove this cert after testing is complete.${CLEAR}"
9 changes: 9 additions & 0 deletions scripts/setup.sh
@@ -0,0 +1,9 @@
#!/bin/bash
# Frontend setup
./scripts/frontend-setup.sh

# Create Local Cert
./scripts/generate-cert.sh

# Setup Chain
./scripts/chain-setup.sh
11 changes: 11 additions & 0 deletions scripts/start.sh
@@ -0,0 +1,11 @@
#!/bin/bash
docker run \
-d \
-p '8888:8888' \
--name 'webauthn-nodeos' \
-v "$(pwd)/webauthn-nodeos-data":/root/.local/share/eosio \
-it eosio/eos-webauthn:latest \
nodeos --data-dir /root/.local/share/eosio --plugin eosio::chain_api_plugin --plugin eosio::producer_api_plugin --http-validate-host 0 --access-control-allow-origin "*" --http-server-address=0.0.0.0:8888 -p eosio -e

haproxy -f haproxy-webauthn.cfg &> haproxy.log &
yarn server
4 changes: 4 additions & 0 deletions scripts/stop.sh
@@ -0,0 +1,4 @@
#!/bin/bash
docker stop webauthn-nodeos
docker rm webauthn-nodeos
pgrep haproxy | xargs kill
14 changes: 7 additions & 7 deletions src/client/ClientRoot.tsx
@@ -1,9 +1,9 @@
import { Key } from '../common/Key';
import { Api, JsonRpc, Serialize } from 'eosjs';
import { WaSignatureProvider } from './wasig';
import * as IoClient from 'socket.io-client';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import * as IoClient from 'socket.io-client';
import { Key } from '../common/Key';
import { WaSignatureProvider } from './wasig';

require('./style.css');

Expand Down Expand Up @@ -84,8 +84,8 @@ async function delay(ms: number): Promise<void> {
async function createKey(appState: AppState) {
try {
appendMessage(appState, 'Create key...');
let rp = { id: 'localhost', name: 'bar' };
let cred = await (navigator as any).credentials.create({
const rp = { id: 'localhost', name: 'bar' };
const cred = await (navigator as any).credentials.create({
publicKey: {
rp,
user: {
Expand Down Expand Up @@ -186,15 +186,15 @@ class ClientRoot extends React.Component<{ appState: AppState }> {
functionality, or other requests from the community, and we encourage the community to take responsibility
for these.
<br /><br />
<a href="https://github.com/EOSIO/webauthn-browser-signature">GitHub Repo</a>
<a href='https://github.com/EOSIO/webauthn-browser-signature'>GitHub Repo</a>
</div>
</div>
);
}
}

export default function init(prev: AppState) {
let appState = new AppState();
const appState = new AppState();
if (prev) {
appState.restore(prev);
prev.alive = false;
Expand Down
2 changes: 1 addition & 1 deletion src/server/server.ts
Expand Up @@ -106,7 +106,7 @@ async function decodeKey(k: AddKeyArgs): Promise<Key> {
const y = pubKey.get(-3);
if (x.length !== 32 || y.length !== 32)
throw new Error('Public key has invalid X or Y size');
const ser = new Serialize.SerialBuffer();
const ser = new Serialize.SerialBuffer({textEncoder: new util.TextEncoder(), textDecoder: new util.TextDecoder()});
ser.push((y[31] & 1) ? 3 : 2);
ser.pushArray(x);
ser.push(flagsToPresence(flags));
Expand Down

0 comments on commit 1fa429a

Please sign in to comment.