diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..41abff2 Binary files /dev/null and b/.DS_Store differ diff --git a/backend/src/learning-go/go.mod b/backend/src/learning-go/go.mod new file mode 100644 index 0000000..e69de29 diff --git a/backend/src/learning-go/go.sum b/backend/src/learning-go/go.sum new file mode 100644 index 0000000..e69de29 diff --git a/backend/src/learning-go/main.go b/backend/src/learning-go/main.go new file mode 100644 index 0000000..e69de29 diff --git a/backend/src/security-layer/Dockerfile b/backend/src/security-layer/Dockerfile new file mode 100644 index 0000000..6ede7c1 --- /dev/null +++ b/backend/src/security-layer/Dockerfile @@ -0,0 +1,27 @@ +# syntax=docker/dockerfile:1 + +FROM golang:1.22.5 + +# Set destination for COPY +WORKDIR /tmp/docker/security-layer + +# Download Go modules +COPY ./container/go.mod ./container/go.sum ./ +RUN go mod download + +# Copy the source code. Note the slash at the end, as explained in +# https://docs.docker.com/reference/dockerfile/#copy +COPY ./container/*.go ./ + +# Build +RUN CGO_ENABLED=0 GOOS=linux go build -o /security-layer + +# Optional: +# To bind to a TCP port, runtime parameters must be supplied to the docker command. +# But we can document in the Dockerfile what ports +# the application is going to listen on by default. +# https://docs.docker.com/reference/dockerfile/#expose +EXPOSE 8000 + +# Run +CMD ["/security-layer"] diff --git a/backend/src/security-layer/container/go.mod b/backend/src/security-layer/container/go.mod new file mode 100644 index 0000000..e24dee7 --- /dev/null +++ b/backend/src/security-layer/container/go.mod @@ -0,0 +1,35 @@ +module example.com/web-service-gin + +go 1.22.5 + +require github.com/gin-gonic/gin v1.10.0 + +require ( + github.com/bytedance/sonic v1.11.6 // indirect + github.com/bytedance/sonic/loader v0.1.1 // indirect + github.com/cloudwego/base64x v0.1.4 // indirect + github.com/cloudwego/iasm v0.2.0 // indirect + github.com/gabriel-vasile/mimetype v1.4.3 // indirect + github.com/gin-contrib/sse v0.1.0 // indirect + github.com/go-playground/locales v0.14.1 // indirect + github.com/go-playground/universal-translator v0.18.1 // indirect + github.com/go-playground/validator/v10 v10.20.0 // indirect + github.com/goccy/go-json v0.10.2 // indirect + github.com/golang-jwt/jwt/v5 v5.2.1 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/klauspost/cpuid/v2 v2.2.7 // indirect + github.com/leodido/go-urn v1.4.0 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/pelletier/go-toml/v2 v2.2.2 // indirect + github.com/twitchyliquid64/golang-asm v0.15.1 // indirect + github.com/ugorji/go/codec v1.2.12 // indirect + golang.org/x/arch v0.8.0 // indirect + golang.org/x/crypto v0.23.0 // indirect + golang.org/x/net v0.25.0 // indirect + golang.org/x/sys v0.20.0 // indirect + golang.org/x/text v0.15.0 // indirect + google.golang.org/protobuf v1.34.1 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/backend/src/security-layer/container/go.sum b/backend/src/security-layer/container/go.sum new file mode 100644 index 0000000..a2282f5 --- /dev/null +++ b/backend/src/security-layer/container/go.sum @@ -0,0 +1,81 @@ +github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0= +github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= +github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM= +github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= +github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y= +github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= +github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= +github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= +github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= +github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= +github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= +github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= +github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= +github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= +github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= +github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= +github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= +github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8= +github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= +github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= +github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk= +github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= +github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= +github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= +github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= +github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= +github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= +github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= +github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc= +golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= +golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= +golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= +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/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= +google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= +rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/backend/src/security-layer/container/main.go b/backend/src/security-layer/container/main.go new file mode 100644 index 0000000..09110f0 --- /dev/null +++ b/backend/src/security-layer/container/main.go @@ -0,0 +1,229 @@ +package main + +import ( + "encoding/base64" + //"encoding/json" + "fmt" + "io" + "net/http" + "time" + + "crypto/aes" + "crypto/cipher" + "crypto/rand" + "crypto/sha1" + + "errors" + "strconv" + "strings" + + "github.com/gin-gonic/gin" + "github.com/golang-jwt/jwt/v5" +) + +// TODO: Test with 256 bits +// TEST VALUES: +// KEY: passphrasewhichneedstobe32bytes! +// INPUT: The ultimate question: of life, the universe, of everything! +// SHA-1 HASH: 0c6ca28f5607d86e5426b46795e0fa827f1627d6 +// BASE64 HASH: string DGyij1YH2G5UJrRnleD6gn8WJ9Y= +// AES OUTPUT: []uint8{104, 215, 184, 35, 194, 120, 115, 112, 133, 21, 160, 158, 11, 136, 201, 160, 233, 3, 12, 29, 133, 211, 207, 98, 35, 199, 89, 31, 203, 230, 39, 210, 225, 99, 96, 101, 3, 5, 198, 82, 243, 179, 176, 217, 8, 4, 63, 22, 134, 184, 68, 102, 255, 183, 176, 172, 6, 176, 249, 28, 127, 120, 235, 135, 73, 235, 249, 118, 194, 4, 137, 27, 158, 190, 134, 68, 21, 105, 26, 134, 10, 224, 233, 115, 28, 0, 153, 209} +// HEX AES: "68 D7 B8 23 C2 78 73 70 85 15 A0 9E B 88 C9 A0 E9 3 C 1D 85 D3 CF 62 23 C7 59 1F CB E6 27 D2 E1 63 60 65 3 5 C6 52 F3 B3 B0 D9 8 4 3F 16 86 B8 44 66 FF B7 B0 AC 6 B0 F9 1C 7F 78 EB 87 49 EB F9 76 C2 4 89 1B 9E BE 86 44 15 69 1A 86 A E0 E9 73 1C 0 99 D1" + +var rawHash = "DGyij1YH2G5UJrRnleD6gn8WJ9Y=" + +type Request struct { + //UserID string `json:"id"` + Prompt string `json:"prompt"` + Sum string `json:"sum"` +} + +var requests []Request + +// TODO: Test if 256 bit key works. +// TODO: Dynamically get key? Need to research best way to store private keys between two devices. +var key = []byte("passphrasewhichneedstobe32bytes!") + +func verifyToken(tokenString string) error { + token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) { + return key, nil + }) + + if err != nil { + return err + } + + if !token.Valid { + return fmt.Errorf("invalid token") + } + + return nil +} + +func createToken(username string) (string, error) { + token := jwt.NewWithClaims(jwt.SigningMethodHS256, + jwt.MapClaims{ + "username": username, + "exp": time.Now().Add(time.Hour * 24).Unix(), + }) + + tokenString, err := token.SignedString(key) + if err != nil { + return "", err + } + + return tokenString, nil +} + +func encrypt() { + text := []byte("The ultimate question: of life, the universe, of everything!") + + // generate a new aes cipher using our 32 byte long key + c, err := aes.NewCipher(key) + // if there are any errors, handle them + if err != nil { + fmt.Println(err) + } + + // gcm or Galois/Counter Mode, is a mode of operation + // for symmetric key cryptographic block ciphers + // - https://en.wikipedia.org/wiki/Galois/Counter_Mode + gcm, err := cipher.NewGCM(c) + // if any error generating new GCM + // handle them + if err != nil { + fmt.Println(err) + } + + // creates a new byte array the size of the nonce + // which must be passed to Seal + nonce := make([]byte, gcm.NonceSize()) + // populates our nonce with a cryptographically secure + // random sequence + if _, err = io.ReadFull(rand.Reader, nonce); err != nil { + fmt.Println(err) + } + + // here we encrypt our text using the Seal function + // Seal encrypts and authenticates plaintext, authenticates the + // additional data and appends the result to dst, returning the updated + // slice. The nonce must be NonceSize() bytes long and unique for all + // time, for a given key. + fmt.Println(gcm.Seal(nonce, nonce, text, nil)) + + //// the WriteFile method returns an error if unsuccessful + //err = ioutil.WriteFile("myfile", gcm.Seal(nonce, nonce, text, nil), 0777) + //// handle this error + //if err != nil { + // // print it out + // fmt.Println(err) + //} +} + +func convertHexToBytes(hexString *string) ([]uint8, error) { + // Handle nil pointer case + if hexString == nil { + return nil, errors.New("nil pointer provided for hex string") + } + + // Split the hex string by spaces + hexBytes := strings.Fields(*hexString) + + // Initialize an empty slice for uint8 + data := make([]uint8, len(hexBytes)) + + // Iterate and convert each hex byte + for i, hexByte := range hexBytes { + // Convert each hex string to a uint8 value (handling errors) + value, err := strconv.ParseUint(hexByte, 16, 8) + if err != nil { + return nil, fmt.Errorf("error parsing hex byte '%s': %w", hexByte, err) + } + + // Assign the converted value to the slice + data[i] = uint8(value) + } + + // Return the slice of uint8 and any errors encountered + return data, nil +} + +func decrypt(input *Request) bool { + //ciphertext, err := ioutil.ReadFile("myfile") + ciphertext, err := convertHexToBytes(&input.Prompt) + + // if our program was unable to read the file + // print out the reason why it can't + if err != nil { + fmt.Println(err) + } + + c, err := aes.NewCipher(key) + if err != nil { + fmt.Println(err) + } + + gcm, err := cipher.NewGCM(c) + if err != nil { + fmt.Println(err) + } + + nonceSize := gcm.NonceSize() + if len(ciphertext) < nonceSize { + fmt.Println(err) + } + + nonce, ciphertext := ciphertext[:nonceSize], ciphertext[nonceSize:] + plaintext, err := gcm.Open(nil, nonce, ciphertext, nil) + if err != nil { + fmt.Println(err) + } + s := string(plaintext) + if validateHash(s) { + input.Prompt = s + return true + } + input.Prompt = "DATA CORRUPTED OR TAMPERED" + return false +} + +// Validate there's no tampering with SHA-1 sum. The decrypted hash and the transmitted hash should be identical. +func validateHash(decrypted string) bool { + // Calculate the SHA256 sum of the decrypted request + hasher := sha1.New() + hasher.Write([]byte(decrypted)) + decryptedHashString := base64.URLEncoding.EncodeToString(hasher.Sum(nil)) + + // TODO: Add error handling if hash doesn't match. + return decryptedHashString == rawHash +} + +// User HTTP GET request has the prompt decrypted and verified with a SHA-1 checksum. +// If there's been no data corruption, re-construct user prompt for ollama +// TODO: Eventually, add additional logic that will allow for re-direction and contextual awareness (pre-processing) +func promptRequest(c *gin.Context) { + var newInput Request + + //Call BindJSON to bind the received JSON to + if err := c.BindJSON(&newInput); err != nil { + return + } + + if decrypt(&newInput) { + requests = append(requests, newInput) + c.IndentedJSON(http.StatusCreated, newInput) // TODO: Formulate prompt and transfer to AI layer to formulate new JSON response back + } else { + c.IndentedJSON(http.StatusBadRequest, gin.H{"message": "Failed checksum. Presumably data corrupted."}) + + } +} + +func main() { + router := gin.Default() + router.POST("/prompt", promptRequest) + + err := router.Run("0.0.0.0:8000") + if err != nil { + return + } +} diff --git a/backend/src/security-layer/test.sh b/backend/src/security-layer/test.sh new file mode 100755 index 0000000..aee1d2d --- /dev/null +++ b/backend/src/security-layer/test.sh @@ -0,0 +1,14 @@ +# Build the Docker image. +docker build --tag security-layer:latest . + +# Create a Docker container from the image and connect host port 8000 to container port 8000. +docker run --name security-layer -d -p 8000:8000 security-layer:latest + +# Send a JSON request to the security layer within the Docker container. +curl http://localhost:8000/prompt -d '{ + "prompt": "68 D7 B8 23 C2 78 73 70 85 15 A0 9E B 88 C9 A0 E9 3 C 1D 85 D3 CF 62 23 C7 59 1F CB E6 27 D2 E1 63 60 65 3 5 C6 52 F3 B3 B0 D9 8 4 3F 16 86 B8 44 66 FF B7 B0 AC 6 B0 F9 1C 7F 78 EB 87 49 EB F9 76 C2 4 89 1B 9E BE 86 44 15 69 1A 86 A E0 E9 73 1C 0 99 D1", + "sum": "DGyij1YH2G5UJrRnleD6gn8WJ9Y=" +}' + +# Delete the container so the next build and container utilize code changes. +docker rm -f security-layer diff --git a/mobile/.DS_Store b/mobile/.DS_Store new file mode 100644 index 0000000..62ddbf7 Binary files /dev/null and b/mobile/.DS_Store differ diff --git a/mobile/app/lib/main.dart b/mobile/app/lib/main.dart index 01f926e..7006fed 100644 --- a/mobile/app/lib/main.dart +++ b/mobile/app/lib/main.dart @@ -4,6 +4,7 @@ import 'package:app/components/conversations_list_widget.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:provider/provider.dart'; +import 'package:network_tools/network_tools.dart'; import 'package:app/theme.dart'; @@ -57,9 +58,23 @@ class MyApp extends ConsumerWidget { const Center(child: ConversationsListWidget()), ]; + Future test() async { + for (final ActiveHost activeHost in await MdnsScanner.searchMdnsDevices()) { + final MdnsInfo? mdnsInfo = await activeHost.mdnsInfo; + print(''' + Address: ${activeHost.address} + Port: ${mdnsInfo!.mdnsPort} + ServiceType: ${mdnsInfo.mdnsServiceType} + MdnsName: ${mdnsInfo.getOnlyTheStartOfMdnsName()} + '''); + // Do anything with the active host + } + + } + // This widget is the root of your application. @override - Widget build(BuildContext context, WidgetRef ref) { + Widget build(BuildContext context, WidgetRef ref) {o final selectedIndex = ref.watch(selectedIndexProvider); return MaterialApp( diff --git a/mobile/app/pubspec.lock b/mobile/app/pubspec.lock index b09a339..f60abb8 100644 --- a/mobile/app/pubspec.lock +++ b/mobile/app/pubspec.lock @@ -25,6 +25,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.7" + args: + dependency: transitive + description: + name: args + sha256: "7cf60b9f0cc88203c5a190b4cd62a99feea42759a7fa695010eb5de1c0b2252a" + url: "https://pub.dev" + source: hosted + version: "2.5.0" async: dependency: transitive description: @@ -193,6 +201,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.0" + csv: + dependency: transitive + description: + name: csv + sha256: c6aa2679b2a18cb57652920f674488d89712efaf4d3fdf2e537215b35fc19d6c + url: "https://pub.dev" + source: hosted + version: "6.0.0" cupertino_icons: dependency: "direct main" description: @@ -201,6 +217,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.8" + dart_ping: + dependency: transitive + description: + name: dart_ping + sha256: "2f5418d0a5c64e53486caaac78677b25725b1e13c33c5be834ce874ea18bd24f" + url: "https://pub.dev" + source: hosted + version: "9.0.1" data_table_2: dependency: transitive description: @@ -696,6 +720,14 @@ packages: url: "https://pub.dev" source: hosted version: "4.0.0" + logging: + dependency: transitive + description: + name: logging + sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" + url: "https://pub.dev" + source: hosted + version: "1.2.0" mapbox_search: dependency: transitive description: @@ -752,6 +784,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.0" + multicast_dns: + dependency: transitive + description: + name: multicast_dns + sha256: "982c4cc4cda5f98dd477bddfd623e8e4bd1014e7dbf9e7b05052e14a5b550b99" + url: "https://pub.dev" + source: hosted + version: "0.3.2+7" native_device_orientation: dependency: transitive description: @@ -768,6 +808,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.0" + network_tools: + dependency: "direct main" + description: + name: network_tools + sha256: cf5726a3c3edd82de5f6d6511cb618259a083225ccc2bdb8a55d87b37014cadf + url: "https://pub.dev" + source: hosted + version: "5.0.2" octo_image: dependency: transitive description: @@ -920,6 +968,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.10.2" + process_run: + dependency: transitive + description: + name: process_run + sha256: "8d9c6198b98fbbfb511edd42e7364e24d85c163e47398919871b952dc86a423e" + url: "https://pub.dev" + source: hosted + version: "0.14.2" provider: dependency: "direct main" description: @@ -928,6 +984,14 @@ packages: url: "https://pub.dev" source: hosted version: "6.1.2" + pub_semver: + dependency: transitive + description: + name: pub_semver + sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c" + url: "https://pub.dev" + source: hosted + version: "2.1.4" qr: dependency: transitive description: @@ -984,6 +1048,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.0" + sembast: + dependency: transitive + description: + name: sembast + sha256: "2a768b145bee5c72ae78c2641842ee348a6d345172af1070a497293c44f65ae1" + url: "https://pub.dev" + source: hosted + version: "3.7.1+2" shared_preferences: dependency: transitive description: @@ -1221,6 +1293,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.2" + universal_io: + dependency: transitive + description: + name: universal_io + sha256: "1722b2dcc462b4b2f3ee7d188dad008b6eb4c40bbd03a3de451d82c78bba9aad" + url: "https://pub.dev" + source: hosted + version: "2.2.2" url_launcher: dependency: transitive description: @@ -1413,6 +1493,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.4" + yaml: + dependency: transitive + description: + name: yaml + sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5" + url: "https://pub.dev" + source: hosted + version: "3.1.2" sdks: dart: ">=3.4.3 <4.0.0" flutter: ">=3.22.0" diff --git a/mobile/app/pubspec.yaml b/mobile/app/pubspec.yaml index 85f8a47..8e3b2ce 100644 --- a/mobile/app/pubspec.yaml +++ b/mobile/app/pubspec.yaml @@ -49,6 +49,7 @@ dependencies: camera: ^0.11.0+1 image_picker: ^1.1.2 file_picker: ^8.0.6 + network_tools: ^5.0.2 dev_dependencies: flutter_test: sdk: flutter