001/*
002 * acme4j - Java ACME client
003 *
004 * Copyright (C) 2015 Richard "Shred" K├Ârber
005 *   http://acme4j.shredzone.org
006 *
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
013 */
014package org.shredzone.acme4j.challenge;
015
016import static org.shredzone.acme4j.toolbox.AcmeUtils.base64UrlEncode;
017import static org.shredzone.acme4j.toolbox.AcmeUtils.sha256hash;
018
019import org.shredzone.acme4j.Login;
020import org.shredzone.acme4j.toolbox.JSON;
021
022/**
023 * Implements the {@value TYPE} challenge.
024 */
025public class Dns01Challenge extends TokenChallenge {
026    private static final long serialVersionUID = 6964687027713533075L;
027
028    /**
029     * Challenge type name: {@value}
030     */
031    public static final String TYPE = "dns-01";
032
033    /**
034     * Creates a new generic {@link Dns01Challenge} object.
035     *
036     * @param login
037     *            {@link Login} the resource is bound with
038     * @param data
039     *            {@link JSON} challenge data
040     */
041    public Dns01Challenge(Login login, JSON data) {
042        super(login, data);
043    }
044
045    /**
046     * Returns the digest string to be set in the domain's {@code _acme-challenge} TXT
047     * record.
048     */
049    public String getDigest() {
050        return base64UrlEncode(sha256hash(getAuthorization()));
051    }
052
053    @Override
054    protected boolean acceptable(String type) {
055        return TYPE.equals(type);
056    }
057
058}