EnvelopedCMS and MailMessage [.NET 2.0 - VB_VS2005]

Discussion in 'ASP .Net Security' started by VIOT Yves, Oct 18, 2006.

  1. VIOT Yves

    VIOT Yves Guest

    Hi all,
    I'm new in VS2005 (and .NET framework 2.0) and i have a problem with
    envelopedCMS and MaiMessage objects. I can't make it work. I've tried
    several things but it doesn't work. I would like to know if anybody have
    a code example ? The only thing i'm sure is that recipients and
    certificates are ok. I seems to be a problem with the envelopedCMS
    encapsulation in the MailMessage, and i think that it commes from the
    headers.
    Thx all...

    Yves VIOT
    VIOT Yves, Oct 18, 2006
    #1
    1. Advertising

  2. VIOT Yves

    Joe Kaplan Guest

    I'm very curious about this too. I know how to create the EnvelopedCms
    message, but I'm also not sure about how to get it into the mail message in
    the proper MIME format so that common mail clients think it is proper SMIME.

    What you might do is create an enveloped message in a mail client and then
    look at the raw message data to see how the body parts are composed.

    It may also be necessary to mess around with System.Net.Mime to get the body
    parts working correctly. Hopefully this doesn't require using CDO via COM
    interop.

    Joe K.

    --
    Joe Kaplan-MS MVP Directory Services Programming
    Co-author of "The .NET Developer's Guide to Directory Services Programming"
    http://www.directoryprogramming.net
    --
    "VIOT Yves" <> wrote in message
    news:%...
    > Hi all,
    > I'm new in VS2005 (and .NET framework 2.0) and i have a problem with
    > envelopedCMS and MaiMessage objects. I can't make it work. I've tried
    > several things but it doesn't work. I would like to know if anybody have a
    > code example ? The only thing i'm sure is that recipients and certificates
    > are ok. I seems to be a problem with the envelopedCMS encapsulation in the
    > MailMessage, and i think that it commes from the headers.
    > Thx all...
    >
    > Yves VIOT
    Joe Kaplan, Oct 18, 2006
    #2
    1. Advertising

  3. VIOT Yves

    VIOT Yves Guest

    Re...
    In fact my code is below.. I don't know if the scheme is correct. I've
    noticed something very strange. The headers i've add (also tried set)
    are duplicate with those that the smtpclient add ???

    ---------------------------------------------------------------------------------------------------
    content-type: application/pkcs7-mime; smime-type=enveloped-data
    content-disposition: attachment;FileName="smime.p7m"
    mime-version: 1.0
    From:
    To:
    date: 18 Oct 2006 17:50:42 +0200
    subject: Test
    content-type: text/plain; charset=utf-8
    content-transfer-encoding: base64
    ---------------------------------------------------------------------------------------------------
    Dim envelop As System.Security.Cryptography.Pkcs.EnvelopedCms
    Dim content As System.Security.Cryptography.Pkcs.ContentInfo
    Dim unicode As New System.Text.UnicodeEncoding
    Dim alg As System.Security.Cryptography.Pkcs.AlgorithmIdentifier
    Dim recipient As System.Security.Cryptography.Pkcs.CmsRecipient

    alg = New System.Security.Cryptography.Pkcs.AlgorithmIdentifier( _
    New Oid("1.2.840.113549.3.7", "3des"), 128)

    content = _
    New System.Security.Cryptography.Pkcs.ContentInfo( _
    unicode.GetBytes((New System.IO.StreamReader(str_File)).ReadToEnd))


    recipient = New System.Security.Cryptography.Pkcs.CmsRecipient( _
    GetRecipientCert)

    envelop = New System.Security.Cryptography.Pkcs.EnvelopedCms(content, alg)
    envelop.Encrypt(recipient)

    obj_SMTPClient = New SmtpClient(str_MailSMTPServer, _
    str_MailSMTPServerPort)



    obj_Message = New MailMessage(str_From, str_To, "Test",
    unicode.GetString(envelop.Encode()))
    obj_Message.Headers.Remove("Content-Type")
    obj_Message.Headers.Add("Content-Type", "application/pkcs7-mime;
    smime-type=enveloped-data")
    obj_Message.Headers.Add("Content-Disposition",
    "attachment;FileName=""smime.p7m""")

    obj_SMTPClient.Send(obj_Message)


    ---------------------------------------------------------------------------------------------------

    Joe Kaplan a écrit :
    > I'm very curious about this too. I know how to create the EnvelopedCms
    > message, but I'm also not sure about how to get it into the mail message in
    > the proper MIME format so that common mail clients think it is proper SMIME.
    >
    > What you might do is create an enveloped message in a mail client and then
    > look at the raw message data to see how the body parts are composed.
    >
    > It may also be necessary to mess around with System.Net.Mime to get the body
    > parts working correctly. Hopefully this doesn't require using CDO via COM
    > interop.
    >
    > Joe K.
    >
    VIOT Yves, Oct 18, 2006
    #3
  4. VIOT Yves

    Joe Kaplan Guest

    I'm not a MIME expert, but I'm pretty sure you don't add the headers
    directly to the message itself. You need to create a body part with the
    correct disposition. I'd suggest poking around in System.Net.Mime and see
    if you can get what you need there.

    Joe K.

    --
    Joe Kaplan-MS MVP Directory Services Programming
    Co-author of "The .NET Developer's Guide to Directory Services Programming"
    http://www.directoryprogramming.net
    --
    "VIOT Yves" <> wrote in message
    news:...
    > Re...
    > In fact my code is below.. I don't know if the scheme is correct. I've
    > noticed something very strange. The headers i've add (also tried set) are
    > duplicate with those that the smtpclient add ???
    >
    > ---------------------------------------------------------------------------------------------------
    > content-type: application/pkcs7-mime; smime-type=enveloped-data
    > content-disposition: attachment;FileName="smime.p7m"
    > mime-version: 1.0
    > From:
    > To:
    > date: 18 Oct 2006 17:50:42 +0200
    > subject: Test
    > content-type: text/plain; charset=utf-8
    > content-transfer-encoding: base64
    > ---------------------------------------------------------------------------------------------------
    > Dim envelop As System.Security.Cryptography.Pkcs.EnvelopedCms
    > Dim content As System.Security.Cryptography.Pkcs.ContentInfo
    > Dim unicode As New System.Text.UnicodeEncoding
    > Dim alg As System.Security.Cryptography.Pkcs.AlgorithmIdentifier
    > Dim recipient As System.Security.Cryptography.Pkcs.CmsRecipient
    >
    > alg = New System.Security.Cryptography.Pkcs.AlgorithmIdentifier( _
    > New Oid("1.2.840.113549.3.7", "3des"), 128)
    >
    > content = _
    > New System.Security.Cryptography.Pkcs.ContentInfo( _
    > unicode.GetBytes((New
    > System.IO.StreamReader(str_File)).ReadToEnd))
    >
    >
    > recipient = New System.Security.Cryptography.Pkcs.CmsRecipient( _
    > GetRecipientCert)
    >
    > envelop = New System.Security.Cryptography.Pkcs.EnvelopedCms(content, alg)
    > envelop.Encrypt(recipient)
    >
    > obj_SMTPClient = New SmtpClient(str_MailSMTPServer, _
    > str_MailSMTPServerPort)
    >
    >
    >
    > obj_Message = New MailMessage(str_From, str_To, "Test",
    > unicode.GetString(envelop.Encode()))
    > obj_Message.Headers.Remove("Content-Type")
    > obj_Message.Headers.Add("Content-Type", "application/pkcs7-mime;
    > smime-type=enveloped-data")
    > obj_Message.Headers.Add("Content-Disposition",
    > "attachment;FileName=""smime.p7m""")
    >
    > obj_SMTPClient.Send(obj_Message)
    >
    >
    > ---------------------------------------------------------------------------------------------------
    >
    > Joe Kaplan a écrit :
    >> I'm very curious about this too. I know how to create the EnvelopedCms
    >> message, but I'm also not sure about how to get it into the mail message
    >> in the proper MIME format so that common mail clients think it is proper
    >> SMIME.
    >>
    >> What you might do is create an enveloped message in a mail client and
    >> then look at the raw message data to see how the body parts are composed.
    >>
    >> It may also be necessary to mess around with System.Net.Mime to get the
    >> body parts working correctly. Hopefully this doesn't require using CDO
    >> via COM interop.
    >>
    >> Joe K.
    >>
    Joe Kaplan, Oct 18, 2006
    #4
  5. VIOT Yves

    VIOT Yves Guest

    Ok thanks i'll take a look tomorrow... (in France it's time to sleep...)
    Goodbye & good night

    Joe Kaplan a écrit :
    > I'm not a MIME expert, but I'm pretty sure you don't add the headers
    > directly to the message itself. You need to create a body part with the
    > correct disposition. I'd suggest poking around in System.Net.Mime and see
    > if you can get what you need there.
    >
    > Joe K.
    >
    VIOT Yves, Oct 18, 2006
    #5
  6. VIOT Yves

    fhtino Guest

    Hi,

    I've the same problem. It seems that NET 2.0 is not able to send a
    SMIME email message.

    http://groups.google.com/group/micr...read/thread/e7fc3045bc87b101/1e57930e6fe40da2

    https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=149485


    Have you found any solution?


    Fabrizio



    VIOT Yves wrote:
    > Hi all,
    > I'm new in VS2005 (and .NET framework 2.0) and i have a problem with
    > envelopedCMS and MaiMessage objects. I can't make it work. I've tried
    > several things but it doesn't work. I would like to know if anybody have
    > a code example ? The only thing i'm sure is that recipients and
    > certificates are ok. I seems to be a problem with the envelopedCMS
    > encapsulation in the MailMessage, and i think that it commes from the
    > headers.
    > Thx all...
    >
    > Yves VIOT
    fhtino, Oct 20, 2006
    #6
  7. VIOT Yves

    VIOT Yves Guest

    Hi,
    I'm investigating... I've tried to force pkcs9 attributes
    unsuccessfully.. I've posted 2 bug report on connect.microsoft.com this
    week but i think it is too early to obtain a response. i've though an
    ugly solution which could be to save the message and to remove
    duplicates headers, but the duplicate headers are added by the send
    method of the smtpclient.
    Keep in touch, i'll post an example if i get news...
    Bye

    Yves

    fhtino a écrit :
    > Hi,
    >
    > I've the same problem. It seems that NET 2.0 is not able to send a
    > SMIME email message.
    >
    > http://groups.google.com/group/micr...read/thread/e7fc3045bc87b101/1e57930e6fe40da2
    >
    > https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=149485
    >
    >
    > Have you found any solution?
    >
    >
    > Fabrizio
    >
    >
    >
    > VIOT Yves wrote:
    >> Hi all,
    >> I'm new in VS2005 (and .NET framework 2.0) and i have a problem with
    >> envelopedCMS and MaiMessage objects. I can't make it work. I've tried
    >> several things but it doesn't work. I would like to know if anybody have
    >> a code example ? The only thing i'm sure is that recipients and
    >> certificates are ok. I seems to be a problem with the envelopedCMS
    >> encapsulation in the MailMessage, and i think that it commes from the
    >> headers.
    >> Thx all...
    >>
    >> Yves VIOT

    >
    VIOT Yves, Oct 20, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Frank

    ASP.NET MailMessage in XP fails

    Frank, Jul 29, 2003, in forum: ASP .Net
    Replies:
    6
    Views:
    504
    Yan-Hong Huang[MSFT]
    Jul 31, 2003
  2. khawar
    Replies:
    1
    Views:
    479
  3. Nathan Sokalski
    Replies:
    6
    Views:
    673
    ...winston
    May 30, 2005
  4. =?Utf-8?B?TWljaGFlbA==?=

    UrlContentBase missing in System.Net.Mail.MailMessage

    =?Utf-8?B?TWljaGFlbA==?=, Dec 2, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,138
    mathijsuitmegen
    May 12, 2009
  5. Gerald S.
    Replies:
    0
    Views:
    2,235
    Gerald S.
    Jan 11, 2006
Loading...

Share This Page