-
-
Notifications
You must be signed in to change notification settings - Fork 95
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
12 changed files
with
278 additions
and
6 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
70 changes: 70 additions & 0 deletions
70
acme4j-client/src/main/java/org/shredzone/acme4j/provider/google/GoogleAcmeProvider.java
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,70 @@ | ||
/* | ||
* acme4j - Java ACME client | ||
* | ||
* Copyright (C) 2024 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.google; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URI; | ||
import java.net.URL; | ||
import java.util.Optional; | ||
|
||
import org.jose4j.jws.AlgorithmIdentifiers; | ||
import org.shredzone.acme4j.exception.AcmeProtocolException; | ||
import org.shredzone.acme4j.provider.AbstractAcmeProvider; | ||
import org.shredzone.acme4j.provider.AcmeProvider; | ||
|
||
/** | ||
* An {@link AcmeProvider} for the <em>Google Trust Services</em>. | ||
* <p> | ||
* The {@code serverUri} is {@code "acme://pki.goog"} for the production server, | ||
* and {@code "acme://pki.goog/staging"} for the staging server. | ||
* | ||
* @see <a href="https://pki.goog/">https://pki.goog/</a> | ||
* @since 3.5.0 | ||
*/ | ||
public class GoogleAcmeProvider extends AbstractAcmeProvider { | ||
|
||
private static final String PRODUCTION_DIRECTORY_URL = "https://dv.acme-v02.api.pki.goog/directory"; | ||
private static final String STAGING_DIRECTORY_URL = "https://dv.acme-v02.test-api.pki.goog/directory"; | ||
|
||
@Override | ||
public boolean accepts(URI serverUri) { | ||
return "acme".equals(serverUri.getScheme()) | ||
&& "pki.goog".equals(serverUri.getHost()); | ||
} | ||
|
||
@Override | ||
public URL resolve(URI serverUri) { | ||
var path = serverUri.getPath(); | ||
String directoryUrl; | ||
if (path == null || path.isEmpty() || "/".equals(path)) { | ||
directoryUrl = PRODUCTION_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); | ||
} | ||
} | ||
|
||
@Override | ||
public Optional<String> getProposedEabMacAlgorithm() { | ||
return Optional.of(AlgorithmIdentifiers.HMAC_SHA256); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
acme4j-client/src/main/java/org/shredzone/acme4j/provider/google/package-info.java
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,29 @@ | ||
/* | ||
* acme4j - Java ACME client | ||
* | ||
* Copyright (C) 2024 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. | ||
*/ | ||
|
||
/** | ||
* This package contains the {@link org.shredzone.acme4j.provider.AcmeProvider} for the | ||
* Google Trust Services. | ||
* | ||
* @see <a href="https://pki.goog/">https://pki.goog/</a> | ||
*/ | ||
@ReturnValuesAreNonnullByDefault | ||
@DefaultAnnotationForParameters(NonNull.class) | ||
@DefaultAnnotationForFields(NonNull.class) | ||
package org.shredzone.acme4j.provider.google; | ||
|
||
import edu.umd.cs.findbugs.annotations.DefaultAnnotationForFields; | ||
import edu.umd.cs.findbugs.annotations.DefaultAnnotationForParameters; | ||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import edu.umd.cs.findbugs.annotations.ReturnValuesAreNonnullByDefault; |
3 changes: 3 additions & 0 deletions
3
...4j-client/src/main/resources/META-INF/services/org.shredzone.acme4j.provider.AcmeProvider
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
75 changes: 75 additions & 0 deletions
75
acme4j-client/src/test/java/org/shredzone/acme4j/provider/google/GoogleAcmeProviderTest.java
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,75 @@ | ||
/* | ||
* acme4j - Java ACME client | ||
* | ||
* Copyright (C) 2024 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.google; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.shredzone.acme4j.toolbox.TestUtils.url; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
import org.assertj.core.api.AutoCloseableSoftAssertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Unit tests for {@link GoogleAcmeProvider}. | ||
*/ | ||
public class GoogleAcmeProviderTest { | ||
|
||
private static final String PRODUCTION_DIRECTORY_URL = "https://dv.acme-v02.api.pki.goog/directory"; | ||
private static final String STAGING_DIRECTORY_URL = "https://dv.acme-v02.test-api.pki.goog/directory"; | ||
|
||
/** | ||
* Tests if the provider accepts the correct URIs. | ||
*/ | ||
@Test | ||
public void testAccepts() throws URISyntaxException { | ||
var provider = new GoogleAcmeProvider(); | ||
|
||
try (var softly = new AutoCloseableSoftAssertions()) { | ||
softly.assertThat(provider.accepts(new URI("acme://pki.goog"))).isTrue(); | ||
softly.assertThat(provider.accepts(new URI("acme://pki.goog/"))).isTrue(); | ||
softly.assertThat(provider.accepts(new URI("acme://pki.goog/staging"))).isTrue(); | ||
softly.assertThat(provider.accepts(new URI("acme://example.com"))).isFalse(); | ||
softly.assertThat(provider.accepts(new URI("http://example.com/acme"))).isFalse(); | ||
softly.assertThat(provider.accepts(new URI("https://example.com/acme"))).isFalse(); | ||
} | ||
} | ||
|
||
/** | ||
* Test if acme URIs are properly resolved. | ||
*/ | ||
@Test | ||
public void testResolve() throws URISyntaxException { | ||
var provider = new GoogleAcmeProvider(); | ||
|
||
assertThat(provider.resolve(new URI("acme://pki.goog"))).isEqualTo(url(PRODUCTION_DIRECTORY_URL)); | ||
assertThat(provider.resolve(new URI("acme://pki.goog/"))).isEqualTo(url(PRODUCTION_DIRECTORY_URL)); | ||
assertThat(provider.resolve(new URI("acme://pki.goog/staging"))).isEqualTo(url(STAGING_DIRECTORY_URL)); | ||
|
||
assertThrows(IllegalArgumentException.class, () -> provider.resolve(new URI("acme://pki.goog/v99"))); | ||
} | ||
|
||
/** | ||
* Test if correct MAC algorithm is proposed. | ||
*/ | ||
@Test | ||
public void testMacAlgorithm() { | ||
var provider = new GoogleAcmeProvider(); | ||
|
||
assertThat(provider.getProposedEabMacAlgorithm()).isNotEmpty().contains("HS256"); | ||
} | ||
|
||
} |
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
Oops, something went wrong.