Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/java/org/spongycastle/asn1/smime')
-rw-r--r--core/src/main/java/org/spongycastle/asn1/smime/SMIMEAttributes.java10
-rw-r--r--core/src/main/java/org/spongycastle/asn1/smime/SMIMECapabilities.java115
-rw-r--r--core/src/main/java/org/spongycastle/asn1/smime/SMIMECapabilitiesAttribute.java16
-rw-r--r--core/src/main/java/org/spongycastle/asn1/smime/SMIMECapability.java103
-rw-r--r--core/src/main/java/org/spongycastle/asn1/smime/SMIMECapabilityVector.java50
-rw-r--r--core/src/main/java/org/spongycastle/asn1/smime/SMIMEEncryptionKeyPreferenceAttribute.java48
6 files changed, 342 insertions, 0 deletions
diff --git a/core/src/main/java/org/spongycastle/asn1/smime/SMIMEAttributes.java b/core/src/main/java/org/spongycastle/asn1/smime/SMIMEAttributes.java
new file mode 100644
index 00000000..cf3f57e3
--- /dev/null
+++ b/core/src/main/java/org/spongycastle/asn1/smime/SMIMEAttributes.java
@@ -0,0 +1,10 @@
+package org.spongycastle.asn1.smime;
+
+import org.spongycastle.asn1.ASN1ObjectIdentifier;
+import org.spongycastle.asn1.pkcs.PKCSObjectIdentifiers;
+
+public interface SMIMEAttributes
+{
+ public static final ASN1ObjectIdentifier smimeCapabilities = PKCSObjectIdentifiers.pkcs_9_at_smimeCapabilities;
+ public static final ASN1ObjectIdentifier encrypKeyPref = PKCSObjectIdentifiers.id_aa_encrypKeyPref;
+}
diff --git a/core/src/main/java/org/spongycastle/asn1/smime/SMIMECapabilities.java b/core/src/main/java/org/spongycastle/asn1/smime/SMIMECapabilities.java
new file mode 100644
index 00000000..e25f5eb3
--- /dev/null
+++ b/core/src/main/java/org/spongycastle/asn1/smime/SMIMECapabilities.java
@@ -0,0 +1,115 @@
+package org.spongycastle.asn1.smime;
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+import org.spongycastle.asn1.ASN1Object;
+import org.spongycastle.asn1.ASN1ObjectIdentifier;
+import org.spongycastle.asn1.ASN1Primitive;
+import org.spongycastle.asn1.ASN1Sequence;
+import org.spongycastle.asn1.cms.Attribute;
+import org.spongycastle.asn1.pkcs.PKCSObjectIdentifiers;
+
+/**
+ * Handler class for dealing with S/MIME Capabilities
+ */
+public class SMIMECapabilities
+ extends ASN1Object
+{
+ /**
+ * general preferences
+ */
+ public static final ASN1ObjectIdentifier preferSignedData = PKCSObjectIdentifiers.preferSignedData;
+ public static final ASN1ObjectIdentifier canNotDecryptAny = PKCSObjectIdentifiers.canNotDecryptAny;
+ public static final ASN1ObjectIdentifier sMIMECapabilitesVersions = PKCSObjectIdentifiers.sMIMECapabilitiesVersions;
+
+ /**
+ * encryption algorithms preferences
+ */
+ public static final ASN1ObjectIdentifier dES_CBC = new ASN1ObjectIdentifier("1.3.14.3.2.7");
+ public static final ASN1ObjectIdentifier dES_EDE3_CBC = PKCSObjectIdentifiers.des_EDE3_CBC;
+ public static final ASN1ObjectIdentifier rC2_CBC = PKCSObjectIdentifiers.RC2_CBC;
+
+ private ASN1Sequence capabilities;
+
+ /**
+ * return an Attribute object from the given object.
+ *
+ * @param o the object we want converted.
+ * @exception IllegalArgumentException if the object cannot be converted.
+ */
+ public static SMIMECapabilities getInstance(
+ Object o)
+ {
+ if (o == null || o instanceof SMIMECapabilities)
+ {
+ return (SMIMECapabilities)o;
+ }
+
+ if (o instanceof ASN1Sequence)
+ {
+ return new SMIMECapabilities((ASN1Sequence)o);
+ }
+
+ if (o instanceof Attribute)
+ {
+ return new SMIMECapabilities(
+ (ASN1Sequence)(((Attribute)o).getAttrValues().getObjectAt(0)));
+ }
+
+ throw new IllegalArgumentException("unknown object in factory: " + o.getClass().getName());
+ }
+
+ public SMIMECapabilities(
+ ASN1Sequence seq)
+ {
+ capabilities = seq;
+ }
+
+ /**
+ * returns a vector with 0 or more objects of all the capabilities
+ * matching the passed in capability OID. If the OID passed is null the
+ * entire set is returned.
+ */
+ public Vector getCapabilities(
+ ASN1ObjectIdentifier capability)
+ {
+ Enumeration e = capabilities.getObjects();
+ Vector list = new Vector();
+
+ if (capability == null)
+ {
+ while (e.hasMoreElements())
+ {
+ SMIMECapability cap = SMIMECapability.getInstance(e.nextElement());
+
+ list.addElement(cap);
+ }
+ }
+ else
+ {
+ while (e.hasMoreElements())
+ {
+ SMIMECapability cap = SMIMECapability.getInstance(e.nextElement());
+
+ if (capability.equals(cap.getCapabilityID()))
+ {
+ list.addElement(cap);
+ }
+ }
+ }
+
+ return list;
+ }
+
+ /**
+ * Produce an object suitable for an ASN1OutputStream.
+ * <pre>
+ * SMIMECapabilities ::= SEQUENCE OF SMIMECapability
+ * </pre>
+ */
+ public ASN1Primitive toASN1Primitive()
+ {
+ return capabilities;
+ }
+}
diff --git a/core/src/main/java/org/spongycastle/asn1/smime/SMIMECapabilitiesAttribute.java b/core/src/main/java/org/spongycastle/asn1/smime/SMIMECapabilitiesAttribute.java
new file mode 100644
index 00000000..53e749aa
--- /dev/null
+++ b/core/src/main/java/org/spongycastle/asn1/smime/SMIMECapabilitiesAttribute.java
@@ -0,0 +1,16 @@
+package org.spongycastle.asn1.smime;
+
+import org.spongycastle.asn1.DERSequence;
+import org.spongycastle.asn1.DERSet;
+import org.spongycastle.asn1.cms.Attribute;
+
+public class SMIMECapabilitiesAttribute
+ extends Attribute
+{
+ public SMIMECapabilitiesAttribute(
+ SMIMECapabilityVector capabilities)
+ {
+ super(SMIMEAttributes.smimeCapabilities,
+ new DERSet(new DERSequence(capabilities.toASN1EncodableVector())));
+ }
+}
diff --git a/core/src/main/java/org/spongycastle/asn1/smime/SMIMECapability.java b/core/src/main/java/org/spongycastle/asn1/smime/SMIMECapability.java
new file mode 100644
index 00000000..c3c4a999
--- /dev/null
+++ b/core/src/main/java/org/spongycastle/asn1/smime/SMIMECapability.java
@@ -0,0 +1,103 @@
+package org.spongycastle.asn1.smime;
+
+import org.spongycastle.asn1.ASN1Encodable;
+import org.spongycastle.asn1.ASN1EncodableVector;
+import org.spongycastle.asn1.ASN1Object;
+import org.spongycastle.asn1.ASN1ObjectIdentifier;
+import org.spongycastle.asn1.ASN1Primitive;
+import org.spongycastle.asn1.ASN1Sequence;
+import org.spongycastle.asn1.DERSequence;
+import org.spongycastle.asn1.nist.NISTObjectIdentifiers;
+import org.spongycastle.asn1.pkcs.PKCSObjectIdentifiers;
+
+public class SMIMECapability
+ extends ASN1Object
+{
+ /**
+ * general preferences
+ */
+ public static final ASN1ObjectIdentifier preferSignedData = PKCSObjectIdentifiers.preferSignedData;
+ public static final ASN1ObjectIdentifier canNotDecryptAny = PKCSObjectIdentifiers.canNotDecryptAny;
+ public static final ASN1ObjectIdentifier sMIMECapabilitiesVersions = PKCSObjectIdentifiers.sMIMECapabilitiesVersions;
+
+ /**
+ * encryption algorithms preferences
+ */
+ public static final ASN1ObjectIdentifier dES_CBC = new ASN1ObjectIdentifier("1.3.14.3.2.7");
+ public static final ASN1ObjectIdentifier dES_EDE3_CBC = PKCSObjectIdentifiers.des_EDE3_CBC;
+ public static final ASN1ObjectIdentifier rC2_CBC = PKCSObjectIdentifiers.RC2_CBC;
+ public static final ASN1ObjectIdentifier aES128_CBC = NISTObjectIdentifiers.id_aes128_CBC;
+ public static final ASN1ObjectIdentifier aES192_CBC = NISTObjectIdentifiers.id_aes192_CBC;
+ public static final ASN1ObjectIdentifier aES256_CBC = NISTObjectIdentifiers.id_aes256_CBC;
+
+ private ASN1ObjectIdentifier capabilityID;
+ private ASN1Encodable parameters;
+
+ public SMIMECapability(
+ ASN1Sequence seq)
+ {
+ capabilityID = (ASN1ObjectIdentifier)seq.getObjectAt(0);
+
+ if (seq.size() > 1)
+ {
+ parameters = (ASN1Primitive)seq.getObjectAt(1);
+ }
+ }
+
+ public SMIMECapability(
+ ASN1ObjectIdentifier capabilityID,
+ ASN1Encodable parameters)
+ {
+ this.capabilityID = capabilityID;
+ this.parameters = parameters;
+ }
+
+ public static SMIMECapability getInstance(
+ Object obj)
+ {
+ if (obj == null || obj instanceof SMIMECapability)
+ {
+ return (SMIMECapability)obj;
+ }
+
+ if (obj instanceof ASN1Sequence)
+ {
+ return new SMIMECapability((ASN1Sequence)obj);
+ }
+
+ throw new IllegalArgumentException("Invalid SMIMECapability");
+ }
+
+ public ASN1ObjectIdentifier getCapabilityID()
+ {
+ return capabilityID;
+ }
+
+ public ASN1Encodable getParameters()
+ {
+ return parameters;
+ }
+
+ /**
+ * Produce an object suitable for an ASN1OutputStream.
+ * <pre>
+ * SMIMECapability ::= SEQUENCE {
+ * capabilityID OBJECT IDENTIFIER,
+ * parameters ANY DEFINED BY capabilityID OPTIONAL
+ * }
+ * </pre>
+ */
+ public ASN1Primitive toASN1Primitive()
+ {
+ ASN1EncodableVector v = new ASN1EncodableVector();
+
+ v.add(capabilityID);
+
+ if (parameters != null)
+ {
+ v.add(parameters);
+ }
+
+ return new DERSequence(v);
+ }
+}
diff --git a/core/src/main/java/org/spongycastle/asn1/smime/SMIMECapabilityVector.java b/core/src/main/java/org/spongycastle/asn1/smime/SMIMECapabilityVector.java
new file mode 100644
index 00000000..91834e38
--- /dev/null
+++ b/core/src/main/java/org/spongycastle/asn1/smime/SMIMECapabilityVector.java
@@ -0,0 +1,50 @@
+package org.spongycastle.asn1.smime;
+
+import org.spongycastle.asn1.ASN1Encodable;
+import org.spongycastle.asn1.ASN1EncodableVector;
+import org.spongycastle.asn1.ASN1Integer;
+import org.spongycastle.asn1.ASN1ObjectIdentifier;
+import org.spongycastle.asn1.DERSequence;
+
+/**
+ * Handler for creating a vector S/MIME Capabilities
+ */
+public class SMIMECapabilityVector
+{
+ private ASN1EncodableVector capabilities = new ASN1EncodableVector();
+
+ public void addCapability(
+ ASN1ObjectIdentifier capability)
+ {
+ capabilities.add(new DERSequence(capability));
+ }
+
+ public void addCapability(
+ ASN1ObjectIdentifier capability,
+ int value)
+ {
+ ASN1EncodableVector v = new ASN1EncodableVector();
+
+ v.add(capability);
+ v.add(new ASN1Integer(value));
+
+ capabilities.add(new DERSequence(v));
+ }
+
+ public void addCapability(
+ ASN1ObjectIdentifier capability,
+ ASN1Encodable params)
+ {
+ ASN1EncodableVector v = new ASN1EncodableVector();
+
+ v.add(capability);
+ v.add(params);
+
+ capabilities.add(new DERSequence(v));
+ }
+
+ public ASN1EncodableVector toASN1EncodableVector()
+ {
+ return capabilities;
+ }
+}
diff --git a/core/src/main/java/org/spongycastle/asn1/smime/SMIMEEncryptionKeyPreferenceAttribute.java b/core/src/main/java/org/spongycastle/asn1/smime/SMIMEEncryptionKeyPreferenceAttribute.java
new file mode 100644
index 00000000..2eacdee9
--- /dev/null
+++ b/core/src/main/java/org/spongycastle/asn1/smime/SMIMEEncryptionKeyPreferenceAttribute.java
@@ -0,0 +1,48 @@
+package org.spongycastle.asn1.smime;
+
+import org.spongycastle.asn1.ASN1OctetString;
+import org.spongycastle.asn1.DERSet;
+import org.spongycastle.asn1.DERTaggedObject;
+import org.spongycastle.asn1.cms.Attribute;
+import org.spongycastle.asn1.cms.IssuerAndSerialNumber;
+import org.spongycastle.asn1.cms.RecipientKeyIdentifier;
+
+/**
+ * The SMIMEEncryptionKeyPreference object.
+ * <pre>
+ * SMIMEEncryptionKeyPreference ::= CHOICE {
+ * issuerAndSerialNumber [0] IssuerAndSerialNumber,
+ * receipentKeyId [1] RecipientKeyIdentifier,
+ * subjectAltKeyIdentifier [2] SubjectKeyIdentifier
+ * }
+ * </pre>
+ */
+public class SMIMEEncryptionKeyPreferenceAttribute
+ extends Attribute
+{
+ public SMIMEEncryptionKeyPreferenceAttribute(
+ IssuerAndSerialNumber issAndSer)
+ {
+ super(SMIMEAttributes.encrypKeyPref,
+ new DERSet(new DERTaggedObject(false, 0, issAndSer)));
+ }
+
+ public SMIMEEncryptionKeyPreferenceAttribute(
+ RecipientKeyIdentifier rKeyId)
+ {
+
+ super(SMIMEAttributes.encrypKeyPref,
+ new DERSet(new DERTaggedObject(false, 1, rKeyId)));
+ }
+
+ /**
+ * @param sKeyId the subjectKeyIdentifier value (normally the X.509 one)
+ */
+ public SMIMEEncryptionKeyPreferenceAttribute(
+ ASN1OctetString sKeyId)
+ {
+
+ super(SMIMEAttributes.encrypKeyPref,
+ new DERSet(new DERTaggedObject(false, 2, sKeyId)));
+ }
+}