mirror of https://github.com/shred/acme4j
DnsChallenge: return digest for TXT record
parent
becab450d8
commit
1e1056d692
|
@ -13,6 +13,10 @@
|
|||
*/
|
||||
package org.shredzone.acme4j.challenge;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import org.jose4j.base64url.Base64Url;
|
||||
import org.shredzone.acme4j.Account;
|
||||
import org.shredzone.acme4j.util.ClaimBuilder;
|
||||
|
@ -55,6 +59,22 @@ public class DnsChallenge extends GenericChallenge {
|
|||
return authorization;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the digest string to be set in the domain's {@code _acme-challenge} TXT
|
||||
* record.
|
||||
*/
|
||||
public String getDigest() {
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||
md.update(getAuthorization().getBytes("UTF-8"));
|
||||
byte[] digest = md.digest();
|
||||
return Base64Url.encode(digest);
|
||||
} catch (NoSuchAlgorithmException | UnsupportedEncodingException ex) {
|
||||
// both should be standard in JDK...
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void authorize(Account account) {
|
||||
super.authorize(account);
|
||||
|
|
|
@ -63,6 +63,7 @@ public class DnsChallengeTest {
|
|||
|
||||
assertThat(challenge.getToken(), is(TOKEN));
|
||||
assertThat(challenge.getAuthorization(), is(KEY_AUTHORIZATION));
|
||||
assertThat(challenge.getDigest(), is("rzMmotrIgsithyBYc0vgiLUEEKYx0WetQRgEF2JIozA"));
|
||||
|
||||
ClaimBuilder cb = new ClaimBuilder();
|
||||
challenge.marshall(cb);
|
||||
|
|
Loading…
Reference in New Issue