Skip to content

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

Closed

Description

@Faelean

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.

Activity

  1. Faelean commented on Feb 11, 2021

    @Faelean
    Author

    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
    
  2. bbottema commented on Feb 13, 2021

    @bbottema
    Owner

    Yes please, that would be most helpful 👍

  3. added a commit that references this issue on Feb 16, 2021
  4. added this to the 6.5.0 milestone on Feb 16, 2021
  5. changed the title [-]Possible NullPointer in SmimeUtilFixed[/-] [+]NullPointerException in SmimeUtilFixed when protocol is missing (which is valid)[/+] on Feb 16, 2021
  6. bbottema commented on Feb 16, 2021

    @bbottema
    Owner

    Released in 6.5.0

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions