mkcert icon indicating copy to clipboard operation
mkcert copied to clipboard

wasm binary?

Open andykais opened this issue 4 years ago • 3 comments

Is there any chance of compiling this code to a wasm binary that can be imported into nodejs and deno projects? I want to use mkcert to generate localhost certificates for a local web app package, but it will require end users to install mkcert themselves, and run commands. If mkcert were usable as a wasm binary (literally just expose the command line interface as a function in js) then local web apps could ship with mkcert as a dependency and install the root CA and generate the localhost certs themselves as part of the initialization process.

An example of what initializing mkcert as a wasm module might look like:

const wasmCode = await Deno.readFile("mkcert.wasm");
const wasmModule = new WebAssembly.Module(wasmCode);
const wasmInstance = new WebAssembly.Instance(wasmModule);
const mkcert = wasmInstance.exports.main as CallableFunction;
await mkcert('-install');
await mkcert('localhost 127.0.0.1');

andykais avatar May 24 '21 19:05 andykais

I wonder if this would be possible to get working with the current state of WASI. Compiling to WASM, as I understand, is the easy part. Getting it to launch external processes (certutil) less so.

Update: until this is implemented, I don’t think there’s a way to make this work: https://github.com/WebAssembly/WASI/issues/414

aral avatar Dec 20 '22 13:12 aral

thanks for looking into this, it does look like we have to wait on upstream changes before this is possible

andykais avatar Jan 03 '23 15:01 andykais

When trying to compile to WASM I'm getting the following errors:

# filippo.io/mkcert
./main.go:193:39: undefined: CertutilInstallHelp
./main.go:195:77: undefined: NSSBrowsers
./main.go:272:9: m.installPlatform undefined (type *mkcert has no field or method installPlatform)
./main.go:280:80: undefined: NSSBrowsers
./main.go:283:104: undefined: NSSBrowsers
./main.go:284:14: undefined: CertutilInstallHelp
./main.go:285:78: undefined: NSSBrowsers
./main.go:287:114: undefined: NSSBrowsers
./main.go:288:82: undefined: CertutilInstallHelp
./main.go:311:13: undefined: CertutilInstallHelp
./main.go:311:13: too many errors

Command run:

GOOS=js GOARCH=wasm go build -ldflags "-X main.Version=$(git describe --tags)" -o mkcert.wasm

Anyone knows what would be the problem? I'm not familiar with these type of Go compilation errors, the variables seems to be defined, but it throws undefined errors nonetheless, maybe a GOARCH=wasm limitation?

augustobmoura avatar Jun 14 '23 13:06 augustobmoura