Ejemplo n.º 1
0
 /**
 * Creates a new <code>CommitmentTypeQualifier</code> instance.
 *
 * @param commitmentTypeIdentifier a <code>CommitmentTypeIdentifier</code> value
 * @param qualifier the qualifier, defined by the above field.
 */
 public CommitmentTypeQualifier(
     DerObjectIdentifier commitmentTypeIdentifier,
     Asn1Encodable qualifier)
 {
     this.commitmentTypeIdentifier = commitmentTypeIdentifier;
     this.qualifier = qualifier;
 }
        public ArrayList GetCapabilities(
            DerObjectIdentifier capability)
        {
            ArrayList list = new ArrayList();
            DoGetCapabilitiesForOid(capability, list);
			return list;
        }
Ejemplo n.º 3
0
		private static void DefineCurve(
			string				name,
			DerObjectIdentifier	oid)
		{
			objIds.Add(name, oid);
			names.Add(oid, name);
		}
		public override void PerformTest()
        {
            CommitmentTypeQualifier ctq = new CommitmentTypeQualifier(CommitmentTypeIdentifier.ProofOfOrigin);

            CheckConstruction(ctq, CommitmentTypeIdentifier.ProofOfOrigin, null);

            Asn1Encodable info = new DerObjectIdentifier("1.2");

            ctq = new CommitmentTypeQualifier(CommitmentTypeIdentifier.ProofOfOrigin, info);

            CheckConstruction(ctq, CommitmentTypeIdentifier.ProofOfOrigin, info);

            ctq = CommitmentTypeQualifier.GetInstance(null);

            if (ctq != null)
            {
                Fail("null GetInstance() failed.");
            }

            try
            {
                CommitmentTypeQualifier.GetInstance(new object());

                Fail("GetInstance() failed to detect bad object.");
            }
            catch (ArgumentException)
            {
                // expected
            }
        }
Ejemplo n.º 5
0
 public QCStatement(
     DerObjectIdentifier qcStatementId,
     Asn1Encodable       qcStatementInfo)
 {
     this.qcStatementId = qcStatementId;
     this.qcStatementInfo = qcStatementInfo;
 }
Ejemplo n.º 6
0
		/**
         * returns an ArrayList 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 ArrayList GetCapabilities(
            DerObjectIdentifier capability)
        {
            ArrayList list = new ArrayList();

			if (capability == null)
            {
				foreach (object o in capabilities)
				{
                    SmimeCapability cap = SmimeCapability.GetInstance(o);

					list.Add(cap);
                }
            }
            else
            {
				foreach (object o in capabilities)
				{
                    SmimeCapability cap = SmimeCapability.GetInstance(o);

					if (capability.Equals(cap.CapabilityID))
                    {
                        list.Add(cap);
                    }
                }
            }

			return list;
        }
 public DHKdfParameters(DerObjectIdentifier algorithm, int keySize, byte[] z, byte[] extraInfo)
 {
     _algorithm = algorithm;
     _keySize = keySize;
     _z = z; // TODO Clone?
     _extraInfo = extraInfo;
 }
Ejemplo n.º 8
0
        internal DerObjectIdentifier(DerObjectIdentifier oid, string branchID)
        {
            if (!IsValidBranchID(branchID, 0))
                throw new ArgumentException("string " + branchID + " not a valid OID branch", "branchID");

            this.identifier = oid.Id + "." + branchID;
        }
		public ECKeyGenerationParameters(
			DerObjectIdentifier	publicKeyParamSet,
			SecureRandom		random)
			: this(LookupParameters(publicKeyParamSet), random)
		{
			this.publicKeyParamSet = publicKeyParamSet;
		}
 /**
  * create an AuthorityInformationAccess with the oid and location provided.
  */
 public AuthorityInformationAccess(
     DerObjectIdentifier	oid,
     GeneralName			location)
 {
     accessMethod = oid;
     accessLocation = location;
 }
Ejemplo n.º 11
0
        private static string Rfc4050XmlMaker(string algo, DerObjectIdentifier keyAlgoOid, X509Certificate2 cert)
        {
            if (!algo.Equals("ECDH", StringComparison.InvariantCultureIgnoreCase) &&
                !algo.Equals("ECDSA", StringComparison.InvariantCultureIgnoreCase))
                throw new Exception("Cannot generate rfc4050 keys for unknown EC algorithm");

            algo = algo.ToUpper();
            var namedCurve = SecNamedCurves.GetByOid(keyAlgoOid);
            var publickey = new ECPublicKeyParameters(algo,
                        namedCurve.Curve.DecodePoint(cert.GetPublicKey()), // Q
                        keyAlgoOid);

            //now we have the public key in bouncy castle
            //we can create the xml to import to CngKey
            string xml = "<" + algo + @"KeyValue xmlns='http://www.w3.org/2001/04/xmldsig-more#'>
                              <DomainParameters>
                                <NamedCurve URN='urn:oid:" + keyAlgoOid.Id + @"' />
                              </DomainParameters>
                              <PublicKey>
                                <X Value='" + publickey.Q.X.ToBigInteger() +
                                                        @"' xsi:type='PrimeFieldElemType' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />
                                <Y Value='" + publickey.Q.Y.ToBigInteger() +
                                                        @"' xsi:type='PrimeFieldElemType' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />
                              </PublicKey>
                            </" + algo + "KeyValue>";

            return xml;
        }
Ejemplo n.º 12
0
 private static void DefineCurveAlias(
     string				name,
     DerObjectIdentifier	oid)
 {
     objIds.Add(Platform.ToUpperInvariant(name), oid);
     names.Add(oid, name);
 }
Ejemplo n.º 13
0
        public SemanticsInformation(
			Asn1Sequence seq)
        {
            if (seq.Count < 1)
            {
                throw new ArgumentException("no objects in SemanticsInformation");
            }

            IEnumerator e = seq.GetEnumerator();
            e.MoveNext();
            object obj = e.Current;
            if (obj is DerObjectIdentifier)
            {
                semanticsIdentifier = DerObjectIdentifier.GetInstance(obj);
                if (e.MoveNext())
                {
                    obj  = e.Current;
                }
                else
                {
                    obj  = null;
                }
            }

            if (obj  != null)
            {
                Asn1Sequence generalNameSeq = Asn1Sequence.GetInstance(obj );
                nameRegistrationAuthorities = new GeneralName[generalNameSeq.Count];
                for (int i= 0; i < generalNameSeq.Count; i++)
                {
                    nameRegistrationAuthorities[i] = GeneralName.GetInstance(generalNameSeq[i]);
                }
            }
        }
Ejemplo n.º 14
0
 protected ECPublicBcpgKey(
     DerObjectIdentifier oid,
     BigInteger encodedPoint)
 {
     this.point = encodedPoint;
     this.oid = oid;
 }
		/**
		 * add a given extension field for the standard extensions tag (tag 3)
		 * @throws IOException
		 */
		public virtual void AddExtension(
			DerObjectIdentifier	oid,
			bool				critical,
			Asn1Encodable 		extValue)
		{
			this.AddExtension(oid, critical, extValue.GetEncoded());
		}
Ejemplo n.º 16
0
		public AttributeX509(
            DerObjectIdentifier	attrType,
            Asn1Set				attrValues)
        {
            this.attrType = attrType;
            this.attrValues = attrValues;
        }
        /// <summary>
        /// Add an extension to this certificate.
        /// </summary>
        /// <param name="oid">Its Object Identifier.</param>
        /// <param name="critical">Is it critical.</param>
        /// <param name="extensionValue">The value.</param>
        public void AddExtension(
			DerObjectIdentifier	oid,
			bool				critical,
			Asn1Encodable		extensionValue)
        {
            extGenerator.AddExtension(oid, critical, extensionValue);
        }
Ejemplo n.º 18
0
		public ContentInfo(
			DerObjectIdentifier	contentType,
			Asn1Encodable		content)
		{
			this.contentType = contentType;
			this.content = content;
		}
        public Gost3410KeyGenerationParameters(
			ISecureRandom		random,
			DerObjectIdentifier	publicKeyParamSet)
            : this(random, LookupParameters(publicKeyParamSet))
        {
            this.publicKeyParamSet = publicKeyParamSet;
        }
Ejemplo n.º 20
0
		private void doTestCreateKeyParameter(
			string				algorithm,
			DerObjectIdentifier	oid,
			int					keyBits,
			Type				expectedType,
			SecureRandom		random)
		{
			int keyLength = keyBits / 8;
			byte[] bytes = new byte[keyLength];
			random.NextBytes(bytes);

			KeyParameter key;

			key = ParameterUtilities.CreateKeyParameter(algorithm, bytes);
			checkKeyParameter(key, expectedType, bytes);

			key = ParameterUtilities.CreateKeyParameter(oid, bytes);
			checkKeyParameter(key, expectedType, bytes);

			bytes = new byte[keyLength * 2];
			random.NextBytes(bytes);

			int offset = random.Next(1, keyLength);
			byte[] expected = new byte[keyLength];
			Array.Copy(bytes, offset, expected, 0, keyLength);

			key = ParameterUtilities.CreateKeyParameter(algorithm, bytes, offset, keyLength);
			checkKeyParameter(key, expectedType, expected);

			key = ParameterUtilities.CreateKeyParameter(oid, bytes, offset, keyLength);
			checkKeyParameter(key, expectedType, expected);
		}
Ejemplo n.º 21
0
		public DHKdfParameters(
			DerObjectIdentifier	algorithm,
			int					keySize,
			byte[]				z)
			: this(algorithm, keySize, z, null)
		{
		}
Ejemplo n.º 22
0
 public SmimeCapability(
     DerObjectIdentifier	capabilityID,
     Asn1Encodable		parameters)
 {
     this.capabilityID = capabilityID;
     this.parameters = parameters;
 }
		public OtherRecipientInfo(
            DerObjectIdentifier	oriType,
            Asn1Encodable		oriValue)
        {
            this.oriType = oriType;
            this.oriValue = oriValue;
        }
Ejemplo n.º 24
0
		public OtherKeyAttribute(
            DerObjectIdentifier	keyAttrId,
            Asn1Encodable		keyAttr)
        {
            this.keyAttrId = keyAttrId;
            this.keyAttr = keyAttr;
        }
Ejemplo n.º 25
0
 public CommitmentTypeIndication(
     DerObjectIdentifier	commitmentTypeId,
     Asn1Sequence		commitmentTypeQualifier)
 {
     this.commitmentTypeId = commitmentTypeId;
     this.commitmentTypeQualifier = commitmentTypeQualifier;
 }
 /**
  * returns an ArrayList 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 IList GetCapabilitiesForOid(
     DerObjectIdentifier capability)
 {
     IList list = Platform.CreateArrayList();
     DoGetCapabilitiesForOid(capability, list);
     return list;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ECDHPublicKeyParameters" /> class.
 /// </summary>
 /// <param name="q">The q.</param>
 /// <param name="publicKeyParamSet">The public key param set.</param>
 /// <param name="hashAlgorithm">The hash algorithm.</param>
 /// <param name="symmetricKeyAlgorithm">The symmetric key algorithm.</param>
 public ECDHPublicKeyParameters(ECPoint q, DerObjectIdentifier publicKeyParamSet, HashAlgorithmTag hashAlgorithm,
                                SymmetricKeyAlgorithmTag symmetricKeyAlgorithm)
     : base("ECDH", q, publicKeyParamSet)
 {
     this.HashAlgorithm = hashAlgorithm;
     this.SymmetricKeyAlgorithm = symmetricKeyAlgorithm;
 }
Ejemplo n.º 28
0
 protected ECPublicBcpgKey(
     DerObjectIdentifier oid,
     ECPoint point)
 {
     this.point = new BigInteger(1, point.GetEncoded());
     this.oid = oid;
 }
		public TimeStampRequest Generate(
			string		digestAlgorithmOid,
			byte[]		digest,
			BigInteger	nonce)
		{
			if (digestAlgorithmOid == null)
			{
				throw new ArgumentException("No digest algorithm specified");
			}

			DerObjectIdentifier digestAlgOid = new DerObjectIdentifier(digestAlgorithmOid);

			AlgorithmIdentifier algID = new AlgorithmIdentifier(digestAlgOid, DerNull.Instance);
			MessageImprint messageImprint = new MessageImprint(algID, digest);

			X509Extensions  ext = null;

			if (extOrdering.Count != 0)
			{
				ext = new X509Extensions(extOrdering, extensions);
			}

			DerInteger derNonce = nonce == null
				?	null
				:	new DerInteger(nonce);

			return new TimeStampRequest(
				new TimeStampReq(messageImprint, reqPolicy, derNonce, certReq, ext));
		}
Ejemplo n.º 30
0
 public SemanticsInformation(
     DerObjectIdentifier semanticsIdentifier,
     GeneralName[] generalNames)
 {
     this.semanticsIdentifier = semanticsIdentifier;
     this.nameRegistrationAuthorities = generalNames;
 }
Ejemplo n.º 31
0
        public static string GetCertificateValue(X509Certificate certificate, string identifier)
        {
            DerObjectIdentifier commonNameOID = new Org.BouncyCastle.Asn1.DerObjectIdentifier(identifier);
            IList values = certificate.SubjectDN.GetValueList(commonNameOID);

            if (values.Count > 0)
            {
                return((string)values[0]);
            }
            return(null);
        }
Ejemplo n.º 32
0
        public override Org.BouncyCastle.Asn1.Asn1Object GetConvertedValue(Org.BouncyCastle.Asn1.DerObjectIdentifier oid, string value)
        {
            Asn1Object obj = base.GetConvertedValue(oid, value);

            if (obj is DerUtf8String)
            {
                return(new DerPrintableString(value));
            }
            else
            {
                return(obj);
            }
        }
Ejemplo n.º 33
0
        /**
         * Return  true if this oid is an extension of the passed in branch, stem.
         * @param stem the arc or branch that is a possible parent.
         * @return  true if the branch is on the passed in stem, false otherwise.
         */
        public virtual bool On(DerObjectIdentifier stem)
        {
            string id = Id, stemId = stem.Id;

            return(id.Length > stemId.Length && id[stemId.Length] == '.' && Platform.StartsWith(id, stemId));
        }