Package org.openas2.lib.helper
Class BCCryptoHelper
- java.lang.Object
-
- org.openas2.lib.helper.BCCryptoHelper
-
- All Implemented Interfaces:
ICryptoHelper
public class BCCryptoHelper extends java.lang.Object implements ICryptoHelper
-
-
Field Summary
Fields Modifier and Type Field Description private org.apache.commons.logging.Log
logger
-
Fields inherited from interface org.openas2.lib.helper.ICryptoHelper
AES128_CBC, AES192_CBC, AES256_CBC, AES256_WRAP, COMPRESSION_NONE, COMPRESSION_UNKNOWN, COMPRESSION_ZLIB, CRYPT_3DES, CRYPT_CAST5, CRYPT_IDEA, CRYPT_RC2, CRYPT_RC2_CBC, DIGEST_MD2, DIGEST_MD5, DIGEST_SHA1, DIGEST_SHA224, DIGEST_SHA256, DIGEST_SHA384, DIGEST_SHA512, JCE_LIMITATION_ERROR, JCE_LIMITED_MAX_LENGTH
-
-
Constructor Summary
Constructors Constructor Description BCCryptoHelper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
calculateMIC(javax.mail.internet.MimeBodyPart part, java.lang.String digest, boolean includeHeaders)
java.lang.String
calculateMIC(javax.mail.internet.MimeBodyPart part, java.lang.String digest, boolean includeHeaders, boolean noCanonicalize)
protected java.security.cert.X509Certificate
castCertificate(java.security.cert.Certificate cert)
protected java.security.PrivateKey
castKey(java.security.Key key)
javax.mail.internet.MimeBodyPart
compress(Message msg, javax.mail.internet.MimeBodyPart mbp, java.lang.String compressionType, java.lang.String contentTxfrEncoding)
protected java.lang.String
convertAlgorithm(java.lang.String algorithm, boolean toBC)
void
decompress(AS2Message msg)
javax.mail.internet.MimeBodyPart
decrypt(javax.mail.internet.MimeBodyPart part, java.security.cert.Certificate cert, java.security.Key key)
void
deinitialize()
javax.mail.internet.MimeBodyPart
encrypt(javax.mail.internet.MimeBodyPart part, java.security.cert.Certificate cert, java.lang.String algorithm, java.lang.String contentTxfrEncoding)
protected java.lang.String
getEncoding(java.lang.String contentTxfrEncoding)
java.lang.String
getHeaderValue(javax.mail.internet.MimeBodyPart part, java.lang.String headerName)
java.security.KeyStore
getKeyStore()
protected org.bouncycastle.operator.OutputEncryptor
getOutputEncryptor(java.lang.String algorithm)
Looks up the correct ASN1 OID of the passed in algorithm string and returns the encryptor.void
initialize()
boolean
isCompressed(javax.mail.internet.MimeBodyPart part)
boolean
isEncrypted(javax.mail.internet.MimeBodyPart part)
boolean
isSigned(javax.mail.internet.MimeBodyPart part)
java.security.KeyStore
loadKeyStore(java.io.InputStream in, char[] password)
java.security.KeyStore
loadKeyStore(java.lang.String filename, char[] password)
void
logSignerInfo(java.lang.String msgPrefix, org.bouncycastle.cms.SignerInformation signer, javax.mail.internet.MimeBodyPart part, java.security.cert.X509Certificate cert)
javax.mail.internet.MimeBodyPart
sign(javax.mail.internet.MimeBodyPart part, java.security.cert.Certificate cert, java.security.Key key, java.lang.String digest, java.lang.String contentTxfrEncoding, boolean adjustDigestToOldName, boolean isRemoveCmsAlgorithmProtectionAttr)
protected java.io.InputStream
trimCRLFPrefix(byte[] data)
javax.mail.internet.MimeBodyPart
verifySignature(javax.mail.internet.MimeBodyPart part, java.security.cert.Certificate cert)
-
-
-
Method Detail
-
isEncrypted
public boolean isEncrypted(javax.mail.internet.MimeBodyPart part) throws javax.mail.MessagingException
- Specified by:
isEncrypted
in interfaceICryptoHelper
- Throws:
javax.mail.MessagingException
-
isSigned
public boolean isSigned(javax.mail.internet.MimeBodyPart part) throws javax.mail.MessagingException
- Specified by:
isSigned
in interfaceICryptoHelper
- Throws:
javax.mail.MessagingException
-
isCompressed
public boolean isCompressed(javax.mail.internet.MimeBodyPart part) throws javax.mail.MessagingException
- Specified by:
isCompressed
in interfaceICryptoHelper
- Throws:
javax.mail.MessagingException
-
calculateMIC
public java.lang.String calculateMIC(javax.mail.internet.MimeBodyPart part, java.lang.String digest, boolean includeHeaders) throws java.security.GeneralSecurityException, javax.mail.MessagingException, java.io.IOException
- Specified by:
calculateMIC
in interfaceICryptoHelper
- Throws:
java.security.GeneralSecurityException
javax.mail.MessagingException
java.io.IOException
-
calculateMIC
public java.lang.String calculateMIC(javax.mail.internet.MimeBodyPart part, java.lang.String digest, boolean includeHeaders, boolean noCanonicalize) throws java.security.GeneralSecurityException, javax.mail.MessagingException, java.io.IOException
- Specified by:
calculateMIC
in interfaceICryptoHelper
- Throws:
java.security.GeneralSecurityException
javax.mail.MessagingException
java.io.IOException
-
decrypt
public javax.mail.internet.MimeBodyPart decrypt(javax.mail.internet.MimeBodyPart part, java.security.cert.Certificate cert, java.security.Key key) throws java.security.GeneralSecurityException, javax.mail.MessagingException, org.bouncycastle.cms.CMSException, java.io.IOException, org.bouncycastle.mail.smime.SMIMEException
- Specified by:
decrypt
in interfaceICryptoHelper
- Throws:
java.security.GeneralSecurityException
javax.mail.MessagingException
org.bouncycastle.cms.CMSException
java.io.IOException
org.bouncycastle.mail.smime.SMIMEException
-
deinitialize
public void deinitialize()
-
encrypt
public javax.mail.internet.MimeBodyPart encrypt(javax.mail.internet.MimeBodyPart part, java.security.cert.Certificate cert, java.lang.String algorithm, java.lang.String contentTxfrEncoding) throws java.security.GeneralSecurityException, org.bouncycastle.mail.smime.SMIMEException, javax.mail.MessagingException
- Specified by:
encrypt
in interfaceICryptoHelper
- Throws:
java.security.GeneralSecurityException
org.bouncycastle.mail.smime.SMIMEException
javax.mail.MessagingException
-
initialize
public void initialize()
- Specified by:
initialize
in interfaceICryptoHelper
-
sign
public javax.mail.internet.MimeBodyPart sign(javax.mail.internet.MimeBodyPart part, java.security.cert.Certificate cert, java.security.Key key, java.lang.String digest, java.lang.String contentTxfrEncoding, boolean adjustDigestToOldName, boolean isRemoveCmsAlgorithmProtectionAttr) throws java.security.GeneralSecurityException, org.bouncycastle.mail.smime.SMIMEException, javax.mail.MessagingException
- Specified by:
sign
in interfaceICryptoHelper
- Throws:
java.security.GeneralSecurityException
org.bouncycastle.mail.smime.SMIMEException
javax.mail.MessagingException
-
verifySignature
public javax.mail.internet.MimeBodyPart verifySignature(javax.mail.internet.MimeBodyPart part, java.security.cert.Certificate cert) throws java.security.GeneralSecurityException, java.io.IOException, javax.mail.MessagingException, org.bouncycastle.cms.CMSException, org.bouncycastle.operator.OperatorCreationException
- Specified by:
verifySignature
in interfaceICryptoHelper
- Throws:
java.security.GeneralSecurityException
java.io.IOException
javax.mail.MessagingException
org.bouncycastle.cms.CMSException
org.bouncycastle.operator.OperatorCreationException
-
compress
public javax.mail.internet.MimeBodyPart compress(Message msg, javax.mail.internet.MimeBodyPart mbp, java.lang.String compressionType, java.lang.String contentTxfrEncoding) throws org.bouncycastle.mail.smime.SMIMEException, OpenAS2Exception
- Specified by:
compress
in interfaceICryptoHelper
- Throws:
org.bouncycastle.mail.smime.SMIMEException
OpenAS2Exception
-
decompress
public void decompress(AS2Message msg) throws DispositionException
- Specified by:
decompress
in interfaceICryptoHelper
- Throws:
DispositionException
-
getEncoding
protected java.lang.String getEncoding(java.lang.String contentTxfrEncoding)
-
castCertificate
protected java.security.cert.X509Certificate castCertificate(java.security.cert.Certificate cert) throws java.security.GeneralSecurityException
- Throws:
java.security.GeneralSecurityException
-
castKey
protected java.security.PrivateKey castKey(java.security.Key key) throws java.security.GeneralSecurityException
- Throws:
java.security.GeneralSecurityException
-
convertAlgorithm
protected java.lang.String convertAlgorithm(java.lang.String algorithm, boolean toBC) throws java.security.NoSuchAlgorithmException
- Throws:
java.security.NoSuchAlgorithmException
-
getOutputEncryptor
protected org.bouncycastle.operator.OutputEncryptor getOutputEncryptor(java.lang.String algorithm) throws java.security.NoSuchAlgorithmException
Looks up the correct ASN1 OID of the passed in algorithm string and returns the encryptor. The encryption key length is set where necessary- Parameters:
algorithm
- The name of the algorithm to use for encryption- Returns:
- the OutputEncryptor of the given hash algorithm
- Throws:
java.security.NoSuchAlgorithmException
- - Houston we have a problem TODO: Possibly just use new ASN1ObjectIdentifier(algorithm) instead of explicit lookup to support random configured algorithms but will require determining if this has any side effects from a security point of view.
-
trimCRLFPrefix
protected java.io.InputStream trimCRLFPrefix(byte[] data)
-
getKeyStore
public java.security.KeyStore getKeyStore() throws java.security.KeyStoreException, java.security.NoSuchProviderException
- Specified by:
getKeyStore
in interfaceICryptoHelper
- Throws:
java.security.KeyStoreException
java.security.NoSuchProviderException
-
loadKeyStore
public java.security.KeyStore loadKeyStore(java.io.InputStream in, char[] password) throws java.lang.Exception
- Specified by:
loadKeyStore
in interfaceICryptoHelper
- Throws:
java.lang.Exception
-
loadKeyStore
public java.security.KeyStore loadKeyStore(java.lang.String filename, char[] password) throws java.lang.Exception
- Specified by:
loadKeyStore
in interfaceICryptoHelper
- Throws:
java.lang.Exception
-
getHeaderValue
public java.lang.String getHeaderValue(javax.mail.internet.MimeBodyPart part, java.lang.String headerName)
-
logSignerInfo
public void logSignerInfo(java.lang.String msgPrefix, org.bouncycastle.cms.SignerInformation signer, javax.mail.internet.MimeBodyPart part, java.security.cert.X509Certificate cert)
-
-