Browse Source

init commit

kmahyyg 4 years ago
commit
4a7b924ad4
3 changed files with 131 additions and 0 deletions
  1. 1 0
      .gitignore
  2. 66 0
      Dockerfile
  3. 64 0
      argon2g.go

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+.vscode

+ 66 - 0
Dockerfile

@@ -0,0 +1,66 @@
+FROM debian:sid-slim AS builder
+ENV NODEJS_MAJOR=14
+
+# BUILD FIRST IN FIRST STAGE
+WORKDIR /build
+RUN apt update -y && \
+    apt install curl gnupg2 ca-certificates zip unzip build-essential git --no-install-recommends -y && \
+    curl -sL -o node_lts.sh https://deb.nodesource.com/setup_lts.x && \
+    bash node_lts.sh && \
+    apt install -y nodejs --no-install-recommends && \
+    rm -f node_lts.sh && \
+    git clone https://github.com/key-networks/ztncui && \
+    npm install -g node-gyp pkg && \
+    cd ztncui/src && \
+    npm install && \
+    pkg -c ./package.json -t "node${NODEJS_MAJOR}-linux-x64" bin/www -o ztncui && \
+    zip -r /build/artifact.zip ztncui node_modules/argon2/build/Release
+
+
+FROM golang:buster AS argong
+
+
+
+# START RUNNER
+FROM debian:sid-slim AS runner
+RUN apt update -y && \
+    apt install curl gnupg2 ca-certificates unzip supervisor --no-install-recommends -y && \
+    curl -sL -o ztone.sh https://install.zerotier.com && \
+    bash ztone.sh && \
+    rm -f ztone.sh && \
+    apt clean -y && \
+    rm -rf /var/lib/zerotier-one
+
+    
+WORKDIR /opt/key-networks/ztncui
+COPY --from=builder /build/artifact.zip .
+RUN unzip ./artifact.zip && \
+    rm -f ./artifact.zip
+
+COPY gosu /bin/gosu
+COPY minica /usr/local/bin/minica
+COPY argon2gen /usr/local/bin/argon2gen
+
+# INSTALL NODEJS AND ZT SECOND STAGE
+# INSTALL MINICA AND GOSU
+# REMOVE PREBUILT ZT IDENTITY
+# COPY SUPERVISOR CONF
+#RUN
+# EXPOSE VOLUME
+
+RUN apt update -y && \
+    apt install curl gnupg2 ca-certificates build-essential supervisor --no-install-recommends -y && \
+    curl -sL -o node_lts.sh https://deb.nodesource.com/setup_lts.x && \
+    bash node_lts.sh && \
+    apt install -y nodejs --no-install-recommends && \
+    curl -sL -o ztone.sh https://install.zerotier.com && \
+    bash ztone.sh && \
+    curl -o ztncui.deb https://s3-us-west-1.amazonaws.com/key-networks/deb/ztncui/1/x86_64/ztncui_${ZTNCUI_VER}_amd64.deb && \
+    dpkg -i ztncui.deb
+
+COPY gosu /bin/gosu
+COPY minica /usr/bin/minica
+
+RUN rm -rf /var/lib/zerotier-one && \
+    
+

+ 64 - 0
argon2g.go

@@ -0,0 +1,64 @@
+package main
+
+import (
+	"crypto/rand"
+	"encoding/base64"
+	"encoding/json"
+	"fmt"
+	"io/ioutil"
+	"log"
+
+	"golang.org/x/crypto/argon2"
+)
+
+type UserDef struct {
+	Name    string `json:"name"`
+	PassSet bool   `json:"pass_set"`
+	Hash    string `json:"hash"`
+}
+
+type PasswdDef struct {
+	Admin UserDef `json:"admin"`
+}
+
+func main() {
+	var password string
+	fmt.Print("Input Password: ")
+	fmt.Scanln(&password)
+
+	var ag2_memory uint32 = 4096
+	var ag2_iter uint32 = 3
+	var ag2_para uint8 = 1
+	var ag2_saltlen uint8 = 16
+	var ag2_hashlen uint32 = 32
+
+	ag2_salt := make([]byte, ag2_saltlen)
+	_, err := rand.Read(ag2_salt)
+	if err != nil {
+		log.Fatal(err)
+	}
+
+	ag2_hash := argon2.Key([]byte(password), ag2_salt, ag2_iter, ag2_memory, ag2_para, ag2_hashlen)
+	ag2_saltb64 := base64.RawStdEncoding.EncodeToString(ag2_salt)
+	ag2_hashb64 := base64.RawStdEncoding.EncodeToString(ag2_hash)
+
+	finalhash := fmt.Sprintf("$argon2i$v=%d$m=%d,t=%d,p=%d$%s$%s", argon2.Version, ag2_memory, ag2_iter, ag2_para, ag2_saltb64, ag2_hashb64)
+
+	u1 := UserDef{
+		Name:    "admin",
+		PassSet: true,
+		Hash:    finalhash,
+	}
+	p1 := PasswdDef{
+		Admin: u1,
+	}
+	v1, err := json.Marshal(p1)
+	if err != nil {
+		log.Fatal(err)
+	}
+	err = ioutil.WriteFile("passwd", v1, 0644)
+	if err != nil {
+		log.Fatal(err)
+	}
+	log.Println("Generate Done, check passwd file.")
+}