Beispiel #1
0
        X509Certificate parseCertificate()
        {
            if (sData != null && sDataObjectCount != sData.getCertificates().size())
            {
                return(new X509Certificate(
                           ASN1Sequence.getInstance(
                               sData.getCertificates().getObjectAt(sDataObjectCount++))));
            }

            sData            = null;
            sDataObjectCount = 0;

            long pos = inStr.Position;

            int tag = inStr.ReadByte();

            if (tag == -1)
            {
                return(null);
            }

            if (tag != 0x30)  // assume ascii PEM encoded.
            {
                inStr.Seek(pos, SeekOrigin.Begin);
                return(readPEMCertificate());
            }
            else if (inStr.ReadByte() == 0x80)    // assume BER encoded.
            {
                inStr.Seek(pos, SeekOrigin.Begin);
                return(readPKCS7Certificate());
            }
            else
            {
                inStr.Seek(pos, SeekOrigin.Begin);
                return(readDERCertificate(inStr));
            }
        }
Beispiel #2
0
        private X509Certificate readPKCS7Certificate()
        {
            ASN1InputStream dIn = new ASN1InputStream(inStr);
            ASN1Sequence    seq = (ASN1Sequence)dIn.readObject();

            if (seq.size() > 1 && seq.getObjectAt(0) is DERObjectIdentifier)
            {
                if (seq.getObjectAt(0).Equals(PKCSObjectIdentifiers.signedData))
                {
                    sData = new SignedData(ASN1Sequence.getInstance((ASN1TaggedObject)seq.getObjectAt(1), true));
                    return(new X509Certificate(ASN1Sequence.getInstance(sData.getCertificates().getObjectAt(sDataObjectCount++))));
                }
            }
            return(new X509Certificate(ASN1Sequence.getInstance(seq)));
        }