[prev in list] [next in list] [prev in thread] [next in thread] 

List:       bouncycastle-crypto-dev
Subject:    Re: [dev-crypto] RE: Create SMIME containing signed PKCS#7
From:       <mark.schlichtmann () globolog ! com>
Date:       2010-05-26 8:12:38
Message-ID: 23650538.6071274861559183.JavaMail.root () teamup
[Download RAW message or body]

Hi Niels,

Sorry, for these ommisions:

.......
public CMSSignedData signCMS(MimeBodyPart aBodyPart, CMSSignedDataGenerator \
generator) throws Exception {  byte[] file = null;
	if (IntegrityUtils.istobediveintoagzipfile(aBodyPart)) {
		file = IntegrityUtils.inputStreamToByteArray(new \
GZIPInputStream(aBodyPart.getInputStream()));  } else {
	file = IntegrityUtils.inputStreamToByteArray(aBodyPart.getInputStream());
		}
	CMSProcessable data = new CMSProcessableByteArray(file);
	CMSSignedData signed = generator.generate(data, BC_PROVIDER);
	return new CMSSignedData(data, signed.getEncoded());
}

......

MimeTypesInterface.APPLICATION_X_PKCS7_SIGNATURE = "application/x-pkcs7-signature";
DISPOSITION_ATTACHMENT		= "attachment";

.......

Greets, Mark Schlichtmann


-----Original message-----
From: Niels Stevens <steniels@gmail.com>
Sent: Tue 25-05-2010 18:38
To: Mark Schlichtmann <mark.schlichtmann@globolog.com>; 
Subject: Re: [dev-crypto] RE: Create SMIME containing signed PKCS#7

> Thanks again for the response !
> 
> I'm trying to use it like that but I have a few questions.
> 
> First could you mail me the code of the signCMS() function ?
> Second how is these consts defined 
> MimeTypesInterface.APPLICATION_X_PKCS7_SIGNATURE  & DISPOSITION_ATTACHMENT ?
> 
> Many thanks,
> 
> Niels Stevens
> 
> Op 25-mei-2010, om 17:13 heeft Mark Schlichtmann het volgende geschreven:
> 
> > Hi there,
> > 
> > For string content we are doing this:
> > 
> > .....
> > 
> > Firstly ...
> > 
> > MimeMultipart newMimeMultipart = new MimeMultipart();
> > newMimeMultipart.setParent(aMimeMessage);
> > aMimeMessage.setContent(newMimeMultipart);
> > aMimeMessage.saveChanges();
> > String content = (String) aContent;
> > MimeBodyPart aMimeBodyPart = new MimeBodyPart();
> > aMimeBodyPart.setText(content);
> > newMimeMultipart.addBodyPart(aMimeBodyPart);
> > CMSSignedData data = signCMS(aMimeBodyPart, generator);
> > aMimeBodyPart = getSignedContentAsBodyPart(data, "mail_inhalt" + POSTFIX_CMS);
> > newMimeMultipart.addBodyPart(aMimeBodyPart);
> > aMimeMessage.saveChanges();
> > 
> > ........
> > 
> > Then ...
> > 
> > private MimeBodyPart getSignedContentAsBodyPart(CMSSignedData data, String 
> filename) throws MessagingException, IOException {
> > 	MimeBodyPart aMimeBodyPart = new MimeBodyPart();
> > 	aMimeBodyPart.setDataHandler(new DataHandler(new 
> ByteArrayDataSource(data.getEncoded(), 
> MimeTypesInterface.APPLICATION_X_PKCS7_SIGNATURE)));
> > 	aMimeBodyPart.setDescription(filename);
> > 	aMimeBodyPart.setFileName(filename);
> > 	aMimeBodyPart.setDisposition(DISPOSITION_ATTACHMENT);
> > 	return aMimeBodyPart;
> > }
> > 
> > And for multiparts this:
> > 
> > if (aContent instanceof MimeMultipart) {
> > 	MimeMultipart aMimeMultipart = (MimeMultipart) aContent;
> > 	int count = aMimeMultipart.getCount();
> > 	for (int indexOfMimeBodyPart = 0; indexOfMimeBodyPart < count; 
> indexOfMimeBodyPart++) {
> > 		MimeBodyPart aBodyPart = (MimeBodyPart) 
> aMimeMultipart.getBodyPart(indexOfMimeBodyPart);
> > 		String filename = aBodyPart.getFileName();
> > 		MimeBodyPart newMimeBodyPart = new MimeBodyPart();
> > 		if (filename == null) {
> > 			newMimeBodyPart = aBodyPart;
> > 			newMimeMultipart.addBodyPart(newMimeBodyPart);
> > 		} else {
> > 			if 
> (aBodyPart.getContentType().toLowerCase().contains(MimeTypesInterface.TEXT_PLAIN
> ) && aBodyPart.getDisposition().equalsIgnoreCase(DISPOSITION_INLINE)) {
> > 				aBodyPart.setDisposition(DISPOSITION_ATTACHMENT);
> > 			}
> > 			newMimeMultipart.addBodyPart(aBodyPart);
> > 			CMSSignedData data = signCMS(aBodyPart, generator);
> > 			MimeBodyPart aMimeBodyPart = getSignedContentAsBodyPart(data, 
> aBodyPart.getFileName() + POSTFIX_CMS);
> > 			newMimeMultipart.addBodyPart(aMimeBodyPart);
> > 		}
> > 		aMimeMessage.saveChanges();
> > 	}
> > }
> > 
> > Hope this helps! Greets, Mark
> > 
> > 
> > -----Original message-----
> > From: Niels Stevens <steniels@gmail.com>
> > Sent: Tue 25-05-2010 17:50
> > To: Mark Schlichtmann <mark.schlichtmann@globolog.com>; 
> > Subject: Re: [dev-crypto] RE: Create SMIME containing signed PKCS#7
> > 
> > > Hi Mark,
> > > 
> > > Yes, I just tried that approach before you send me the mail. It didn't work 
> > > because it's creating a multi part message separating the signing and the 
> > > content.
> > > I already created the signed pkcs7 like this :
> > > 
> > > 
> > > CMSSignedDataGenerator generator = new CMSSignedDataGenerator();
> > > generator.addSigner(privKey, (X509Certificate) userCert, 
> > > CMSSignedDataGenerator.DIGEST_SHA1);
> > > generator.addCertificatesAndCRLs(store);
> > > CMSProcessable content = new 
> > > CMSProcessableByteArray(json.toString().getBytes("ASCII"));
> > > CMSSignedData signedData = generator.generate(content, true, 
> "BC");
> > > 
> > > 
> > > and afterwards I want to put this in a simple SMIME without signing , 
> > > encrypting , compressing or something else.
> > > I want to create a smime like this :
> > > 
> > > 
> > > MIME-Version: 1.0
> > > Content-Disposition: attachment; filename="smime.p7m"
> > > Content-Type: application/x-pkcs7-mime; smime-type=signed-data; 
> name="smime.p7m"
> > > Content-Transfer-Encoding: base64
> > > 
> > > 
> > > MIILCAYJKoZIhvcNAQcCoIIK+TCCCvUCAQExCzAJBgUrDgMCGgUAMIIB5QYJKoZI
> > > hvcNAQcBoIIB1gSCAdJDb250ZW50LVR5cGU6IHRleHQvcGxhaW4NCg0KeyANCiAi
> > > bG9jYWxDaGFsbGVuZ2UiCTogImIzMzBlODA3NmNkNWY1ZjkzYjMzOGJjNTU0MGE3
> > > NTdhZTRhOWU4OGI0NjNhNWEwOGE1ZWE2ZDAyNzdiYTQ5YjIwYmM1MGYyNTUzMDE4
> > > ZWFhZmE3ZTcyZWQ2YzJjNDgwNDVkMzNkYjBlZDExYWI0Mzc0ZmY1NGEyYjM5YTEy
> > > 
> > > 
> > > ............
> > > 
> > > 
> > > 
> > > The funniest thing is that It was working, I added to the svn repository , 
> my 
> > > collage tried to run it on it's pc and it failed. 
> > > The problem with going with another solution on the moment obliges me to 
> change 
> > > also the system in mine C++ library.
> > > 
> > > 
> > > Do you now something that could mess up project ? Im using netbeans 6.8.
> > > 
> > > 
> > > Thanks in advance,
> > > 
> > > 
> > > Niels Stevens
> > > 
> > > 
> > > 
> > > Op 25-mei-2010, om 16:22 heeft Mark Schlichtmann het volgende geschreven:
> > > 
> > > Hi Niels,
> > > 
> > > 
> > > Well, the most straightforward way of putting a signed part into a MIME 
> message 
> > > is like this:
> > > 
> > > MimeMultipart signedMultipart = 
> aSMIMESignedGenerator.generate(aMimeBodyPart, 
> > > BC_PROVIDER);
> > > aMimeMessage.setContent(signedMultipart, signedMultipart.getContentType());
> > > aMimeMessage.saveChanges();
> > > 
> > > Is that what you are looking for or am I out of touch? Greets, Mark
> > > 
> > > 
> > > -----Original message-----
> > > From: Niels Stevens <steniels@gmail.com>
> > > Sent: Tue 25-05-2010 17:14
> > > To: dev-crypto@bouncycastle.org; 
> > > Subject: [dev-crypto] RE: Create SMIME containing signed PKCS#7
> > > 
> > > 
> > > Thanks for the response,
> > > 
> > > I don't want to sign the SMIME at all.
> > > I already have a signed PKCS7 object and I want to put that one inside of a
> > > SMIME.
> > > 
> > > I already had it working but suddenly the padding of the TLV's is all messed
> > > up.
> > > 
> > > The problem is I must also work with openssl. 
> > > The output is redirected to an C++ library to verify the smime containing a
> > > signed PKCS7.
> > > I tested that C++ with unit test in boost and that validating is working
> > > perfectly.
> > > 
> > > Do you have a solution for it ?
> > > 
> > > Thanks in advance !
> > > 
> > > Niels Stevens
> > > -- 
> > > View this message in context: 
> > > 
> http://bouncy-castle.1462172.n4.nabble.com/Create-SMIME-containing-signed-PKCS-7
> > > -tp2230007p2230171.html
> > > Sent from the Bouncy Castle - Dev mailing list archive at Nabble.com.
> > > 
> > > 
> > > 
> > > Mark Schlichtmann
> > > 
> > > Entwickler
> > > Tel: +49 234 388 77 221 - +49 234 388 77 210  - 
> mark.schlichtmann@globolog.com
> > > 
> > > Globolog GmbH - Lise-Meitner-Allee 4 - 44801 Bochum
> > > Tel.: +49 234 38877 200 - Fax: +49 234 38877 210 - Email: info@globolog.com 
> - 
> > > Web: www.globolog.com
> > > Geschäftsführer: Rainer Schulz - Rainer Stecken - HRB 10560 - USt.IdNr.: 
> > > DE244850223
> > > 
> > > Der Inhalt dieser Email, inklusive seiner Anhänge, ist vertraulich und 
> > > ausschließlich für den bezeichneten Empfänger bestimmt. Wenn Sie nicht der 
> > > vorgesehene Empfänger dieser Email oder dessen Vertreter sind, so beachten 
> Sie 
> > > bitte, dass jede Form der Kenntnisnahme, Nutzung, Veröffentlichung, 
> > > Vervielfältigung oder Weitergabe unzulässig ist. Wir bitten Sie in diesem 
> Fall, 
> > > sich mit dem Absender dieser Email in Verbindung zu setzen.
> > > 
> > > This e-mail is intended exclusively for the individual or entity to which it 
> is 
> > > addressed and may contain confidential or legally privileged information, 
> which 
> > > may not be disclosed under current legislation. Any form of disclosure, 
> copying 
> > > or distribution of this e-mail is strictly prohibited. If you have received 
> > > this message in error, please notify the sender immediately by e-mail and 
> > > delete all copies of the message.
> > > 
> > > 
> > > 
> > > 
> > > 
> > Mark Schlichtmann
> > 
> > Entwickler
> > Tel: +49 234 388 77 221 - +49 234 388 77 210  - mark.schlichtmann@globolog.com
> > 
> > Globolog GmbH - Lise-Meitner-Allee 4 - 44801 Bochum
> > Tel.: +49 234 38877 200 - Fax: +49 234 38877 210 - Email: info@globolog.com - 
> Web: www.globolog.com
> > Geschäftsführer: Rainer Schulz - Rainer Stecken - HRB 10560 - USt.IdNr.: 
> DE244850223
> > 
> > Der Inhalt dieser Email, inklusive seiner Anhänge, ist vertraulich und 
> ausschließlich für den bezeichneten Empfänger bestimmt. Wenn Sie nicht der 
> vorgesehene Empfänger dieser Email oder dessen Vertreter sind, so beachten Sie 
> bitte, dass jede Form der Kenntnisnahme, Nutzung, Veröffentlichung, 
> Vervielfältigung oder Weitergabe unzulässig ist. Wir bitten Sie in diesem Fall, 
> sich mit dem Absender dieser Email in Verbindung zu setzen.
> > 
> > This e-mail is intended exclusively for the individual or entity to which it 
> is addressed and may contain confidential or legally privileged information, 
> which may not be disclosed under current legislation. Any form of disclosure, 
> copying or distribution of this e-mail is strictly prohibited. If you have 
> received this message in error, please notify the sender immediately by e-mail 
> and delete all copies of the message.
> 
> 
> 
Mark Schlichtmann

Entwickler
Tel: +49 234 388 77 221 - +49 234 388 77 210  - mark.schlichtmann@globolog.com

Globolog GmbH - Lise-Meitner-Allee 4 - 44801 Bochum
Tel.: +49 234 38877 200 - Fax: +49 234 38877 210 - Email: info@globolog.com - Web: \
www.globolog.com Geschäftsführer: Rainer Schulz - Rainer Stecken - HRB 10560 - \
USt.IdNr.: DE244850223

Der Inhalt dieser Email, inklusive seiner Anhänge, ist vertraulich und ausschließlich \
für den bezeichneten Empfänger bestimmt. Wenn Sie nicht der vorgesehene Empfänger \
dieser Email oder dessen Vertreter sind, so beachten Sie bitte, dass jede Form der \
Kenntnisnahme, Nutzung, Veröffentlichung, Vervielfältigung oder Weitergabe unzulässig \
ist. Wir bitten Sie in diesem Fall, sich mit dem Absender dieser Email in Verbindung \
zu setzen.

This e-mail is intended exclusively for the individual or entity to which it is \
addressed and may contain confidential or legally privileged information, which may \
not be disclosed under current legislation. Any form of disclosure, copying or \
distribution of this e-mail is strictly prohibited. If you have received this message \
in error, please notify the sender immediately by e-mail and delete all copies of the \
message.


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic