All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.shredzone.acme4j.provider.letsencrypt.LetsEncryptAcmeProvider Maven / Gradle / Ivy

There is a newer version: 3.4.0
Show newest version
/*
 * acme4j - Java ACME client
 *
 * Copyright (C) 2015 Richard "Shred" Körber
 *   http://acme4j.shredzone.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */
package org.shredzone.acme4j.provider.letsencrypt;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;

import org.shredzone.acme4j.exception.AcmeProtocolException;
import org.shredzone.acme4j.provider.AbstractAcmeProvider;
import org.shredzone.acme4j.provider.AcmeProvider;

/**
 * An {@link AcmeProvider} for Let's Encrypt.
 * 

* The {@code serverUri} is {@code "acme://letsencrypt.org"} for the production server, * and {@code "acme://letsencrypt.org/staging"} for a testing server. *

* If you want to use Let's Encrypt, always prefer to use this provider. * * @see Let's Encrypt */ public class LetsEncryptAcmeProvider extends AbstractAcmeProvider { private static final String V02_DIRECTORY_URL = "https://acme-v02.api.letsencrypt.org/directory"; private static final String STAGING_DIRECTORY_URL = "https://acme-staging-v02.api.letsencrypt.org/directory"; @Override public boolean accepts(URI serverUri) { return "acme".equals(serverUri.getScheme()) && "letsencrypt.org".equals(serverUri.getHost()); } @Override public URL resolve(URI serverUri) { var path = serverUri.getPath(); String directoryUrl; if (path == null || path.isEmpty() || "/".equals(path) || "/v02".equals(path)) { directoryUrl = V02_DIRECTORY_URL; } else if ("/staging".equals(path)) { directoryUrl = STAGING_DIRECTORY_URL; } else { throw new IllegalArgumentException("Unknown URI " + serverUri); } try { return new URL(directoryUrl); } catch (MalformedURLException ex) { throw new AcmeProtocolException(directoryUrl, ex); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy