👏🎉 Message verification works on the Golang version! Hooray!

This commit is contained in:
Netscape Navigator 2020-10-15 07:30:30 -05:00
parent 3068b474ed
commit d930e68e53
4 changed files with 27 additions and 9 deletions

View File

@ -20,14 +20,13 @@ Email `contact@vaporsfot.xyz` if you have any questions.
* Writing a BNF grammar for message parsing
* Test coverage increases
* Manual QA of features and edge cases
* Providing constructive feedback on documentation
* Cross-compiling windows binaries
* General Golang help (I am a Golang novice- project structure could be improved)
* Security auditing and vulnerability discovery. Please send security concerns to `contact@vaporsoft.xyz`.
* Security auditing and vulnerability discovery. Please send security concerns to `contact@vaporsoft.xyz` privately.
# TODO
**CURRENT TASK:** Write a message parser.
- [ ] Add a real testing lib to DRY things up.
- [ ] Get a good CI system going? Run tests at PR time, provide prebuilt binaries, prevent coverage slips, etc..
- [ ] Add a `transact()` helper to ensure all transactions are closed out.
@ -38,8 +37,8 @@ Email `contact@vaporsfot.xyz` if you have any questions.
|Done?|Noun |Verb | Flag / arg 1 | Flag 2 |
|-----|------------|-----------|---------------|-----------|
| |blob |remove | mhash | |
| |bundle |ingest | | |
| |blob |remove | mhash | |
| |message |show | message mhash | |
| |message |find | --all | |
| |message |find | --last | |

View File

@ -21,6 +21,10 @@ func B32Decode(input string) []byte {
return output
}
func decodeMhash(input string) []byte {
return []byte(B32Decode(input[5:]))
}
func validateMhash(input string) string {
arry := strings.Split(input, ".")
if len(arry) != 2 {

View File

@ -119,13 +119,17 @@ func parseBody(state *parserState) {
}
func parseFooter(state *parserState) {
t := state.scanner.Text()
chunks := strings.Split(t, " ")
state.buffer.signature = chunks[1]
state.mode = parsingDone
err := verifyShallow(&state.buffer)
if err != nil {
state.results = append(state.results, state.buffer)
state.buffer = pigeonMessage{}
panicf("Message verification failed for %s. %s", state.buffer.signature, err)
}
state.results = append(state.results, state.buffer)
state.buffer.body = []pigeonBodyItem{}
state.buffer = pigeonMessage{}
}
func maybeContinue(state *parserState) {

View File

@ -1,6 +1,7 @@
package main
import (
"crypto/ed25519"
"errors"
"fmt"
"regexp"
@ -69,8 +70,18 @@ func validateBodyValue(value *string) error {
return nil
}
func validateSignature(_topHalf string, _b32signature string) error {
return errors.New("WIP")
func validateSignature(message *pigeonMessage, topHalf string) error {
asciiSignature := message.signature
signature := []byte(B32Decode(asciiSignature))
publicKey := decodeMhash(message.author)
ok := ed25519.Verify(publicKey, []byte(topHalf), signature)
if ok {
return nil
}
error := fmt.Sprintf("Can't verify message %s", message.signature)
return errors.New(error)
}
func verifyBodyItem(bodyItem *pigeonBodyItem) error {
@ -113,6 +124,6 @@ func verifyShallow(message *pigeonMessage) error {
}
buffer.Write([]byte("\n"))
validateSignature(buffer.String(), message.signature)
validateSignature(message, buffer.String())
return nil
}