nan0chat

package module
v0.0.0-...-e176e9e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2018 License: MIT Imports: 11 Imported by: 1

README

Nan0Chat

Secure Chat Client using Nan0 Services

This is a terminal-based chat server and client that demonstrates the Nan0 API

Building

From the project root directory, do go build on entrypoint to create the program.

go build Nan0Chat nan0chat/entrypoint
Running

There are a number of command-line flags that are used to configure the application:

Usage of Nan0Chat:
  -host string
        Host name for server (default "localhost")
  -key string
        Encryption Key encoded in Base64.
  -port int
        Port number for server (if --server is [true]) (default 6865)
  -server
        Is this a server? [[false]/true]
  -sig string
        HMAC Signature encoded in Base64.
  -username string
        A custom user name
  • server is a flag that indicates whether or not a server is to be started, this defaults to false
  • host is the host name for the server, with the default being "localhost"
  • port is the port for the server, with the default being 6865
  • key is the encryption key, a 256bit string encoded in Base64, used for encryption
  • sig is the signature (HMAC), a 256bit string encoded in Base64, used for authentication
  • username is a custom username assigned to the client application (if a client is started)
Start a server:
./Nan0Chat  --key <encryption key> --sig <signature> --server=true --port=6865

Replace <encryption key> with the encryption key and <signature> with the signature

Start a client:
./Nan0Chat  --key <encryption key> --sig <signature> --host=localhost --server=false --port=6865 --username=Bob

Replace <encryption key> with the encryption key and <signature> with the signature

Obtaining an Encryption Key and Signature

To obtain an encryption key and signature in base64, run the following snippet in a console:

package main

import (
	"github.com/yomiji/nan0"
	"encoding/base64"
	"fmt"
)

// A simple function to make the keys generated a sharable string
func shareKeys() (encKeyShare, authKeyShare string) {
	encKeyBytes := nan0.NewEncryptionKey()
	authKeyBytes := nan0.NewHMACKey()

	encKeyShare = base64.StdEncoding.EncodeToString(encKeyBytes[:])
	authKeyShare = base64.StdEncoding.EncodeToString(authKeyBytes[:])

	return
}

func main() {
	// create the keys
	encKey, sig := shareKeys()
	// print the keys to the console
	fmt.Printf("Encryption Key: %v\nSignature: %v", encKey, sig)
}

Output:

Do NOT use these specific keys in your application

Encryption Key: eQypV5GrNg0Vh+E3A90HJq+89KL/52g/IQApnUm7E+I=
Signature: Ll0RHmOxfYJi9Y5X5YaK078ZjCOHo4wBnDGenjtyqAw=

Do NOT use these specific keys in your application

Usage

The server application will start with a message indicating that it is currently running. The server application must be interrupted to close. In windows command prompt and linux terminal, you can achieve this by pressing the Ctrl+C combination.

The client application is a simple edit box below a text area. Inside the text area, there will appear all text entered into the edit box as well as all incoming messages dispatched from the service. The messages will be prepended with the name of the user who sent the message. Press the escape key to exit the client application.

TODO
  • Better client disconnection handling

Documentation

Overview

*

Taken and repurposed from https://github.com/nsf/termbox-go/tree/master/_demos/editbox.go
author: termbox-go authors & nan0 authors

Index

Constants

This section is empty.

Variables

View Source
var CustomUsername = flag.String("username", "", "A custom user name")
View Source
var EncryptKey = flag.String("key", "", "(Required) Encryption Key encoded in Base64")

application parameter flags definitions

View Source
var Host = flag.String("host", "localhost", "Host name for server")
View Source
var IsServer = flag.Bool("server", false, "Is this a server?")
View Source
var Port = flag.Int("port", 6865, "Port number for server (if --server is [true])")
View Source
var Signature = flag.String("sig", "", "(Required) HMAC Signature encoded in Base64")

Functions

func KeysToNan0Bytes

func KeysToNan0Bytes(encKeyShare, authKeyShare string) (encKey, authKey *[32]byte)

The nan0 functions require a specific key type and width, this is a way to make that conversion from strings to the required type.

func Serve

func Serve(port int) (err error)

Types

type ChatClient

type ChatClient struct {
	// contains filtered or unexported fields
}

func NewChatClient

func NewChatClient() (client *ChatClient)

func (*ChatClient) Connect

func (client *ChatClient) Connect()

Connects to the target service (defined in the application flags)

type ChatClientUI

type ChatClientUI struct {
	// contains filtered or unexported fields
}

func (*ChatClientUI) Start

func (chatUi *ChatClientUI) Start(prefix string, messageChannel chan<- string)

type ChatMessage

type ChatMessage struct {
	UserId               int64    `protobuf:"varint,3,opt,name=userId,proto3" json:"userId,omitempty"`
	MessageId            int64    `protobuf:"varint,4,opt,name=messageId,proto3" json:"messageId,omitempty"`
	Time                 int64    `protobuf:"varint,5,opt,name=time,proto3" json:"time,omitempty"`
	Message              string   `protobuf:"bytes,6,opt,name=message,proto3" json:"message,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*ChatMessage) Descriptor

func (*ChatMessage) Descriptor() ([]byte, []int)

func (*ChatMessage) GetMessage

func (m *ChatMessage) GetMessage() string

func (*ChatMessage) GetMessageId

func (m *ChatMessage) GetMessageId() int64

func (*ChatMessage) GetTime

func (m *ChatMessage) GetTime() int64

func (*ChatMessage) GetUserId

func (m *ChatMessage) GetUserId() int64

func (*ChatMessage) ProtoMessage

func (*ChatMessage) ProtoMessage()

func (*ChatMessage) Reset

func (m *ChatMessage) Reset()

func (*ChatMessage) String

func (m *ChatMessage) String() string

func (*ChatMessage) XXX_DiscardUnknown

func (m *ChatMessage) XXX_DiscardUnknown()

func (*ChatMessage) XXX_Marshal

func (m *ChatMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*ChatMessage) XXX_Merge

func (dst *ChatMessage) XXX_Merge(src proto.Message)

func (*ChatMessage) XXX_Size

func (m *ChatMessage) XXX_Size() int

func (*ChatMessage) XXX_Unmarshal

func (m *ChatMessage) XXX_Unmarshal(b []byte) error

type ChatServer

type ChatServer struct {
	// contains filtered or unexported fields
}

type ConnectedUser

type ConnectedUser struct {
	// contains filtered or unexported fields
}

type EditBox

type EditBox struct {
	// contains filtered or unexported fields
}

func (*EditBox) AdjustVOffset

func (eb *EditBox) AdjustVOffset(width int)

Adjusts line visual offset to a proper value depending on width

func (*EditBox) Clear

func (eb *EditBox) Clear()

func (*EditBox) CursorX

func (eb *EditBox) CursorX() int

Please, keep in mind that cursor depends on the value of line_voffset, which is being set on Draw() call, so.. call this method after Draw() one.

func (*EditBox) DeleteRuneBackward

func (eb *EditBox) DeleteRuneBackward()

func (*EditBox) DeleteRuneForward

func (eb *EditBox) DeleteRuneForward()

func (*EditBox) DeleteTheRestOfTheLine

func (eb *EditBox) DeleteTheRestOfTheLine()

func (*EditBox) Draw

func (eb *EditBox) Draw(x, y, w, h int)

Draws the EditBox in the given location, 'h' is not used at the moment

func (*EditBox) InsertRune

func (eb *EditBox) InsertRune(r rune)

func (*EditBox) MoveCursorOneRuneBackward

func (eb *EditBox) MoveCursorOneRuneBackward()

func (*EditBox) MoveCursorOneRuneForward

func (eb *EditBox) MoveCursorOneRuneForward()

func (*EditBox) MoveCursorTo

func (eb *EditBox) MoveCursorTo(boffset int)

func (*EditBox) MoveCursorToBeginningOfTheLine

func (eb *EditBox) MoveCursorToBeginningOfTheLine()

func (*EditBox) MoveCursorToEndOfTheLine

func (eb *EditBox) MoveCursorToEndOfTheLine()

func (*EditBox) RuneBeforeCursor

func (eb *EditBox) RuneBeforeCursor() (rune, int)

func (*EditBox) RuneUnderCursor

func (eb *EditBox) RuneUnderCursor() (rune, int)

type OutputBox

type OutputBox struct {
	// contains filtered or unexported fields
}

type User

type User struct {
	UserId               int64    `protobuf:"varint,1,opt,name=userId,proto3" json:"userId,omitempty"`
	UserName             string   `protobuf:"bytes,2,opt,name=userName,proto3" json:"userName,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*User) Descriptor

func (*User) Descriptor() ([]byte, []int)

func (*User) GetUserId

func (m *User) GetUserId() int64

func (*User) GetUserName

func (m *User) GetUserName() string

func (*User) ProtoMessage

func (*User) ProtoMessage()

func (*User) Reset

func (m *User) Reset()

func (*User) SetUserId

func (user *User) SetUserId(id int64)

func (*User) SetUserName

func (user *User) SetUserName(name string)

func (*User) String

func (m *User) String() string

func (*User) XXX_DiscardUnknown

func (m *User) XXX_DiscardUnknown()

func (*User) XXX_Marshal

func (m *User) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*User) XXX_Merge

func (dst *User) XXX_Merge(src proto.Message)

func (*User) XXX_Size

func (m *User) XXX_Size() int

func (*User) XXX_Unmarshal

func (m *User) XXX_Unmarshal(b []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL