Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException in SmimeUtilFixed when protocol is missing (which is valid) #292

Closed
Faelean opened this issue Sep 29, 2020 · 3 comments

Comments

@Faelean
Copy link

Faelean commented Sep 29, 2020

When using the outlookMsgToEmailBuilder function

public static EmailFromOutlookMessage outlookMsgToEmailBuilder(@NotNull final InputStream msgInputStream) {

I sometimes get this error message:

org.simplejavamail.internal.smimesupport.SmimeException: Error unwrapping S/MIME enveloped attachment: 
	AttachmentResource{
		name='smime.p7s',
		dataSource.name=smime.p7s,
		dataSource.getContentType=multipart/signed
	}

This is caused by a Nullpointer in this function when the contentType in the calling function does not contain the parameter protocol:

private static boolean isSmimeSignatureProtocoll(String protocol) {
return protocol.equalsIgnoreCase("application/pkcs7-signature")
|| protocol.equalsIgnoreCase("application/x-pkcs7-signature");
}

private static boolean isSmimeSignatureContentType(ContentType contentType) {
String baseContentType = contentType.getBaseType();
return baseContentType.equalsIgnoreCase("multipart/signed")
&& isSmimeSignatureProtocoll(contentType.getParameter("protocol"));
}

I haven't been able to create an email with this problem myself (if necessary I can obtain one) but here is the way we handle these emails:

  • Drag & Drop from Outlook to a Browser
  • Transfer the file to a server
  • Convert the file to a ByteArrayInputStream
  • Call outlookMsgToEmailBuilder with that InputStream

I don't know why these mails don't contain a protocol, but the easiest way to prevent the NullPointer would be to make the isSmimeSignatureProtocoll function nullsave by using protocol as input parameter for equalsIgnoreCase:

"application/pkcs7-signature".equalsIgnoreCase(protocol) || "application/x-pkcs7-signature".equalsIgnoreCase(protocol)

This would change the NullPointer to a false.

@Faelean
Copy link
Author

Faelean commented Feb 11, 2021

If you want I can now provide an example mail that causes the error, I'd have to send it to you via mail though.
The mail crashes the program I used in #303.

Exception in thread "main" org.simplejavamail.internal.smimesupport.SmimeException: Error unwrapping S/MIME enveloped attachment: 
	AttachmentResource{
		name='smime.p7m',
		dataSource.name=smime.p7m,
		dataSource.getContentType=multipart/signed
	}
	at org.simplejavamail.internal.smimesupport.SMIMESupport.decryptAttachments(SMIMESupport.java:232)
	at org.simplejavamail.internal.smimesupport.SMIMESupport.decryptAttachments(SMIMESupport.java:188)
	at org.simplejavamail.internal.smimesupport.SMIMESupport.decryptAttachments(SMIMESupport.java:121)
	at org.simplejavamail.internal.smimesupport.SMIMESupport.decryptAttachments(SMIMESupport.java:91)
	at org.simplejavamail.converter.EmailConverter.decryptAttachments(EmailConverter.java:233)
	at org.simplejavamail.converter.EmailConverter.outlookMsgToEmailBuilder(EmailConverter.java:227)
	at org.simplejavamail.converter.EmailConverter.outlookMsgToEmail(EmailConverter.java:209)
	at org.simplejavamail.converter.EmailConverter.outlookMsgToEmail(EmailConverter.java:201)
	at ReadMail.main(ReadMail.java:29)
Caused by: net.markenwerk.utils.mail.smime.SmimeException
	at org.simplejavamail.internal.smimesupport.SmimeUtilFixed.handledException(SmimeUtilFixed.java:83)
	at org.simplejavamail.internal.smimesupport.SmimeUtilFixed.getStatus(SmimeUtilFixed.java:40)
	at org.simplejavamail.internal.smimesupport.SMIMESupport.determineStatus(SMIMESupport.java:333)
	at org.simplejavamail.internal.smimesupport.SMIMESupport.decryptAndUnsignAttachment(SMIMESupport.java:260)
	at org.simplejavamail.internal.smimesupport.SMIMESupport.decryptAttachments(SMIMESupport.java:230)
	... 8 more
Caused by: java.lang.NullPointerException
	at org.simplejavamail.internal.smimesupport.SmimeUtilFixed.isSmimeSignatureProtocoll(SmimeUtilFixed.java:75)
	at org.simplejavamail.internal.smimesupport.SmimeUtilFixed.isSmimeSignatureContentType(SmimeUtilFixed.java:71)
	at org.simplejavamail.internal.smimesupport.SmimeUtilFixed.getStatus(SmimeUtilFixed.java:45)
	at org.simplejavamail.internal.smimesupport.SmimeUtilFixed.getStatus(SmimeUtilFixed.java:38)
	... 11 more

@bbottema
Copy link
Owner

Yes please, that would be most helpful 👍

bbottema added a commit that referenced this issue Feb 16, 2021
@bbottema bbottema added this to the 6.5.0 milestone Feb 16, 2021
@bbottema bbottema changed the title Possible NullPointer in SmimeUtilFixed NullPointerException in SmimeUtilFixed when protocol is missing (which is valid) Feb 16, 2021
@bbottema
Copy link
Owner

Released in 6.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants