Esempio n. 1
0
        private TimeStampResponse getTimeStamp(string URL)
        {
            //RFC3161 compliant Time Stamp Authority (TSA) server
            TimeStampResponse response = null;

            byte[] sha1Digest = new byte [20];
            TimeStampRequestGenerator reqGen = new TimeStampRequestGenerator();

            //SecureRandom randomGenerator = SecureRandom.GetInstance("SHA1PRNG");
            //long nonce = randomGenerator.NextLong();


            Org.BouncyCastle.Asn1.DerObjectIdentifier oDR = new Org.BouncyCastle.Asn1.DerObjectIdentifier("1.3.6.1.4.1.311.3.2.1");
            // request with digestAlgorithmOID, byte[] digest, java.math.BigInteger nonc
            //byte[] digest = TSToken.TimeStampInfo.GetMessageImprintDigest();

            TimeStampRequest request = reqGen.Generate(oDR, sha1Digest, Org.BouncyCastle.Math.BigInteger.ValueOf(100));

            byte[]     reqData = request.GetEncoded();
            WebRequest conn    = WebRequest.Create(URL);
            Stream     st      = conn.GetRequestStream();

            st.Write(reqData, 0, reqData.Length);
            st.Flush();
            st.Close();
            var    resposta  = conn.GetResponse();
            Stream stReponse = resposta.GetResponseStream();

            response = new TimeStampResponse(stReponse);
            stReponse.Close();
            return(response);
        }
Esempio n. 2
0
            public object GetResult()
            {
                // Org.BouncyCastle.Crypto.Tls.TlsContext
                // https://github.com/bcgit/bc-csharp/blob/master/crypto/src/crypto/tls/Chacha20Poly1305.cs
                // var ccp = new Org.BouncyCastle.Crypto.Tls.Chacha20Poly1305(null);


                Org.BouncyCastle.Asn1.DerObjectIdentifier cc  = Org.BouncyCastle.Asn1.X509.X509Name.CountryOfCitizenship;
                Org.BouncyCastle.Asn1.DerObjectIdentifier cr  = Org.BouncyCastle.Asn1.X509.X509Name.CountryOfResidence;
                Org.BouncyCastle.Asn1.DerObjectIdentifier coi = Org.BouncyCastle.Asn1.X509.X509Name.OrganizationIdentifier;

                // https://deliciousbrains.com/ssl-certificate-authority-for-local-https-development/
                // https://dzone.com/articles/creating-self-signed-certificate
                // https://stackoverflow.com/questions/10175812/how-to-create-a-self-signed-certificate-with-openssl
                // https://www.akadia.com/services/ssh_test_certificate.html
                // https://coderanch.com/how-to/javadoc/itext-2.1.7/com/lowagie/text/pdf/PdfPKCS7.X509Name.html#CN


                var oc   = Org.BouncyCastle.Asn1.X509.X509Name.C;            // Country code
                var oST  = Org.BouncyCastle.Asn1.X509.X509Name.ST;           // State or Province
                var ol   = Org.BouncyCastle.Asn1.X509.X509Name.L;            // Locality
                var oo   = Org.BouncyCastle.Asn1.X509.X509Name.O;            // Organization name
                var ou   = Org.BouncyCastle.Asn1.X509.X509Name.OU;           // Organizational Unit Name
                var ocn  = Org.BouncyCastle.Asn1.X509.X509Name.CN;           // Common name
                var oce  = Org.BouncyCastle.Asn1.X509.X509Name.E;            // email address in Verisign certificates
                var ocee = Org.BouncyCastle.Asn1.X509.X509Name.EmailAddress; // Email address (RSA PKCS#9 extension) - IA5String


                Org.BouncyCastle.Asn1.X509.X509Name a = new Org.BouncyCastle.Asn1.X509.X509Name("ou");


                throw new System.NotImplementedException();
            }
Esempio n. 3
0
 /// <summary>
 /// Get the value of an extension oid.
 /// </summary>
 private static Org.BouncyCastle.Asn1.Asn1Object GetExtensionValue(
     Org.BouncyCastle.X509.IX509Extension extension,
     Org.BouncyCastle.Asn1.DerObjectIdentifier oid)
 {
     Org.BouncyCastle.Asn1.Asn1OctetString asn1Octet = extension.GetExtensionValue(oid);
     if (asn1Octet != null)
     {
         return(Org.BouncyCastle.X509.Extension.X509ExtensionUtilities.FromExtensionValue(asn1Octet));
     }
     return(null);
 }
Esempio n. 4
0
        } // End Function SignHashInternal

        private byte[] DerEncode(byte[] hash,
                                 Org.BouncyCastle.Crypto.IDigest digest
                                 )
        {
            Org.BouncyCastle.Asn1.DerObjectIdentifier      digestOid = this.m_oidMap[digest.AlgorithmName];
            Org.BouncyCastle.Asn1.X509.AlgorithmIdentifier algid     =
                new Org.BouncyCastle.Asn1.X509.AlgorithmIdentifier(
                    digestOid, Org.BouncyCastle.Asn1.DerNull.Instance
                    );

            Org.BouncyCastle.Asn1.X509.DigestInfo di =
                new Org.BouncyCastle.Asn1.X509.DigestInfo(algid, hash);

            return(di.GetDerEncoded());
        } // End Function DerEncode
Esempio n. 5
0
        /// <summary>
        /// Gets the issuer name info.
        /// </summary>
        /// <remarks>
        /// For a list of available identifiers, see <see cref="Org.BouncyCastle.Asn1.X509.X509Name"/>.
        /// </remarks>
        /// <returns>The issuer name info.</returns>
        /// <param name="certificate">The certificate.</param>
        /// <param name="identifier">The name identifier.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="certificate"/> is <c>null</c>.
        /// </exception>
        private static string GetSubjectNameInfo(
            Org.BouncyCastle.X509.X509Certificate certificate
            , Org.BouncyCastle.Asn1.DerObjectIdentifier identifier)
        {
            if (certificate == null)
            {
                throw new System.ArgumentNullException(nameof(certificate));
            }

            // FIXME: GetValueList() should be fixed to return IList<string>
            System.Collections.IList list = certificate.SubjectDN.GetValueList(identifier);
            if (list.Count == 0)
            {
                return(string.Empty);
            }

            return((string)list[0]);
        }
Esempio n. 6
0
 private static void AddCurveParameters(TEllipticCurve curve, Org.BouncyCastle.Asn1.DerObjectIdentifier id)
 {
     Org.BouncyCastle.Asn1.X9.X9ECParameters ecP = Org.BouncyCastle.Crypto.EC.CustomNamedCurves.GetByOid(id);
     _CurveParameters.Add(curve, new Org.BouncyCastle.Crypto.Parameters.ECDomainParameters(ecP.Curve, ecP.G, ecP.N, ecP.H, ecP.GetSeed()));
 }