Пример #1
0
        public static bool AddCACertificate(string certName, X509Certificate cert)
        {
            if (certName == null || cert == null)
            {
                throw new ArgumentException();
            }

            if (-1 != s_CACertData.Names.IndexOf(certName))
            {
                throw new ArgumentException();
            }

            s_CACertData.Names.Add(certName);
            s_CACertData.Values.Add(cert);

            s_ewrCALookup.Target = s_CACertData;
            s_ewrCALookup.PushBackIntoRecoverList();

            if (OnCACertificateChange != null)
            {
                OnCACertificateChange(CertificateNotificationType.Added, certName);
            }

            return(true);
        }
Пример #2
0
            internal X509Certificate Get(string certName)
            {
                int idx = m_names.IndexOf(certName);

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

                ExtendedWeakReference ewr = ExtendedWeakReference.Recover(typeof(_CertStore_), (uint)m_values[idx]);

                if (ewr == null)
                {
                    return(null);
                }

                X509Certificate cert = ewr.Target as X509Certificate;

                if (cert.Issuer == null || cert.Issuer.Length == 0)
                {
                    cert.Initialize();
                }

                ewr.PushBackIntoRecoverList();

                return(cert);
            }
Пример #3
0
        public static bool AddPersonalCertificate(string certName, X509Certificate cert)
        {
            if (certName == null || cert == null)
            {
                throw new ArgumentException();
            }

            if (!s_personalCertData.Add(certName, cert))
            {
                throw new ArgumentException();
            }

            s_ewrCertLookup.Target = s_personalCertData;
            s_ewrCertLookup.PushBackIntoRecoverList();

            return(true);
        }
Пример #4
0
        /// <summary>
        /// Save addres mapping to persistent storage
        /// </summary>
        public void Save()
        {
#if MICROFRAMEWORK
            ExtendedWeakReference ewr = ExtendedWeakReference.RecoverOrCreate(typeof(Addresses), 0, ExtendedWeakReference.c_SurvivePowerdown);
            if (ewr != null)
            {
                ewr.Priority = (int)ExtendedWeakReference.PriorityLevel.System;
                ewr.Target   = _addresses;
                ewr.PushBackIntoRecoverList();
            }
#endif
        }
Пример #5
0
            private uint GetNextFreeIndex()
            {
                uint idx = 0;

                if (m_values.Count > 0)
                {
                    idx = (uint)m_values[m_values.Count - 1] + 1;

                    // overflow - collapse indexes
                    if (idx == 0)
                    {
                        for (int i = 0; i < m_values.Count; i++)
                        {
                            // if the current index matches the lookup value then we are already in the correct position
                            if (idx == (uint)m_values[i])
                            {
                                idx++;
                            }
                            else
                            {
                                // collapse cert indexes
                                ExtendedWeakReference ewr = ExtendedWeakReference.Recover(typeof(_CertStore_), (uint)m_values[i]);

                                if (ewr != null)
                                {
                                    X509Certificate cert = ewr.Target as X509Certificate;
                                    ewr.Target = null;

                                    ewr          = new ExtendedWeakReference(cert, typeof(_CertStore_), idx, ExtendedWeakReference.c_SurvivePowerdown);
                                    ewr.Priority = (int)ExtendedWeakReference.PriorityLevel.Critical;
                                    ewr.Target   = cert;
                                    ewr.PushBackIntoRecoverList();

                                    m_values[i] = (uint)idx;

                                    // increment active index count only if we have a valid EWR certificate
                                    idx++;
                                }
                            }
                        }
                    }
                }

                return(idx);
            }
Пример #6
0
        private void On()
        {
            lock (_hal)
            {
                _hal._powerPort.Write(true);
                Thread.Sleep(200);

                SWReset();
                InitRegisters();
                StartOsc();
                EnableInterrupts();
                Channel    = _channel;
                Power      = _rfPower;
                _rxEnabled = false;

                // CC2420 ext address is a random value. Recover/generate ext address from flash if needed
                {
                    CC2420Address addr = null;
                    // try to recover address
                    ExtendedWeakReference ewr = ExtendedWeakReference.Recover(typeof(CC2420Address), 0);
                    if (addr != null)
                    {
                        // address recovered from flash
                        _hal.ExtendedAddress = addr.extAddress;
                    }
                    else
                    {
                        // save current address in flash
                        ewr = ExtendedWeakReference.RecoverOrCreate(typeof(CC2420Address), 0, ExtendedWeakReference.c_SurvivePowerdown);
                        if (ewr != null)
                        {
                            addr            = new CC2420Address();
                            addr.extAddress = _hal.ExtendedAddress;
                            ewr.Priority    = (int)ExtendedWeakReference.PriorityLevel.System;
                            ewr.Target      = addr;
                            ewr.PushBackIntoRecoverList();
                        }
                    }
                }
            }
        }
Пример #7
0
            internal bool Update(string certName, X509Certificate cert)
            {
                int idx = m_names.IndexOf(certName);

                if (-1 == idx)
                {
                    return(false);
                }

                ExtendedWeakReference ewr = ExtendedWeakReference.Recover(typeof(_CertStore_), (uint)m_values[idx]);

                if (ewr == null)
                {
                    return(false);
                }

                ewr.Target = cert;
                ewr.PushBackIntoRecoverList();

                return(true);
            }
Пример #8
0
            internal bool Add(string certName, X509Certificate cert)
            {
                if (-1 != m_names.IndexOf(certName))
                {
                    return(false);
                }

                m_names.Add(certName);

                uint idx = GetNextFreeIndex();

                m_values.Add(idx);

                ExtendedWeakReference ewr = ExtendedWeakReference.RecoverOrCreate(typeof(_CertStore_), (uint)idx, ExtendedWeakReference.c_SurvivePowerdown);

                ewr.Priority = (int)ExtendedWeakReference.PriorityLevel.Critical;

                ewr.Target = cert;

                ewr.PushBackIntoRecoverList();

                return(true);
            }