-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
121 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
bin/ | ||
.env | ||
.zig-cache/ | ||
zig-out/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Containerfile | ||
zig-out/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FROM quay.io/fedora/fedora-minimal AS build | ||
WORKDIR /app/src | ||
COPY . ./ | ||
RUN microdnf install -y zig binutils | ||
RUN zig build -Doptimize=ReleaseSmall | ||
RUN strip ./zig-out/bin/haxesandbox-keygen | ||
|
||
FROM scratch | ||
COPY --from=build /app/src/zig-out/bin/haxesandbox-keygen / | ||
CMD ["/haxesandbox-keygen"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const std = @import("std"); | ||
|
||
pub fn build(b: *std.Build) void { | ||
const target = b.standardTargetOptions(.{}); | ||
const optimize = b.standardOptimizeOption(.{}); | ||
|
||
const chameleon = b.dependency("chameleon", .{}).module("chameleon"); | ||
const exe = b.addExecutable(.{ | ||
.name = "haxesandbox-keygen", | ||
.root_source_file = b.path("src/main.zig"), | ||
.target = target, | ||
.optimize = optimize, | ||
}); | ||
exe.root_module.addImport("chameleon", chameleon); | ||
|
||
b.installArtifact(exe); | ||
|
||
const run_cmd = b.addRunArtifact(exe); | ||
run_cmd.step.dependOn(b.getInstallStep()); | ||
|
||
if (b.args) |args| { | ||
run_cmd.addArgs(args); | ||
} | ||
|
||
const run_step = b.step("run", "Run the app"); | ||
run_step.dependOn(&run_cmd.step); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.{ | ||
.name = "haxesandbox-keygen", | ||
.version = "0.0.0", | ||
.dependencies = .{ | ||
.chameleon = .{ | ||
.url = "https://github.com/tr1ckydev/chameleon/archive/e94bf213e542dbfa932469e921a4bd2b8f7bb8b1.zip", | ||
.hash = "1220a497e4583061a32a500d6886bc440f34dc54ccd9c08b27769c583baff1c2954f", | ||
}, | ||
}, | ||
.paths = .{ | ||
"build.zig", | ||
"build.zig.zon", | ||
"src", | ||
// For example... | ||
//"LICENSE", | ||
//"README.md", | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const std = @import("std"); | ||
const Chameleon = @import("chameleon").Chameleon; | ||
const base64 = std.base64.standard; | ||
const sha256 = std.crypto.hash.sha2.Sha256; | ||
|
||
const length = 24; | ||
|
||
pub fn main() !void { | ||
// Create allocator | ||
var ally = std.heap.ArenaAllocator.init(std.heap.page_allocator); | ||
defer ally.deinit(); | ||
|
||
// Initialize stdout | ||
const stdout_file = std.io.getStdOut().writer(); | ||
var bw = std.io.bufferedWriter(stdout_file); | ||
const stdout = bw.writer(); | ||
|
||
// Generate some random bytes to generate the base64 from | ||
var bytes: [length]u8 = undefined; | ||
std.crypto.random.bytes(&bytes); | ||
|
||
// Generate the base64 | ||
var b64 = try ally.allocator().alloc(u8, base64.Encoder.calcSize(length)); | ||
b64 = @constCast(base64.Encoder.encode(b64, &bytes)); | ||
|
||
// And the sha256 hash | ||
var hash: [32]u8 = undefined; | ||
sha256.hash(b64, &hash, .{}); | ||
|
||
// Now print everything to the user | ||
comptime var cham = Chameleon.init(.Auto); | ||
try stdout.print(cham.redBright().fmt( | ||
\\ | ||
\\ _ _ _____ _ _ | ||
\\| | | | / ___| | || | | ||
\\| |_| | __ _ __ __ ___ \ `--. __ _ _ __ __| || |__ ___ __ __ | ||
\\| _ | / _` |\ \/ / / _ \ `--. \ / _` || '_ \ / _` || '_ \ / _ \ \ \/ / | ||
\\| | | || (_| | > < | __//\__/ /| (_| || | | || (_| || |_) || (_) | > < | ||
\\\_| |_/ \__,_|/_/\_\ \___|\____/ \__,_||_| |_| \__,_||_.__/ \___/ /_/\_\ | ||
\\ | ||
\\ | ||
\\ | ||
), .{}); | ||
try stdout.print(cham.yellow().fmt("Run this command to save the hashed key:\n"), .{}); | ||
try stdout.print(cham.grey().fmt("printf \"{s}\" | podman secret create --replace haxe_authkey -\n\n"), .{std.fmt.fmtSliceHexLower(&hash)}); | ||
try stdout.print(cham.yellow().fmt("The following is the base64 key you should provide to HaxeSandbox during requests. Keep this secret!\n"), .{}); | ||
try stdout.print(cham.grey().fmt("{s}\n"), .{b64}); | ||
|
||
try bw.flush(); | ||
} |