Fields Summary |
---|
public static final String | DIGEST_SHA1 |
public static final String | DIGEST_MD5 |
public static final String | DIGEST_SHA224 |
public static final String | DIGEST_SHA256 |
public static final String | DIGEST_SHA384 |
public static final String | DIGEST_SHA512 |
public static final String | DIGEST_GOST3411 |
public static final String | DIGEST_RIPEMD128 |
public static final String | DIGEST_RIPEMD160 |
public static final String | DIGEST_RIPEMD256 |
public static final String | ENCRYPTION_RSA |
public static final String | ENCRYPTION_DSA |
public static final String | ENCRYPTION_ECDSA |
public static final String | ENCRYPTION_RSA_PSS |
public static final String | ENCRYPTION_GOST3410 |
public static final String | ENCRYPTION_ECGOST3410 |
private static final String | CERTIFICATE_MANAGEMENT_CONTENT |
private static final String | DETACHED_SIGNATURE_TYPE |
private static final String | ENCAPSULATED_SIGNED_CONTENT_TYPE |
private final String | _defaultContentTransferEncoding |
private List | _certStores |
private List | _signers |
private List | _oldSigners |
private List | _attributeCerts |
private Map | _digests |
Methods Summary |
---|
public void | addAttributeCertificates(org.bouncycastle.x509.X509Store store)Add the attribute certificates contained in the passed in store to the
generator.
_attributeCerts.add(store);
|
public void | addCertificatesAndCRLs(java.security.cert.CertStore certStore)add the certificates and CRLs contained in the given CertStore
to the pool that will be included in the encoded signature block.
Note: this assumes the CertStore will support null in the get
methods.
_certStores.add(certStore);
|
private void | addHashHeader(java.lang.StringBuffer header, java.util.List signers)
int count = 0;
//
// build the hash header
//
Iterator it = signers.iterator();
Set micAlgs = new HashSet();
while (it.hasNext())
{
Signer signer = (Signer)it.next();
if (signer.getDigestOID().equals(DIGEST_SHA1))
{
micAlgs.add("sha1");
}
else if (signer.getDigestOID().equals(DIGEST_MD5))
{
micAlgs.add("md5");
}
else if (signer.getDigestOID().equals(DIGEST_SHA224))
{
micAlgs.add("sha224");
}
else if (signer.getDigestOID().equals(DIGEST_SHA256))
{
micAlgs.add("sha256");
}
else if (signer.getDigestOID().equals(DIGEST_SHA384))
{
micAlgs.add("sha384");
}
else if (signer.getDigestOID().equals(DIGEST_SHA512))
{
micAlgs.add("sha512");
}
else if (signer.getDigestOID().equals(DIGEST_GOST3411))
{
micAlgs.add("gostr3411-94");
}
else
{
micAlgs.add("unknown");
}
}
it = micAlgs.iterator();
while (it.hasNext())
{
String alg = (String)it.next();
if (count == 0)
{
if (micAlgs.size() != 1)
{
header.append("; micalg=\"");
}
else
{
header.append("; micalg=");
}
}
else
{
header.append(',");
}
header.append(alg);
count++;
}
if (count != 0)
{
if (micAlgs.size() != 1)
{
header.append('\"");
}
}
|
public void | addSigner(java.security.PrivateKey key, java.security.cert.X509Certificate cert, java.lang.String digestOID)add a signer - no attributes other than the default ones will be
provided here.
_signers.add(new Signer(key, cert, digestOID, null, null));
|
public void | addSigner(java.security.PrivateKey key, java.security.cert.X509Certificate cert, java.lang.String digestOID, org.bouncycastle.asn1.cms.AttributeTable signedAttr, org.bouncycastle.asn1.cms.AttributeTable unsignedAttr)Add a signer with extra signed/unsigned attributes or overrides
for the standard attributes. For example this method can be used to
explictly set default attributes such as the signing time.
_signers.add(new Signer(key, cert, digestOID, signedAttr, unsignedAttr));
|
public void | addSigners(org.bouncycastle.cms.SignerInformationStore signerStore)Add a store of precalculated signers to the generator.
Iterator it = signerStore.getSigners().iterator();
while (it.hasNext())
{
_oldSigners.add(it.next());
}
|
public javax.mail.internet.MimeMultipart | generate(javax.mail.internet.MimeBodyPart content, java.lang.String sigProvider)generate a signed object that contains an SMIME Signed Multipart
object using the given provider.
return make(makeContentBodyPart(content), SMIMEUtil.getProvider(sigProvider));
|
public javax.mail.internet.MimeMultipart | generate(javax.mail.internet.MimeBodyPart content, java.security.Provider sigProvider)generate a signed object that contains an SMIME Signed Multipart
object using the given provider.
return make(makeContentBodyPart(content), sigProvider);
|
public javax.mail.internet.MimeMultipart | generate(javax.mail.internet.MimeMessage message, java.lang.String sigProvider)generate a signed object that contains an SMIME Signed Multipart
object using the given provider from the given MimeMessage
return generate(message, SMIMEUtil.getProvider(sigProvider));
|
public javax.mail.internet.MimeMultipart | generate(javax.mail.internet.MimeMessage message, java.security.Provider sigProvider)generate a signed object that contains an SMIME Signed Multipart
object using the given provider from the given MimeMessage
try
{
message.saveChanges(); // make sure we're up to date.
}
catch (MessagingException e)
{
throw new SMIMEException("unable to save message", e);
}
return make(makeContentBodyPart(message), sigProvider);
|
public javax.mail.internet.MimeBodyPart | generateCertificateManagement(java.lang.String provider)Creates a certificate management message which is like a signed message with no content
or signers but that still carries certificates and CRLs.
return generateCertificateManagement(SMIMEUtil.getProvider(provider));
|
public javax.mail.internet.MimeBodyPart | generateCertificateManagement(java.security.Provider provider)Creates a certificate management message which is like a signed message with no content
or signers but that still carries certificates and CRLs.
try
{
MimeBodyPart sig = new MimeBodyPart();
sig.setContent(new ContentSigner(null, true, provider), CERTIFICATE_MANAGEMENT_CONTENT);
sig.addHeader("Content-Type", CERTIFICATE_MANAGEMENT_CONTENT);
sig.addHeader("Content-Disposition", "attachment; filename=\"smime.p7c\"");
sig.addHeader("Content-Description", "S/MIME Certificate Management Message");
sig.addHeader("Content-Transfer-Encoding", encoding);
return sig;
}
catch (MessagingException e)
{
throw new SMIMEException("exception putting body part together.", e);
}
|
public javax.mail.internet.MimeBodyPart | generateEncapsulated(javax.mail.internet.MimeBodyPart content, java.lang.String sigProvider)generate a signed message with encapsulated content
Note: doing this is strongly not recommended as it means a
recipient of the message will have to be able to read the signature to read the
message.
return makeEncapsulated(makeContentBodyPart(content), SMIMEUtil.getProvider(sigProvider));
|
public javax.mail.internet.MimeBodyPart | generateEncapsulated(javax.mail.internet.MimeBodyPart content, java.security.Provider sigProvider)generate a signed message with encapsulated content
Note: doing this is strongly not recommended as it means a
recipient of the message will have to be able to read the signature to read the
message.
return makeEncapsulated(makeContentBodyPart(content), sigProvider);
|
public javax.mail.internet.MimeBodyPart | generateEncapsulated(javax.mail.internet.MimeMessage message, java.lang.String sigProvider)generate a signed object that contains an SMIME Signed Multipart
object using the given provider from the given MimeMessage.
Note: doing this is strongly not recommended as it means a
recipient of the message will have to be able to read the signature to read the
message.
return generateEncapsulated(message, SMIMEUtil.getProvider(sigProvider));
|
public javax.mail.internet.MimeBodyPart | generateEncapsulated(javax.mail.internet.MimeMessage message, java.security.Provider sigProvider)generate a signed object that contains an SMIME Signed Multipart
object using the given provider from the given MimeMessage.
Note: doing this is strongly not recommended as it means a
recipient of the message will have to be able to read the signature to read the
message.
try
{
message.saveChanges(); // make sure we're up to date.
}
catch (MessagingException e)
{
throw new SMIMEException("unable to save message", e);
}
return makeEncapsulated(makeContentBodyPart(message), sigProvider);
|
public java.util.Map | getGeneratedDigests()Return a map of oids and byte arrays representing the digests calculated on the content during
the last generate.
return new HashMap(_digests);
|
private javax.mail.internet.MimeMultipart | make(javax.mail.internet.MimeBodyPart content, java.security.Provider sigProvider)
try
{
MimeBodyPart sig = new MimeBodyPart();
sig.setContent(new ContentSigner(content, false, sigProvider), DETACHED_SIGNATURE_TYPE);
sig.addHeader("Content-Type", DETACHED_SIGNATURE_TYPE);
sig.addHeader("Content-Disposition", "attachment; filename=\"smime.p7s\"");
sig.addHeader("Content-Description", "S/MIME Cryptographic Signature");
sig.addHeader("Content-Transfer-Encoding", encoding);
//
// build the multipart header
//
StringBuffer header = new StringBuffer(
"signed; protocol=\"application/pkcs7-signature\"");
addHashHeader(header, _signers);
MimeMultipart mm = new MimeMultipart(header.toString());
mm.addBodyPart(content);
mm.addBodyPart(sig);
return mm;
}
catch (MessagingException e)
{
throw new SMIMEException("exception putting multi-part together.", e);
}
|
private javax.mail.internet.MimeBodyPart | makeEncapsulated(javax.mail.internet.MimeBodyPart content, java.security.Provider sigProvider)
try
{
MimeBodyPart sig = new MimeBodyPart();
sig.setContent(new ContentSigner(content, true, sigProvider), ENCAPSULATED_SIGNED_CONTENT_TYPE);
sig.addHeader("Content-Type", ENCAPSULATED_SIGNED_CONTENT_TYPE);
sig.addHeader("Content-Disposition", "attachment; filename=\"smime.p7m\"");
sig.addHeader("Content-Description", "S/MIME Cryptographic Signed Data");
sig.addHeader("Content-Transfer-Encoding", encoding);
return sig;
}
catch (MessagingException e)
{
throw new SMIMEException("exception putting body part together.", e);
}
|