private AttributeCertificateInfo(
            Asn1Sequence seq)
        {
			if (seq.Count < 7 || seq.Count > 9)
			{
				throw new ArgumentException("Bad sequence size: " + seq.Count);
			}

			this.version = DerInteger.GetInstance(seq[0]);
            this.holder = Holder.GetInstance(seq[1]);
            this.issuer = AttCertIssuer.GetInstance(seq[2]);
            this.signature = AlgorithmIdentifier.GetInstance(seq[3]);
            this.serialNumber = DerInteger.GetInstance(seq[4]);
            this.attrCertValidityPeriod = AttCertValidityPeriod.GetInstance(seq[5]);
            this.attributes = Asn1Sequence.GetInstance(seq[6]);

			for (int i = 7; i < seq.Count; i++)
            {
                Asn1Encodable obj = (Asn1Encodable) seq[i];

				if (obj is DerBitString)
                {
                    this.issuerUniqueID = DerBitString.GetInstance(seq[i]);
                }
                else if (obj is Asn1Sequence || obj is X509Extensions)
                {
                    this.extensions = X509Extensions.GetInstance(seq[i]);
                }
            }
        }
Ejemplo n.º 2
0
        public PkiStatusInfo(
			Asn1Sequence seq)
        {
            this.status = DerInteger.GetInstance(seq[0]);

            this.statusString = null;
            this.failInfo = null;

            if (seq.Count > 2)
            {
                this.statusString = PkiFreeText.GetInstance(seq[1]);
                this.failInfo = DerBitString.GetInstance(seq[2]);
            }
            else if (seq.Count > 1)
            {
                object obj = seq[1];
                if (obj is DerBitString)
                {
                    this.failInfo = DerBitString.GetInstance(obj);
                }
                else
                {
                    this.statusString = PkiFreeText.GetInstance(obj);
                }
            }
        }
Ejemplo n.º 3
0
		public RC2CbcParameter(
            int		parameterVersion,
            byte[]	iv)
        {
            this.version = new DerInteger(parameterVersion);
            this.iv = new DerOctetString(iv);
        }
Ejemplo n.º 4
0
        /**
         * @param status
         * @param statusString
         */
        public PkiStatusInfo(
			int			status,
			PkiFreeText	statusString)
        {
            this.status = new DerInteger(status);
            this.statusString = statusString;
        }
Ejemplo n.º 5
0
		public DHPublicKey(DerInteger y)
		{
			if (y == null)
				throw new ArgumentNullException("y");

			this.y = y;
		}
Ejemplo n.º 6
0
		private GeneralSubtree(
			Asn1Sequence seq)
		{
			baseName = GeneralName.GetInstance(seq[0]);

			switch (seq.Count)
			{
				case 1:
					break;
				case 2:
				{
					Asn1TaggedObject o = Asn1TaggedObject.GetInstance(seq[1]);
					switch (o.TagNo)
					{
						case 0:
							minimum = DerInteger.GetInstance(o, false);
							break;
						case 1:
							maximum = DerInteger.GetInstance(o, false);
							break;
						default:
							throw new ArgumentException("Bad tag number: " + o.TagNo);
					}
					break;
				}
				case 3:
				{
					minimum = DerInteger.GetInstance(Asn1TaggedObject.GetInstance(seq[1]));
					maximum = DerInteger.GetInstance(Asn1TaggedObject.GetInstance(seq[2]));
					break;
				}
				default:
					throw new ArgumentException("Bad sequence size: " + seq.Count);
			}
		}
Ejemplo n.º 7
0
		public AuthenticatedData(
			OriginatorInfo		originatorInfo,
			Asn1Set				recipientInfos,
			AlgorithmIdentifier	macAlgorithm,
			AlgorithmIdentifier	digestAlgorithm,
			ContentInfo			encapsulatedContent,
			Asn1Set				authAttrs,
			Asn1OctetString		mac,
			Asn1Set				unauthAttrs)
		{
			if (digestAlgorithm != null || authAttrs != null)
			{
				if (digestAlgorithm == null || authAttrs == null)
				{
					throw new ArgumentException("digestAlgorithm and authAttrs must be set together");
				}
			}

			version = new DerInteger(CalculateVersion(originatorInfo));

			this.originatorInfo = originatorInfo;
			this.macAlgorithm = macAlgorithm;
			this.digestAlgorithm = digestAlgorithm;
			this.recipientInfos = recipientInfos;
			this.encapsulatedContentInfo = encapsulatedContent;
			this.authAttrs = authAttrs;
			this.mac = mac;
			this.unauthAttrs = unauthAttrs;
		}
Ejemplo n.º 8
0
		public Accuracy(
			DerInteger seconds,
			DerInteger millis,
			DerInteger micros)
		{
			//Verifications
			if (millis != null
				&& (millis.Value.IntValue < MinMillis
					|| millis.Value.IntValue > MaxMillis))
			{
				throw new ArgumentException(
					"Invalid millis field : not in (1..999)");
			}

			if (micros != null
				&& (micros.Value.IntValue < MinMicros
					|| micros.Value.IntValue > MaxMicros))
			{
				throw new ArgumentException(
					"Invalid micros field : not in (1..999)");
			}

			this.seconds = seconds;
			this.millis = millis;
			this.micros = micros;
		}
Ejemplo n.º 9
0
		/**
		 * The default version
		 */
		public RsassaPssParameters()
		{
			hashAlgorithm = DefaultHashAlgorithm;
			maskGenAlgorithm = DefaultMaskGenFunction;
			saltLength = DefaultSaltLength;
			trailerField = DefaultTrailerField;
		}
        private TimeStampedDataParser(Asn1SequenceParser parser)
        {
            this.parser = parser;
            this.version = DerInteger.GetInstance(parser.ReadObject());

            Asn1Object obj = parser.ReadObject().ToAsn1Object();

            if (obj is DerIA5String)
            {
                this.dataUri = DerIA5String.GetInstance(obj);
                obj = parser.ReadObject().ToAsn1Object();
            }

            if (//obj is MetaData ||
                obj is Asn1SequenceParser)
            {
                this.metaData = MetaData.GetInstance(obj.ToAsn1Object());
                obj = parser.ReadObject().ToAsn1Object();
            }

            if (obj is Asn1OctetStringParser)
            {
                this.content = (Asn1OctetStringParser)obj;
            }
        }
Ejemplo n.º 11
0
		public CompressedData(
            Asn1Sequence seq)
        {
            this.version = (DerInteger) seq[0];
            this.compressionAlgorithm = AlgorithmIdentifier.GetInstance(seq[1]);
            this.encapContentInfo = ContentInfo.GetInstance(seq[2]);
        }
Ejemplo n.º 12
0
		public Pbkdf2Params(
			byte[] salt,
			int iterationCount)
		{
			this.octStr = new DerOctetString(salt);
			this.iterationCount = new DerInteger(iterationCount);
		}
        public AuthEnvelopedData(
            OriginatorInfo			originatorInfo,
            Asn1Set					recipientInfos,
            EncryptedContentInfo	authEncryptedContentInfo,
            Asn1Set					authAttrs,
            Asn1OctetString			mac,
            Asn1Set					unauthAttrs)
        {
            // "It MUST be set to 0."
            this.version = new DerInteger(0);

            this.originatorInfo = originatorInfo;

            // TODO
            // "There MUST be at least one element in the collection."
            this.recipientInfos = recipientInfos;

            this.authEncryptedContentInfo = authEncryptedContentInfo;

            // TODO
            // "The authAttrs MUST be present if the content type carried in
            // EncryptedContentInfo is not id-data."
            this.authAttrs = authAttrs;

            this.mac = mac;

            this.unauthAttrs = unauthAttrs;
        }
Ejemplo n.º 14
0
		public RsassaPssParameters(
			Asn1Sequence seq)
		{
			hashAlgorithm = DefaultHashAlgorithm;
			maskGenAlgorithm = DefaultMaskGenFunction;
			saltLength = DefaultSaltLength;
			trailerField = DefaultTrailerField;

			for (int i = 0; i != seq.Count; i++)
			{
				Asn1TaggedObject o = (Asn1TaggedObject)seq[i];

				switch (o.TagNo)
				{
					case 0:
						hashAlgorithm = AlgorithmIdentifier.GetInstance(o, true);
						break;
					case 1:
						maskGenAlgorithm = AlgorithmIdentifier.GetInstance(o, true);
						break;
					case 2:
						saltLength = DerInteger.GetInstance(o, true);
						break;
					case 3:
						trailerField = DerInteger.GetInstance(o, true);
						break;
					default:
						throw new ArgumentException("unknown tag");
				}
			}
		}
Ejemplo n.º 15
0
		public Pkcs12PbeParams(
            byte[]	salt,
            int		iterations)
        {
            this.iv = new DerOctetString(salt);
            this.iterations = new DerInteger(iterations);
        }
 public IssuerAndSerialNumber(
     X509Name	name,
     BigInteger	certSerialNumber)
 {
     this.name = name;
     this.certSerialNumber = new DerInteger(certSerialNumber);
 }
Ejemplo n.º 17
0
        public Pbkdf2Params(
            Asn1Sequence seq)
        {
            if (seq.Count < 2 || seq.Count > 4)
                throw new ArgumentException("Wrong number of elements in sequence", "seq");

            this.octStr = (Asn1OctetString)seq[0];
            this.iterationCount = (DerInteger)seq[1];

            Asn1Encodable kl = null, d = null;
            if (seq.Count > 3)
            {
                kl = seq[2];
                d = seq[3];
            }
            else if (seq.Count > 2)
            {
                if (seq[2] is DerInteger)
                {
                    kl = seq[2];
                }
                else
                {
                    d = seq[2];
                }
            }
            if (kl != null)
            {
                keyLength = (DerInteger)kl;
            }
            if (d != null)
            {
                prf = AlgorithmIdentifier.GetInstance(d);
            }
        }
 public IssuerAndSerialNumber(
     X509Name	name,
     DerInteger	certSerialNumber)
 {
     this.name = name;
     this.certSerialNumber = certSerialNumber;
 }
Ejemplo n.º 19
0
        private static Asn1EncodableVector ConvertVector(IList numbers)
        {
            Asn1EncodableVector av = new Asn1EncodableVector();

            foreach (object o in numbers)
            {
                DerInteger di;

                if (o is BigInteger)
                {
                    di = new DerInteger((BigInteger)o);
                }
                else if (o is int)
                {
                    di = new DerInteger((int)o);
                }
                else
                {
                    throw new ArgumentException();
                }

                av.Add(di);
            }
            return av;
        }
        public override void PerformTest()
        {
            DerInteger val = new DerInteger(9);

            DerApplicationSpecific tagged = new DerApplicationSpecific(false, 3, val);

            if (!AreEqual(impData, tagged.GetEncoded()))
            {
                Fail("implicit encoding failed");
            }

            DerInteger recVal = (DerInteger) tagged.GetObject(Asn1Tags.Integer);

            if (!val.Equals(recVal))
            {
                Fail("implicit read back failed");
            }

            DerApplicationSpecific certObj = (DerApplicationSpecific)
                Asn1Object.FromByteArray(certData);

            if (!certObj.IsConstructed() || certObj.ApplicationTag != 33)
            {
                Fail("parsing of certificate data failed");
            }

            byte[] encoded = certObj.GetDerEncoded();

            if (!Arrays.AreEqual(certData, encoded))
            {
                Console.WriteLine(Encoding.ASCII.GetString(certData, 0, certData.Length).Substring(0, 20));
                Console.WriteLine(Encoding.ASCII.GetString(encoded, 0, encoded.Length).Substring(0, 20));
                Fail("re-encoding of certificate data failed");
            }
        }
Ejemplo n.º 21
0
		private CertResponse(Asn1Sequence seq)
		{
			certReqId = DerInteger.GetInstance(seq[0]);
			status = PkiStatusInfo.GetInstance(seq[1]);

			if (seq.Count >= 3)
			{
				if (seq.Count == 3)
				{
					Asn1Encodable o = seq[2];
					if (o is Asn1OctetString)
					{
						rspInfo = Asn1OctetString.GetInstance(o);
					}
					else
					{
						certifiedKeyPair = CertifiedKeyPair.GetInstance(o);
					}
				}
				else
				{
					certifiedKeyPair = CertifiedKeyPair.GetInstance(seq[2]);
					rspInfo = Asn1OctetString.GetInstance(seq[3]);
				}
			}
		}
Ejemplo n.º 22
0
		public IssuerSerial(
			GeneralNames	issuer,
			DerInteger		serial)
		{
			this.issuer = issuer;
			this.serial = serial;
		}
Ejemplo n.º 23
0
 private PbmParameter(Asn1Sequence seq)
 {
     salt = Asn1OctetString.GetInstance(seq[0]);
     owf = AlgorithmIdentifier.GetInstance(seq[1]);
     iterationCount = DerInteger.GetInstance(seq[2]);
     mac = AlgorithmIdentifier.GetInstance(seq[3]);
 }
Ejemplo n.º 24
0
		public KeyTransRecipientInfo(
            Asn1Sequence seq)
        {
            this.version = (DerInteger) seq[0];
            this.rid = RecipientIdentifier.GetInstance(seq[1]);
            this.keyEncryptionAlgorithm = AlgorithmIdentifier.GetInstance(seq[2]);
            this.encryptedKey = (Asn1OctetString) seq[3];
        }
Ejemplo n.º 25
0
		public PasswordRecipientInfo(
            AlgorithmIdentifier	keyEncryptionAlgorithm,
            Asn1OctetString		encryptedKey)
        {
            this.version = new DerInteger(0);
            this.keyEncryptionAlgorithm = keyEncryptionAlgorithm;
            this.encryptedKey = encryptedKey;
        }
Ejemplo n.º 26
0
		private PbeParameter(Asn1Sequence seq)
		{
			if (seq.Count != 2)
				throw new ArgumentException("Wrong number of elements in sequence", "seq");

			salt = Asn1OctetString.GetInstance(seq[0]);
			iterationCount = DerInteger.GetInstance(seq[1]);
		}
Ejemplo n.º 27
0
		public CompressedData(
            AlgorithmIdentifier	compressionAlgorithm,
            ContentInfo			encapContentInfo)
        {
            this.version = new DerInteger(0);
            this.compressionAlgorithm = compressionAlgorithm;
            this.encapContentInfo = encapContentInfo;
        }
Ejemplo n.º 28
0
 public Pbkdf2Params(
     byte[]  salt,
     int     iterationCount,
     int     keyLength)
     : this(salt, iterationCount)
 {
     this.keyLength = new DerInteger(keyLength);
 }
Ejemplo n.º 29
0
		public KekRecipientInfo(
            Asn1Sequence seq)
        {
            version = (DerInteger) seq[0];
            kekID = KekIdentifier.GetInstance(seq[1]);
            keyEncryptionAlgorithm = AlgorithmIdentifier.GetInstance(seq[2]);
            encryptedKey = (Asn1OctetString) seq[3];
        }
Ejemplo n.º 30
0
		private DHValidationParms(Asn1Sequence seq)
		{
			if (seq.Count != 2)
				throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");

			this.seed = DerBitString.GetInstance(seq[0]);
			this.pgenCounter = DerInteger.GetInstance(seq[1]);
		}
Ejemplo n.º 31
0
        public CrlIdentifier(
            X509Name crlIssuer,
            DateTime crlIssuedTime,
            BigInteger crlNumber)
        {
            if (crlIssuer == null)
            {
                throw new ArgumentNullException("crlIssuer");
            }

            this.crlIssuer     = crlIssuer;
            this.crlIssuedTime = new DerUtcTime(crlIssuedTime);

            if (crlNumber != null)
            {
                this.crlNumber = new DerInteger(crlNumber);
            }
        }
        public X509Crl Update(
            string algorithm,
            X509Crl existingCrl,
            X509Certificate[] certificates,
            X509Certificate caCert,
            AsymmetricCipherKeyPair caKey,
            DateTime thisUpdate,
            DateTime nextUpdate,
            int /*CrlReason*/ reason)
        {
            var crlGenerator = new X509V2CrlGenerator();

            crlGenerator.SetIssuerDN(PrincipalUtilities.GetSubjectX509Principal(caCert));

            crlGenerator.SetThisUpdate(thisUpdate);
            crlGenerator.SetNextUpdate(nextUpdate);

            var signatureFactory = new Asn1SignatureFactory(
                algorithm,
                caKey.Private);

            crlGenerator.AddCrl(existingCrl);

            if (!certificates.IsNullOrEmpty())
            {
                foreach (X509Certificate certificate in certificates)
                {
                    // a ver... a questão da CrlRerason... pode ser individual ?!?!?!
                    crlGenerator.AddCrlEntry(certificate.SerialNumber, thisUpdate, reason);
                }
            }

            crlGenerator.AddExtension(X509Extensions.AuthorityKeyIdentifier, false,
                                      new AuthorityKeyIdentifierStructure(caCert));

            BigInteger existingCrlNumber = DerInteger.GetInstance(
                Asn1Object.FromByteArray(existingCrl.GetExtensionValue(X509Extensions.CrlNumber).GetOctets())
                ).PositiveValue;

            crlGenerator.AddExtension(
                X509Extensions.CrlNumber, false, new CrlNumber(existingCrlNumber.Add(BigInteger.One)));

            return(crlGenerator.Generate(signatureFactory));
        }
Ejemplo n.º 33
0
 public void AddCrlEntry(DerInteger userCertificate, Time revocationDate, int reason, DerGeneralizedTime invalidityDate)
 {
     //IL_003d: Expected O, but got Unknown
     //IL_0048: Unknown result type (might be due to invalid IL or missing references)
     //IL_007b: Expected O, but got Unknown
     //IL_0087: Unknown result type (might be due to invalid IL or missing references)
     global::System.Collections.IList list  = Platform.CreateArrayList();
     global::System.Collections.IList list2 = Platform.CreateArrayList();
     if (reason != 0)
     {
         CrlReason crlReason = new CrlReason(reason);
         try
         {
             list.Add((object)X509Extensions.ReasonCode);
             list2.Add((object)new X509Extension(critical: false, new DerOctetString(crlReason.GetEncoded())));
         }
         catch (IOException val)
         {
             IOException val2 = val;
             throw new ArgumentException(string.Concat((object)"error encoding reason: ", (object)val2));
         }
     }
     if (invalidityDate != null)
     {
         try
         {
             list.Add((object)X509Extensions.InvalidityDate);
             list2.Add((object)new X509Extension(critical: false, new DerOctetString(invalidityDate.GetEncoded())));
         }
         catch (IOException val3)
         {
             IOException val4 = val3;
             throw new ArgumentException(string.Concat((object)"error encoding invalidityDate: ", (object)val4));
         }
     }
     if (((global::System.Collections.ICollection)list).get_Count() != 0)
     {
         AddCrlEntry(userCertificate, revocationDate, new X509Extensions(list, list2));
     }
     else
     {
         AddCrlEntry(userCertificate, revocationDate, null);
     }
 }
Ejemplo n.º 34
0
        public void DoTestInvalidEncoding_00_32bits()
        {
            SetAllowUnsafeProperty(false);

            //
            // Check what would pass loose validation fails outside of loose validation.
            //
            try
            {
                byte[]     rawInt = Hex.Decode("0000000010FF");
                DerInteger i      = new DerInteger(rawInt);
                IsEquals(i.Value.IntValue, 4351);
                Fail("Expecting illegal argument exception.");
            }
            catch (ArgumentException e)
            {
                IsEquals("malformed integer", e.Message);
            }
        }
Ejemplo n.º 35
0
        internal static MPInteger[] DsaSigToMpi(
            byte[] encoding)
        {
            DerInteger i1, i2;

            try
            {
                Asn1Sequence s = Asn1Sequence.GetInstance(encoding);

                i1 = DerInteger.GetInstance(s[0]);
                i2 = DerInteger.GetInstance(s[1]);
            }
            catch (IOException e)
            {
                throw new PgpException("exception encoding signature", e);
            }

            return(new MPInteger[] { new MPInteger(i1.Value), new MPInteger(i2.Value) });
        }
Ejemplo n.º 36
0
        private AuthenticatedData(
            Asn1Sequence seq)
        {
            int index = 0;

            version = (DerInteger)seq[index++];

            Asn1Encodable tmp = seq[index++];

            if (tmp is Asn1TaggedObject)
            {
                originatorInfo = OriginatorInfo.GetInstance((Asn1TaggedObject)tmp, false);
                tmp            = seq[index++];
            }

            recipientInfos = Asn1Set.GetInstance(tmp);
            macAlgorithm   = AlgorithmIdentifier.GetInstance(seq[index++]);

            tmp = seq[index++];

            if (tmp is Asn1TaggedObject)
            {
                digestAlgorithm = AlgorithmIdentifier.GetInstance((Asn1TaggedObject)tmp, false);
                tmp             = seq[index++];
            }

            encapsulatedContentInfo = ContentInfo.GetInstance(tmp);

            tmp = seq[index++];

            if (tmp is Asn1TaggedObject)
            {
                authAttrs = Asn1Set.GetInstance((Asn1TaggedObject)tmp, false);
                tmp       = seq[index++];
            }

            mac = Asn1OctetString.GetInstance(tmp);

            if (seq.Count > index)
            {
                unauthAttrs = Asn1Set.GetInstance((Asn1TaggedObject)seq[index], false);
            }
        }
        public TimeStampRequest Generate(string digestAlgorithmOid, byte[] digest, BigInteger nonce)
        {
            if (digestAlgorithmOid == null)
            {
                throw new ArgumentException("No digest algorithm specified");
            }
            DerObjectIdentifier objectID       = new DerObjectIdentifier(digestAlgorithmOid);
            AlgorithmIdentifier hashAlgorithm  = new AlgorithmIdentifier(objectID, DerNull.Instance);
            MessageImprint      messageImprint = new MessageImprint(hashAlgorithm, digest);
            X509Extensions      x509Extensions = null;

            if (this.extOrdering.Count != 0)
            {
                x509Extensions = new X509Extensions(this.extOrdering, this.extensions);
            }
            DerInteger nonce2 = (nonce == null) ? null : new DerInteger(nonce);

            return(new TimeStampRequest(new TimeStampReq(messageImprint, this.reqPolicy, nonce2, this.certReq, x509Extensions)));
        }
Ejemplo n.º 38
0
 public static Iso4217CurrencyCode GetInstance(object obj)
 {
     if (obj == null || obj is Iso4217CurrencyCode)
     {
         return((Iso4217CurrencyCode)obj);
     }
     if (obj is DerInteger)
     {
         DerInteger instance = DerInteger.GetInstance(obj);
         int        intValue = instance.Value.IntValue;
         return(new Iso4217CurrencyCode(intValue));
     }
     if (obj is DerPrintableString)
     {
         DerPrintableString instance2 = DerPrintableString.GetInstance(obj);
         return(new Iso4217CurrencyCode(instance2.GetString()));
     }
     throw new ArgumentException("unknown object in GetInstance: " + obj.GetType().FullName, "obj");
 }
Ejemplo n.º 39
0
 private CrlIdentifier(Asn1Sequence seq)
 {
     //IL_000e: Unknown result type (might be due to invalid IL or missing references)
     //IL_0040: Unknown result type (might be due to invalid IL or missing references)
     if (seq == null)
     {
         throw new ArgumentNullException("seq");
     }
     if (seq.Count < 2 || seq.Count > 3)
     {
         throw new ArgumentException(string.Concat((object)"Bad sequence size: ", (object)seq.Count), "seq");
     }
     crlIssuer     = X509Name.GetInstance(seq[0]);
     crlIssuedTime = DerUtcTime.GetInstance(seq[1]);
     if (seq.Count > 2)
     {
         crlNumber = DerInteger.GetInstance(seq[2]);
     }
 }
Ejemplo n.º 40
0
        private TimeStampedData(Asn1Sequence seq)
        {
            version = DerInteger.GetInstance(seq[0]);
            int index = 1;

            if (seq[index] is DerIA5String)
            {
                dataUri = DerIA5String.GetInstance(seq[index++]);
            }
            if (seq[index] is MetaData || seq[index] is Asn1Sequence)
            {
                metaData = MetaData.GetInstance(seq[index++]);
            }
            if (seq[index] is Asn1OctetString)
            {
                content = Asn1OctetString.GetInstance(seq[index++]);
            }
            temporalEvidence = Evidence.GetInstance(seq[index]);
        }
Ejemplo n.º 41
0
        public void AddCrlEntry(DerInteger userCertificate, Time revocationDate, int reason,
                                DerGeneralizedTime invalidityDate)
        {
            IList extOids   = Platform.CreateArrayList();
            IList extValues = Platform.CreateArrayList();

            if (reason != 0)
            {
                CrlReason crlReason = new CrlReason(reason);

                try
                {
                    extOids.Add(X509Extensions.ReasonCode);
                    extValues.Add(new X509Extension(false, new DerOctetString(crlReason.GetEncoded())));
                }
                catch (IOException e)
                {
                    throw new ArgumentException("error encoding reason: " + e);
                }
            }

            if (invalidityDate != null)
            {
                try
                {
                    extOids.Add(X509Extensions.InvalidityDate);
                    extValues.Add(new X509Extension(false, new DerOctetString(invalidityDate.GetEncoded())));
                }
                catch (IOException e)
                {
                    throw new ArgumentException("error encoding invalidityDate: " + e);
                }
            }

            if (extOids.Count != 0)
            {
                AddCrlEntry(userCertificate, revocationDate, new X509Extensions(extOids, extValues));
            }
            else
            {
                AddCrlEntry(userCertificate, revocationDate, null);
            }
        }
 /**
  * Constructor from a given details.
  *
  * According RFC 3280, the minimum and maximum fields are not used with any
  * name forms, thus minimum MUST be zero, and maximum MUST be absent.
  * <p>
  * If minimum is <code>null</code>, zero is assumed, if
  * maximum is <code>null</code>, maximum is absent.
  *
  * @param baseName
  *            A restriction.
  * @param minimum
  *            Minimum
  *
  * @param maximum
  *            Maximum
  */
 public GeneralSubtree(
     GeneralName baseName,
     BigInteger minimum,
     BigInteger maximum)
 {
     this.baseName = baseName;
     if (maximum != null)
     {
         this.maximum = new DerInteger(maximum);
     }
     if (minimum == null)
     {
         this.minimum = null;
     }
     else
     {
         this.minimum = new DerInteger(minimum);
     }
 }
Ejemplo n.º 43
0
    private CscaMasterList(Asn1Sequence seq)
    {
        if (seq == null || seq.Count == 0)
        {
            throw new ArgumentException("null or empty sequence passed.");
        }
        if (seq.Count != 2)
        {
            throw new ArgumentException("Incorrect sequence size: " + seq.Count);
        }
        version = DerInteger.GetInstance(seq[0]);
        Asn1Set instance = Asn1Set.GetInstance(seq[1]);

        certList = new X509CertificateStructure[instance.Count];
        for (int i = 0; i < certList.Length; i++)
        {
            certList[i] = X509CertificateStructure.GetInstance(instance[i]);
        }
    }
Ejemplo n.º 44
0
        private Accuracy(
            Asn1Sequence seq)
        {
            for (int i = 0; i < seq.Count; ++i)
            {
                // seconds
                if (seq[i] is DerInteger)
                {
                    seconds = (DerInteger)seq[i];
                }
                else if (seq[i] is DerTaggedObject)
                {
                    DerTaggedObject extra = (DerTaggedObject)seq[i];

                    switch (extra.TagNo)
                    {
                    case 0:
                        millis = DerInteger.GetInstance(extra, false);
                        if (millis.Value.IntValue < MinMillis ||
                            millis.Value.IntValue > MaxMillis)
                        {
                            throw new ArgumentException(
                                      "Invalid millis field : not in (1..999).");
                        }
                        break;

                    case 1:
                        micros = DerInteger.GetInstance(extra, false);
                        if (micros.Value.IntValue < MinMicros ||
                            micros.Value.IntValue > MaxMicros)
                        {
                            throw new ArgumentException(
                                      "Invalid micros field : not in (1..999).");
                        }
                        break;

                    default:
                        throw new ArgumentException("Invalig tag number");
                    }
                }
            }
        }
Ejemplo n.º 45
0
        private Accuracy(Asn1Sequence seq)
        {
            //IL_00a6: Unknown result type (might be due to invalid IL or missing references)
            //IL_00e8: Unknown result type (might be due to invalid IL or missing references)
            //IL_00f3: Unknown result type (might be due to invalid IL or missing references)
            for (int i = 0; i < seq.Count; i++)
            {
                if (seq[i] is DerInteger)
                {
                    seconds = (DerInteger)seq[i];
                }
                else
                {
                    if (!(seq[i] is DerTaggedObject))
                    {
                        continue;
                    }
                    DerTaggedObject derTaggedObject = (DerTaggedObject)seq[i];
                    switch (derTaggedObject.TagNo)
                    {
                    case 0:
                        millis = DerInteger.GetInstance(derTaggedObject, isExplicit: false);
                        if (millis.Value.IntValue < 1 || millis.Value.IntValue > 999)
                        {
                            throw new ArgumentException("Invalid millis field : not in (1..999).");
                        }
                        break;

                    case 1:
                        micros = DerInteger.GetInstance(derTaggedObject, isExplicit: false);
                        if (micros.Value.IntValue < 1 || micros.Value.IntValue > 999)
                        {
                            throw new ArgumentException("Invalid micros field : not in (1..999).");
                        }
                        break;

                    default:
                        throw new ArgumentException("Invalig tag number");
                    }
                }
            }
        }
Ejemplo n.º 46
0
        internal TbsCertificateStructure(Asn1Sequence seq)
        {
            int num = 0;

            this.seq = seq;
            if (seq[0] is DerTaggedObject)
            {
                version = DerInteger.GetInstance((Asn1TaggedObject)seq[0], isExplicit: true);
            }
            else
            {
                num     = -1;
                version = new DerInteger(0);
            }
            serialNumber = DerInteger.GetInstance(seq[num + 1]);
            signature    = AlgorithmIdentifier.GetInstance(seq[num + 2]);
            issuer       = X509Name.GetInstance(seq[num + 3]);
            Asn1Sequence asn1Sequence = (Asn1Sequence)seq[num + 4];

            startDate            = Time.GetInstance(asn1Sequence[0]);
            endDate              = Time.GetInstance(asn1Sequence[1]);
            subject              = X509Name.GetInstance(seq[num + 5]);
            subjectPublicKeyInfo = SubjectPublicKeyInfo.GetInstance(seq[num + 6]);
            for (int num2 = seq.Count - (num + 6) - 1; num2 > 0; num2--)
            {
                DerTaggedObject derTaggedObject = (DerTaggedObject)seq[num + 6 + num2];
                switch (derTaggedObject.TagNo)
                {
                case 1:
                    issuerUniqueID = DerBitString.GetInstance(derTaggedObject, isExplicit: false);
                    break;

                case 2:
                    subjectUniqueID = DerBitString.GetInstance(derTaggedObject, isExplicit: false);
                    break;

                case 3:
                    extensions = X509Extensions.GetInstance(derTaggedObject);
                    break;
                }
            }
        }
Ejemplo n.º 47
0
        public SignerInfo(
            Asn1Sequence seq)
        {
            IEnumerator e = seq.GetEnumerator();

            e.MoveNext();
            version = (DerInteger)e.Current;

            e.MoveNext();
            sid = SignerIdentifier.GetInstance(e.Current);

            e.MoveNext();
            digAlgorithm = AlgorithmIdentifier.GetInstance(e.Current);

            e.MoveNext();
            object obj = e.Current;

            if (obj is Asn1TaggedObject)
            {
                authenticatedAttributes = Asn1Set.GetInstance((Asn1TaggedObject)obj, false);

                e.MoveNext();
                digEncryptionAlgorithm = AlgorithmIdentifier.GetInstance(e.Current);
            }
            else
            {
                authenticatedAttributes = null;
                digEncryptionAlgorithm  = AlgorithmIdentifier.GetInstance(obj);
            }

            e.MoveNext();
            encryptedDigest = DerOctetString.GetInstance(e.Current);

            if (e.MoveNext())
            {
                unauthenticatedAttributes = Asn1Set.GetInstance((Asn1TaggedObject)e.Current, false);
            }
            else
            {
                unauthenticatedAttributes = null;
            }
        }
Ejemplo n.º 48
0
        public override void PerformTest()
        {
            TestTaggedObject();

            DerApplicationSpecific appSpec = (DerApplicationSpecific)Asn1Object.FromByteArray(sampleData);

            if (1 != appSpec.ApplicationTag)
            {
                Fail("wrong tag detected");
            }

            DerInteger val = new DerInteger(9);

            DerApplicationSpecific tagged = new DerApplicationSpecific(false, 3, val);

            if (!AreEqual(impData, tagged.GetEncoded()))
            {
                Fail("implicit encoding failed");
            }

            DerInteger recVal = (DerInteger)tagged.GetObject(Asn1Tags.Integer);

            if (!val.Equals(recVal))
            {
                Fail("implicit read back failed");
            }

            DerApplicationSpecific certObj = (DerApplicationSpecific)
                                             Asn1Object.FromByteArray(certData);

            if (!certObj.IsConstructed() || certObj.ApplicationTag != 33)
            {
                Fail("parsing of certificate data failed");
            }

            byte[] encoded = certObj.GetDerEncoded();

            if (!Arrays.AreEqual(certData, encoded))
            {
                Fail("re-encoding of certificate data failed");
            }
        }
        private AttributeCertificateInfo(
            Asn1Sequence seq)
        {
            if (seq.Count < 6 || seq.Count > 9)
            {
                throw new ArgumentException("Bad sequence size: " + seq.Count);
            }

            int start;

            if (seq[0] is DerInteger)   // in version 1 certs version is DEFAULT  v1(0)
            {
                this.version = DerInteger.GetInstance(seq[0]);
                start        = 1;
            }
            else
            {
                this.version = new DerInteger(0);
                start        = 0;
            }

            this.holder                 = Holder.GetInstance(seq[start]);
            this.issuer                 = AttCertIssuer.GetInstance(seq[start + 1]);
            this.signature              = AlgorithmIdentifier.GetInstance(seq[start + 2]);
            this.serialNumber           = DerInteger.GetInstance(seq[start + 3]);
            this.attrCertValidityPeriod = AttCertValidityPeriod.GetInstance(seq[start + 4]);
            this.attributes             = Asn1Sequence.GetInstance(seq[start + 5]);

            for (int i = start + 6; i < seq.Count; i++)
            {
                Asn1Encodable obj = (Asn1Encodable)seq[i];

                if (obj is DerBitString)
                {
                    this.issuerUniqueID = DerBitString.GetInstance(seq[i]);
                }
                else if (obj is Asn1Sequence || obj is X509Extensions)
                {
                    this.extensions = X509Extensions.GetInstance(seq[i]);
                }
            }
        }
Ejemplo n.º 50
0
        public void TestFormatSignature()
        {
            var random  = new Random();
            var dsa_key = new SshKey(SshVersion.SSH2, new DsaPublicKeyParameters(
                                         new BigInteger("1"),
                                         new DsaParameters(new BigInteger("2"), new BigInteger("3"),
                                                           new BigInteger("4"))));

            // test that dsa signature works when values are not full 20 bytes.
            byte[] r_bytes = new byte[19];
            byte[] s_bytes = new byte[19];
            random.NextBytes(r_bytes);
            random.NextBytes(s_bytes);
            var r         = new DerInteger(r_bytes);
            var s         = new DerInteger(s_bytes);
            var sequence  = new DerSequence(r, s);
            var signature = dsa_key.FormatSignature(sequence.GetEncoded());

            Assert.That(signature.Count(), Is.EqualTo(40));
        }
Ejemplo n.º 51
0
 public DHDomainParameters(DerInteger p, DerInteger g, DerInteger q, DerInteger j, DHValidationParms validationParms)
 {
     if (p == null)
     {
         throw new ArgumentNullException("p");
     }
     if (g == null)
     {
         throw new ArgumentNullException("g");
     }
     if (q == null)
     {
         throw new ArgumentNullException("q");
     }
     this.p = p;
     this.g = g;
     this.q = q;
     this.j = j;
     this.validationParms = validationParms;
 }
Ejemplo n.º 52
0
        private CrlIdentifier(
            Asn1Sequence seq)
        {
            if (seq == null)
            {
                throw new ArgumentNullException("seq");
            }
            if (seq.Count < 2 || seq.Count > 3)
            {
                throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
            }

            this.crlIssuer     = X509Name.GetInstance(seq[0]);
            this.crlIssuedTime = DerUtcTime.GetInstance(seq[1]);

            if (seq.Count > 2)
            {
                this.crlNumber = DerInteger.GetInstance(seq[2]);
            }
        }
Ejemplo n.º 53
0
 public static Iso4217CurrencyCode GetInstance(object obj)
 {
     //IL_0064: Unknown result type (might be due to invalid IL or missing references)
     if (obj == null || obj is Iso4217CurrencyCode)
     {
         return((Iso4217CurrencyCode)obj);
     }
     if (obj is DerInteger)
     {
         DerInteger instance = DerInteger.GetInstance(obj);
         int        intValue = instance.Value.IntValue;
         return(new Iso4217CurrencyCode(intValue));
     }
     if (obj is DerPrintableString)
     {
         DerPrintableString instance2 = DerPrintableString.GetInstance(obj);
         return(new Iso4217CurrencyCode(instance2.GetString()));
     }
     throw new ArgumentException("unknown object in GetInstance: " + Platform.GetTypeName(obj), "obj");
 }
Ejemplo n.º 54
0
        private EncryptedData(
            Asn1Sequence seq)
        {
            if (seq == null)
            {
                throw new ArgumentNullException("seq");
            }
            if (seq.Count < 2 || seq.Count > 3)
            {
                throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
            }

            this.version = DerInteger.GetInstance(seq[0]);
            this.encryptedContentInfo = EncryptedContentInfo.GetInstance(seq[1]);

            if (seq.Count > 2)
            {
                this.unprotectedAttrs = Asn1Set.GetInstance((Asn1TaggedObject)seq[2], false);
            }
        }
Ejemplo n.º 55
0
        public static ECPrivateKeyParameters GetPrivateKey(byte[] privateKey)
        {
            Asn1Object version           = new DerInteger(1);
            Asn1Object derEncodedKey     = new DerOctetString(privateKey);
            Asn1Object keyTypeParameters = new DerTaggedObject(0, new DerObjectIdentifier(@"1.2.840.10045.3.1.7"));

            Asn1Object derSequence = new DerSequence(version, derEncodedKey, keyTypeParameters);

            var base64EncodedDerSequence = Convert.ToBase64String(derSequence.GetDerEncoded());
            var pemKey = "-----BEGIN EC PRIVATE KEY-----\n";

            pemKey += base64EncodedDerSequence;
            pemKey += "\n-----END EC PRIVATE KEY----";

            StringReader            reader    = new StringReader(pemKey);
            PemReader               pemReader = new PemReader(reader);
            AsymmetricCipherKeyPair keyPair   = (AsymmetricCipherKeyPair)pemReader.ReadObject();

            return((ECPrivateKeyParameters)keyPair.Private);
        }
Ejemplo n.º 56
0
        public KeyAgreeRecipientInfo(
            Asn1Sequence seq)
        {
            int index = 0;

            version    = (DerInteger)seq[index++];
            originator = OriginatorIdentifierOrKey.GetInstance(
                (Asn1TaggedObject)seq[index++], true);

            if (seq[index] is Asn1TaggedObject)
            {
                ukm = Asn1OctetString.GetInstance(
                    (Asn1TaggedObject)seq[index++], true);
            }

            keyEncryptionAlgorithm = AlgorithmIdentifier.GetInstance(
                seq[index++]);

            recipientEncryptedKeys = (Asn1Sequence)seq[index++];
        }
Ejemplo n.º 57
0
        public TimeStampRequest Generate(string digestAlgorithmOid, byte[] digest, BigInteger nonce)
        {
            //IL_0008: Unknown result type (might be due to invalid IL or missing references)
            if (digestAlgorithmOid == null)
            {
                throw new ArgumentException("No digest algorithm specified");
            }
            DerObjectIdentifier algorithm      = new DerObjectIdentifier(digestAlgorithmOid);
            AlgorithmIdentifier hashAlgorithm  = new AlgorithmIdentifier(algorithm, DerNull.Instance);
            MessageImprint      messageImprint = new MessageImprint(hashAlgorithm, digest);
            X509Extensions      x509Extensions = null;

            if (((global::System.Collections.ICollection)extOrdering).get_Count() != 0)
            {
                x509Extensions = new X509Extensions(extOrdering, extensions);
            }
            DerInteger nonce2 = ((nonce == null) ? null : new DerInteger(nonce));

            return(new TimeStampRequest(new TimeStampReq(messageImprint, reqPolicy, nonce2, certReq, x509Extensions)));
        }
Ejemplo n.º 58
0
        protected virtual BigInteger[] DerDecode(byte[] encoding)
        {
            Asn1Sequence seq = Asn1Sequence.GetInstance(Asn1Object.FromByteArray(encoding));

            if (seq.Count != 2)
            {
                return(null);
            }

            BigInteger r = DerInteger.GetInstance(seq[0]).Value;
            BigInteger s = DerInteger.GetInstance(seq[1]).Value;

            byte[] expectedEncoding = DerEncode(r, s);
            if (!Arrays.ConstantTimeAreEqual(expectedEncoding, encoding))
            {
                return(null);
            }

            return(new BigInteger[] { r, s });
        }
Ejemplo n.º 59
0
        private async Task InitConnection()
        {
            OnConnectionEstablished?.Invoke(this, System.EventArgs.Empty);

            var publicKey = await webApi.GetRequest <GetPublicKeyResponse>("jdev/sys/getPublicKey");;

            _pubKey = Convert.FromBase64String(publicKey.Data.PublicKey.Replace("-----END CERTIFICATE-----", "").Replace("-----BEGIN CERTIFICATE-----", ""));
            string stringDataToEncrypt;

            SecureRandom random = new SecureRandom();

            _aesKey = GenerateAesKey(LoxoneUuid);

            _aesIv = new byte[128 / 8];
            random.NextBytes(_aesIv);

            stringDataToEncrypt = $"{_aesKey.ToHex(false)}:{_aesIv.ToHex(false)}";

            Asn1Object  obj = Asn1Object.FromByteArray(_pubKey);
            DerSequence publicKeySequence = (DerSequence)obj;

            DerBitString encodedPublicKey = (DerBitString)publicKeySequence[1];
            DerSequence  publicKeyDer     = (DerSequence)Asn1Object.FromByteArray(encodedPublicKey.GetBytes());

            DerInteger modulus  = (DerInteger)publicKeyDer[0];
            DerInteger exponent = (DerInteger)publicKeyDer[1];

            RsaKeyParameters keyParameters = new RsaKeyParameters(false, modulus.PositiveValue, exponent.PositiveValue);
            var encryptEngine = new Pkcs1Encoding(new RsaEngine());

            encryptEngine.Init(true, keyParameters);

            byte[] dataToEncrypt = Encoding.UTF8.GetBytes(stringDataToEncrypt);
            byte[] encryptedData = encryptEngine.ProcessBlock(dataToEncrypt, 0, dataToEncrypt.Length);

            var publicKeySelf = Convert.ToBase64String(encryptedData);

            _connectionState = ConnectionState.ExchangeKeys;

            _webSocket.Send($"jdev/sys/keyexchange/{publicKeySelf}");
        }
Ejemplo n.º 60
0
        public CertResponse(
            DerInteger certReqId,
            PkiStatusInfo status,
            CertifiedKeyPair certifiedKeyPair,
            Asn1OctetString rspInfo)
        {
            if (certReqId == null)
            {
                throw new ArgumentNullException("certReqId");
            }

            if (status == null)
            {
                throw new ArgumentNullException("status");
            }

            this.certReqId        = certReqId;
            this.status           = status;
            this.certifiedKeyPair = certifiedKeyPair;
            this.rspInfo          = rspInfo;
        }