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.*;
017
018import org.shredzone.acme4j.Session;
019
020/**
021 * Implements the {@value TYPE} challenge.
022 */
023public class Dns01Challenge extends TokenChallenge {
024    private static final long serialVersionUID = 6964687027713533075L;
025
026    /**
027     * Challenge type name: {@value}
028     */
029    public static final String TYPE = "dns-01";
030
031    /**
032     * Creates a new generic {@link Dns01Challenge} object.
033     *
034     * @param session
035     *            {@link Session} to bind to.
036     */
037    public Dns01Challenge(Session session) {
038        super(session);
039    }
040
041    /**
042     * Returns the digest string to be set in the domain's {@code _acme-challenge} TXT
043     * record.
044     */
045    public String getDigest() {
046        return base64UrlEncode(sha256hash(getAuthorization()));
047    }
048
049    @Override
050    protected boolean acceptable(String type) {
051        return TYPE.equals(type);
052    }
053
054}