Key identifier is a String

pull/55/head
Richard Körber 2017-04-19 00:48:05 +02:00
parent f2cd592b2e
commit 5de6efce95
7 changed files with 13 additions and 21 deletions

View File

@ -14,12 +14,9 @@
package org.shredzone.acme4j;
import java.io.Serializable;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Objects;
import org.shredzone.acme4j.exception.AcmeProtocolException;
/**
* A generic ACME resource.
*/
@ -62,11 +59,7 @@ public abstract class AcmeResource implements Serializable {
*/
protected void setLocation(URL location) {
this.location = Objects.requireNonNull(location, "location");
try {
session.setKeyIdentifier(this.location.toURI());
} catch (URISyntaxException ex) {
throw new AcmeProtocolException("Location cannot be used as key identifier", ex);
}
session.setKeyIdentifier(this.location.toString());
}
/**

View File

@ -47,7 +47,7 @@ public class Session {
private final AcmeProvider provider;
private KeyPair keyPair;
private URI keyIdentifier;
private String keyIdentifier;
private byte[] nonce;
private JSON directoryJson;
private Locale locale = Locale.getDefault();
@ -117,14 +117,14 @@ public class Session {
/**
* Gets the key identifier of the ACME account.
*/
public URI getKeyIdentifier() {
public String getKeyIdentifier() {
return keyIdentifier;
}
/**
* Sets the key identifier of the ACME account.
*/
public void setKeyIdentifier(URI keyIdentifier) {
public void setKeyIdentifier(String keyIdentifier) {
this.keyIdentifier = keyIdentifier;
}

View File

@ -94,7 +94,7 @@ public class RegistrationBuilderTest {
assertThat(registration.getLocation(), is(locationUrl));
assertThat(registration.getTermsOfServiceAgreed(), is(true));
assertThat(session.getKeyIdentifier(), is(locationUrl.toURI()));
assertThat(session.getKeyIdentifier(), is(locationUrl.toString()));
try {
RegistrationBuilder builder2 = new RegistrationBuilder();

View File

@ -134,7 +134,7 @@ public class RegistrationTest {
Registration registration = new Registration(session, locationUrl);
registration.update();
assertThat(session.getKeyIdentifier(), is(locationUrl.toURI()));
assertThat(session.getKeyIdentifier(), is(locationUrl.toString()));
assertThat(registration.getLocation(), is(locationUrl));
assertThat(registration.getTermsOfServiceAgreed(), is(true));
assertThat(registration.getContacts(), hasSize(1));

View File

@ -97,7 +97,7 @@ public class SessionTest {
KeyPair kp1 = TestUtils.createKeyPair();
KeyPair kp2 = TestUtils.createDomainKeyPair();
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);
@ -111,8 +111,8 @@ public class SessionTest {
assertThat(session.getKeyPair(), is(kp2));
assertThat(session.getKeyIdentifier(), is(nullValue()));
session.setKeyIdentifier(keyIdentifierUri);
assertThat(session.getKeyIdentifier(), is(keyIdentifierUri));
session.setKeyIdentifier(keyIdentifier);
assertThat(session.getKeyIdentifier(), is(keyIdentifier));
assertThat(session.getServerUri(), is(serverUri));
}

View File

@ -57,7 +57,7 @@ import org.shredzone.acme4j.util.TestUtils;
public class DefaultConnectionTest {
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 HttpConnector mockHttpConnection;
private Session session;
@ -585,7 +585,7 @@ public class DefaultConnectionTest {
}) {
JSONBuilder cb = new JSONBuilder();
cb.put("foo", 123).put("bar", "a-string");
session.setKeyIdentifier(keyIdentifierUri);
session.setKeyIdentifier(keyIdentifier);
conn.sendSignedRequest(requestUrl, cb, session);
}
@ -612,7 +612,7 @@ public class DefaultConnectionTest {
expectedHeader.append("\"nonce\":\"").append(Base64Url.encode(nonce1)).append("\",");
expectedHeader.append("\"url\":\"").append(requestUrl).append("\",");
expectedHeader.append("\"alg\":\"RS256\",");
expectedHeader.append("\"kid\":\"").append(keyIdentifierUri).append('"');
expectedHeader.append("\"kid\":\"").append(keyIdentifier).append('"');
expectedHeader.append('}');
assertThat(header, sameJSONAs(expectedHeader.toString()));

View File

@ -47,8 +47,7 @@ public class RegistrationIT extends AbstractPebbleIT {
Registration reg = rb.create(session);
URL location = reg.getLocation();
assertIsPebbleUrl(location);
URI keyIdentifier = session.getKeyIdentifier();
assertThat(keyIdentifier.toString(), is(location.toString()));
assertThat(session.getKeyIdentifier(), is(location.toString()));
// TODO: Not yet supported by Pebble
/*