Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
number571 committed Oct 29, 2024
1 parent cba840e commit 2e3deea
Show file tree
Hide file tree
Showing 12 changed files with 395 additions and 359 deletions.
15 changes: 13 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@

*??? ??, ????*

### CHANGES

- `cmd/hlm,cmd/hlf`: add HLR link to HL services in /about page
- `cmd/hlf`: file hashing: sha256 -> sha384
- `cmd/hlm,cmd/hlf`: hash(pubkey.bytes()) -> hash(pubkey.string())

### BUG FIXES

- `cmd/hlm,cmd/hlf`: fix links to HL services in /about page
- `cmd/hlm`: fix emoji replacer

<!-- ... -->

## v1.7.2
Expand All @@ -14,7 +25,7 @@

### IMPROVEMENTS

- `cmd/hls|cmd/hle|cmd/hlt|cmd/hll`: add 'network' run option
- `cmd/hls,cmd/hle,cmd/hlt,cmd/hll`: add 'network' run option

### CHANGES

Expand All @@ -36,7 +47,7 @@

- `cmd/hls`: rename /api/network/pubkey -> /api/service/pubkey
- `cmd/hle`: update API encrypt/decrypt messages
- `cmd/hls|cmd/hlt`: delete rand_ prefix parameters (message_size_bytes, queue_period_ms)
- `cmd/hls,cmd/hlt`: delete rand_ prefix parameters (message_size_bytes, queue_period_ms)
- `go.mod`: update go-peer version: 1.7.0 -> 1.7.2

<!-- ... -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package handler

import (
"crypto/sha256"
"crypto/sha512"
"io"
"io/fs"
"net/http"
Expand Down Expand Up @@ -98,10 +98,9 @@ func getFileHash(filename string) string {
}
defer f.Close()

h := sha256.New()
h := sha512.New384()
if _, err := io.Copy(h, f); err != nil {
return ""
}

return encoding.HexEncode(h.Sum(nil))
}
8 changes: 6 additions & 2 deletions internal/applications/filesharer/internal/handler/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strconv"
"strings"

"github.com/number571/go-peer/pkg/crypto/hashing"
"github.com/number571/go-peer/pkg/logger"
"github.com/number571/go-peer/pkg/utils"
"github.com/number571/hidden-lake/internal/applications/filesharer/internal/config"
Expand Down Expand Up @@ -131,8 +132,11 @@ func getSettings(
return nil, utils.MergeErrors(ErrGetPublicKey, err)
}

result.FPublicKey = myPubKey.ToString()
result.FPublicKeyHash = myPubKey.GetHasher().ToString()
myPubKeyStr := myPubKey.ToString()
result.FPublicKey = myPubKeyStr

// echo PubKey{...} | sha384sum
result.FPublicKeyHash = hashing.NewHasher([]byte(myPubKeyStr)).ToString()

gotSettings, err := pHlsClient.GetSettings(pCtx)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/applications/filesharer/internal/handler/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package handler

import (
"context"
"crypto/sha256"
"crypto/sha512"
"html/template"
"net/http"
"strconv"
Expand Down Expand Up @@ -102,7 +102,7 @@ func downloadFile(
fileName := query.Get("file_name")

fileHash := query.Get("file_hash")
if fileHash == "" || len(fileHash) != (sha256.Size<<1) {
if len(fileHash) != (sha512.Size384 << 1) {
ErrorPage(pLogger, pCfg, "file_hash_error", "incorrect file hash")(pW, pR)
return
}
Expand Down
4 changes: 2 additions & 2 deletions internal/applications/filesharer/internal/stream/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package stream

import (
"context"
"crypto/sha256"
"crypto/sha512"
"hash"
"io"

Expand Down Expand Up @@ -49,7 +49,7 @@ func BuildStream(
hlf_client.NewRequester(pHlsClient),
),
fAliasName: pAliasName,
fHasher: sha256.New(),
fHasher: sha512.New384(),
fChunkSize: chunkSize,
fFileInfo: pFileInfo,
}, nil
Expand Down
4 changes: 2 additions & 2 deletions internal/applications/filesharer/pkg/client/requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package client

import (
"context"
"crypto/sha256"
"crypto/sha512"
"net/http"

"github.com/number571/go-peer/pkg/encoding"
Expand Down Expand Up @@ -42,7 +42,7 @@ func (p *sRequester) GetListFiles(pCtx context.Context, pAliasName string, pRequ
}

for _, info := range list {
if len(info.FHash) != (sha256.Size << 1) {
if len(info.FHash) != (sha512.Size384 << 1) {
return nil, ErrInvalidResponse
}
}
Expand Down
18 changes: 12 additions & 6 deletions internal/applications/filesharer/web/template/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -239,40 +239,46 @@ <h1 class="col-md-10 mb-3 mx-auto h3 text-white">Hidden Lake Filesharer</h1>
<ol>
<li>
<p class="text-left">
<a href="https://github.com/number571/hidden-lake/tree/master/cmd/service"
<a href="https://github.com/number571/hidden-lake/tree/master/cmd/hls"
class="text-info">Hidden Lake Service</a>;
</p>
</li>
<li>
<p class="text-left">
<a href="https://github.com/number571/hidden-lake/tree/master/cmd/helpers/traffic"
<a href="https://github.com/number571/hidden-lake/tree/master/cmd/hlt"
class="text-info">Hidden Lake Traffic</a>;
</p>
</li>
<li>
<p class="text-left">
<a href="https://github.com/number571/hidden-lake/tree/master/cmd/helpers/encryptor"
<a href="https://github.com/number571/hidden-lake/tree/master/cmd/hle"
class="text-info">Hidden Lake Encryptor</a>;
</p>
</li>
<li>
<p class="text-left">
<a href="https://github.com/number571/hidden-lake/tree/master/cmd/helpers/loader"
<a href="https://github.com/number571/hidden-lake/tree/master/cmd/hll"
class="text-info">Hidden Lake Loader</a>;
</p>
</li>
<li>
<p class="text-left">
<a href="https://github.com/number571/hidden-lake/tree/master/cmd/applications/messenger"
<a href="https://github.com/number571/hidden-lake/tree/master/cmd/hlm"
class="text-info">Hidden Lake Messenger</a>;
</p>
</li>
<li>
<p class="text-left">
<a href="https://github.com/number571/hidden-lake/tree/master/cmd/applications/filesharer"
<a href="https://github.com/number571/hidden-lake/tree/master/cmd/hlf"
class="text-info">Hidden Lake Filesharer</a>;
</p>
</li>
<li>
<p class="text-left">
<a href="https://github.com/number571/hidden-lake/tree/master/cmd/hlr"
class="text-info">Hidden Lake Remoter</a>;
</p>
</li>
</ol>
</div>
</div>
Expand Down
8 changes: 6 additions & 2 deletions internal/applications/messenger/internal/handler/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strconv"
"strings"

"github.com/number571/go-peer/pkg/crypto/hashing"
"github.com/number571/go-peer/pkg/logger"
"github.com/number571/go-peer/pkg/utils"
"github.com/number571/hidden-lake/internal/applications/messenger/internal/config"
Expand Down Expand Up @@ -127,8 +128,11 @@ func getSettings(pCtx context.Context, pCfg config.IConfig, pHlsClient hls_clien
return nil, utils.MergeErrors(ErrGetPublicKey, err)
}

result.FPublicKey = myPubKey.ToString()
result.FPublicKeyHash = myPubKey.GetHasher().ToString()
myPubKeyStr := myPubKey.ToString()
result.FPublicKey = myPubKeyStr

// echo PubKey{...} | sha384sum
result.FPublicKeyHash = hashing.NewHasher([]byte(myPubKeyStr)).ToString()

gotSettings, err := pHlsClient.GetSettings(pCtx)
if err != nil {
Expand Down
20 changes: 13 additions & 7 deletions internal/applications/messenger/internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type sEmojis struct {
}

var (
gEmojiReplacer *strings.Replacer
gEmojiReplacer map[string]string
)

func init() {
Expand All @@ -29,18 +29,24 @@ func init() {
panic(err)
}

replacerList := make([]string, 0, len(emojiSimple.Emojis)+len(emoji.Emojis))
gEmojiReplacer = make(map[string]string, len(emojiSimple.Emojis)+len(emoji.Emojis))

for _, emoji := range emojiSimple.Emojis {
replacerList = append(replacerList, emoji.Shortname, emoji.Emoji)
gEmojiReplacer[emoji.Shortname] = emoji.Emoji
}
for _, emoji := range emoji.Emojis {
replacerList = append(replacerList, emoji.Shortname, emoji.Emoji)
gEmojiReplacer[emoji.Shortname] = emoji.Emoji
}

gEmojiReplacer = strings.NewReplacer(replacerList...)
}

func ReplaceTextToEmoji(pS string) string {
return gEmojiReplacer.Replace(pS)
splited := strings.Split(pS, " ")
for i, s := range splited {
v, ok := gEmojiReplacer[s]
if !ok {
continue
}
splited[i] = v
}
return strings.Join(splited, " ")
}
18 changes: 12 additions & 6 deletions internal/applications/messenger/web/template/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -236,40 +236,46 @@ <h1 class="col-md-10 mb-3 mx-auto h3 text-white">Hidden Lake Messenger</h1>
<ol>
<li>
<p class="text-left">
<a href="https://github.com/number571/hidden-lake/tree/master/cmd/service"
<a href="https://github.com/number571/hidden-lake/tree/master/cmd/hls"
class="text-info">Hidden Lake Service</a>;
</p>
</li>
<li>
<p class="text-left">
<a href="https://github.com/number571/hidden-lake/tree/master/cmd/helpers/traffic"
<a href="https://github.com/number571/hidden-lake/tree/master/cmd/hlt"
class="text-info">Hidden Lake Traffic</a>;
</p>
</li>
<li>
<p class="text-left">
<a href="https://github.com/number571/hidden-lake/tree/master/cmd/helpers/encryptor"
<a href="https://github.com/number571/hidden-lake/tree/master/cmd/hle"
class="text-info">Hidden Lake Encryptor</a>;
</p>
</li>
<li>
<p class="text-left">
<a href="https://github.com/number571/hidden-lake/tree/master/cmd/helpers/loader"
<a href="https://github.com/number571/hidden-lake/tree/master/cmd/hll"
class="text-info">Hidden Lake Loader</a>;
</p>
</li>
<li>
<p class="text-left">
<a href="https://github.com/number571/hidden-lake/tree/master/cmd/applications/messenger"
<a href="https://github.com/number571/hidden-lake/tree/master/cmd/hlm"
class="text-info">Hidden Lake Messenger</a>;
</p>
</li>
<li>
<p class="text-left">
<a href="https://github.com/number571/hidden-lake/tree/master/cmd/applications/filesharer"
<a href="https://github.com/number571/hidden-lake/tree/master/cmd/hlf"
class="text-info">Hidden Lake Filesharer</a>;
</p>
</li>
<li>
<p class="text-left">
<a href="https://github.com/number571/hidden-lake/tree/master/cmd/hlr"
class="text-info">Hidden Lake Remoter</a>;
</p>
</li>
</ol>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion test/result/badge_codelines.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 2e3deea

Please sign in to comment.