mirror of
https://github.com/shred/acme4j.git
synced 2025-12-13 11:14:02 +08:00
Upgrade to Java 17
This commit is contained in:
@@ -13,6 +13,8 @@
|
||||
*/
|
||||
package org.shredzone.acme4j.smime;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import jakarta.mail.internet.AddressException;
|
||||
import jakarta.mail.internet.InternetAddress;
|
||||
import org.shredzone.acme4j.Identifier;
|
||||
@@ -24,6 +26,7 @@ import org.shredzone.acme4j.exception.AcmeProtocolException;
|
||||
* @since 2.12
|
||||
*/
|
||||
public class EmailIdentifier extends Identifier {
|
||||
@Serial
|
||||
private static final long serialVersionUID = -1473014167038845395L;
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,6 +16,8 @@ package org.shredzone.acme4j.smime.challenge;
|
||||
import static org.shredzone.acme4j.toolbox.AcmeUtils.base64UrlEncode;
|
||||
import static org.shredzone.acme4j.toolbox.AcmeUtils.sha256hash;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import jakarta.mail.internet.AddressException;
|
||||
import jakarta.mail.internet.InternetAddress;
|
||||
import org.shredzone.acme4j.Login;
|
||||
@@ -30,6 +32,7 @@ import org.shredzone.acme4j.toolbox.JSON;
|
||||
* @since 2.12
|
||||
*/
|
||||
public class EmailReply00Challenge extends TokenChallenge {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 2502329538019544794L;
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,6 +15,7 @@ package org.shredzone.acme4j.smime.exception;
|
||||
|
||||
import static java.util.Collections.unmodifiableList;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -40,6 +41,7 @@ import org.shredzone.acme4j.exception.AcmeException;
|
||||
* @since 2.15
|
||||
*/
|
||||
public class AcmeInvalidMessageException extends AcmeException {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 5607857024718309330L;
|
||||
|
||||
private final List<ErrorBundle> errors;
|
||||
|
||||
@@ -149,24 +149,19 @@ public class SignedMail implements Mail {
|
||||
|
||||
var relaxed = false;
|
||||
for (var element : (ASN1Set) attr.getAttributeValues()[0]) {
|
||||
if (element instanceof ASN1Enumerated) {
|
||||
var algorithm = ((ASN1Enumerated) element).intValueExact();
|
||||
switch (algorithm) {
|
||||
case 0:
|
||||
relaxed = false;
|
||||
break;
|
||||
case 1:
|
||||
relaxed = true;
|
||||
break;
|
||||
default:
|
||||
throw new AcmeInvalidMessageException("Unknown algorithm: " + algorithm);
|
||||
}
|
||||
if (element instanceof ASN1Enumerated asn1element) {
|
||||
var algorithm = asn1element.intValueExact();
|
||||
relaxed = switch (algorithm) {
|
||||
case 0 -> false;
|
||||
case 1 -> true;
|
||||
default -> throw new AcmeInvalidMessageException("Unknown algorithm: " + algorithm);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
for (var element : (ASN1Set) attr.getAttributeValues()[0]) {
|
||||
if (element instanceof ASN1Sequence) {
|
||||
for (var sequenceElement : (ASN1Sequence) element) {
|
||||
if (element instanceof ASN1Sequence asn1sequence) {
|
||||
for (var sequenceElement : asn1sequence) {
|
||||
var headerField = (ASN1Sequence) sequenceElement;
|
||||
var fieldName = ((ASN1String) headerField.getObjectAt(0)).getString();
|
||||
var fieldValue = ((ASN1String) headerField.getObjectAt(1)).getString();
|
||||
|
||||
@@ -163,12 +163,11 @@ public class SignedMailBuilder {
|
||||
requireNonNull(message, "message");
|
||||
try {
|
||||
// Check all parameters
|
||||
if (!(message instanceof MimeMessage)) {
|
||||
if (!(message instanceof MimeMessage mimeMessage)) {
|
||||
throw new IllegalArgumentException("Message must be a MimeMessage");
|
||||
}
|
||||
MimeMessage mimeMessage = (MimeMessage) message;
|
||||
|
||||
if (!(mimeMessage.getContent() instanceof MimeMultipart)) {
|
||||
if (!(mimeMessage.getContent() instanceof MimeMultipart contentMultipart)) {
|
||||
throw new AcmeProtocolException("S/MIME signed message must contain MimeMultipart");
|
||||
}
|
||||
|
||||
@@ -177,7 +176,7 @@ public class SignedMailBuilder {
|
||||
}
|
||||
|
||||
// Get the signed message
|
||||
SMIMESigned signed = new SMIMESigned((MimeMultipart) mimeMessage.getContent());
|
||||
SMIMESigned signed = new SMIMESigned(contentMultipart);
|
||||
|
||||
// Validate the signature
|
||||
SignerInformation si = validateSignature(mimeMessage, pkixParameters);
|
||||
|
||||
@@ -55,10 +55,10 @@ public class SimpleMail implements Mail {
|
||||
if (from.length != 1) {
|
||||
throw new AcmeInvalidMessageException("Message must have exactly one sender, but has " + from.length);
|
||||
}
|
||||
if (!(from[0] instanceof InternetAddress)) {
|
||||
if (!(from[0] instanceof InternetAddress from0)) {
|
||||
throw new AcmeInvalidMessageException("Invalid sender message type: " + from[0].getClass().getName());
|
||||
}
|
||||
return (InternetAddress) from[0];
|
||||
return from0;
|
||||
} catch (MessagingException ex) {
|
||||
throw new AcmeInvalidMessageException("Could not read 'From' header", ex);
|
||||
}
|
||||
@@ -74,10 +74,10 @@ public class SimpleMail implements Mail {
|
||||
if (to.length != 1) {
|
||||
throw new AcmeInvalidMessageException("Message must have exactly one recipient, but has " + to.length);
|
||||
}
|
||||
if (!(to[0] instanceof InternetAddress)) {
|
||||
if (!(to[0] instanceof InternetAddress to0)) {
|
||||
throw new AcmeInvalidMessageException("Invalid recipient message type: " + to[0].getClass().getName());
|
||||
}
|
||||
return (InternetAddress) to[0];
|
||||
return to0;
|
||||
} catch (MessagingException ex) {
|
||||
throw new AcmeInvalidMessageException("Could not read 'To' header", ex);
|
||||
}
|
||||
|
||||
@@ -37,8 +37,8 @@ public class EmailIdentifierTest {
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideTestEmails")
|
||||
public void testEmail(Object input, String expected) {
|
||||
var id = input instanceof InternetAddress
|
||||
? EmailIdentifier.email((InternetAddress) input)
|
||||
var id = input instanceof InternetAddress internetAddress
|
||||
? EmailIdentifier.email(internetAddress)
|
||||
: EmailIdentifier.email(input.toString());
|
||||
|
||||
assertThat(id.getType()).isEqualTo(EmailIdentifier.TYPE_EMAIL);
|
||||
|
||||
Reference in New Issue
Block a user