Skip to content

Commit

Permalink
general linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Hener committed Nov 9, 2021
1 parent 52cb396 commit 1bb4b44
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 46 deletions.
7 changes: 2 additions & 5 deletions internal/myca/ca.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ import (
// Sum will give the sha256 and sha1 sum of the certificate
func Sum(cert []byte) (sha256s, sha1s string) {
// Building sha256 sum
var f256 [32]byte
f256 = sha256.Sum256(cert)
f256 := sha256.Sum256(cert)
sha256s = fmt.Sprintf("%X", f256)

b := strings.Builder{}
Expand All @@ -46,10 +45,9 @@ func Sum(cert []byte) (sha256s, sha1s string) {
sha256s = b.String()

// building sha1 sum
var f1 [20]byte
// disable "G401 (CWE-326): Use of weak cryptographic primitive"
// #nosec G401
f1 = sha1.Sum(cert)
f1 := sha1.Sum(cert)
sha1s = fmt.Sprintf("%X", f1)

b = strings.Builder{}
Expand All @@ -65,7 +63,6 @@ func Sum(cert []byte) (sha256s, sha1s string) {
sha1s = b.String()

return sha256s, sha1s

}

// ParseAndSum will take the user provided cert and return the sha256 and sha1 sum
Expand Down
27 changes: 12 additions & 15 deletions internal/myhttp/fileserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ import (
"golang.org/x/net/webdav"
)

const (
modeWeb = "web"
)

// Static will provide the embedded files as http.FS
//go:embed static
var static embed.FS
Expand Down Expand Up @@ -104,7 +108,6 @@ func (fs *FileServer) BasicAuthMiddleware(next http.Handler) http.Handler {

next.ServeHTTP(w, r)
})

}

// Start will start the file server
Expand All @@ -114,7 +117,7 @@ func (fs *FileServer) Start(what string) {
mux := mux.NewRouter()

switch what {
case "web":
case modeWeb:
mux.PathPrefix("/425bda8487e36deccb30dd24be590b8744e3a28a8bb5a57d9b3fcd24ae09ad3c/").HandlerFunc(fs.static)
// Websocket
mux.PathPrefix("/14644be038ea0118a1aadfacca2a7d1517d7b209c4b9674ee893b1944d1c2d54/ws").HandlerFunc(fs.socket)
Expand All @@ -133,10 +136,8 @@ func (fs *FileServer) Start(what string) {
if e != nil && r.Method != "PROPFIND" {
log.Printf("WEBDAV ERROR: %s - - \"%s %s %s\"", r.RemoteAddr, r.Method, r.URL.Path, r.Proto)
return
} else {
if r.Method != "PROPFIND" {
log.Printf("WEBDAV: %s - - \"%s %s %s\"", r.RemoteAddr, r.Method, r.URL.Path, r.Proto)
}
} else if r.Method != "PROPFIND" {
log.Printf("WEBDAV: %s - - \"%s %s %s\"", r.RemoteAddr, r.Method, r.URL.Path, r.Proto)
}
},
}
Expand Down Expand Up @@ -165,7 +166,7 @@ func (fs *FileServer) Start(what string) {
go fs.Hub.Run()

// Check BasicAuth and use middleware
if fs.User != "" && what == "web" {
if fs.User != "" && what == modeWeb {
if !fs.SSL {
log.Printf("WARNING!: You are using basic auth without SSL. Your credentials will be transferred in cleartext. Consider using -s, too.\n")
}
Expand Down Expand Up @@ -203,7 +204,6 @@ func (fs *FileServer) Start(what string) {

log.Panic(server.ListenAndServeTLS(fs.MyCert, fs.MyKey))
}

} else {
fs.logStart(what)
log.Panic(server.ListenAndServe())
Expand Down Expand Up @@ -358,7 +358,6 @@ func (fs *FileServer) upload(w http.ResponseWriter, req *http.Request) {
log.Println("ERROR: Not able to write file to disk")
fs.handleError(w, req, err, http.StatusInternalServerError)
}

}

// Log request
Expand All @@ -379,7 +378,7 @@ func (fs *FileServer) bulkDownload(w http.ResponseWriter, req *http.Request) {
files := req.URL.Query()["file"]

// Handle if no files are selected
if len(files) <= 0 {
if len(files) == 0 {
fs.handleError(w, req, errors.New("you need to select a file before you can download a zip archive"), 404)
}

Expand Down Expand Up @@ -473,7 +472,7 @@ func (fs *FileServer) processDir(w http.ResponseWriter, req *http.Request, file
items := make([]item, 0, len(fis))
// Iterate over FileInfo of dir
for _, fi := range fis {
var item = item{}
item := item{}
// Need to set this up here for directories to work
item.Name = fi.Name()
item.Ext = strings.ToLower(myutils.ReturnExt(fi.Name()))
Expand Down Expand Up @@ -528,12 +527,11 @@ func (fs *FileServer) processDir(w http.ResponseWriter, req *http.Request, file
if len(pathSlice) > 2 {
pathSlice = pathSlice[1 : len(pathSlice)-1]

var backString string = ""
var backString string
for _, part := range pathSlice {
backString += "/" + part
}
d.Back = backString

} else {
d.Back = "/"
}
Expand Down Expand Up @@ -613,7 +611,6 @@ func (fs *FileServer) handleError(w http.ResponseWriter, req *http.Request, err
t := template.New("error")
if _, err := t.Parse(string(file)); err != nil {
log.Printf("Error parsing the template: %+v", err)

}
if err := t.Execute(w, e); err != nil {
log.Printf("Error executing the template: %+v", err)
Expand All @@ -622,7 +619,7 @@ func (fs *FileServer) handleError(w http.ResponseWriter, req *http.Request, err

func (fs *FileServer) logStart(what string) {
switch what {
case "web":
case modeWeb:
if fs.SSL {
// Check if selfsigned
if fs.SelfSigned {
Expand Down
4 changes: 1 addition & 3 deletions internal/mysock/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ const (
maxMessageSize = 8000000
)

var (
newline = []byte{'\n'}
)
var newline = []byte{'\n'}

var wsupgrader = websocket.Upgrader{
ReadBufferSize: 1024,
Expand Down
40 changes: 20 additions & 20 deletions internal/myutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,24 @@ func CheckSpecialPath(check string) bool {

// GetInterfaceIpv4Addr will return the ip address by name
func GetInterfaceIpv4Addr(interfaceName string) (addr string, err error) {
var (
ief *net.Interface
addrs []net.Addr
ipv4Addr net.IP
)
if ief, err = net.InterfaceByName(interfaceName); err != nil { // get interface
return
}
if addrs, err = ief.Addrs(); err != nil { // get addresses
return
}
for _, addr := range addrs { // get ipv4 address
if ipv4Addr = addr.(*net.IPNet).IP.To4(); ipv4Addr != nil {
break
}
}
if ipv4Addr == nil {
return "", fmt.Errorf("interface %s doesn't have an ipv4 address\n", interfaceName)
}
return ipv4Addr.String(), nil
var (
ief *net.Interface
addrs []net.Addr
ipv4Addr net.IP
)
if ief, err = net.InterfaceByName(interfaceName); err != nil { // get interface
return
}
if addrs, err = ief.Addrs(); err != nil { // get addresses
return
}
for _, addr := range addrs { // get ipv4 address
if ipv4Addr = addr.(*net.IPNet).IP.To4(); ipv4Addr != nil {
break
}
}
if ipv4Addr == nil {
return "", fmt.Errorf("interface %s doesn't have an ipv4 address", interfaceName)
}
return ipv4Addr.String(), nil
}
4 changes: 1 addition & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ var (
// Man page
func usage() func() {
return func() {

fmt.Printf(`
goshs %s
Usage: %s [options]
Expand Down Expand Up @@ -147,13 +146,12 @@ func init() {
func parseBasicAuth() (string, string) {
auth := strings.SplitN(basicAuth, ":", 2)
if len(auth) < 2 {
fmt.Println("Wrong basic auth format. Please provide user:password seperated by a colon")
fmt.Println("Wrong basic auth format. Please provide user:password separated by a colon")
os.Exit(-1)
}
user := auth[0]
pass := auth[1]
return user, pass

}

func main() {
Expand Down

0 comments on commit 1bb4b44

Please sign in to comment.