Beispiel #1
0
        /**
         * Add a friend to socialvpn from an X509 certificate.
         * @param certData the X509 certificate as a byte array.
         * @param key the dht_key containing fingerprint.
         */
        public void AddCertificate(byte[] certData, string key)
        {
            Certificate cert   = new Certificate(certData);
            SocialUser  friend = new SocialUser(cert);

            string[] parts       = key.Split(':');
            string   uid         = parts[1];
            string   fingerprint = parts[2];

            // Verification on the certificate by email and fingerprint
            if (friend.DhtKey == _local_user.DhtKey ||
                _friends.ContainsKey(friend.DhtKey))
            {
                ProtocolLog.Write(SocialLog.SVPNLog, "ADD CERT KEY FOUND: " +
                                  key);
            }
            else if (fingerprint != friend.Fingerprint || uid != friend.Uid)
            {
                ProtocolLog.Write(SocialLog.SVPNLog, "ADD CERT KEY MISMATCH: " +
                                  key + " " + friend.DhtKey);
            }
            else
            {
                friend.Alias = CreateAlias(friend.Uid, friend.PCID);

                // Save certificate to file system
                SocialUtils.SaveCertificate(cert, _cert_dir);

                // Add certificates to handler
                _bso.CertificateHandler.AddCACertificate(cert.X509);

                // Add friend to list
                _friends.Add(friend.DhtKey, friend);

                // Temporary
                AddFriend(friend);

                // RPC ping to newly added friend
                _srh.PingFriend(friend);

                ProtocolLog.Write(SocialLog.SVPNLog, "ADD CERT KEY SUCCESS: " +
                                  friend.DhtKey + " " + friend.IP + " " +
                                  friend.Alias);
            }
        }