001/* 002 * acme4j - Java ACME client 003 * 004 * Copyright (C) 2018 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.sha256hash; 017 018import org.shredzone.acme4j.Login; 019import org.shredzone.acme4j.toolbox.JSON; 020 021/** 022 * Implements the {@value TYPE} challenge. 023 * 024 * @since 2.1 025 */ 026public class TlsAlpn01Challenge extends TokenChallenge { 027 private static final long serialVersionUID = -5590351078176091228L; 028 029 /** 030 * Challenge type name: {@value} 031 */ 032 public static final String TYPE = "tls-alpn-01"; 033 034 /** 035 * OID of the {@code acmeValidation} extension. 036 */ 037 public static final String ACME_VALIDATION_OID = "1.3.6.1.5.5.7.1.31"; 038 039 /** 040 * {@code acme-tls/1} protocol. 041 */ 042 public static final String ACME_TLS_1_PROTOCOL = "acme-tls/1"; 043 044 /** 045 * Creates a new generic {@link TlsAlpn01Challenge} object. 046 * 047 * @param login 048 * {@link Login} the resource is bound with 049 * @param data 050 * {@link JSON} challenge data 051 */ 052 public TlsAlpn01Challenge(Login login, JSON data) { 053 super(login, data); 054 } 055 056 /** 057 * Returns the value that is to be used as {@code acmeValidation} extension in 058 * the test certificate. 059 */ 060 public byte[] getAcmeValidation() { 061 return sha256hash(getAuthorization()); 062 } 063 064 @Override 065 protected boolean acceptable(String type) { 066 return TYPE.equals(type); 067 } 068 069}