diff options
author | David Hook <dgh@cryptoworkshop.com> | 2013-11-13 02:56:17 +0400 |
---|---|---|
committer | David Hook <dgh@cryptoworkshop.com> | 2013-11-13 02:56:17 +0400 |
commit | 854c6c4445d43a87d3cd173dbf0f704e786a7a5c (patch) | |
tree | 6a0520af0370fd26ad5b632d13446d8d289e082f /pkix | |
parent | b9e310ed77eeedf6d08823581c14d38fd9a845a6 (diff) |
removed extra files
Diffstat (limited to 'pkix')
-rw-r--r-- | pkix/src/main/jdk1.1/org/bouncycastle/cms/CMSAuthenticatedDataGenerator.java | 266 | ||||
-rw-r--r-- | pkix/src/main/jdk1.1/org/bouncycastle/cms/CMSAuthenticatedDataStreamGenerator.java | 392 |
2 files changed, 0 insertions, 658 deletions
diff --git a/pkix/src/main/jdk1.1/org/bouncycastle/cms/CMSAuthenticatedDataGenerator.java b/pkix/src/main/jdk1.1/org/bouncycastle/cms/CMSAuthenticatedDataGenerator.java deleted file mode 100644 index 54d88b01..00000000 --- a/pkix/src/main/jdk1.1/org/bouncycastle/cms/CMSAuthenticatedDataGenerator.java +++ /dev/null @@ -1,266 +0,0 @@ -package org.bouncycastle.cms; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.security.Provider; -import java.security.SecureRandom; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import javax.crypto.KeyGenerator; - -import org.bouncycastle.asn1.ASN1EncodableVector; -import org.bouncycastle.asn1.ASN1Encoding; -import org.bouncycastle.asn1.ASN1ObjectIdentifier; -import org.bouncycastle.asn1.ASN1OctetString; -import org.bouncycastle.asn1.ASN1Set; -import org.bouncycastle.asn1.BEROctetString; -import org.bouncycastle.asn1.BERSet; -import org.bouncycastle.asn1.DEROctetString; -import org.bouncycastle.asn1.DERSet; -import org.bouncycastle.asn1.cms.AuthenticatedData; -import org.bouncycastle.asn1.cms.CMSObjectIdentifiers; -import org.bouncycastle.asn1.cms.ContentInfo; -import org.bouncycastle.asn1.x509.AlgorithmIdentifier; -import org.bouncycastle.cms.jcajce.JceCMSMacCalculatorBuilder; -import org.bouncycastle.operator.DigestCalculator; -import org.bouncycastle.operator.DigestCalculatorProvider; -import org.bouncycastle.operator.MacCalculator; -import org.bouncycastle.operator.OperatorCreationException; -import org.bouncycastle.util.io.TeeOutputStream; - -/** - * General class for generating a CMS authenticated-data message. - * - * A simple example of usage. - * - * <pre> - * CMSAuthenticatedDataGenerator fact = new CMSAuthenticatedDataGenerator(); - * - * adGen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(recipientCert).setProvider("BC")); - * - * CMSAuthenticatedData data = fact.generate(new CMSProcessableByteArray(data), - * new JceCMSMacCalculatorBuilder(CMSAlgorithm.DES_EDE3_CBC).setProvider(BC).build())); - * </pre> - */ -public class CMSAuthenticatedDataGenerator - extends CMSAuthenticatedGenerator -{ - /** - * base constructor - */ - public CMSAuthenticatedDataGenerator() - { - } - - /** - * Generate an authenticated data object from the passed in typedData and MacCalculator. - * - * @param typedData the data to have a MAC attached. - * @param macCalculator the calculator of the MAC to be attached. - * @return the resulting CMSAuthenticatedData object. - * @throws CMSException on failure in encoding data or processing recipients. - */ - public CMSAuthenticatedData generate(CMSTypedData typedData, MacCalculator macCalculator) - throws CMSException - { - return generate(typedData, macCalculator, null); - } - - /** - * Generate an authenticated data object from the passed in typedData and MacCalculator. - * - * @param typedData the data to have a MAC attached. - * @param macCalculator the calculator of the MAC to be attached. - * @param digestCalculator calculator for computing digest of the encapsulated data. - * @return the resulting CMSAuthenticatedData object. - * @throws CMSException on failure in encoding data or processing recipients. - */ - public CMSAuthenticatedData generate(CMSTypedData typedData, MacCalculator macCalculator, final DigestCalculator digestCalculator) - throws CMSException - { - ASN1EncodableVector recipientInfos = new ASN1EncodableVector(); - ASN1OctetString encContent; - ASN1OctetString macResult; - - for (Iterator it = recipientInfoGenerators.iterator(); it.hasNext();) - { - RecipientInfoGenerator recipient = (RecipientInfoGenerator)it.next(); - - recipientInfos.add(recipient.generate(macCalculator.getKey())); - } - - AuthenticatedData authData; - - if (digestCalculator != null) - { - try - { - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - OutputStream out = new TeeOutputStream(digestCalculator.getOutputStream(), bOut); - - typedData.write(out); - - out.close(); - - encContent = new BEROctetString(bOut.toByteArray()); - } - catch (IOException e) - { - throw new CMSException("unable to perform digest calculation: " + e.getMessage(), e); - } - - Map parameters = getBaseParameters(typedData.getContentType(), digestCalculator.getAlgorithmIdentifier(), digestCalculator.getDigest()); - - if (authGen == null) - { - authGen = new DefaultAuthenticatedAttributeTableGenerator(); - } - ASN1Set authed = new DERSet(authGen.getAttributes(parameters).toASN1EncodableVector()); - - try - { - OutputStream mOut = macCalculator.getOutputStream(); - - mOut.write(authed.getEncoded(ASN1Encoding.DER)); - - mOut.close(); - - macResult = new DEROctetString(macCalculator.getMac()); - } - catch (IOException e) - { - throw new CMSException("exception decoding algorithm parameters.", e); - } - ASN1Set unauthed = (unauthGen != null) ? new BERSet(unauthGen.getAttributes(parameters).toASN1EncodableVector()) : null; - - ContentInfo eci = new ContentInfo( - CMSObjectIdentifiers.data, - encContent); - - authData = new AuthenticatedData(originatorInfo, new DERSet(recipientInfos), macCalculator.getAlgorithmIdentifier(), digestCalculator.getAlgorithmIdentifier(), eci, authed, macResult, unauthed); - } - else - { - try - { - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - OutputStream mOut = new TeeOutputStream(bOut, macCalculator.getOutputStream()); - - typedData.write(mOut); - - mOut.close(); - - encContent = new BEROctetString(bOut.toByteArray()); - - macResult = new DEROctetString(macCalculator.getMac()); - } - catch (IOException e) - { - throw new CMSException("exception decoding algorithm parameters.", e); - } - - ASN1Set unauthed = (unauthGen != null) ? new BERSet(unauthGen.getAttributes(new HashMap()).toASN1EncodableVector()) : null; - - ContentInfo eci = new ContentInfo( - CMSObjectIdentifiers.data, - encContent); - - authData = new AuthenticatedData(originatorInfo, new DERSet(recipientInfos), macCalculator.getAlgorithmIdentifier(), null, eci, null, macResult, unauthed); - } - - ContentInfo contentInfo = new ContentInfo( - CMSObjectIdentifiers.authenticatedData, authData); - - return new CMSAuthenticatedData(contentInfo, new DigestCalculatorProvider() - { - public DigestCalculator get(AlgorithmIdentifier digestAlgorithmIdentifier) - throws OperatorCreationException - { - return digestCalculator; - } - }); - } - - /** - * constructor allowing specific source of randomness - * @param rand instance of SecureRandom to use - * @deprecated no longer required, use simple constructor. - */ - public CMSAuthenticatedDataGenerator( - SecureRandom rand) - { - super(rand); - } - - /** - * generate an authenticated object that contains an CMS Authenticated Data - * object using the given provider and the passed in key generator. - * @deprecated - */ - private CMSAuthenticatedData generate( - final CMSProcessable content, - String macOID, - KeyGenerator keyGen, - Provider provider) - throws NoSuchAlgorithmException, CMSException - { - Provider encProvider = keyGen.getProvider(); - - convertOldRecipients(rand, provider); - - return generate(new CMSTypedData() - { - public ASN1ObjectIdentifier getContentType() - { - return CMSObjectIdentifiers.data; - } - - public void write(OutputStream out) - throws IOException, CMSException - { - content.write(out); - } - - public Object getContent() - { - return content; - } - }, new JceCMSMacCalculatorBuilder(new ASN1ObjectIdentifier(macOID)).setProvider(encProvider).setSecureRandom(rand).build()); - } - - /** - * generate an authenticated object that contains an CMS Authenticated Data - * object using the given provider. - * @deprecated use addRecipientInfoGenerator method. - */ - public CMSAuthenticatedData generate( - CMSProcessable content, - String macOID, - String provider) - throws NoSuchAlgorithmException, NoSuchProviderException, CMSException - { - return generate(content, macOID, CMSUtils.getProvider(provider)); - } - - /** - * generate an authenticated object that contains an CMS Authenticated Data - * object using the given provider - * @deprecated use addRecipientInfoGenerator method.. - */ - public CMSAuthenticatedData generate( - CMSProcessable content, - String encryptionOID, - Provider provider) - throws NoSuchAlgorithmException, CMSException - { - KeyGenerator keyGen = CMSEnvelopedHelper.INSTANCE.createSymmetricKeyGenerator(encryptionOID, provider); - - return generate(content, encryptionOID, keyGen, provider); - } -} diff --git a/pkix/src/main/jdk1.1/org/bouncycastle/cms/CMSAuthenticatedDataStreamGenerator.java b/pkix/src/main/jdk1.1/org/bouncycastle/cms/CMSAuthenticatedDataStreamGenerator.java deleted file mode 100644 index 31343382..00000000 --- a/pkix/src/main/jdk1.1/org/bouncycastle/cms/CMSAuthenticatedDataStreamGenerator.java +++ /dev/null @@ -1,392 +0,0 @@ -package org.bouncycastle.cms; - -import java.io.IOException; -import java.io.OutputStream; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.security.Provider; -import java.security.SecureRandom; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.bouncycastle.asn1.ASN1EncodableVector; -import org.bouncycastle.asn1.ASN1Encoding; -import org.bouncycastle.asn1.ASN1ObjectIdentifier; -import org.bouncycastle.asn1.ASN1Set; -import org.bouncycastle.asn1.BERSequenceGenerator; -import org.bouncycastle.asn1.BERSet; -import org.bouncycastle.asn1.DERInteger; -import org.bouncycastle.asn1.DEROctetString; -import org.bouncycastle.asn1.DERSet; -import org.bouncycastle.asn1.DERTaggedObject; -import org.bouncycastle.asn1.cms.AuthenticatedData; -import org.bouncycastle.asn1.cms.CMSObjectIdentifiers; -import org.bouncycastle.asn1.x509.AlgorithmIdentifier; -import org.bouncycastle.cms.jcajce.JceCMSMacCalculatorBuilder; -import org.bouncycastle.operator.DigestCalculator; -import org.bouncycastle.operator.MacCalculator; -import org.bouncycastle.util.io.TeeOutputStream; - -/** - * General class for generating a CMS authenticated-data message stream. - * <p> - * A simple example of usage. - * <pre> - * CMSAuthenticatedDataStreamGenerator edGen = new CMSAuthenticatedDataStreamGenerator(); - * - * edGen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(cert).setProvider("BC")); - * - * ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - * - * OutputStream out = edGen.open( - * bOut, new JceCMSMacCalculatorBuilder(CMSAlgorithm.DES_EDE3_CBC).setProvider("BC").build());* - * out.write(data); - * - * out.close(); - * </pre> - */ -public class CMSAuthenticatedDataStreamGenerator - extends CMSAuthenticatedGenerator -{ - // Currently not handled -// private Object _originatorInfo = null; -// private Object _unprotectedAttributes = null; - private int bufferSize; - private boolean berEncodeRecipientSet; - private MacCalculator macCalculator; - - /** - * base constructor - */ - public CMSAuthenticatedDataStreamGenerator() - { - } - - /** - * Set the underlying string size for encapsulated data - * - * @param bufferSize length of octet strings to buffer the data. - */ - public void setBufferSize( - int bufferSize) - { - this.bufferSize = bufferSize; - } - - /** - * Use a BER Set to store the recipient information. By default recipients are - * stored in a DER encoding. - * - * @param useBerEncodingForRecipients true if a BER set should be used, false if DER. - */ - public void setBEREncodeRecipients( - boolean useBerEncodingForRecipients) - { - berEncodeRecipientSet = useBerEncodingForRecipients; - } - - /** - * generate an authenticated data structure with the encapsulated bytes marked as DATA. - * - * @param out the stream to store the authenticated structure in. - * @param macCalculator calculator for the MAC to be attached to the data. - */ - public OutputStream open( - OutputStream out, - MacCalculator macCalculator) - throws CMSException - { - return open(CMSObjectIdentifiers.data, out, macCalculator); - } - - public OutputStream open( - OutputStream out, - MacCalculator macCalculator, - DigestCalculator digestCalculator) - throws CMSException - { - return open(CMSObjectIdentifiers.data, out, macCalculator, digestCalculator); - } - - /** - * generate an authenticated data structure with the encapsulated bytes marked as type dataType. - * - * @param dataType the type of the data been written to the object. - * @param out the stream to store the authenticated structure in. - * @param macCalculator calculator for the MAC to be attached to the data. - */ - public OutputStream open( - ASN1ObjectIdentifier dataType, - OutputStream out, - MacCalculator macCalculator) - throws CMSException - { - return open(dataType, out, macCalculator, null); - } - - /** - * generate an authenticated data structure with the encapsulated bytes marked as type dataType. - * - * @param dataType the type of the data been written to the object. - * @param out the stream to store the authenticated structure in. - * @param macCalculator calculator for the MAC to be attached to the data. - * @param digestCalculator calculator for computing digest of the encapsulated data. - */ - public OutputStream open( - ASN1ObjectIdentifier dataType, - OutputStream out, - MacCalculator macCalculator, - DigestCalculator digestCalculator) - throws CMSException - { - this.macCalculator = macCalculator; - - try - { - ASN1EncodableVector recipientInfos = new ASN1EncodableVector(); - - for (Iterator it = recipientInfoGenerators.iterator(); it.hasNext();) - { - RecipientInfoGenerator recipient = (RecipientInfoGenerator)it.next(); - - recipientInfos.add(recipient.generate(macCalculator.getKey())); - } - - // - // ContentInfo - // - BERSequenceGenerator cGen = new BERSequenceGenerator(out); - - cGen.addObject(CMSObjectIdentifiers.authenticatedData); - - // - // Authenticated Data - // - BERSequenceGenerator authGen = new BERSequenceGenerator(cGen.getRawOutputStream(), 0, true); - - authGen.addObject(new DERInteger(AuthenticatedData.calculateVersion(originatorInfo))); - - if (originatorInfo != null) - { - authGen.addObject(new DERTaggedObject(false, 0, originatorInfo)); - } - - if (berEncodeRecipientSet) - { - authGen.getRawOutputStream().write(new BERSet(recipientInfos).getEncoded()); - } - else - { - authGen.getRawOutputStream().write(new DERSet(recipientInfos).getEncoded()); - } - - AlgorithmIdentifier macAlgId = macCalculator.getAlgorithmIdentifier(); - - authGen.getRawOutputStream().write(macAlgId.getEncoded()); - - if (digestCalculator != null) - { - authGen.addObject(new DERTaggedObject(false, 1, digestCalculator.getAlgorithmIdentifier())); - } - - BERSequenceGenerator eiGen = new BERSequenceGenerator(authGen.getRawOutputStream()); - - eiGen.addObject(dataType); - - OutputStream octetStream = CMSUtils.createBEROctetOutputStream( - eiGen.getRawOutputStream(), 0, false, bufferSize); - - OutputStream mOut; - - if (digestCalculator != null) - { - mOut = new TeeOutputStream(octetStream, digestCalculator.getOutputStream()); - } - else - { - mOut = new TeeOutputStream(octetStream, macCalculator.getOutputStream()); - } - - return new CmsAuthenticatedDataOutputStream(macCalculator, digestCalculator, dataType, mOut, cGen, authGen, eiGen); - } - catch (IOException e) - { - throw new CMSException("exception decoding algorithm parameters.", e); - } - } - - private class CmsAuthenticatedDataOutputStream - extends OutputStream - { - private OutputStream dataStream; - private BERSequenceGenerator cGen; - private BERSequenceGenerator envGen; - private BERSequenceGenerator eiGen; - private MacCalculator macCalculator; - private DigestCalculator digestCalculator; - private ASN1ObjectIdentifier contentType; - - public CmsAuthenticatedDataOutputStream( - MacCalculator macCalculator, - DigestCalculator digestCalculator, - ASN1ObjectIdentifier contentType, - OutputStream dataStream, - BERSequenceGenerator cGen, - BERSequenceGenerator envGen, - BERSequenceGenerator eiGen) - { - this.macCalculator = macCalculator; - this.digestCalculator = digestCalculator; - this.contentType = contentType; - this.dataStream = dataStream; - this.cGen = cGen; - this.envGen = envGen; - this.eiGen = eiGen; - } - - public void write( - int b) - throws IOException - { - dataStream.write(b); - } - - public void write( - byte[] bytes, - int off, - int len) - throws IOException - { - dataStream.write(bytes, off, len); - } - - public void write( - byte[] bytes) - throws IOException - { - dataStream.write(bytes); - } - - public void close() - throws IOException - { - dataStream.close(); - eiGen.close(); - - Map parameters; - - if (digestCalculator != null) - { - parameters = getBaseParameters(contentType, digestCalculator.getAlgorithmIdentifier(), digestCalculator.getDigest()); - - if (authGen == null) - { - authGen = new DefaultAuthenticatedAttributeTableGenerator(); - } - - ASN1Set authed = new DERSet(authGen.getAttributes(parameters).toASN1EncodableVector()); - - OutputStream mOut = macCalculator.getOutputStream(); - - mOut.write(authed.getEncoded(ASN1Encoding.DER)); - - mOut.close(); - - envGen.addObject(new DERTaggedObject(false, 2, authed)); - } - else - { - parameters = new HashMap(); - } - - envGen.addObject(new DEROctetString(macCalculator.getMac())); - - if (unauthGen != null) - { - envGen.addObject(new DERTaggedObject(false, 3, new BERSet(unauthGen.getAttributes(parameters).toASN1EncodableVector()))); - } - - envGen.close(); - cGen.close(); - } - } - - - /** - * constructor allowing specific source of randomness - * @param rand instance of SecureRandom to use - * @deprecated no longer of any use, use basic constructor. - */ - public CMSAuthenticatedDataStreamGenerator( - SecureRandom rand) - { - super(rand); - } - - /** - * generate an authenticated object that contains an CMS Authenticated Data - * object using the given provider. - * @throws java.io.IOException - * @deprecated use open(out, MacCalculator) - */ - public OutputStream open( - OutputStream out, - String encryptionOID, - String provider) - throws NoSuchAlgorithmException, NoSuchProviderException, CMSException, IOException - { - convertOldRecipients(rand, CMSUtils.getProvider(provider)); - - return open(out, new JceCMSMacCalculatorBuilder(new ASN1ObjectIdentifier(encryptionOID)).setSecureRandom(rand).setProvider(provider).build()); - } - - /** - * @deprecated use open(out, MacCalculator) - */ - public OutputStream open( - OutputStream out, - String encryptionOID, - Provider provider) - throws NoSuchAlgorithmException, CMSException, IOException - { - convertOldRecipients(rand, provider); - - return open(out, new JceCMSMacCalculatorBuilder(new ASN1ObjectIdentifier(encryptionOID)).setSecureRandom(rand).setProvider(provider).build()); - } - - /** - * generate an enveloped object that contains an CMS Enveloped Data - * object using the given provider. - * @deprecated use open(out, MacCalculator) - */ - public OutputStream open( - OutputStream out, - String encryptionOID, - int keySize, - String provider) - throws NoSuchAlgorithmException, NoSuchProviderException, CMSException, IOException - { - convertOldRecipients(rand, CMSUtils.getProvider(provider)); - - return open(out, new JceCMSMacCalculatorBuilder(new ASN1ObjectIdentifier(encryptionOID), keySize).setSecureRandom(rand).setProvider(provider).build()); - } - - /** - * generate an enveloped object that contains an CMS Enveloped Data - * object using the given provider. - * @deprecated use open(out, MacCalculator) - */ - public OutputStream open( - OutputStream out, - String encryptionOID, - int keySize, - Provider provider) - throws NoSuchAlgorithmException, CMSException, IOException - { - convertOldRecipients(rand, provider); - - return open(out, new JceCMSMacCalculatorBuilder(new ASN1ObjectIdentifier(encryptionOID), keySize).setSecureRandom(rand).setProvider(provider).build()); - } -} |