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
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
base64UrlDecode
(String base64) Base64 decodes to a byte array, using URL style encoding.static String
base64UrlEncode
(byte[] data) Base64 encodes the given byte array, using URL style encoding.static String
getContentType
(String header) Extracts the content type of a Content-Type header.static String
hexEncode
(byte[] data) Hex encodes the given byte array.static boolean
isValidBase64Url
(String base64) Validates that the givenString
is a valid base64url encoded value.static Instant
parseTimestamp
(String str) Parses a RFC 3339 formatted date.static byte[]
sha256hash
(String z) Computes a SHA-256 hash of the given string.static String
stripErrorPrefix
(String type) Strips the acme error prefix from the error string.static String
ASCII encodes a domain name.static void
validateContact
(URI contact) Validates a contactURI
.static void
writeToPem
(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 givenString
is 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:
Instant
that 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.null
is safe.- Returns:
- Stripped error type, or
null
if 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.PemLabel
to be usedout
-Writer
to 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
null
if 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
- ContactURI
to validate- Throws:
IllegalArgumentException
- if the contactURI
is not suitable for account contacts.
-