diff --git a/Makefile b/Makefile index 55ea6ff..90c8a5a 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,8 @@ export GOPATH:=$(shell pwd) export GOBIN=$(shell pwd)/bin +PLATFORMS := windows linux darwin +PKGS := $(shell go list ./src/docsdocs...) SHELL := /bin/bash default: all @@ -13,19 +15,24 @@ deps: @cp -R vendor/* src/ @echo "" -client: +install_client: @echo "--> intall client" @go install docsdocs/main/docs @echo "" -fmt: - @echo "--> formating" - @go fmt docsdocs/... +install_server: + @echo "--> intall server" + @go install docsdocs/main/docsd @echo "" lint: - @echo "--> lint " - @golint src/docsdocs/... + @echo "--> linting" + @golint $(PKGS) + @echo "" + +fmt: + @echo "--> formating" + @go fmt docsdocs/... @echo "" clean: @@ -45,4 +52,4 @@ test: coverage: @goverage -v -coverprofile=coverage.txt $(shell go list docsdocs/... | grep -v docsdocs/client/views/gui) -all: fmt client +all: fmt lint client diff --git a/README.md b/README.md index 01f1f93..e193f89 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,10 @@ ![DocsDocs Logo](assets/client/images/logo.png) -[![license](https://img.shields.io/badge/License-BSD-blue.svg?style=for-the-badge)](LICENSE) +[![License](https://img.shields.io/badge/License-BSD-blue.svg?style=for-the-badge)](LICENSE) [![Travis](https://img.shields.io/travis/murilobsd/docsdocs/master.svg?style=for-the-badge)](https://travis-ci.org/murilobsd/docsdocs) [![Codecov](https://img.shields.io/codecov/c/gh/murilobsd/docsdocs.svg?style=for-the-badge)](https://codecov.io/gh/murilobsd/docsdocs) +[![Telegram](https://img.shields.io/badge/telegram-chat-blue.svg?style=for-the-badge&logo=telegram)](https://t.me/joinchat/BEU4pxK-Ow8IXiKTQEJZxg) > The easiest and safest way for **accountants** to share documents to their clients. @@ -32,7 +33,7 @@ Two main safety issues may occur and are being currently worked on: - File Cryptography - Node Cryptography -If you find a vulnerability please send your report and we kindly ask you not to file a public report, our GPG key is ... security@docsdocs.com +If you find a vulnerability please send your report and we kindly ask you not to file a public report, our GPG key is [076C2D5451A74153](https://murilo.net.br) murilo@lab804.com.br ## Install diff --git a/README.pt.md b/README.pt.md index 30bc84f..defe60b 100644 --- a/README.pt.md +++ b/README.pt.md @@ -4,6 +4,8 @@ [![license](https://img.shields.io/badge/License-BSD-blue.svg?style=for-the-badge)](LICENSE) [![Travis](https://img.shields.io/travis/murilobsd/docsdocs/master.svg?style=for-the-badge)](https://travis-ci.org/murilobsd/docsdocs) +[![Codecov](https://img.shields.io/codecov/c/gh/murilobsd/docsdocs.svg?style=for-the-badge)](https://codecov.io/gh/murilobsd/docsdocs) +[![Telegram](https://img.shields.io/badge/telegram-chat-blue.svg?style=for-the-badge&logo=telegram)](https://t.me/joinchat/BEU4pxK-Ow8IXiKTQEJZxg) > A maneira simples e segura para **Contadores** compartilharem documentos com seus clientes. @@ -35,7 +37,7 @@ Duas questões de segurança precisam ser imediamente estruturada: - Criptografia na comunicação entre os nós Caso encontre alguma falha de segurança por favor entre em contato imediatamente conosco, -a nossa chave GPG security@docsdocs.com.br +a nossa chave GPG [076C2D5451A74153](https://murilo.net.br) murilo@lab804.com.br ## Instalação diff --git a/assets/client/glade/#main.glade# b/assets/client/glade/#main.glade# new file mode 100644 index 0000000..585b7ac --- /dev/null +++ b/assets/client/glade/#main.glade# @@ -0,0 +1,272 @@ + + + + + + False + dialog + + + + + + False + vertical + 2 + + + False + end + + + + + + + + + False + False + 0 + + + + + + + + + + False + dialog + Docs Docs + 0.0.1 + Todos os direitos reservados + Compartilhar documentos fiscais criptografado de forma distribuída. + https://docsdocs.com.br + Docs Docs WebSite + Murilo Ijanc + ../../../../../Imagens/logo_docsdocs.png + bsd + + + + + + False + vertical + 2 + + + False + end + + + False + False + 0 + + + + + + + + + + window + False + Docs Docs + center + 600 + 400 + applications-office + center + + + + + + True + False + vertical + + + True + False + + + True + False + _Arquivo + True + + + True + False + + + gtk-new + True + False + True + True + + + + + gtk-open + True + False + True + True + + + + + gtk-save + True + False + True + True + + + + + gtk-save-as + True + False + True + True + + + + + True + False + + + + + gtk-quit + True + False + True + True + + + + + + + + + True + False + _Editar + True + + + True + False + + + gtk-cut + True + False + True + True + + + + + gtk-copy + True + False + True + True + + + + + gtk-paste + True + False + True + True + + + + + gtk-delete + True + False + True + True + + + + + + + + + True + False + _Ver + True + + + + + True + False + Ajuda + + + True + False + + + gtk-help + True + False + True + True + + + + + True + False + Sobre + True + + + + + + + + + False + True + 0 + + + + + True + False + DocsDocs + + + True + True + 1 + + + + + + diff --git a/src/docsdocs/crypto/generate.go b/src/docsdocs/crypto/generate.go index dbce201..d8bbad1 100644 --- a/src/docsdocs/crypto/generate.go +++ b/src/docsdocs/crypto/generate.go @@ -33,8 +33,8 @@ type Encrypter interface { ExportPublic(io.Writer) error GetPrivate() *rsa.PrivateKey GetPublic() *rsa.PublicKey - // ReadPrivate() (*rsa.PrivateKey, error) - // ReadPublic() (*rsa.PublicKey, error) + // ReadPrivateFile(r io.Reader) (*rsa.PrivateKey, error) + // ReadPublicFile(r io.Reader) (*rsa.PublicKey, error) } // DocsCrypto This is struct to manager crypto files diff --git a/src/docsdocs/main/docs/docs.go b/src/docsdocs/main/docs/docs.go index 74cb530..8e784a0 100644 --- a/src/docsdocs/main/docs/docs.go +++ b/src/docsdocs/main/docs/docs.go @@ -2,8 +2,32 @@ package main import ( "docsdocs/log" + "docsdocs/proto" + "fmt" ) func main() { log.Settings("json", "stdout", "debug") + t, err := proto.NewTransport("tcp", "localhost:3000") + if err != nil { + panic(err) + } + for _, method := range []proto.Method{ + proto.MethodGet, + proto.MethodPost, + proto.MethodDelete, + 42, + } { + fmt.Println("starting request: ", method) + resp, err := t.RoundTrip(&proto.Request{ + Header: proto.Header{}, + Method: method, + BodyBytes: []byte("hello =]"), + }) + if err != nil { + fmt.Printf("Erro: %v\n", err) + } + fmt.Printf("Response: %v\n\n", resp) + } + } diff --git a/src/docsdocs/main/docsd/docsd.go b/src/docsdocs/main/docsd/docsd.go new file mode 100644 index 0000000..14dc294 --- /dev/null +++ b/src/docsdocs/main/docsd/docsd.go @@ -0,0 +1,16 @@ +package main + +import ( + "docsdocs/log" + "docsdocs/server" +) + +func main() { + log.Settings("json", "stdout", "debug") + serv, err := server.NewServer("tcp", "localhost:3000") + if err != nil { + panic(err) + } + quit := serv.Run() + defer func() { quit <- struct{}{} }() +} diff --git a/src/docsdocs/proto/doc.go b/src/docsdocs/proto/doc.go new file mode 100644 index 0000000..ee90f71 --- /dev/null +++ b/src/docsdocs/proto/doc.go @@ -0,0 +1,4 @@ +/* +Package proto .... +*/ +package proto diff --git a/src/docsdocs/proto/method.go b/src/docsdocs/proto/method.go new file mode 100644 index 0000000..d32c055 --- /dev/null +++ b/src/docsdocs/proto/method.go @@ -0,0 +1,15 @@ +package proto + +// Commom Protocol methods. + +// Method type +type Method uint64 + +const ( + // MethodGet ... + MethodGet Method = 1 << iota + // MethodPost ... + MethodPost + // MethodDelete ... + MethodDelete +) diff --git a/src/docsdocs/proto/request.go b/src/docsdocs/proto/request.go new file mode 100644 index 0000000..0678141 --- /dev/null +++ b/src/docsdocs/proto/request.go @@ -0,0 +1,35 @@ +package proto + +import ( + "bytes" + "encoding/gob" +) + +func init() { + gob.Register(Request{}) +} + +// Request ... +type Request struct { + Header Header + Method Method + BodyBytes []byte +} + +// Serialize ... +func (r *Request) Serialize() ([]byte, error) { + b := bytes.Buffer{} + encoder := gob.NewEncoder(&b) + err := encoder.Encode(r) + return b.Bytes(), err +} + +// DeserualizeRequest ... +func DeserualizeRequest(reqBytes []byte) (Request, error) { + b := bytes.Buffer{} + b.Write(reqBytes) + decoder := gob.NewDecoder(&b) + req := &Request{} + err := decoder.Decode(req) + return *req, err +} diff --git a/src/docsdocs/proto/response.go b/src/docsdocs/proto/response.go new file mode 100644 index 0000000..90e2b10 --- /dev/null +++ b/src/docsdocs/proto/response.go @@ -0,0 +1,41 @@ +package proto + +import ( + "bytes" + "encoding/gob" +) + +// Status ... +type Status int64 + +const ( + // Sucess ... + Sucess Status = 1 << iota + // Error ... + Error +) + +// Response ... +type Response struct { + Header Header + Status Status + BodyBytes []byte +} + +// Serialize - convert the response to the wire format +func (r *Response) Serialize() ([]byte, error) { + b := bytes.Buffer{} + encoder := gob.NewEncoder(&b) + err := encoder.Encode(r) + return b.Bytes(), err +} + +// DeserializeResponse - convert the response from the wire format +func DeserializeResponse(responseBytes []byte) (Response, error) { + b := bytes.Buffer{} + b.Write(responseBytes) + decoder := gob.NewDecoder(&b) + resp := &Response{} + err := decoder.Decode(resp) + return *resp, err +} diff --git a/src/docsdocs/proto/transport.go b/src/docsdocs/proto/transport.go new file mode 100644 index 0000000..4f0bc8d --- /dev/null +++ b/src/docsdocs/proto/transport.go @@ -0,0 +1,54 @@ +package proto + +import ( + "encoding/gob" + "net" +) + +// Header ... +type Header struct{} + +// Encoder ... +type Encoder interface { + Encode(interface{}) error +} + +// Decoder ... +type Decoder interface { + Decode(interface{}) error +} + +// Transport ... +type Transport struct { + conn net.Conn + enc Encoder + dec Decoder +} + +// NewTransport - create a new transport structure +func NewTransport(proto, remote string) (*Transport, error) { + conn, err := net.Dial(proto, remote) + enc := gob.NewEncoder(conn) + dec := gob.NewDecoder(conn) + return &Transport{ + conn: conn, + enc: enc, + dec: dec, + }, err +} + +// RoundTrip - Implementation of a round tripper interface, +// effectively this is how the request will be serialized, +// and put on the wire, and how the response will be deserialized +func (t *Transport) RoundTrip(request *Request) (Response, error) { + var response Response + // serialize request + if err := t.enc.Encode(request); err != nil { + return response, err + } + // unserialize response + if err := t.dec.Decode(&response); err != nil { + return response, err + } + return response, nil +} diff --git a/src/docsdocs/server/doc.go b/src/docsdocs/server/doc.go new file mode 100644 index 0000000..0b16ffa --- /dev/null +++ b/src/docsdocs/server/doc.go @@ -0,0 +1,4 @@ +/* +package server ... +*/ +package server diff --git a/src/docsdocs/server/main.go b/src/docsdocs/server/main.go new file mode 100644 index 0000000..e610ad0 --- /dev/null +++ b/src/docsdocs/server/main.go @@ -0,0 +1,70 @@ +package server + +import ( + "docsdocs/log" + "docsdocs/proto" + "encoding/gob" + "net" +) + +type Server struct { + log.Logger + listener net.Listener +} + +func NewServer(proto, address string) (*Server, error) { + listener, err := net.Listen(proto, address) + if err != nil { + return nil, err + } + return &Server{ + Logger: log.NewDocsLogger(), + listener: listener, + }, nil +} + +func (s *Server) Run() chan struct{} { + q := make(chan struct{}) + go func(quit chan struct{}) { + for { + conn, err := s.listener.Accept() + if err != nil { + s.Error(err) + return + } + go s.handlerConn(conn) + + } + }(q) + return q +} + +func (s *Server) handlerConn(conn net.Conn) { + decoder := gob.NewDecoder(conn) + encoder := gob.NewEncoder(conn) + for { + var req proto.Request + err := decoder.Decode(&req) + if err != nil { + s.Error(err) + return + } + s.Info("Got request: %v\n", req) + var resp = new(proto.Response) + switch req.Method { + case proto.MethodGet: + s.Info("request is a get method.") + resp.Status = proto.Sucess + case proto.MethodPost: + s.Info("request is a post method.") + resp.Status = proto.Sucess + case proto.MethodDelete: + s.Info("request is a delete method.") + resp.Status = proto.Sucess + default: + s.Warn("unknow request method") + resp.Status = proto.Error + } + encoder.Encode(*resp) + } +} diff --git a/src/docsdocs/util/doc.go b/src/docsdocs/util/doc.go new file mode 100644 index 0000000..1132abd --- /dev/null +++ b/src/docsdocs/util/doc.go @@ -0,0 +1,4 @@ +/* +Package util some functions +*/ +package util diff --git a/src/docsdocs/util/file.go b/src/docsdocs/util/file.go new file mode 100644 index 0000000..f9b57b7 --- /dev/null +++ b/src/docsdocs/util/file.go @@ -0,0 +1,15 @@ +package util + +import ( + "io/ioutil" +) + +// SaveFile this function save content to file +func SaveFile(filename string, content []byte) error { + return ioutil.WriteFile(filename, content, 0644) +} + +// ReadFile this function read content +func ReadFile(filename string) ([]byte, error) { + return ioutil.ReadFile(filename) +} diff --git a/src/docsdocs/util/file_test.go b/src/docsdocs/util/file_test.go new file mode 100644 index 0000000..666454e --- /dev/null +++ b/src/docsdocs/util/file_test.go @@ -0,0 +1,50 @@ +package util + +import ( + "io/ioutil" + "os" + "testing" +) + +func TestReadFile(t *testing.T) { + filename := "notexist" + contents, err := ReadFile(filename) + if err == nil { + t.Fatalf("Readfile %s: error expected, none found", filename) + } + filename = "file_test.go" + contents, err = ReadFile(filename) + if err != nil { + t.Fatalf("ReadFile %s: %v", filename, err) + } + dir, _ := os.Stat(filename) + + if dir.Size() != int64(len(contents)) { + t.Errorf("Stat %q: size %d want %d", filename, dir.Size(), int64(len(contents))) + } + +} +func TestSaveFile(t *testing.T) { + f, err := ioutil.TempFile("", "docsfile") + if err != nil { + t.Fatal(err) + } + filename := f.Name() + data := "hi =]" + + if err := SaveFile(filename, []byte(data)); err != nil { + t.Fatalf("SaveFile %s: %v", filename, err) + } + contents, err := ReadFile(filename) + if err != nil { + t.Fatalf("Reafile %s: %v", filename, err) + } + + if string(contents) != data { + t.Fatalf("contents = %q\nexpected = %q", string(contents), data) + } + + f.Close() + os.Remove(filename) + +}