public static NSString ToStringNative(this EncryptionKeyType self)
        {
            switch (self)
            {
            case EncryptionKeyType.Rsa:
                return(new NSString("RSASSA-PKCS1-v1_5"));

            case EncryptionKeyType.Ecdsa:
                return(new NSString("ECDSA"));

            default:
                throw new ArgumentOutOfRangeException(nameof(self), self, null);
            }
        }
示例#2
0
        public ChatChannel GetAvailableChannels(bool transmitOnly = true)
        {
            PlayerMove pm = gameObject.GetComponent <PlayerMove>();

            if (pm.isGhost)
            {
                ChatChannel ghostTransmitChannels = ChatChannel.Ghost | ChatChannel.OOC;
                ChatChannel ghostReceiveChannels  = ChatChannel.Examine | ChatChannel.System;
                if (transmitOnly)
                {
                    return(ghostTransmitChannels);
                }
                return(ghostTransmitChannels | ghostReceiveChannels);
            }

            //TODO: Checks if player can speak (is not gagged, unconcious, has no mouth)
            ChatChannel transmitChannels = ChatChannel.OOC | ChatChannel.Local;

            if (CustomNetworkManager.Instance._isServer)
            {
                PlayerNetworkActions pna = gameObject.GetComponent <PlayerNetworkActions>();
                if (pna)
                {
                    EncryptionKeyType key = pna.Inventory["ear"].GetComponent <Headset>().GetComponent <Headset>().EncryptionKey;
                    transmitChannels = transmitChannels | EncryptionKey.Permissions[key];
                }
            }
            else
            {
                GameObject headset = UIManager.InventorySlots.EarSlot.Item;
                if (headset)
                {
                    EncryptionKeyType key = headset.GetComponent <Headset>().EncryptionKey;
                    transmitChannels = transmitChannels | EncryptionKey.Permissions[key];
                }
            }


            ChatChannel receiveChannels = ChatChannel.Examine | ChatChannel.System;

            if (transmitOnly)
            {
                return(transmitChannels);
            }
            return(transmitChannels | receiveChannels);
        }
示例#3
0
    public ChatChannel GetAvailableChannelsMask(bool transmitOnly = true)
    {
        if (IsDeadOrGhost && !IsPlayerSemiGhost)
        {
            ChatChannel ghostTransmitChannels = ChatChannel.Ghost | ChatChannel.OOC;
            ChatChannel ghostReceiveChannels  = ChatChannel.Examine | ChatChannel.System | ChatChannel.Combat |
                                                ChatChannel.Binary | ChatChannel.Command | ChatChannel.Common | ChatChannel.Engineering |
                                                ChatChannel.Medical | ChatChannel.Science | ChatChannel.Security | ChatChannel.Service
                                                | ChatChannel.Supply | ChatChannel.Syndicate;
            if (transmitOnly)
            {
                return(ghostTransmitChannels);
            }
            return(ghostTransmitChannels | ghostReceiveChannels);
        }

        if (IsPlayerSemiGhost)
        {
            ChatChannel blobTransmitChannels = ChatChannel.Blob | ChatChannel.OOC;
            ChatChannel blobReceiveChannels  = ChatChannel.Examine | ChatChannel.System | ChatChannel.Combat;

            if (transmitOnly)
            {
                return(blobTransmitChannels);
            }

            return(blobTransmitChannels | blobReceiveChannels);
        }

        //TODO: Checks if player can speak (is not gagged, unconcious, has no mouth)
        ChatChannel transmitChannels = ChatChannel.OOC | ChatChannel.Local;

        if (CustomNetworkManager.Instance._isServer)
        {
            var playerStorage = gameObject.GetComponent <ItemStorage>();
            if (playerStorage && !playerStorage.GetNamedItemSlot(NamedSlot.ear).IsEmpty)
            {
                Headset headset = playerStorage.GetNamedItemSlot(NamedSlot.ear)?.Item?.GetComponent <Headset>();
                if (headset)
                {
                    EncryptionKeyType key = headset.EncryptionKey;
                    transmitChannels = transmitChannels | EncryptionKey.Permissions[key];
                }
            }
        }
        else
        {
            GameObject earSlotItem = gameObject.GetComponent <ItemStorage>().GetNamedItemSlot(NamedSlot.ear).ItemObject;
            if (earSlotItem)
            {
                Headset headset = earSlotItem.GetComponent <Headset>();
                if (headset)
                {
                    EncryptionKeyType key = headset.EncryptionKey;
                    transmitChannels = transmitChannels | EncryptionKey.Permissions[key];
                }
            }
        }

        ChatChannel receiveChannels = ChatChannel.Examine | ChatChannel.System | ChatChannel.Combat;

        if (transmitOnly)
        {
            return(transmitChannels);
        }

        return(transmitChannels | receiveChannels);
    }
示例#4
0
    public ChatChannel GetAvailableChannelsMask(bool transmitOnly = true)
    {
        if (IsDeadOrGhost && !IsPlayerSemiGhost)
        {
            ChatChannel ghostTransmitChannels = ChatChannel.Ghost | ChatChannel.OOC;
            ChatChannel ghostReceiveChannels  = ChatChannel.Examine | ChatChannel.System | ChatChannel.Combat |
                                                ChatChannel.Binary | ChatChannel.Command | ChatChannel.Common | ChatChannel.Engineering |
                                                ChatChannel.Medical | ChatChannel.Science | ChatChannel.Security | ChatChannel.Service
                                                | ChatChannel.Supply | ChatChannel.Syndicate;

            if (transmitOnly)
            {
                return(ghostTransmitChannels);
            }
            return(ghostTransmitChannels | ghostReceiveChannels);
        }

        if (playerState == PlayerStates.Ai)
        {
            ChatChannel aiTransmitChannels = ChatChannel.OOC | ChatChannel.Local | ChatChannel.Binary | ChatChannel.Command
                                             | ChatChannel.Common | ChatChannel.Engineering |
                                             ChatChannel.Medical | ChatChannel.Science | ChatChannel.Security | ChatChannel.Service
                                             | ChatChannel.Supply;
            ChatChannel aiReceiveChannels = ChatChannel.Examine | ChatChannel.System | ChatChannel.Combat |
                                            ChatChannel.Binary | ChatChannel.Command | ChatChannel.Common | ChatChannel.Engineering |
                                            ChatChannel.Medical | ChatChannel.Science | ChatChannel.Security | ChatChannel.Service
                                            | ChatChannel.Supply;

            if (GetComponent <AiPlayer>().AllowRadio == false)
            {
                aiTransmitChannels = ChatChannel.OOC | ChatChannel.Local;
                aiReceiveChannels  = ChatChannel.Examine | ChatChannel.System | ChatChannel.Combat;
            }

            if (transmitOnly)
            {
                return(aiTransmitChannels);
            }
            return(aiTransmitChannels | aiReceiveChannels);
        }

        if (playerState == PlayerStates.Blob)
        {
            ChatChannel blobTransmitChannels = ChatChannel.Blob | ChatChannel.OOC;
            ChatChannel blobReceiveChannels  = ChatChannel.Examine | ChatChannel.System | ChatChannel.Combat;

            if (transmitOnly)
            {
                return(blobTransmitChannels);
            }

            return(blobTransmitChannels | blobReceiveChannels);
        }

        //TODO: Checks if player can speak (is not gagged, unconcious, has no mouth)
        ChatChannel transmitChannels = ChatChannel.OOC | ChatChannel.Local;

        var playerStorage = gameObject.GetComponent <DynamicItemStorage>();

        if (playerStorage != null)
        {
            foreach (var earSlot in playerStorage.GetNamedItemSlots(NamedSlot.ear))
            {
                if (earSlot.IsEmpty)
                {
                    continue;
                }
                if (earSlot.Item.TryGetComponent <Headset>(out var headset) == false)
                {
                    continue;
                }

                EncryptionKeyType key = headset.EncryptionKey;
                transmitChannels = transmitChannels | EncryptionKey.Permissions[key];
            }
        }

        ChatChannel receiveChannels = ChatChannel.Examine | ChatChannel.System | ChatChannel.Combat;

        if (transmitOnly)
        {
            return(transmitChannels);
        }

        return(transmitChannels | receiveChannels);
    }
        public override string LoadAccountKey(string wallet, string address, string key, IDbConnectorService dbservice, string pubkey = "", string password = "", string name = "", bool storeInDb = true, bool isItMainAccountKey = false, bool alreadyEncrypted = false, EncryptionKeyType type = EncryptionKeyType.BasicSecurity)
        {
            try
            {
                if (EconomyMainContext.Wallets.TryGetValue(wallet, out var w))
                {
                    if (w.Accounts.TryGetValue(address, out var account))
                    {
                        if (isItMainAccountKey)
                        {
                            // todo load already encrypted key
                            account.AccountKey = new Security.EncryptionKey(key, password);
                            account.AccountKey.RelatedItemId = account.Id;
                            account.AccountKey.Type          = Security.EncryptionKeyType.AccountKey;
                            account.AccountKeyId             = account.AccountKey.Id;
                            account.AccountKey.PublicKey     = account.Address;

                            if (!string.IsNullOrEmpty(password))
                            {
                                account.AccountKey.PasswordHash = Security.SecurityUtil.HashPassword(password);
                            }

                            account.AccountKey.Name = name;

                            if (EconomyMainContext.WorkWithDb)
                            {
                                dbservice.SaveKey(account.AccountKey);
                            }

                            account.AccountKeyId = account.AccountKey.Id;

                            if (EconomyMainContext.WorkWithDb)
                            {
                                dbservice.SaveAccount(account);
                            }

                            return("OK");
                        }
                        else
                        {
                            EncryptionKey k = null;
                            if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(pubkey))
                            {
                                // validate the key pair if it is correct combination of RSA keys
                                try
                                {
                                    if (type != EncryptionKeyType.AccountKey)
                                    {
                                        if (alreadyEncrypted)
                                        {
                                            var kd = SymetricProvider.DecryptString(password, key);
                                            if (kd != null)
                                            {
                                                key = kd;
                                            }
                                        }

                                        var m = AsymmetricProvider.EncryptString("test", pubkey);
                                        var r = AsymmetricProvider.DecryptString(m, key);
                                        if (r != "test")
                                        {
                                            throw new Exception("Key pair is not valid RSA key pair!");
                                        }
                                    }

                                    k = new EncryptionKey(key, password);
                                }
                                catch (Exception ex)
                                {
                                    throw new Exception("Key pair is not valid RSA key pair!");
                                }
                            }
                            else if (!string.IsNullOrEmpty(key) && string.IsNullOrEmpty(pubkey))
                            {
                                if (alreadyEncrypted)
                                {
                                    var kd = SymetricProvider.DecryptString(password, key);
                                    if (kd != null)
                                    {
                                        k = new Security.EncryptionKey(kd, password);
                                    }
                                }
                                else
                                {
                                    k = new Security.EncryptionKey(key, password);
                                    k.LoadNewKey(key, fromDb: true);
                                }
                            }
                            else if (!string.IsNullOrEmpty(pubkey) && string.IsNullOrEmpty(key))
                            {
                                // create enc object
                                k           = new Security.EncryptionKey("passtest", password, true); // this can be used for testing the password
                                k.PublicKey = pubkey;
                            }
                            else if (string.IsNullOrEmpty(key) && string.IsNullOrEmpty(pubkey))
                            {
                                // obtain new RSA key pair
                                var keypair = Security.AsymmetricProvider.GenerateNewKeyPair();
                                // create enc object
                                k           = new EncryptionKey(keypair.PrivateKey, password);
                                k.PublicKey = keypair.PublicKey;
                            }
                            else
                            {
                                throw new Exception("Strange input!");
                            }

                            k.RelatedItemId = account.Id;
                            k.Type          = Security.EncryptionKeyType.BasicSecurity;

                            if (!string.IsNullOrEmpty(password))
                            {
                                k.PasswordHash = Security.SecurityUtil.HashPassword(password);
                            }

                            k.Name = name;
                            account.AccountKeys.Add(k);

                            if (EconomyMainContext.WorkWithDb)
                            {
                                dbservice.SaveKey(k);
                            }

                            if (isItMainAccountKey)
                            {
                                account.AccountKeyId = account.AccountKey.Id;

                                if (EconomyMainContext.WorkWithDb)
                                {
                                    dbservice.SaveAccount(account);
                                }
                            }

                            return("OK");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("Cannot load key to the account!", ex);
            }

            return("Load Account Key - ERROR");
        }
示例#6
0
 public RTCCertificate GenerateCertificate(EncryptionKeyType keyType, long expires) => RtcCertificatePem.GenerateCertificate(keyType.ToNative(), expires).ToNet();
 public Core.RTCCertificate CreateCertificate(EncryptionKeyType encryptionKeyType, long expiries)
 {
     return(RTCCertificate.GenerateCertificateWithParams(new NSDictionary <NSString, NSObject>(new[] { "expires".ToPlatformNative(), "name".ToPlatformNative() }, new NSObject[] { new NSNumber(expiries), encryptionKeyType.ToStringNative() })).ToNativePort());
 }
 public static RTCEncryptionKeyType ToPlatformNative(this EncryptionKeyType nativePort) => (RTCEncryptionKeyType)nativePort;
 public static RTCEncryptionKeyType ToNative(this EncryptionKeyType self)
 {
     return((RTCEncryptionKeyType)self);
 }
示例#10
0
 internal static RTCCertificate CreateCertificate(EncryptionKeyType encryptionKeyType, long expires)
 {
     IsNativeFactoryInitialized();
     return(_nativeFactory?.CreateCertificate(encryptionKeyType, expires));
 }
示例#11
0
 public static RTCCertificate GenerateCertificate(EncryptionKeyType keyType, long expires) =>
 NativeFactory.GenerateCertificate(keyType, expires);
示例#12
0
 public static RTCCertificate GenerateCertificate(EncryptionKeyType keyType) =>
 GenerateCertificate(keyType, DefaultExpiry);
 public abstract string LoadAccountKey(string wallet, string address, string key, IDbConnectorService dbservice, string pubkey = "", string password = "", string name = "", bool storeInDb = true, bool isItMainAccountKey = false, bool alreadyEncrypted = false, EncryptionKeyType type = EncryptionKeyType.BasicSecurity);
示例#14
0
    private void getEncryptionTypeFromHier()
    {
        ItemAttributes attr = GetComponent <ItemAttributes>();

        switch (attr.hierarchy)
        {
        case "/obj/item/device/radio/headset":
            EncryptionKey = EncryptionKeyType.Common;
            break;

        case "/obj/item/device/radio/headset/heads/captain":
        case "/obj/item/device/radio/headset/heads/captain/alt":
            EncryptionKey = EncryptionKeyType.Captain;
            break;

        case "/obj/item/device/radio/headset/heads/ce":
            EncryptionKey = EncryptionKeyType.ChiefEngineer;
            break;

        case "/obj/item/device/radio/headset/heads/cmo":
            EncryptionKey = EncryptionKeyType.ChiefMedicalOfficer;
            break;

        case "/obj/item/device/radio/headset/heads/hop":
            EncryptionKey = EncryptionKeyType.HeadOfPersonnel;
            break;

        case "/obj/item/device/radio/headset/heads/hos":
        case "/obj/item/device/radio/headset/heads/hos/alt":
            EncryptionKey = EncryptionKeyType.HeadOfSecurity;
            break;

        case "/obj/item/device/radio/headset/heads/rd":
            EncryptionKey = EncryptionKeyType.ResearchDirector;
            break;

        case "/obj/item/device/radio/headset/headset_cargo":
            EncryptionKey = EncryptionKeyType.Supply;
            break;

        case "/obj/item/device/radio/headset/headset_cent":
        case "/obj/item/device/radio/headset/headset_cent/alt":
            EncryptionKey = EncryptionKeyType.CentComm;
            break;

        case "/obj/item/device/radio/headset/headset_eng":
            EncryptionKey = EncryptionKeyType.Engineering;
            break;

        case "/obj/item/device/radio/headset/headset_med":
            EncryptionKey = EncryptionKeyType.Medical;
            break;

        case "/obj/item/device/radio/headset/headset_sci":
            EncryptionKey = EncryptionKeyType.Science;
            break;

        case "/obj/item/device/radio/headset/headset_sec":
        case "/obj/item/device/radio/headset/headset_sec/alt":
            EncryptionKey = EncryptionKeyType.Security;
            break;

        case "/obj/item/device/radio/headset/headset_srv":
            EncryptionKey = EncryptionKeyType.Service;
            break;

        case "/obj/item/device/radio/headset/syndicate/alt":
            EncryptionKey = EncryptionKeyType.Syndicate;
            break;

        default:
            EncryptionKey = EncryptionKeyType.Common;
            break;
        }
    }
示例#15
0
    /// Generates a description for headset encryption key type
    private static string hotkeyDescription(EncryptionKeyType keyType)
    {
        List <ChatChannel> chatChannels = getChannelList(keyType);

        return($"{genericDescription}{string.Join(",\n",getChannelDescriptions(chatChannels))}");
    }
示例#16
0
    /// For dumb people like me who can't do bitwise. Better cache these
    private static List <ChatChannel> getChannelList(EncryptionKeyType keyType)
    {
        ChatChannel channelMask = Permissions[keyType];

        return(getChannelsByMask(channelMask));
    }
 internal static RTCCertificate GenerateCertificate(EncryptionKeyType keyType, long expires)
 {
     CheckIfInit();
     return(_factory.GenerateCertificate(keyType, expires));
 }