Class DkimSigner
java.lang.Object
org.exoplatform.services.mail.impl.DkimSigner
Signs a serialized RFC 5322 message with a DKIM signature (RFC 6376),
rsa-sha256 with relaxed/relaxed canonicalization. It needs
only the JDK. The signature covers the bytes as they are written on the
wire, so the message must be serialized once, signed, and sent as is.-
Field Summary
FieldsModifier and TypeFieldDescriptionHeaders signed by default, when they are present in the message.static final intRFC 8301 section 3.2: signers must use at least 1024 bits and should use 2048 bits. -
Constructor Summary
ConstructorsConstructorDescriptionDkimSigner(String domain, String selector, PrivateKey key, List<String> headers) Creates a signer for a domain and a selector. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancanCheckPermissions(Path file) Tells whetherisReadableByOthers(Path)can tell anything about the file.intGives the size of the signing key.booleanisAligned(byte[] message) Tells whether the From address of a message is in the signing domain.static booleanisReadableByOthers(Path file) Tells whether the group or the other users can read or write the file.booleanTells whether the signing key is weaker than recommended.static PrivateKeyloadPrivateKey(Path file) Reads an unencrypted RSA private key in PKCS#8 PEM format (-----BEGIN PRIVATE KEY-----).static PrivateKeyparsePrivateKey(String pem) Parses an unencrypted RSA private key in PKCS#8 PEM format.byte[]sign(byte[] message) Signs a message.static byte[]toCrlf(byte[] message) Turns every lone CR and lone LF into CRLF, as the SMTP transport does when it writes the message, so that a signature covers the bytes a receiver gets.
-
Field Details
-
DEFAULT_SIGNED_HEADERS
-
RECOMMENDED_RSA_BITS
public static final int RECOMMENDED_RSA_BITSRFC 8301 section 3.2: signers must use at least 1024 bits and should use 2048 bits.- See Also:
-
-
Constructor Details
-
DkimSigner
Creates a signer for a domain and a selector.- Parameters:
domain- the signing domain, thed=tag, as dot separated labels of letters, digits and hyphens (an IDN in its A-label form)selector- the selector of the DNS record that holds the public key, written like a domain namekey- an RSA private key of at least 1024 bits, the floor of RFC 8301 section 3.2 that no mode relaxesheaders- the names of the headers to sign when present, ornullforDEFAULT_SIGNED_HEADERS; From is always signed, and Bcc cannot be signed because the transport removes it before sending- Throws:
IllegalArgumentException- when the domain, the selector, a header name or the key is not usable
-
-
Method Details
-
loadPrivateKey
Reads an unencrypted RSA private key in PKCS#8 PEM format (-----BEGIN PRIVATE KEY-----).- Parameters:
file- the PEM file- Returns:
- the key
- Throws:
IllegalArgumentException- when the file is not a PKCS#8 RSA key
-
isReadableByOthers
Tells whether the group or the other users can read or write the file.- Parameters:
file- the private key file- Returns:
truewhen the group or the others can read or write the file;falsewhen only its owner can, or when the file system has no POSIX permissions to tell (seecanCheckPermissions(Path))
-
canCheckPermissions
Tells whetherisReadableByOthers(Path)can tell anything about the file.- Parameters:
file- the private key file- Returns:
falsewhen the file system has no POSIX permissions, so that the permission check is skipped;trueotherwise, also when the file cannot be read, which the loading of the key reports
-
parsePrivateKey
Parses an unencrypted RSA private key in PKCS#8 PEM format.- Parameters:
pem- the content of the PEM file- Returns:
- the key
- Throws:
IllegalArgumentException- when it is not a PKCS#8 RSA key
-
getKeyBits
public int getKeyBits()Gives the size of the signing key.- Returns:
- the size of the RSA modulus, in bits
-
isWeakKey
public boolean isWeakKey()Tells whether the signing key is weaker than recommended.- Returns:
truewhen the key is accepted but shorter thanRECOMMENDED_RSA_BITS
-
getDomain
- Returns:
- the signing domain, the
d=tag
-
getSelector
- Returns:
- the selector, the
s=tag
-
isAligned
public boolean isAligned(byte[] message) Tells whether the From address of a message is in the signing domain.- Parameters:
message- a serialized message, with CRLF line ends- Returns:
truewhen the From address belongs to the signing domain or one of its subdomains, so that the signature is aligned
-
toCrlf
public static byte[] toCrlf(byte[] message) Turns every lone CR and lone LF into CRLF, as the SMTP transport does when it writes the message, so that a signature covers the bytes a receiver gets.- Parameters:
message- a serialized message- Returns:
- the message with CRLF line ends only
-
sign
public byte[] sign(byte[] message) Signs a message.- Parameters:
message- a serialized message, with CRLF line ends (seetoCrlf(byte[]))- Returns:
- the same message with a DKIM-Signature header in front of it
-