Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

#7: Added missing case for eneveloped S/MIME sign (smime-type) #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,18 @@ public enum SmimeState {
* encrypted.
*/
ENCRYPTED,

/**
* Indicates that the {@link MimePart} or {@link MimeMultipart} is S/MIME
* signed.
*/
SIGNED,

/**
* Indicates that the {@link MimePart} or {@link MimeMultipart} is S/MIME
* signed using the older envelope style.
*/
SIGNED_ENVELOPED,

/**
* Indicates that the {@link MimePart} or {@link MimeMultipart} is neither
Expand Down
24 changes: 14 additions & 10 deletions src/main/java/net/markenwerk/utils/mail/smime/SmimeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -576,17 +576,15 @@ public static SmimeState getStatus(MimePart mimePart) {
throw handledException(e);
}
}

private static SmimeState getStatus(ContentType contentType) {
try {
if (isSmimeSignatureContentType(contentType)) {
return SmimeState.SIGNED;
} else if (isSmimeEncryptionContenttype(contentType)) {
return SmimeState.ENCRYPTED;
} else {
return SmimeState.NEITHER;
}
} catch (Exception e) {
if (isSmimeSignatureContentType(contentType)) {
return SmimeState.SIGNED;
} else if (isSignatureSmimeType(contentType)) {
return SmimeState.SIGNED_ENVELOPED;
} else if (isSmimeEncryptionContenttype(contentType)) {
return SmimeState.ENCRYPTED;
} else {
return SmimeState.NEITHER;
}
}
Expand All @@ -602,6 +600,12 @@ private static boolean isSmimeSignatureContentType(ContentType contentType) {
return baseContentType.equalsIgnoreCase("multipart/signed")
&& isSmimeSignatureProtocoll(contentType.getParameter("protocol"));
}

private static boolean isSignatureSmimeType(ContentType contentType) {
String baseContentType = contentType.getBaseType();
return baseContentType.equalsIgnoreCase("application/x-pkcs7-mime")
&& "signed-data".equals(contentType.getParameter("smime-type"));
}

private static boolean isSmimeSignatureProtocoll(String protocol) {
return protocol.equalsIgnoreCase("application/pkcs7-signature")
Expand Down