mirror of https://github.com/shred/acme4j
Key identifier is a String
parent
f2cd592b2e
commit
5de6efce95
|
@ -14,12 +14,9 @@
|
||||||
package org.shredzone.acme4j;
|
package org.shredzone.acme4j;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.shredzone.acme4j.exception.AcmeProtocolException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A generic ACME resource.
|
* A generic ACME resource.
|
||||||
*/
|
*/
|
||||||
|
@ -62,11 +59,7 @@ public abstract class AcmeResource implements Serializable {
|
||||||
*/
|
*/
|
||||||
protected void setLocation(URL location) {
|
protected void setLocation(URL location) {
|
||||||
this.location = Objects.requireNonNull(location, "location");
|
this.location = Objects.requireNonNull(location, "location");
|
||||||
try {
|
session.setKeyIdentifier(this.location.toString());
|
||||||
session.setKeyIdentifier(this.location.toURI());
|
|
||||||
} catch (URISyntaxException ex) {
|
|
||||||
throw new AcmeProtocolException("Location cannot be used as key identifier", ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class Session {
|
||||||
private final AcmeProvider provider;
|
private final AcmeProvider provider;
|
||||||
|
|
||||||
private KeyPair keyPair;
|
private KeyPair keyPair;
|
||||||
private URI keyIdentifier;
|
private String keyIdentifier;
|
||||||
private byte[] nonce;
|
private byte[] nonce;
|
||||||
private JSON directoryJson;
|
private JSON directoryJson;
|
||||||
private Locale locale = Locale.getDefault();
|
private Locale locale = Locale.getDefault();
|
||||||
|
@ -117,14 +117,14 @@ public class Session {
|
||||||
/**
|
/**
|
||||||
* Gets the key identifier of the ACME account.
|
* Gets the key identifier of the ACME account.
|
||||||
*/
|
*/
|
||||||
public URI getKeyIdentifier() {
|
public String getKeyIdentifier() {
|
||||||
return keyIdentifier;
|
return keyIdentifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the key identifier of the ACME account.
|
* Sets the key identifier of the ACME account.
|
||||||
*/
|
*/
|
||||||
public void setKeyIdentifier(URI keyIdentifier) {
|
public void setKeyIdentifier(String keyIdentifier) {
|
||||||
this.keyIdentifier = keyIdentifier;
|
this.keyIdentifier = keyIdentifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,7 +94,7 @@ public class RegistrationBuilderTest {
|
||||||
|
|
||||||
assertThat(registration.getLocation(), is(locationUrl));
|
assertThat(registration.getLocation(), is(locationUrl));
|
||||||
assertThat(registration.getTermsOfServiceAgreed(), is(true));
|
assertThat(registration.getTermsOfServiceAgreed(), is(true));
|
||||||
assertThat(session.getKeyIdentifier(), is(locationUrl.toURI()));
|
assertThat(session.getKeyIdentifier(), is(locationUrl.toString()));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
RegistrationBuilder builder2 = new RegistrationBuilder();
|
RegistrationBuilder builder2 = new RegistrationBuilder();
|
||||||
|
|
|
@ -134,7 +134,7 @@ public class RegistrationTest {
|
||||||
Registration registration = new Registration(session, locationUrl);
|
Registration registration = new Registration(session, locationUrl);
|
||||||
registration.update();
|
registration.update();
|
||||||
|
|
||||||
assertThat(session.getKeyIdentifier(), is(locationUrl.toURI()));
|
assertThat(session.getKeyIdentifier(), is(locationUrl.toString()));
|
||||||
assertThat(registration.getLocation(), is(locationUrl));
|
assertThat(registration.getLocation(), is(locationUrl));
|
||||||
assertThat(registration.getTermsOfServiceAgreed(), is(true));
|
assertThat(registration.getTermsOfServiceAgreed(), is(true));
|
||||||
assertThat(registration.getContacts(), hasSize(1));
|
assertThat(registration.getContacts(), hasSize(1));
|
||||||
|
|
|
@ -97,7 +97,7 @@ public class SessionTest {
|
||||||
KeyPair kp1 = TestUtils.createKeyPair();
|
KeyPair kp1 = TestUtils.createKeyPair();
|
||||||
KeyPair kp2 = TestUtils.createDomainKeyPair();
|
KeyPair kp2 = TestUtils.createDomainKeyPair();
|
||||||
URI serverUri = URI.create(TestUtils.ACME_SERVER_URI);
|
URI serverUri = URI.create(TestUtils.ACME_SERVER_URI);
|
||||||
URI keyIdentifierUri = URI.create(TestUtils.ACME_SERVER_URI + "/acct/1");
|
String keyIdentifier = TestUtils.ACME_SERVER_URI + "/acct/1";
|
||||||
|
|
||||||
Session session = new Session(serverUri, kp1);
|
Session session = new Session(serverUri, kp1);
|
||||||
|
|
||||||
|
@ -111,8 +111,8 @@ public class SessionTest {
|
||||||
assertThat(session.getKeyPair(), is(kp2));
|
assertThat(session.getKeyPair(), is(kp2));
|
||||||
|
|
||||||
assertThat(session.getKeyIdentifier(), is(nullValue()));
|
assertThat(session.getKeyIdentifier(), is(nullValue()));
|
||||||
session.setKeyIdentifier(keyIdentifierUri);
|
session.setKeyIdentifier(keyIdentifier);
|
||||||
assertThat(session.getKeyIdentifier(), is(keyIdentifierUri));
|
assertThat(session.getKeyIdentifier(), is(keyIdentifier));
|
||||||
|
|
||||||
assertThat(session.getServerUri(), is(serverUri));
|
assertThat(session.getServerUri(), is(serverUri));
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ import org.shredzone.acme4j.util.TestUtils;
|
||||||
public class DefaultConnectionTest {
|
public class DefaultConnectionTest {
|
||||||
|
|
||||||
private URL requestUrl = TestUtils.url("http://example.com/acme/");
|
private URL requestUrl = TestUtils.url("http://example.com/acme/");
|
||||||
private URI keyIdentifierUri = URI.create(TestUtils.ACME_SERVER_URI + "/acct/1");
|
private String keyIdentifier = TestUtils.ACME_SERVER_URI + "/acct/1";
|
||||||
private HttpURLConnection mockUrlConnection;
|
private HttpURLConnection mockUrlConnection;
|
||||||
private HttpConnector mockHttpConnection;
|
private HttpConnector mockHttpConnection;
|
||||||
private Session session;
|
private Session session;
|
||||||
|
@ -585,7 +585,7 @@ public class DefaultConnectionTest {
|
||||||
}) {
|
}) {
|
||||||
JSONBuilder cb = new JSONBuilder();
|
JSONBuilder cb = new JSONBuilder();
|
||||||
cb.put("foo", 123).put("bar", "a-string");
|
cb.put("foo", 123).put("bar", "a-string");
|
||||||
session.setKeyIdentifier(keyIdentifierUri);
|
session.setKeyIdentifier(keyIdentifier);
|
||||||
conn.sendSignedRequest(requestUrl, cb, session);
|
conn.sendSignedRequest(requestUrl, cb, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -612,7 +612,7 @@ public class DefaultConnectionTest {
|
||||||
expectedHeader.append("\"nonce\":\"").append(Base64Url.encode(nonce1)).append("\",");
|
expectedHeader.append("\"nonce\":\"").append(Base64Url.encode(nonce1)).append("\",");
|
||||||
expectedHeader.append("\"url\":\"").append(requestUrl).append("\",");
|
expectedHeader.append("\"url\":\"").append(requestUrl).append("\",");
|
||||||
expectedHeader.append("\"alg\":\"RS256\",");
|
expectedHeader.append("\"alg\":\"RS256\",");
|
||||||
expectedHeader.append("\"kid\":\"").append(keyIdentifierUri).append('"');
|
expectedHeader.append("\"kid\":\"").append(keyIdentifier).append('"');
|
||||||
expectedHeader.append('}');
|
expectedHeader.append('}');
|
||||||
|
|
||||||
assertThat(header, sameJSONAs(expectedHeader.toString()));
|
assertThat(header, sameJSONAs(expectedHeader.toString()));
|
||||||
|
|
|
@ -47,8 +47,7 @@ public class RegistrationIT extends AbstractPebbleIT {
|
||||||
Registration reg = rb.create(session);
|
Registration reg = rb.create(session);
|
||||||
URL location = reg.getLocation();
|
URL location = reg.getLocation();
|
||||||
assertIsPebbleUrl(location);
|
assertIsPebbleUrl(location);
|
||||||
URI keyIdentifier = session.getKeyIdentifier();
|
assertThat(session.getKeyIdentifier(), is(location.toString()));
|
||||||
assertThat(keyIdentifier.toString(), is(location.toString()));
|
|
||||||
|
|
||||||
// TODO: Not yet supported by Pebble
|
// TODO: Not yet supported by Pebble
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue