private CachedEncoding GetCachedEncoding()
        {
            lock (cacheLock)
            {
                if (null != cachedEncoding)
                {
                    return(cachedEncoding);
                }
            }

            byte[] encoding = null;
            CertificateEncodingException exception = null;

            try
            {
                encoding = c.GetEncoded(Asn1Encodable.Der);
            }
            catch (IOException e)
            {
                exception = new CertificateEncodingException("Failed to DER-encode certificate", e);
            }

            CachedEncoding temp = new CachedEncoding(encoding, exception);

            lock (cacheLock)
            {
                if (null == cachedEncoding)
                {
                    cachedEncoding = temp;
                }

                return(cachedEncoding);
            }
        }
Exemplo n.º 2
0
        public static RTCDtlsFingerprint Fingerprint(X509CertificateStructure c)
        {
            IDigest sha256 = DigestUtilities.GetDigest(HashAlgorithmTag.Sha256.ToString());

            byte[] der        = c.GetEncoded();
            byte[] sha256Hash = DigestOf(sha256, der);

            return(new RTCDtlsFingerprint
            {
                algorithm = sha256.AlgorithmName.ToLower(),
                value = sha256Hash.HexStr(':')
            });
        }
Exemplo n.º 3
0
        private void checkValues(
            RequestedCertificate requested,
            RequestedCertificate.Choice type,
            byte[]                                          certOctets,
            X509CertificateStructure cert)
        {
            checkMandatoryField("certType", (int)type, (int)requested.Type);

            if (requested.Type == RequestedCertificate.Choice.Certificate)
            {
                checkMandatoryField("certificate", cert.GetEncoded(), requested.GetCertificateBytes());
            }
            else
            {
                checkMandatoryField("certificateOctets", certOctets, requested.GetCertificateBytes());
            }
        }
Exemplo n.º 4
0
        internal static string Fingerprint(X509CertificateStructure c)
        {
            byte[] der      = c.GetEncoded();
            byte[] sha1     = Sha256DigestOf(der);
            byte[] hexBytes = Hex.Encode(sha1);
            string hex      = Encoding.ASCII.GetString(hexBytes).ToUpper(CultureInfo.InvariantCulture);

            StringBuilder fp = new StringBuilder();
            int           i  = 0;

            fp.Append(hex.Substring(i, 2));
            while ((i += 2) < hex.Length)
            {
                fp.Append(':');
                fp.Append(hex.Substring(i, 2));
            }
            return(fp.ToString());
        }
Exemplo n.º 5
0
        public static RTCDtlsFingerprint Fingerprint(string hashAlgorithm, X509CertificateStructure c)
        {
            if (!IsHashSupported(hashAlgorithm))
            {
                throw new ApplicationException($"Hash algorithm {hashAlgorithm} is not supported for DTLS fingerprints.");
            }

            IDigest digestAlgorithm = DigestUtilities.GetDigest(hashAlgorithm.ToString());

            byte[] der  = c.GetEncoded();
            byte[] hash = DigestOf(digestAlgorithm, der);

            return(new RTCDtlsFingerprint
            {
                algorithm = digestAlgorithm.AlgorithmName.ToLower(),
                value = hash.HexStr(':')
            });
        }
Exemplo n.º 6
0
 public byte[] GetCertificateBytes()
 {
     if (cert != null)
     {
         try
         {
             return(cert.GetEncoded());
         }
         catch (IOException arg)
         {
             throw new InvalidOperationException("can't decode certificate: " + arg);
         }
     }
     if (publicKeyCert != null)
     {
         return(publicKeyCert);
     }
     return(attributeCert);
 }
 public byte[] GetCertificateBytes()
 {
     //IL_0017: Expected O, but got Unknown
     //IL_0022: Unknown result type (might be due to invalid IL or missing references)
     if (cert != null)
     {
         try
         {
             return(cert.GetEncoded());
         }
         catch (IOException val)
         {
             IOException val2 = val;
             throw new InvalidOperationException(string.Concat((object)"can't decode certificate: ", (object)val2));
         }
     }
     if (publicKeyCert != null)
     {
         return(publicKeyCert);
     }
     return(attributeCert);
 }
Exemplo n.º 8
0
 public Pkcs12SafeBagBuilder(X509CertificateStructure certificate)
 {
     this.bagType  = PkcsObjectIdentifiers.CertBag;
     this.bagValue = new CertBag(PkcsObjectIdentifiers.X509Certificate, new DerOctetString(certificate.GetEncoded()));
 }