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

How to manually issue a certificate #276

Closed
devhaozi opened this issue Mar 17, 2024 · 3 comments
Closed

How to manually issue a certificate #276

devhaozi opened this issue Mar 17, 2024 · 3 comments
Labels
question Further information is requested

Comments

@devhaozi
Copy link

devhaozi commented Mar 17, 2024

What is your question?

Hello, I am planning to use this package to replace go-acme/lego, but I don't know how to manually issue the certificate like lego:

// code to get a lego.Client

httpProvider, err := webroot.NewHTTPProvider(path/to/nginx/wwwroot)
if err != nil {
	return err
}

err = client.Challenge.SetHTTP01Provider(httpProvider)

request := certificate.ObtainRequest{
	Domains:    domains,
	Bundle:     true,
	MustStaple: false,
}

certificates, err := client.Certificate.Obtain(request)
if err != nil {
	return err
}

I only need to issue the certificate and do not use domain on this issuance process, can you give me a demo similar to lego?

What have you already tried?

I tried looking through the README and issue lists, and found GetACMEChallenge method, but I don't know how to use it.

Include any other information or discussion.

The code I wrote using go-acme/lego is here: https://github.com/TheTNB/panel/blob/main/pkg/acme/client.go

Bonus: What do you use this package for, and does it help you?

When using certmagic to replace lego, dozens of dependent packages will be deleted from my go.mod.

@mholt
Copy link
Member

mholt commented Mar 20, 2024

Ah I think you want ACMEz, which is the package CertMagic uses under the hood!

Here's an example you can run with pebble: https://github.com/mholt/acmez/blob/master/examples/porcelain/main.go

Edit: But if you want to use all of CertMagic's features, you can call ManageSync() or ManageAsync() depending on whether you need to block or not:

https://pkg.go.dev/github.com/caddyserver/certmagic#Config.ManageSync

Manage* will cause CertMagic to obtain a certificate if necessary; and just keep it renewed while running.

@mholt mholt closed this as completed Mar 20, 2024
@devhaozi
Copy link
Author

Thanks, I will try.

@mholt
Copy link
Member

mholt commented Mar 25, 2024

I guess you can also use the ObtainCert*() methods directly: https://pkg.go.dev/github.com/caddyserver/certmagic#Config.ObtainCertSync

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants