Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segment test cases for system metadata #63

Merged
merged 45 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
db850be
feat: creating sample Go module
TechSolomon Nov 3, 2023
4d4b447
feat: example error handling
TechSolomon Nov 3, 2023
cfe708c
refactor: random example communication message
TechSolomon Nov 3, 2023
d5184a2
feat: example map data type (slice) & test cases
TechSolomon Nov 4, 2023
cded158
Template for suggested experimental expectations (#24)
TechSolomon Mar 2, 2024
034b7ba
Merge branch 'dev' of github.com:acep-uaf/data-diode into dev
TechSolomon Mar 5, 2024
867925f
fix: text cache source location
TechSolomon Mar 5, 2024
7676ab7
Delete `message` directory
TechSolomon Mar 5, 2024
b630302
Delete `example` directory
TechSolomon Mar 5, 2024
7d4f705
bump: latest Go milestone (minor release)
TechSolomon Mar 5, 2024
d25f5a9
Topic levels for MQTT (#27)
TechSolomon Mar 10, 2024
9a7f7f1
docs: finalize project directory structure
TechSolomon Mar 10, 2024
2c24f25
refactor: variables for testing content publisher
TechSolomon Mar 10, 2024
aadd7d9
feat: placeholder client + server (I/O)
TechSolomon Mar 12, 2024
56e17f6
refactor: data diode settings & connection constants
TechSolomon Mar 12, 2024
3cae110
refactor: application constants with minimal error handling
TechSolomon Mar 12, 2024
63f2ea8
fix: brange merge conflicts via command line
TechSolomon Mar 13, 2024
a9ba3e4
deps: remove outdated string metrics library
TechSolomon Mar 13, 2024
a09895f
docs: create B4-0144-355112.json (via Fend_B4_4.0.2.fw)
TechSolomon Mar 14, 2024
5010e61
refactor: diode test variables
TechSolomon Mar 14, 2024
16d57a0
docs: mock external API for schema validation
TechSolomon Mar 14, 2024
af9ef76
Mock system connection & message crafting (#34)
TechSolomon Mar 22, 2024
541088f
feat: MQTT test subscription + application (client/server)
TechSolomon Mar 22, 2024
88b9bf7
refactor: diode test command & server continuous stream
TechSolomon Mar 23, 2024
9d27891
Merge branch 'main' into dev
TechSolomon Mar 25, 2024
ffcf54d
fix: broken build with undefined import
TechSolomon Mar 25, 2024
bd39b60
refactor: draft goroutine for server connection(s)
TechSolomon Mar 25, 2024
bad9451
Merge remote-tracking branch 'origin/main' into dev
TechSolomon Mar 25, 2024
21d8678
nit: minor code format
TechSolomon Mar 25, 2024
16a479e
refactor: remove duplicate function contents
TechSolomon Mar 25, 2024
b033a84
Updated configuration flow of control (#38)
TechSolomon Apr 1, 2024
85e8c4e
docs: update main program directory name
TechSolomon Apr 1, 2024
e120498
Saturate components for testing diode system behavior (#42)
TechSolomon Apr 19, 2024
57b2f37
refactor: Dockerfile command, MQTT broker ports, & code comments
TechSolomon Apr 20, 2024
2936e11
Merge branch 'main' into dev
TechSolomon Apr 20, 2024
0b3f5eb
docs: build requirements for `make`
TechSolomon Apr 26, 2024
d58628a
fix: match MQTT client ID
TechSolomon Apr 27, 2024
0b67fa1
Merge branch 'main' into dev
TechSolomon Apr 27, 2024
86f7e11
Maintain MQTT topic prefix + suffix structure (#61)
TechSolomon Jul 12, 2024
fe5cb54
Merge remote-tracking branch 'origin/main' into dev
TechSolomon Jul 12, 2024
f1a3979
feat: create experimental dev container
TechSolomon Jul 12, 2024
1af2823
feat: outline basic application + republisher content testing
TechSolomon Jul 13, 2024
e39a7d7
refactor: test payload attributes w/ verification & timestamp
TechSolomon Jul 13, 2024
fa89727
fix: check on missing topic & test cases for payload contents
TechSolomon Jul 16, 2024
a6b0019
ci: workflow for testing code (coverage)
TechSolomon Jul 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/go
{
"name": "Go",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/go:1-1.22-bookworm"

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "go version",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for more information:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
# https://containers.dev/guide/dependabot

version: 2
updates:
- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: weekly
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will build a Go project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: ARCTIC CAMIO Lab
name: CAMIO Lab

on:
push:
Expand All @@ -27,4 +27,4 @@ jobs:
run: go build -o diode .

- name: Test with the Go CLI
run: go test
run: go test -v ./...
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ build:
test:
go test -v ./...

coverage:
go test -cover ./...

run: build
./${BIN_NAME} --help

Expand Down
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@ Scripts for verifying TCP passthrough functionality.

> [!TIP]
> This project utilizes [`go`](https://go.dev/) for module management.
> You can find installation instructions via https://go.dev/doc/install.
> You can find installation instructions via [relevant operating system](https://go.dev/doc/install) documentation.

- Clone repository: `gh repo clone acep-uaf/data-diode`
- Source navigation: `cd data-diode`
- Build binary: `make`
- [`build-essential`](https://packages.ubuntu.com/focal/build-essential)
- Build binary: [`make`](https://www.gnu.org/software/make/)
- CLI: `./diode [options...]`

#### Branch Management
### Branch Management

- `main` → production ready environment.
- `dev` → testing changes to be merged into `main`.

#### Directory Structure
### Directory Structure

```zsh
.
Expand All @@ -39,7 +38,7 @@ Scripts for verifying TCP passthrough functionality.
5 directories, 7 files
```

#### Architecture Diagram
### Architecture Diagram

```mermaid
graph LR
Expand All @@ -52,23 +51,23 @@ graph LR

## User Stories

#### Scenario Planning
### Scenario Planning

1. Power Plant Operator
1. Information Security Auditor
1. Energy Awareness Application Developer
1. Community Member

#### Threat Model[^1]
### Threat Model[^1]

- [ ] Tactics
- [ ] Techniques
- [ ] Procedures

## System Benchmarking
### System Benchmarking

#### Experimental Design
### Experimental Design

###### [Device Configuration](docs/SOP.md)
#### [Device Configuration](docs/SOP.md)

[^1]: https://csrc.nist.gov/glossary/term/tactics_techniques_and_procedures
[^1]: <https://csrc.nist.gov/glossary/term/tactics_techniques_and_procedures>
10 changes: 5 additions & 5 deletions docs/SOP.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

## Research Question

#### State Synchronization
### State Synchronization

#### System Replication
### System Replication

## System Analysis

#### Latency
### Latency

#### Bandwidth
### Bandwidth

#### Throughput
### Throughput

## Data Integrity
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ require (

require (
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sync v0.7.0 // indirect
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lV
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/eclipse/paho.mqtt.golang v1.4.3 h1:2kwcUGn8seMUfWndX0hGbvH8r7crgcJguQNCyp70xik=
github.com/eclipse/paho.mqtt.golang v1.4.3/go.mod h1:CSYvoAlsMkhYOXh/oKyxa8EcBci6dVkLCbo5tTC1RIE=
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI=
github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func main() {
Action: func(dCtx *cli.Context) error {
fmt.Println("----- DIAGNOSTICS -----")
fmt.Printf("%+v\n", config)
// TODO: Flag for current data diode ACK response.
return nil
},
},
Expand All @@ -147,7 +148,7 @@ func main() {
{
Name: "mqtt-subscribe",
Aliases: []string{"ms"},
Usage: "Recieve payload, encapsulate message, & stream to diode",
Usage: "Receive payload, encapsulate message, & stream to diode",
Action: func(msCtx *cli.Context) error {
utility.InboundMessageFlow(subBrokerIP, subBrokerPort, subBrokerTopic, clientLocation)
return nil
Expand Down
3 changes: 2 additions & 1 deletion utility/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const (
SAMPLE = 10240
)

// For versions prior to Go 1.21 (built-ins).
func min(a, b int) int {
if a < b {
return a
Expand Down Expand Up @@ -150,7 +151,7 @@ func StartPlaceholderServer(host string, port int) {
}
}

func RecieveMessage(destination string, messages chan<- string) error {
func ReceiveMessage(destination string, messages chan<- string) error {
server, err := net.Listen("tcp", destination)
if err != nil {
fmt.Println(">> [!] Error connecting to diode: ", err)
Expand Down
38 changes: 24 additions & 14 deletions utility/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,36 @@ import (
"testing"
)

func TestRecieveMessage(t *testing.T) {
serverMock, err := net.Listen("tcp", "localhost:0")
func TestSendMessage(t *testing.T) {
server, err := net.Listen(CONN_TYPE, "localhost:0")
if err != nil {
t.Fatalf("[!] Failed to start the mock server: %v", err)
t.Fatalf(">> [!] Failed to create mock server: %v", err)
}
defer serverMock.Close()
defer server.Close()

serverMockAddress := serverMock.Addr().String()

contents := make(chan string)
go func() {
err := RecieveMessage(serverMockAddress, contents)
conn, err := server.Accept()
if err != nil {
t.Errorf("[?] Returned an error: %v", err)
t.Error(">> [!] Failed to accept connection:", err)
return
}
defer conn.Close()

buffer := make([]byte, CHUNK_SIZE)
_, err = conn.Read(buffer)
if err != nil {
t.Error("[!] Failed to read data:", err)
return
}

_, err = conn.Write([]byte(ACKNOWLEDGEMENT))
if err != nil {
t.Error("[!] Failed to send acknowledgement:", err)
return
}
}()

conn, err := net.Dial("tcp", serverMockAddress)
if err != nil {
t.Fatalf("[!] Failed to connect to the mock server: %v", err)
}
defer conn.Close()
input := "data-diode"
client := server.Addr().String()
SendMessage(input, client)
}
31 changes: 31 additions & 0 deletions utility/metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package utility

import (
"crypto/md5"
"encoding/base64"
"fmt"
"time"
)

func MakeTimestamp() int64 {
return time.Now().UnixMicro()
}

func Verification(data string) string {
hash := md5.New()
hash.Write([]byte(data))
return fmt.Sprintf("%x", hash.Sum(nil))
}

func EncapsulatePayload(message string) string {
encoded := base64.StdEncoding.EncodeToString([]byte(message))
return encoded
}

func UnencapsulatePayload(message string) string {
decoded, err := base64.StdEncoding.DecodeString(message)
if err != nil {
fmt.Println(">> [!] Error decoding the message: ", err)
}
return string(decoded)
}
68 changes: 68 additions & 0 deletions utility/metadata_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package utility

import (
"fmt"
"testing"
)

func TestMakeTimestamp(t *testing.T) {
actual := MakeTimestamp()
expected := 16

length := len(fmt.Sprintf("%d", actual))

if length != expected {
t.Errorf("Expected %d but got %d", expected, length)
}
}

func TestVerification(t *testing.T) {
testcases := []struct {
input string
}{
{"data-diode"},
}

for _, test := range testcases {
actual := Verification(test.input)
expected := "ef217cdf54b0b3ece89a0d7686da550b"

if actual != expected {
t.Errorf("Expected %s but got %s", expected, actual)
}
}
}

func TestEncapsulatePayload(t *testing.T) {
testcases := []struct {
input string
}{
{"data-diode"},
}

for _, test := range testcases {
actual := EncapsulatePayload(test.input)
expected := "ZGF0YS1kaW9kZQ=="

if actual != expected {
t.Errorf("Expected %s but got %s", expected, actual)
}
}
}

func TestUnencapsulatePayload(t *testing.T) {
testcases := []struct {
input string
}{
{"ZGF0YS1kaW9kZQ=="},
}

for _, test := range testcases {
actual := UnencapsulatePayload(test.input)
expected := "data-diode"

if actual != expected {
t.Errorf("Expected %s but got %s", expected, actual)
}
}
}
Loading