mirror of
https://github.com/ultravioletrs/cocos.git
synced 2026-08-07 07:14:50 +00:00
NOISSUE - Support non-chunked computation requests and add KBS decryption for uploaded algorithms and datasets. (#608)
CI / lint (push) Has been cancelled
CI / test (agent) (push) Has been cancelled
CI / test (cli) (push) Has been cancelled
CI / test (cmd) (push) Has been cancelled
CI / test (internal) (push) Has been cancelled
CI / test (manager, true) (push) Has been cancelled
CI / test (pkg) (push) Has been cancelled
CI / upload-coverage (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / test (agent) (push) Has been cancelled
CI / test (cli) (push) Has been cancelled
CI / test (cmd) (push) Has been cancelled
CI / test (internal) (push) Has been cancelled
CI / test (manager, true) (push) Has been cancelled
CI / test (pkg) (push) Has been cancelled
CI / upload-coverage (push) Has been cancelled
* feat: support non-chunked computation requests and add KBS decryption for uploaded algorithms and datasets. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * feat: update dataset resolution logic with context-based index verification and add extensive service error handling tests Signed-off-by: Sammy Oina <sammyoina@gmail.com> * feat: add AES encryption script and update package sources to connector-mods fork Signed-off-by: Sammy Oina <sammyoina@gmail.com> * fix: update file permission syntax in encrypt.go Signed-off-by: Sammy Oina <sammyoina@gmail.com> --------- Signed-off-by: Sammy Oina <sammyoina@gmail.com>
This commit is contained in:
committed by
GitHub
parent
6169766666
commit
5c3561f85d
@@ -0,0 +1,74 @@
|
||||
// Copyright (c) Ultraviolet
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 4 {
|
||||
fmt.Println("Usage: go run encrypt.go <key_file> <input_file> <output_file>")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
keyFile := os.Args[1]
|
||||
inputFile := os.Args[2]
|
||||
outputFile := os.Args[3]
|
||||
|
||||
// Read key
|
||||
key, err := os.ReadFile(keyFile)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to read key file: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if len(key) != 32 {
|
||||
fmt.Printf("Key must be 32 bytes, got %d\n", len(key))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Read plaintext
|
||||
plaintext, err := os.ReadFile(inputFile)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to read input file: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
block, err := aes.NewCipher(key)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to create cipher: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
aesgcm, err := cipher.NewGCM(block)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to create GCM: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
nonce := make([]byte, 12)
|
||||
if _, err := io.ReadFull(rand.Reader, nonce); err != nil {
|
||||
fmt.Printf("Failed to generate nonce: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
ciphertext := aesgcm.Seal(nil, nonce, plaintext, nil)
|
||||
|
||||
// Combine nonce + ciphertext + tag
|
||||
// Seal returns ciphertext || tag, so we just append it to nonce
|
||||
output := append(nonce, ciphertext...)
|
||||
|
||||
err = os.WriteFile(outputFile, output, 0o644)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to write output file: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Printf("Successfully encrypted %s to %s\n", inputFile, outputFile)
|
||||
}
|
||||
Reference in New Issue
Block a user