Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
chibiegg committed Mar 9, 2021
0 parents commit ca293f4
Show file tree
Hide file tree
Showing 8 changed files with 765 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
### Go ###
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

### Go Patch ###
/vendor/
/Godeps/
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM golang:1.15 as builder

RUN mkdir /opt/app/
WORKDIR /opt/app/

ENV GOOS=js
ENV GOARCH=wasm

ADD golang/ssh-keygen.go /opt/app/
RUN go get golang.org/x/crypto/ssh
RUN go build -o ssh-keygen.wasm ssh-keygen.go

FROM nginx

RUN sed -i -e "5a application/wasm wasm;" /etc/nginx/mime.types

COPY --from=builder /opt/app/ssh-keygen.wasm /usr/share/nginx/html/
ADD docs/* /usr/share/nginx/html/
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# WASM ssh-keygen example

これはWASMを利用して、ブラウザ上でSSH鍵ペアを生成するサンプルです。

9 changes: 9 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

export GOOS=js
export GOARCH=wasm

mkdir -p dist/
cd golang/
go get "golang.org/x/crypto/ssh"
go build -o ../docs/ssh-keygen.wasm ssh-keygen.go
58 changes: 58 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!doctype html>
<!--
Copyright 2018 The Go Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
-->
<html>

<head>
<meta charset="utf-8">
<title>Go wasm</title>
</head>

<body>
<!--
Add the following polyfill for Microsoft Edge 17/18 support:
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/encoding.min.js"></script>
(see https://caniuse.com/#feat=textencoder)
-->
<script src="wasm_exec.js"></script>
<script>
if (!WebAssembly.instantiateStreaming) { // polyfill
WebAssembly.instantiateStreaming = async (resp, importObject) => {
const source = await (await resp).arrayBuffer();
return await WebAssembly.instantiate(source, importObject);
};
}

const go = new Go();
let mod, inst;
WebAssembly.instantiateStreaming(fetch("ssh-keygen.wasm"), go.importObject).then((result) => {
mod = result.module;
inst = result.instance;
go.run(result.instance);
document.getElementById("runButton").disabled = false;
}).catch((err) => {
console.error(err);
});

async function run() {
keypair = sshKeyGen.GenerateRSAKeyPair();
console.log(keypair);

document.getElementById("publicKey").value = keypair.publicKey;
document.getElementById("privateKey").value = keypair.privateKey;
}
</script>

<button onClick="run();" id="runButton" disabled>Run</button>

<h3>PublicKey</h3>
<textarea id="publicKey"></textarea>
<h3>PrivateKey</h3>
<textarea id="privateKey"></textarea>

</body>

</html>
Binary file added docs/ssh-keygen.wasm
Binary file not shown.
Loading

0 comments on commit ca293f4

Please sign in to comment.