MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / ObtainIPSSL

Method ObtainIPSSL

agent/utils/ssl/client.go:169–220  ·  view source on GitHub ↗
(ctx context.Context, ipAddress string, privKey crypto.Signer)

Source from the content-addressed store, hash-verified

167}
168
169func (c *AcmeClient) ObtainIPSSL(ctx context.Context, ipAddress string, privKey crypto.Signer) (certificate.Resource, error) {
170 unlockDNSChallenge := c.lockDNSChallenge()
171 defer unlockDNSChallenge()
172
173 csrTemplate := &x509.CertificateRequest{
174 Subject: pkix.Name{
175 CommonName: "",
176 },
177 IPAddresses: []net.IP{
178 net.ParseIP(ipAddress),
179 },
180 }
181 csrDER, err := x509.CreateCertificateRequest(
182 rand.Reader,
183 csrTemplate,
184 privKey,
185 )
186 if err != nil {
187 return certificate.Resource{}, err
188 }
189 csr, err := x509.ParseCertificateRequest(csrDER)
190 if err != nil {
191 return certificate.Resource{}, err
192 }
193 req := certificate.ObtainForCSRRequest{
194 CSR: csr,
195 PrivateKey: privKey,
196 Profile: "shortlived",
197 Bundle: true,
198 }
199
200 var certificates *certificate.Resource
201 for attempt := 1; attempt <= maxRetryAttempts; attempt++ {
202 certificates, err = c.Client.Certificate.ObtainForCSR(ctx, req)
203 if err == nil {
204 return *certificates, nil
205 }
206
207 if isHTTP503Error(err) && attempt < maxRetryAttempts {
208 global.LOG.Warnf("ACME server returned 503 for IP SSL, retrying in %v (attempt %d/%d)",
209 retryDelayOn503, attempt, maxRetryAttempts)
210 if err := waitForRetry(ctx, retryDelayOn503); err != nil {
211 return certificate.Resource{}, err
212 }
213 continue
214 }
215
216 return certificate.Resource{}, err
217 }
218
219 return certificate.Resource{}, err
220}
221
222func (c *AcmeClient) RevokeSSL(pemSSL []byte) error {
223 return c.Client.Certificate.Revoke(context.Background(), pemSSL)

Callers 1

obtainSSLMethod · 0.80

Calls 3

lockDNSChallengeMethod · 0.95
isHTTP503ErrorFunction · 0.85
waitForRetryFunction · 0.85

Tested by

no test coverage detected