java.lang.Object
org.shredzone.acme4j.toolbox.AcmeUtils
Contains utility methods that are frequently used for the ACME protocol.
This class is internal. You may use it in your own code, but be warned that methods may change their signature or disappear without prior announcement.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]base64UrlDecode(String base64) Base64 decodes to a byte array, using URL style encoding.static Stringbase64UrlEncode(byte[] data) Base64 encodes the given byte array, using URL style encoding.static StringgetContentType(String header) Extracts the content type of a Content-Type header.static StringhexEncode(byte[] data) Hex encodes the given byte array.static booleanisValidBase64Url(String base64) Validates that the givenStringis a valid base64url encoded value.static InstantparseTimestamp(String str) Parses a RFC 3339 formatted date.static byte[]sha256hash(String z) Computes a SHA-256 hash of the given string.static StringstripErrorPrefix(String type) Strips the acme error prefix from the error string.static StringASCII encodes a domain name.static voidvalidateContact(URI contact) Validates a contactURI.static voidwriteToPem(byte[] encoded, AcmeUtils.PemLabel label, Writer out) Writes an encoded key or certificate to a file in PEM format.
-
Method Details
-
sha256hash
Computes a SHA-256 hash of the given string.- Parameters:
z- String to hash- Returns:
- Hash
-
hexEncode
Hex encodes the given byte array.- Parameters:
data- byte array to hex encode- Returns:
- Hex encoded string of the data (with lower case characters)
-
base64UrlEncode
Base64 encodes the given byte array, using URL style encoding.- Parameters:
data- byte array to base64 encode- Returns:
- base64 encoded string
-
base64UrlDecode
Base64 decodes to a byte array, using URL style encoding.- Parameters:
base64- base64 encoded string- Returns:
- decoded data
-
isValidBase64Url
Validates that the givenStringis a valid base64url encoded value. -
toAce
ASCII encodes a domain name.The conversion is done as described in RFC 3490. Additionally, all leading and trailing white spaces are trimmed, and the result is lowercased.
It is safe to pass in ACE encoded domains, they will be returned unchanged.
- Parameters:
domain- Domain name to encode- Returns:
- Encoded domain name, white space trimmed and lower cased.
-
parseTimestamp
Parses a RFC 3339 formatted date.- Parameters:
str- Date string- Returns:
Instantthat was parsed- Throws:
IllegalArgumentException- if the date string was not RFC 3339 formatted- See Also:
-
stripErrorPrefix
Strips the acme error prefix from the error string.For example, for "urn:ietf:params:acme:error:unauthorized", "unauthorized" is returned.
- Parameters:
type- Error type to strip the prefix from.nullis safe.- Returns:
- Stripped error type, or
nullif the prefix was not found.
-
writeToPem
public static void writeToPem(byte[] encoded, AcmeUtils.PemLabel label, Writer out) throws IOException Writes an encoded key or certificate to a file in PEM format.- Parameters:
encoded- Encoded data to writelabel-AcmeUtils.PemLabelto be usedout-Writerto write to. It will not be closed after use!- Throws:
IOException
-
getContentType
Extracts the content type of a Content-Type header.- Parameters:
header- Content-Type header- Returns:
- Content-Type, or
nullif the header was invalid or empty - Throws:
AcmeProtocolException- if the Content-Type header contains a different charset than "utf-8".
-
validateContact
Validates a contactURI.- Parameters:
contact- ContactURIto validate- Throws:
IllegalArgumentException- if the contactURIis not suitable for account contacts.
-