public static X509CertificateStructure GetInstance( Asn1TaggedObject obj, bool explicitly) { return(GetInstance(Asn1Sequence.GetInstance(obj, explicitly))); }
public static AsymmetricKeyParameter CreateKey( SubjectPublicKeyInfo keyInfo) { AlgorithmIdentifier algID = keyInfo.AlgorithmID; DerObjectIdentifier algOid = algID.Algorithm; // TODO See RSAUtil.isRsaOid in Java build if (algOid.Equals(PkcsObjectIdentifiers.RsaEncryption) || algOid.Equals(X509ObjectIdentifiers.IdEARsa) || algOid.Equals(PkcsObjectIdentifiers.IdRsassaPss) || algOid.Equals(PkcsObjectIdentifiers.IdRsaesOaep)) { RsaPublicKeyStructure pubKey = RsaPublicKeyStructure.GetInstance( keyInfo.GetPublicKey()); return(new RsaKeyParameters(false, pubKey.Modulus, pubKey.PublicExponent)); } else if (algOid.Equals(X9ObjectIdentifiers.DHPublicNumber)) { Asn1Sequence seq = Asn1Sequence.GetInstance(algID.Parameters.ToAsn1Object()); DHPublicKey dhPublicKey = DHPublicKey.GetInstance(keyInfo.GetPublicKey()); BigInteger y = dhPublicKey.Y.Value; if (IsPkcsDHParam(seq)) { return(ReadPkcsDHParam(algOid, y, seq)); } DHDomainParameters dhParams = DHDomainParameters.GetInstance(seq); BigInteger p = dhParams.P.Value; BigInteger g = dhParams.G.Value; BigInteger q = dhParams.Q.Value; BigInteger j = null; if (dhParams.J != null) { j = dhParams.J.Value; } DHValidationParameters validation = null; DHValidationParms dhValidationParms = dhParams.ValidationParms; if (dhValidationParms != null) { byte[] seed = dhValidationParms.Seed.GetBytes(); BigInteger pgenCounter = dhValidationParms.PgenCounter.Value; // TODO Check pgenCounter size? validation = new DHValidationParameters(seed, pgenCounter.IntValue); } return(new DHPublicKeyParameters(y, new DHParameters(p, g, q, j, validation))); } else if (algOid.Equals(PkcsObjectIdentifiers.DhKeyAgreement)) { Asn1Sequence seq = Asn1Sequence.GetInstance(algID.Parameters.ToAsn1Object()); DerInteger derY = (DerInteger)keyInfo.GetPublicKey(); return(ReadPkcsDHParam(algOid, derY.Value, seq)); } else if (algOid.Equals(OiwObjectIdentifiers.ElGamalAlgorithm)) { ElGamalParameter para = new ElGamalParameter( Asn1Sequence.GetInstance(algID.Parameters.ToAsn1Object())); DerInteger derY = (DerInteger)keyInfo.GetPublicKey(); return(new ElGamalPublicKeyParameters( derY.Value, new ElGamalParameters(para.P, para.G))); } else if (algOid.Equals(X9ObjectIdentifiers.IdDsa) || algOid.Equals(OiwObjectIdentifiers.DsaWithSha1)) { DerInteger derY = (DerInteger)keyInfo.GetPublicKey(); Asn1Encodable ae = algID.Parameters; DsaParameters parameters = null; if (ae != null) { DsaParameter para = DsaParameter.GetInstance(ae.ToAsn1Object()); parameters = new DsaParameters(para.P, para.Q, para.G); } return(new DsaPublicKeyParameters(derY.Value, parameters)); } else if (algOid.Equals(X9ObjectIdentifiers.IdECPublicKey)) { X962Parameters para = new X962Parameters(algID.Parameters.ToAsn1Object()); X9ECParameters x9; if (para.IsNamedCurve) { x9 = ECKeyPairGenerator.FindECCurveByOid((DerObjectIdentifier)para.Parameters); } else { x9 = new X9ECParameters((Asn1Sequence)para.Parameters); } Asn1OctetString key = new DerOctetString(keyInfo.PublicKeyData.GetBytes()); X9ECPoint derQ = new X9ECPoint(x9.Curve, key); ECPoint q = derQ.Point; if (para.IsNamedCurve) { return(new ECPublicKeyParameters("EC", q, (DerObjectIdentifier)para.Parameters)); } ECDomainParameters dParams = new ECDomainParameters(x9.Curve, x9.G, x9.N, x9.H, x9.GetSeed()); return(new ECPublicKeyParameters(q, dParams)); } else if (algOid.Equals(CryptoProObjectIdentifiers.GostR3410x2001)) { Gost3410PublicKeyAlgParameters gostParams = new Gost3410PublicKeyAlgParameters( (Asn1Sequence)algID.Parameters); Asn1OctetString key; try { key = (Asn1OctetString)keyInfo.GetPublicKey(); } catch (IOException) { throw new ArgumentException("invalid info structure in GOST3410 public key"); } byte[] keyEnc = key.GetOctets(); byte[] x = new byte[32]; byte[] y = new byte[32]; for (int i = 0; i != y.Length; i++) { x[i] = keyEnc[32 - 1 - i]; } for (int i = 0; i != x.Length; i++) { y[i] = keyEnc[64 - 1 - i]; } ECDomainParameters ecP = ECGost3410NamedCurves.GetByOid(gostParams.PublicKeyParamSet); if (ecP == null) { return(null); } ECPoint q = ecP.Curve.CreatePoint(new BigInteger(1, x), new BigInteger(1, y)); return(new ECPublicKeyParameters("ECGOST3410", q, gostParams.PublicKeyParamSet)); } else if (algOid.Equals(CryptoProObjectIdentifiers.GostR3410x94)) { Gost3410PublicKeyAlgParameters algParams = new Gost3410PublicKeyAlgParameters( (Asn1Sequence)algID.Parameters); DerOctetString derY; try { derY = (DerOctetString)keyInfo.GetPublicKey(); } catch (IOException) { throw new ArgumentException("invalid info structure in GOST3410 public key"); } byte[] keyEnc = derY.GetOctets(); byte[] keyBytes = new byte[keyEnc.Length]; for (int i = 0; i != keyEnc.Length; i++) { keyBytes[i] = keyEnc[keyEnc.Length - 1 - i]; // was little endian } BigInteger y = new BigInteger(1, keyBytes); return(new Gost3410PublicKeyParameters(y, algParams.PublicKeyParamSet)); } else if (algOid.Equals(EdECObjectIdentifiers.id_X25519)) { return(new X25519PublicKeyParameters(GetRawKey(keyInfo, X25519PublicKeyParameters.KeySize), 0)); } else if (algOid.Equals(EdECObjectIdentifiers.id_X448)) { return(new X448PublicKeyParameters(GetRawKey(keyInfo, X448PublicKeyParameters.KeySize), 0)); } else if (algOid.Equals(EdECObjectIdentifiers.id_Ed25519)) { return(new Ed25519PublicKeyParameters(GetRawKey(keyInfo, Ed25519PublicKeyParameters.KeySize), 0)); } else if (algOid.Equals(EdECObjectIdentifiers.id_Ed448)) { return(new Ed448PublicKeyParameters(GetRawKey(keyInfo, Ed448PublicKeyParameters.KeySize), 0)); } else if ( algOid.Equals(RosstandartObjectIdentifiers.id_tc26_gost_3410_12_256) || algOid.Equals(RosstandartObjectIdentifiers.id_tc26_gost_3410_12_512)) { byte[] keyEnc = ((DerOctetString)Asn1Object.FromByteArray(keyInfo.PublicKeyData.GetOctets())).str; int fieldSize = 32; if (algOid.Equals(RosstandartObjectIdentifiers.id_tc26_gost_3410_12_512)) { fieldSize = 64; } int keySize = 2 * fieldSize; byte[] x9Encoding = new byte[1 + keySize]; x9Encoding[0] = 0x04; for (int i = 1; i <= fieldSize; ++i) { x9Encoding[i] = keyEnc[fieldSize - i]; x9Encoding[i + fieldSize] = keyEnc[keySize - i]; } Gost3410PublicKeyAlgParameters gostParams = Gost3410PublicKeyAlgParameters.GetInstance(keyInfo.AlgorithmID.Parameters); ECGost3410Parameters ecDomainParameters = new ECGost3410Parameters( new ECNamedDomainParameters(gostParams.PublicKeyParamSet, ECGost3410NamedCurves.GetByOid(gostParams.PublicKeyParamSet)), gostParams.PublicKeyParamSet, gostParams.DigestParamSet, gostParams.EncryptionParamSet); return(new ECPublicKeyParameters(ecDomainParameters.Curve.DecodePoint(x9Encoding), ecDomainParameters)); } else { throw new SecurityUtilityException("algorithm identifier in public key not recognised: " + algOid); } }
public static ResponseData GetInstance( Asn1TaggedObject obj, bool explicitly) { return(GetInstance(Asn1Sequence.GetInstance(obj, explicitly))); }
public static DsaParameter GetInstance( Asn1TaggedObject obj, bool explicitly) { return(GetInstance(Asn1Sequence.GetInstance(obj, explicitly))); }
private PkiPublicationInfo(Asn1Sequence seq) { action = DerInteger.GetInstance(seq[0]); pubInfos = Asn1Sequence.GetInstance(seq[1]); }
public static ECGost3410ParamSetParameters GetInstance( Asn1TaggedObject obj, bool explicitly) { return(GetInstance(Asn1Sequence.GetInstance(obj, explicitly))); }
public static DistributionPoint GetInstance(Asn1TaggedObject obj, bool explicitly) { return(DistributionPoint.GetInstance(Asn1Sequence.GetInstance(obj, explicitly))); }
/** * return an AuthenticatedData object from a tagged object. * * @param obj the tagged object holding the object we want. * @param isExplicit true if the object is meant to be explicitly * tagged false otherwise. * @throws ArgumentException if the object held by the * tagged object cannot be converted. */ public static AuthenticatedData GetInstance( Asn1TaggedObject obj, bool isExplicit) { return(GetInstance(Asn1Sequence.GetInstance(obj, isExplicit))); }
public static AsymmetricKeyParameter CreateKey( PrivateKeyInfo keyInfo) { AlgorithmIdentifier algID = keyInfo.AlgorithmID; DerObjectIdentifier algOid = algID.ObjectID; // TODO See RSAUtil.isRsaOid in Java build if (algOid.Equals(PkcsObjectIdentifiers.RsaEncryption) || algOid.Equals(X509ObjectIdentifiers.IdEARsa) || algOid.Equals(PkcsObjectIdentifiers.IdRsassaPss) || algOid.Equals(PkcsObjectIdentifiers.IdRsaesOaep)) { RsaPrivateKeyStructure keyStructure = new RsaPrivateKeyStructure( Asn1Sequence.GetInstance(keyInfo.PrivateKey)); return(new RsaPrivateCrtKeyParameters( keyStructure.Modulus, keyStructure.PublicExponent, keyStructure.PrivateExponent, keyStructure.Prime1, keyStructure.Prime2, keyStructure.Exponent1, keyStructure.Exponent2, keyStructure.Coefficient)); } // TODO? // else if (algOid.Equals(X9ObjectIdentifiers.DHPublicNumber)) else if (algOid.Equals(PkcsObjectIdentifiers.DhKeyAgreement)) { DHParameter para = new DHParameter( Asn1Sequence.GetInstance(algID.Parameters.ToAsn1Object())); DerInteger derX = (DerInteger)keyInfo.PrivateKey; BigInteger lVal = para.L; int l = lVal == null ? 0 : lVal.IntValue; DHParameters dhParams = new DHParameters(para.P, para.G, null, l); return(new DHPrivateKeyParameters(derX.Value, dhParams, algOid)); } else if (algOid.Equals(OiwObjectIdentifiers.ElGamalAlgorithm)) { ElGamalParameter para = new ElGamalParameter( Asn1Sequence.GetInstance(algID.Parameters.ToAsn1Object())); DerInteger derX = (DerInteger)keyInfo.PrivateKey; return(new ElGamalPrivateKeyParameters( derX.Value, new ElGamalParameters(para.P, para.G))); } else if (algOid.Equals(X9ObjectIdentifiers.IdDsa)) { DerInteger derX = (DerInteger)keyInfo.PrivateKey; Asn1Encodable ae = algID.Parameters; DsaParameters parameters = null; if (ae != null) { DsaParameter para = DsaParameter.GetInstance(ae.ToAsn1Object()); parameters = new DsaParameters(para.P, para.Q, para.G); } return(new DsaPrivateKeyParameters(derX.Value, parameters)); } else if (algOid.Equals(X9ObjectIdentifiers.IdECPublicKey)) { X962Parameters para = new X962Parameters(algID.Parameters.ToAsn1Object()); X9ECParameters ecP; if (para.IsNamedCurve) { ecP = ECKeyPairGenerator.FindECCurveByOid((DerObjectIdentifier)para.Parameters); } else { ecP = new X9ECParameters((Asn1Sequence)para.Parameters); } ECDomainParameters dParams = new ECDomainParameters( ecP.Curve, ecP.G, ecP.N, ecP.H, ecP.GetSeed()); ECPrivateKeyStructure ec = new ECPrivateKeyStructure( Asn1Sequence.GetInstance(keyInfo.PrivateKey)); return(new ECPrivateKeyParameters(ec.GetKey(), dParams)); } else if (algOid.Equals(CryptoProObjectIdentifiers.GostR3410x2001)) { Gost3410PublicKeyAlgParameters gostParams = new Gost3410PublicKeyAlgParameters( Asn1Sequence.GetInstance(algID.Parameters.ToAsn1Object())); ECPrivateKeyStructure ec = new ECPrivateKeyStructure( Asn1Sequence.GetInstance(keyInfo.PrivateKey)); ECDomainParameters ecP = ECGost3410NamedCurves.GetByOid(gostParams.PublicKeyParamSet); if (ecP == null) { return(null); } return(new ECPrivateKeyParameters("ECGOST3410", ec.GetKey(), gostParams.PublicKeyParamSet)); } else if (algOid.Equals(CryptoProObjectIdentifiers.GostR3410x94)) { Gost3410PublicKeyAlgParameters gostParams = new Gost3410PublicKeyAlgParameters( Asn1Sequence.GetInstance(algID.Parameters.ToAsn1Object())); DerOctetString derX = (DerOctetString)keyInfo.PrivateKey; byte[] keyEnc = derX.GetOctets(); byte[] keyBytes = new byte[keyEnc.Length]; for (int i = 0; i != keyEnc.Length; i++) { keyBytes[i] = keyEnc[keyEnc.Length - 1 - i]; // was little endian } BigInteger x = new BigInteger(1, keyBytes); return(new Gost3410PrivateKeyParameters(x, gostParams.PublicKeyParamSet)); } else { throw new SecurityUtilityException("algorithm identifier in key not recognised"); } }
public static OcspRequest GetInstance( Asn1TaggedObject obj, bool explicitly) { return(GetInstance(Asn1Sequence.GetInstance(obj, explicitly))); }
public static AttCertValidityPeriod GetInstance(Asn1TaggedObject obj, bool explicitly) { return(GetInstance(Asn1Sequence.GetInstance(obj, explicitly))); }
public static AttributeCertificateInfo GetInstance( Asn1TaggedObject obj, bool isExplicit) { return(GetInstance(Asn1Sequence.GetInstance(obj, isExplicit))); }
public static PKMacValue GetInstance(Asn1TaggedObject obj, bool isExplicit) { return(GetInstance(Asn1Sequence.GetInstance(obj, isExplicit))); }
public static ExtendedKeyUsage GetInstance( Asn1TaggedObject obj, bool explicitly) { return(GetInstance(Asn1Sequence.GetInstance(obj, explicitly))); }
public static ObjectDigestInfo GetInstance( Asn1TaggedObject obj, bool isExplicit) { return(GetInstance(Asn1Sequence.GetInstance(obj, isExplicit))); }
public virtual bool Match( object obj) { X509Certificate c = obj as X509Certificate; if (c == null) { return(false); } if (!MatchExtension(authorityKeyIdentifier, c, X509Extensions.AuthorityKeyIdentifier)) { return(false); } if (basicConstraints != -1) { int bc = c.GetBasicConstraints(); if (basicConstraints == -2) { if (bc != -1) { return(false); } } else { if (bc < basicConstraints) { return(false); } } } if (certificate != null && !certificate.Equals(c)) { return(false); } if (certificateValid != null && !c.IsValid(certificateValid.Value)) { return(false); } if (extendedKeyUsage != null) { IList eku = c.GetExtendedKeyUsage(); // Note: if no extended key usage set, all key purposes are implicitly allowed if (eku != null) { foreach (DerObjectIdentifier oid in extendedKeyUsage) { if (!eku.Contains(oid.Id)) { return(false); } } } } if (issuer != null && !issuer.Equivalent(c.IssuerDN, !ignoreX509NameOrdering)) { return(false); } if (keyUsage != null) { bool[] ku = c.GetKeyUsage(); // Note: if no key usage set, all key purposes are implicitly allowed if (ku != null) { for (int i = 0; i < 9; ++i) { if (keyUsage[i] && !ku[i]) { return(false); } } } } if (policy != null) { Asn1OctetString extVal = c.GetExtensionValue(X509Extensions.CertificatePolicies); if (extVal == null) { return(false); } Asn1Sequence certPolicies = Asn1Sequence.GetInstance( X509ExtensionUtilities.FromExtensionValue(extVal)); if (policy.Count < 1 && certPolicies.Count < 1) { return(false); } bool found = false; foreach (PolicyInformation pi in certPolicies) { if (policy.Contains(pi.PolicyIdentifier)) { found = true; break; } } if (!found) { return(false); } } if (privateKeyValid != null) { Asn1OctetString extVal = c.GetExtensionValue(X509Extensions.PrivateKeyUsagePeriod); if (extVal == null) { return(false); } PrivateKeyUsagePeriod pkup = PrivateKeyUsagePeriod.GetInstance( X509ExtensionUtilities.FromExtensionValue(extVal)); DateTime dt = privateKeyValid.Value; DateTime notAfter = pkup.NotAfter.ToDateTime(); DateTime notBefore = pkup.NotBefore.ToDateTime(); if (dt.CompareTo(notAfter) > 0 || dt.CompareTo(notBefore) < 0) { return(false); } } if (serialNumber != null && !serialNumber.Equals(c.SerialNumber)) { return(false); } if (subject != null && !subject.Equivalent(c.SubjectDN, !ignoreX509NameOrdering)) { return(false); } if (!MatchExtension(subjectKeyIdentifier, c, X509Extensions.SubjectKeyIdentifier)) { return(false); } if (subjectPublicKey != null && !subjectPublicKey.Equals(GetSubjectPublicKey(c))) { return(false); } if (subjectPublicKeyAlgID != null && !subjectPublicKeyAlgID.Equals(GetSubjectPublicKey(c).AlgorithmID)) { return(false); } return(true); }
private ProfessionInfo(Asn1Sequence seq) { if (seq.Count > 5) { throw new ArgumentException("Bad sequence size: " + seq.Count); } IEnumerator enumerator = seq.GetEnumerator(); enumerator.MoveNext(); Asn1Encodable asn1Encodable = (Asn1Encodable)enumerator.Current; if (asn1Encodable is Asn1TaggedObject) { Asn1TaggedObject asn1TaggedObject = (Asn1TaggedObject)asn1Encodable; if (asn1TaggedObject.TagNo != 0) { throw new ArgumentException("Bad tag number: " + asn1TaggedObject.TagNo); } this.namingAuthority = NamingAuthority.GetInstance(asn1TaggedObject, true); enumerator.MoveNext(); asn1Encodable = (Asn1Encodable)enumerator.Current; } this.professionItems = Asn1Sequence.GetInstance(asn1Encodable); if (enumerator.MoveNext()) { asn1Encodable = (Asn1Encodable)enumerator.Current; if (asn1Encodable is Asn1Sequence) { this.professionOids = Asn1Sequence.GetInstance(asn1Encodable); } else if (asn1Encodable is DerPrintableString) { this.registrationNumber = DerPrintableString.GetInstance(asn1Encodable).GetString(); } else { if (!(asn1Encodable is Asn1OctetString)) { throw new ArgumentException("Bad object encountered: " + asn1Encodable.GetType().Name); } this.addProfessionInfo = Asn1OctetString.GetInstance(asn1Encodable); } } if (enumerator.MoveNext()) { asn1Encodable = (Asn1Encodable)enumerator.Current; if (asn1Encodable is DerPrintableString) { this.registrationNumber = DerPrintableString.GetInstance(asn1Encodable).GetString(); } else { if (!(asn1Encodable is DerOctetString)) { throw new ArgumentException("Bad object encountered: " + asn1Encodable.GetType().Name); } this.addProfessionInfo = (DerOctetString)asn1Encodable; } } if (!enumerator.MoveNext()) { return; } asn1Encodable = (Asn1Encodable)enumerator.Current; if (asn1Encodable is DerOctetString) { this.addProfessionInfo = (DerOctetString)asn1Encodable; return; } throw new ArgumentException("Bad object encountered: " + asn1Encodable.GetType().Name); }
public static GeneralNames GetInstance( Asn1TaggedObject obj, bool explicitly) { return(GetInstance(Asn1Sequence.GetInstance(obj, explicitly))); }
public static RsaPrivateKeyStructure GetInstance(Asn1TaggedObject obj, bool isExplicit) { return(GetInstance(Asn1Sequence.GetInstance(obj, isExplicit))); }
public static X509Extensions GetInstance( Asn1TaggedObject obj, bool explicitly) { return(GetInstance(Asn1Sequence.GetInstance(obj, explicitly))); }
public static TbsCertificateList GetInstance( Asn1TaggedObject obj, bool explicitly) { return(GetInstance(Asn1Sequence.GetInstance(obj, explicitly))); }
public static CrlDistPoint GetInstance(Asn1TaggedObject obj, bool explicitly) { return(GetInstance(Asn1Sequence.GetInstance(obj, explicitly))); }
public static OriginatorInfo GetInstance(Asn1TaggedObject obj, bool explicitly) { return(GetInstance(Asn1Sequence.GetInstance(obj, explicitly))); }
public static NamingAuthority GetInstance( Asn1TaggedObject obj, bool isExplicit) { return(GetInstance(Asn1Sequence.GetInstance(obj, isExplicit))); }
public static PopoSigningKey GetInstance(Asn1TaggedObject obj, bool isExplicit) { return(GetInstance(Asn1Sequence.GetInstance(obj, isExplicit))); }
public static AlgorithmIdentifier GetInstance( Asn1TaggedObject obj, bool explicitly) { return(GetInstance(Asn1Sequence.GetInstance(obj, explicitly))); }
/** * return a KeyAgreeRecipientInfo object from a tagged object. * * @param obj the tagged object holding the object we want. * @param explicitly true if the object is meant to be explicitly * tagged false otherwise. * @exception ArgumentException if the object held by the * tagged object cannot be converted. */ public static KeyAgreeRecipientInfo GetInstance( Asn1TaggedObject obj, bool explicitly) { return(GetInstance(Asn1Sequence.GetInstance(obj, explicitly))); }
public static IssuerSerial GetInstance( Asn1TaggedObject obj, bool explicitly) { return(GetInstance(Asn1Sequence.GetInstance(obj, explicitly))); }
public static PkiFreeText GetInstance( Asn1TaggedObject obj, bool isExplicit) { return(GetInstance(Asn1Sequence.GetInstance(obj, isExplicit))); }
public static GeneralSubtree GetInstance( Asn1TaggedObject o, bool isExplicit) { return(new GeneralSubtree(Asn1Sequence.GetInstance(o, isExplicit))); }