Skip to content

Commit

Permalink
Merge pull request #20 from NetSepio/refactor
Browse files Browse the repository at this point in the history
chore: code refactor
  • Loading branch information
Shachindra authored Dec 28, 2024
2 parents c8bd133 + de34283 commit 7aa0819
Show file tree
Hide file tree
Showing 28 changed files with 614 additions and 877 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ erebrus-linux-x64


# bin folder
/bin
/bin

env.text
D:/jjsahdd/server.json
D:/jjsahdd/wg0.conf
45 changes: 45 additions & 0 deletions .sample-env
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#Application Parameters
LOAD_CONFIG_FILE=false
RUNTYPE=debug
SERVER=0.0.0.0
HTTP_PORT=9080
GRPC_PORT=9090
REGION=EU

# PASETO Specifications
PASETO_EXPIRATION_IN_HOURS=168
AUTH_EULA=I Accept the Erebrus Terms of Service https://erebrus.io/terms.html for accessing the application.
SIGNED_BY=Erebrus
FOOTER=Erebrus 2024

#Node Specifications
HOST_IP=ip_addr
DOMAIN=http://ip_addr:9080/
NODE_NAME=
MNEMONIC=
CHAIN_NAME=
NODE_TYPE=
NODE_CONFIG=

#Gateway Specifications
GATEWAY_WALLET=0x0
GATEWAY_DOMAIN=https://dev.gateway.erebrus.io/
GATEWAY_PEERID=/ip4/35.239.34.5/tcp/9001/p2p/12D3KooWH6NjtNwQ3QRELdjqTce38marCzXkA7hHxnuVmJwc8oJA

#Wireguard Specifications
WG_CONF_DIR=
WG_CLIENTS_DIR=
WG_INTERFACE_NAME=wg0.conf
WG_ENDPOINT_HOST=ip_addr
WG_ENDPOINT_PORT=51820
WG_IPv4_SUBNET=10.0.0.1/24
WG_IPv6_SUBNET=fd9f:0000::10:0:0:1/64
WG_DNS=1.1.1.1
WG_ALLOWED_IP_1=0.0.0.0/0
WG_ALLOWED_IP_2=::/0
WG_PRE_UP=echo WireGuard PreUp
WG_POST_UP=iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
WG_PRE_DOWN=echo WireGuard PreDown
WG_POST_DOWN=iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE


23 changes: 0 additions & 23 deletions D:\jjsahdd/server.json

This file was deleted.

10 changes: 0 additions & 10 deletions D:\jjsahdd/wg0.conf

This file was deleted.

7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM golang:alpine AS build-app
RUN apk update && apk add --no-cache git
WORKDIR /app
COPY . .
RUN go build -o erebrus .
RUN go build -ldflags "-X main.version=1.0.0 -X main.codeHash=$(git rev-parse HEAD)" -o erebrus .

FROM alpine:latest
WORKDIR /app
Expand All @@ -13,12 +13,13 @@ COPY --from=build-app /app/webapp ./webapp
COPY wg-watcher.sh .
RUN chmod +x ./erebrus ./wg-watcher.sh
RUN apk update && apk add --no-cache bash openresolv bind-tools wireguard-tools gettext inotify-tools iptables
ENV LOAD_CONFIG_FILE=$LOAD_CONFIG_FILE RUNTYPE=$RUNTYPE SERVER=$SERVER HTTP_PORT=$HTTP_PORT GRPC_PORT=$GRPC_PORT MASTERNODE_URL=$MASTERNODE_URL
ENV REGION=$REGION DOMAIN=$DOMAIN REGION_NAME=$REGION_NAME REGION_CODE=$REGION_CODE
ENV LOAD_CONFIG_FILE=$LOAD_CONFIG_FILE RUNTYPE=$RUNTYPE SERVER=$SERVER HTTP_PORT=$HTTP_PORT GRPC_PORT=$GRPC_PORT GATEWAY_DOMAIN=$GATEWAY_DOMAIN
ENV NODE_NAME=$NODE_NAME REGION=$REGION DOMAIN=$DOMAIN REGION_NAME=$REGION_NAME REGION_CODE=$REGION_CODE
ENV WG_CONF_DIR=$WG_CONF_DIR WG_CLIENTS_DIR=$WG_CLIENTS_DIR WG_KEYS_DIR=$WG_KEYS_DIR WG_INTERFACE_NAME=$WG_INTERFACE_NAME
ENV WG_ENDPOINT_HOST=$WG_ENDPOINT_HOST WG_ENDPOINT_PORT=$WG_ENDPOINT_PORT WG_IPv4_SUBNET=$WG_IPv4_SUBNET WG_IPv6_SUBNET=$WG_IPv6_SUBNET
ENV WG_DNS=$WG_DNS WG_ALLOWED_IP_1=$WG_ALLOWED_IP_1 WG_ALLOWED_IP_2=$WG_ALLOWED_IP_2
ENV WG_PRE_UP=$WG_PRE_UP WG_POST_UP=$WG_POST_UP WG_PRE_DOWN=$WG_PRE_DOWN WG_POST_DOWN=$WG_POST_DOWN
ENV NODE_CONFIG=$NODE_CONFIG NODE_TYPE=$NODE_TYPE
RUN echo $'#!/usr/bin/env bash\n\
set -eo pipefail\n\
/app/erebrus &\n\
Expand Down
104 changes: 91 additions & 13 deletions api/v1/authenticate/authenticate.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package authenticate

import (
"fmt"
"net/http"
"os"

"github.com/NetSepio/erebrus/api/v1/authenticate/challengeid"
"github.com/NetSepio/erebrus/util/pkg/auth"
"github.com/NetSepio/erebrus/util/pkg/claims"
"github.com/NetSepio/erebrus/util/pkg/cryptosign"

"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -38,22 +38,100 @@ func authenticate(c *gin.Context) {
}
userAuthEULA := os.Getenv("AUTH_EULA")
message := userAuthEULA + req.ChallengeId
walletAddress, isCorrect, err := cryptosign.CheckSign(req.Signature, req.ChallengeId, message)

if err == cryptosign.ErrFlowIdNotFound {
log.WithFields(log.Fields{
"err": err,
}).Error("FlowId Not Found")
errResponse := ErrAuthenticate(err.Error())
c.JSON(http.StatusNotFound, errResponse)
return
}
var (
isCorrect bool
walletAddress string
)

if err != nil {
switch req.ChainName {
case "ethereum", "peaq":
userAuthEULA := userAuthEULA
message := userAuthEULA + req.ChallengeId
walletAddress, isCorrect, err = CheckSignEthereum(req.Signature, req.ChallengeId, message)

if err == ErrChallengeIdNotFound {

log.WithFields(log.Fields{"err": err}).Errorf("Challenge Id not found")

c.JSON(http.StatusNotFound, ErrAuthenticate("Challenge Id not found"))

return
}

if err != nil {
fmt.Println("error", err)

log.WithFields(log.Fields{"err": err}).Errorf("failed to CheckSignature, error %v", err.Error())

c.JSON(http.StatusNotFound, ErrAuthenticate("failed to CheckSignature, error :"+err.Error()))
return
}

case "aptos":
userAuthEULA := userAuthEULA
message := fmt.Sprintf("APTOS\nmessage: %v\nnonce: %v", userAuthEULA, req.ChallengeId)
walletAddress, isCorrect, err = CheckSignAptos(req.Signature, req.ChallengeId, message, req.PubKey)

if err == ErrChallengeIdNotFound {
log.WithFields(log.Fields{"err": err}).Errorf("Challenge Id not found")

c.JSON(http.StatusNotFound, ErrAuthenticate("Challenge Id not found"))

return
}

if err != nil {

log.WithFields(log.Fields{"err": err}).Errorf("failed to CheckSignature, error %v", err.Error())

c.JSON(http.StatusNotFound, ErrAuthenticate("failed to CheckSignature, error :"+err.Error()))
return
}

case "sui":
walletAddress, isCorrect, err = CheckSignSui(req.Signature, req.ChallengeId)

if err == ErrChallengeIdNotFound {

log.WithFields(log.Fields{"err": err}).Errorf("Challenge Id not found")

c.JSON(http.StatusNotFound, ErrAuthenticate("Challenge Id not found"))
return
}

if err != nil {
log.WithFields(log.Fields{"err": err}).Errorf("failed to CheckSignature, error %v", err.Error())

c.JSON(http.StatusNotFound, ErrAuthenticate("failed to CheckSignature, error : "+err.Error()))
return
}

case "solana":
walletAddress, isCorrect, err = CheckSignSolana(req.Signature, req.ChallengeId, message, req.PubKey)

if err == ErrChallengeIdNotFound {
log.WithFields(log.Fields{"err": err}).Errorf("Challenge Id not found")
c.JSON(http.StatusNotFound, ErrAuthenticate("Challenge Id not found"))
return
}

if err != nil {
log.WithFields(log.Fields{
"err": err,
}).Errorf("failed to CheckSignature, error : %v", err.Error())
errResponse := ErrAuthenticate("failed to CheckSignature, error :" + err.Error())
c.JSON(http.StatusInternalServerError, errResponse)
return

}

default:
info := "chain name must be between solana, peaq, aptos, sui, eclipse, ethereum"
log.WithFields(log.Fields{
"err": err,
}).Error("failed to CheckSignature")
errResponse := ErrAuthenticate(err.Error())
}).Errorf("Invalid chain name, INFO : %s\n", info)
errResponse := ErrAuthenticate("failed to CheckSignature, error :" + "Invalid chain name, INFO : " + info)
c.JSON(http.StatusInternalServerError, errResponse)
return
}
Expand Down
Loading

0 comments on commit 7aa0819

Please sign in to comment.