Search in sources :

Example 16 with Port

use of verdict.vdm.vdm_model.Port in project VERDICT by ge-high-assurance.

the class Instrumentor method softwareVirus.

// SV:
// - Select components c in the model M such that:
// c.ComponentType = 'Software' v c.ComponentType = 'Hybrid' & c.Manufacturer =
// 'ThirdParty'
// & \exists ch\in M. p\in InputPort(c). ch = p.channel & ch.Connectin-Type =
// Remote
@Override
public void softwareVirus(HashSet<ComponentType> vdm_components) {
    try {
        HashSet<String> components = new HashSet<String>();
        HashSet<String> svComponentTypeSet = new HashSet<String>(Arrays.asList("software", "swhwhybrid", "swhumanhybrid", "hybrid"));
        BlockImpl blockImpl = null;
        for (ComponentImpl componentImpl : vdm_model.getComponentImpl()) {
            blockImpl = componentImpl.getBlockImpl();
            // BlockImpl
            if (blockImpl != null) {
                ComponentType componentType = componentImpl.getType();
                for (ComponentInstance componentInstance : blockImpl.getSubcomponent()) {
                    componentType = componentInstance.getSpecification();
                    ComponentImpl subcomponentImpl = componentInstance.getImplementation();
                    // Option 1) Specification
                    if (componentType != null) {
                    } else // Option 2) Implementation
                    if (subcomponentImpl != null) {
                        componentType = subcomponentImpl.getType();
                    }
                    List<GenericAttribute> attributeList = componentInstance.getAttribute();
                    GenericAttribute componentKindAttribute = getAttributeByName(attributeList, "ComponentType", componentInstance.getName());
                    GenericAttribute staticCodeAnalysisAttribute = getAttributeByName(attributeList, "StaticCodeAnalysis", componentInstance.getName());
                    GenericAttribute inputValidationAttribute = getAttributeByName(attributeList, "InputValidation", componentInstance.getName());
                    GenericAttribute memoryProtectionAttribute = getAttributeByName(attributeList, "MemoryProtection", componentInstance.getName());
                    GenericAttribute secureBootAttribute = getAttributeByName(attributeList, "SecureBoot", componentInstance.getName());
                    String componentKind = componentKindAttribute.getValue().toString().toLowerCase();
                    int staticCodeAnalysis = Integer.parseInt(staticCodeAnalysisAttribute.getValue().toString());
                    int inputValidation = Integer.parseInt(inputValidationAttribute.getValue().toString());
                    int memoryProtection = Integer.parseInt(memoryProtectionAttribute.getValue().toString());
                    int secureBoot = Integer.parseInt(secureBootAttribute.getValue().toString());
                    if (svComponentTypeSet.contains(componentKind.toLowerCase()) && (staticCodeAnalysis == 0 || inputValidation == 0 || memoryProtection == 0 || secureBoot == 0)) {
                        Boolean hasEligibleIncomingChannels = false;
                        for (Port port : componentType.getPort()) {
                            PortMode mode = port.getMode();
                            if (mode == PortMode.IN) {
                                for (Connection connection : blockImpl.getConnection()) {
                                    if (connection.getDestination().getSubcomponentPort() != null) {
                                        if (connection.getDestination().getSubcomponentPort().getPort() == port) {
                                            Boolean scInsideTrustedBoundary;
                                            String scComponentKind;
                                            String scPedigree;
                                            int scStrongCryptoAlgorithms;
                                            int scSupplyChainSecurity;
                                            int scTamperProtection;
                                            if (connection.getSource().getSubcomponentPort() != null) {
                                                ComponentInstance sourceComponent = connection.getSource().getSubcomponentPort().getSubcomponent();
                                                List<GenericAttribute> sourceComponentAttributeList = sourceComponent.getAttribute();
                                                GenericAttribute sourceComponentInsideTrustedBoundaryAttribute = getAttributeByName(sourceComponentAttributeList, "InsideTrustedBoundary", sourceComponent.getName());
                                                GenericAttribute sourceComponentComponentKindAttribute = getAttributeByName(sourceComponentAttributeList, "ComponentType", sourceComponent.getName());
                                                GenericAttribute sourceComponentPedigreeAttribute = getAttributeByName(sourceComponentAttributeList, "Pedigree", sourceComponent.getName());
                                                GenericAttribute sourceComponentStrongCryptoAlgorithmsAttribute = getAttributeByName(sourceComponentAttributeList, "StrongCryptoAlgorithms", sourceComponent.getName());
                                                GenericAttribute sourceComponentSupplyChainSecurityAttribute = getAttributeByName(sourceComponentAttributeList, "SupplyChainSecurity", sourceComponent.getName());
                                                GenericAttribute sourceComponentTamperProtectionAttribute = getAttributeByName(sourceComponentAttributeList, "TamperProtection", sourceComponent.getName());
                                                scInsideTrustedBoundary = Boolean.parseBoolean(sourceComponentInsideTrustedBoundaryAttribute.getValue().toString());
                                                scComponentKind = sourceComponentComponentKindAttribute.getValue().toString().toLowerCase();
                                                scPedigree = sourceComponentPedigreeAttribute.getValue().toString().toLowerCase();
                                                scStrongCryptoAlgorithms = Integer.parseInt(sourceComponentStrongCryptoAlgorithmsAttribute.getValue().toString());
                                                scSupplyChainSecurity = Integer.parseInt(sourceComponentSupplyChainSecurityAttribute.getValue().toString());
                                                scTamperProtection = Integer.parseInt(sourceComponentTamperProtectionAttribute.getValue().toString());
                                            } else {
                                                scInsideTrustedBoundary = true;
                                                scComponentKind = "";
                                                scPedigree = "";
                                                scStrongCryptoAlgorithms = -1;
                                                scSupplyChainSecurity = -1;
                                                scTamperProtection = -1;
                                            }
                                            List<GenericAttribute> connectionAttributeList = connection.getAttribute();
                                            GenericAttribute connectionTypeAttribute = getAttributeByName(connectionAttributeList, "ConnectionType", connection.getName());
                                            GenericAttribute deviceAuthenticationAttribute = getAttributeByName(connectionAttributeList, "DeviceAuthentication", connection.getName());
                                            GenericAttribute sessionAuthenticityAttribute = getAttributeByName(connectionAttributeList, "SessionAuthenticity", connection.getName());
                                            String connectionType = connectionTypeAttribute.getValue().toString().toLowerCase();
                                            int deviceAuthentication = Integer.parseInt(deviceAuthenticationAttribute.getValue().toString());
                                            int sessionAuthenticity = Integer.parseInt(sessionAuthenticityAttribute.getValue().toString());
                                            if ((!scInsideTrustedBoundary || connectionType.equalsIgnoreCase("untrusted")) && !scComponentKind.equalsIgnoreCase("hardware") && ((scPedigree.equalsIgnoreCase("cots") || (scPedigree.equalsIgnoreCase("sourced") && scSupplyChainSecurity == 0 && scTamperProtection == 0)) || ((deviceAuthentication == 0 && sessionAuthenticity == 0) || scStrongCryptoAlgorithms == 0))) {
                                                hasEligibleIncomingChannels = true;
                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                            if (hasEligibleIncomingChannels) {
                                break;
                            }
                        }
                        if (hasEligibleIncomingChannels) {
                            vdm_components.add(componentType);
                            components.add(componentType.getId());
                        }
                    }
                }
            }
        }
        this.attack_cmp_link_map.put("SV", components);
    } catch (CRVException e) {
        System.out.println("\tCRV Error " + e.getCode() + " " + e.getMessage());
    }
}
Also used : BlockImpl(verdict.vdm.vdm_model.BlockImpl) ComponentType(verdict.vdm.vdm_model.ComponentType) PortMode(verdict.vdm.vdm_model.PortMode) CompInstancePort(verdict.vdm.vdm_model.CompInstancePort) Port(verdict.vdm.vdm_model.Port) GenericAttribute(verdict.vdm.vdm_data.GenericAttribute) Connection(verdict.vdm.vdm_model.Connection) ComponentImpl(verdict.vdm.vdm_model.ComponentImpl) ComponentInstance(verdict.vdm.vdm_model.ComponentInstance) HashSet(java.util.HashSet)

Example 17 with Port

use of verdict.vdm.vdm_model.Port in project VERDICT by ge-high-assurance.

the class Instrumentor method get_ports.

private HashSet<String> get_ports(Connection link) {
    HashSet<String> ports = new HashSet<String>();
    ConnectionEnd con_end = link.getSource();
    Port dest_port = con_end.getComponentPort();
    if (dest_port == null) {
        CompInstancePort instance_port = con_end.getSubcomponentPort();
        dest_port = instance_port.getPort();
    }
    ports.add(dest_port.getName());
    con_end = link.getDestination();
    dest_port = con_end.getComponentPort();
    if (dest_port == null) {
        CompInstancePort instance_port = con_end.getSubcomponentPort();
        dest_port = instance_port.getPort();
    }
    ports.add(dest_port.getName());
    return ports;
}
Also used : CompInstancePort(verdict.vdm.vdm_model.CompInstancePort) CompInstancePort(verdict.vdm.vdm_model.CompInstancePort) Port(verdict.vdm.vdm_model.Port) ConnectionEnd(verdict.vdm.vdm_model.ConnectionEnd) HashSet(java.util.HashSet)

Example 18 with Port

use of verdict.vdm.vdm_model.Port in project VERDICT by ge-high-assurance.

the class Instrumentor method instrument_component.

// Instrument Link for all outgoing edges
@Override
public HashSet<Connection> instrument_component(ComponentType component, BlockImpl blockImpl) {
    HashSet<Connection> vdm_links = new HashSet<Connection>();
    HashSet<String> links = new HashSet<String>();
    for (Port port : component.getPort()) {
        PortMode mode = port.getMode();
        if (mode == PortMode.OUT) {
        // for (Connection connection : blockImpl.getConnection()) {
        // links.add(connection.getName());
        // links.add(port.getName());
        // links.addAll(get_ports(connection));
        // }
        // links.add(port.getName());
        }
        {
            // instrument_link(port, blockImpl);
            if (blockImpl != null) {
                for (Connection connection : blockImpl.getConnection()) {
                    if (retrieve_links(component, connection, port)) {
                        vdm_links.add(connection);
                        links.add(connection.getName());
                    // links.add(get_ports(vdm_links));
                    }
                // links.addAll(get_ports(connection));
                }
            } else {
            }
        }
    }
    String attack_type = getThreatID(component.getId());
    if (this.attack_cmp_link_map.containsKey(attack_type)) {
        HashSet<String> cmp_links = this.attack_cmp_link_map.get(attack_type);
        for (Connection con : vdm_links) {
            if (!isProbePort(con)) {
                cmp_links.addAll(get_ports(con));
            }
        }
    }
    // System.out.println(links);
    return vdm_links;
}
Also used : PortMode(verdict.vdm.vdm_model.PortMode) CompInstancePort(verdict.vdm.vdm_model.CompInstancePort) Port(verdict.vdm.vdm_model.Port) Connection(verdict.vdm.vdm_model.Connection) HashSet(java.util.HashSet)

Example 19 with Port

use of verdict.vdm.vdm_model.Port in project VERDICT by ge-high-assurance.

the class VDM2Lustre method visit.

// 1) Node signature +/- contract
// a) Imported Node (Contract, no Implementation)
// b) Node Impl
// c) Node Impl + contract
// d) @TODO: no Contract, no Implementation -- (*@contract gurantee true*)
public Node visit(ComponentType componentType, boolean is_implemented) {
    Node node = new Node();
    String identifier = componentType.getName();
    // Replace dot identifier to support lustre naming compliance
    identifier = identifier.replace(".", "_dot_");
    identifier = identifier.replace("::", "_double_colon_");
    if (is_implemented) {
        identifier += "_dot_Impl";
    } else {
        // Imported Node
        node.setIsImported(true);
    // System.out.println("Imported Nodes:" +identifier );
    }
    node.setName(identifier);
    for (Port port : componentType.getPort()) {
        if (port.isEvent() != null && port.isEvent()) {
            this.eventDeclarations.put(port.getName(), port.getType());
        }
        visit(port, node);
    }
    // + Contract (Optional)
    ContractSpec contractSpec = componentType.getContract();
    if (is_implemented == false && contractSpec == null) {
        // Rename output renaming to avoid Duplicate.
        // List<NodeParameter> node_parameters = node.getOutputParameter();
        // for (NodeParameter instrumented_param : node_parameters) {
        // String param_identifier = instrumented_param.getName();
        // instrumented_param.setName(param_identifier + "_intrumented");
        // }
        ContractItem true_guarantee_item = new ContractItem();
        Expression true_expr = new Expression();
        Boolean true_lit = Boolean.TRUE;
        true_expr.setBoolLiteral(true_lit);
        true_guarantee_item.setExpression(true_expr);
        contractSpec = new ContractSpec();
        contractSpec.getGuarantee().add(true_guarantee_item);
        componentType.setContract(contractSpec);
    }
    if (contractSpec != null) {
        visit(contractSpec);
        if (contractSpec.getGuarantee().size() != 0) {
            node.setContract(contractSpec);
            this.eventDeclarations.clear();
        }
    }
    return node;
}
Also used : ContractItem(verdict.vdm.vdm_lustre.ContractItem) Expression(verdict.vdm.vdm_lustre.Expression) Node(verdict.vdm.vdm_lustre.Node) CompInstancePort(verdict.vdm.vdm_model.CompInstancePort) Port(verdict.vdm.vdm_model.Port) ContractSpec(verdict.vdm.vdm_lustre.ContractSpec)

Example 20 with Port

use of verdict.vdm.vdm_model.Port in project VERDICT by ge-high-assurance.

the class Instrumentor method remoteCodeInjection.

// Remote Code Injection:
// - Select components c in the model M such that:
// c.ComponentType = 'Software' v c.ComponentType = 'Hybrid'
// & \exists ch\in M. p\in InputPort(c). ch = p.channel & ch.Connectin-Type =
// Remote
@Override
public void remoteCodeInjection(HashSet<ComponentType> vdm_components) {
    try {
        HashSet<String> components = new HashSet<String>();
        HashSet<String> rciComponentTypeSet = new HashSet<String>(Arrays.asList("software", "swhwhybrid", "swhumanhybrid", "hybrid"));
        BlockImpl blockImpl = null;
        for (ComponentImpl componentImpl : vdm_model.getComponentImpl()) {
            blockImpl = componentImpl.getBlockImpl();
            // BlockImpl
            if (blockImpl != null) {
                ComponentType componentType = componentImpl.getType();
                for (ComponentInstance componentInstance : blockImpl.getSubcomponent()) {
                    componentType = componentInstance.getSpecification();
                    ComponentImpl subcomponentImpl = componentInstance.getImplementation();
                    // Option 1) Specification
                    if (componentType != null) {
                    } else // Option 2) Implementation
                    if (subcomponentImpl != null) {
                        componentType = subcomponentImpl.getType();
                    }
                    List<GenericAttribute> attributeList = componentInstance.getAttribute();
                    GenericAttribute componentKindAttribute = getAttributeByName(attributeList, "ComponentType", componentInstance.getName());
                    GenericAttribute staticCodeAnalysisAttribute = getAttributeByName(attributeList, "StaticCodeAnalysis", componentInstance.getName());
                    GenericAttribute inputValidationAttribute = getAttributeByName(attributeList, "InputValidation", componentInstance.getName());
                    GenericAttribute memoryProtectionAttribute = getAttributeByName(attributeList, "MemoryProtection", componentInstance.getName());
                    String componentKind = componentKindAttribute.getValue().toString().toLowerCase();
                    int staticCodeAnalysis = Integer.parseInt(staticCodeAnalysisAttribute.getValue().toString());
                    int inputValidation = Integer.parseInt(inputValidationAttribute.getValue().toString());
                    int memoryProtection = Integer.parseInt(memoryProtectionAttribute.getValue().toString());
                    if (rciComponentTypeSet.contains(componentKind.toLowerCase()) && (staticCodeAnalysis == 0 || inputValidation == 0 || memoryProtection == 0)) {
                        Boolean hasEligibleIncomingChannels = false;
                        for (Port port : componentType.getPort()) {
                            PortMode mode = port.getMode();
                            if (mode == PortMode.IN) {
                                for (Connection connection : blockImpl.getConnection()) {
                                    if (connection.getDestination().getSubcomponentPort() != null) {
                                        if (connection.getDestination().getSubcomponentPort().getPort() == port) {
                                            Boolean scInsideTrustedBoundary;
                                            String scComponentKind;
                                            String scPedigree;
                                            int scStrongCryptoAlgorithms;
                                            int scSupplyChainSecurity;
                                            int scTamperProtection;
                                            if (connection.getSource().getSubcomponentPort() != null) {
                                                ComponentInstance sourceComponent = connection.getSource().getSubcomponentPort().getSubcomponent();
                                                List<GenericAttribute> sourceComponentAttributeList = sourceComponent.getAttribute();
                                                GenericAttribute sourceComponentInsideTrustedBoundaryAttribute = getAttributeByName(sourceComponentAttributeList, "InsideTrustedBoundary", sourceComponent.getName());
                                                GenericAttribute sourceComponentComponentKindAttribute = getAttributeByName(sourceComponentAttributeList, "ComponentType", sourceComponent.getName());
                                                GenericAttribute sourceComponentPedigreeAttribute = getAttributeByName(sourceComponentAttributeList, "Pedigree", sourceComponent.getName());
                                                GenericAttribute sourceComponentStrongCryptoAlgorithmsAttribute = getAttributeByName(sourceComponentAttributeList, "StrongCryptoAlgorithms", sourceComponent.getName());
                                                GenericAttribute sourceComponentSupplyChainSecurityAttribute = getAttributeByName(sourceComponentAttributeList, "SupplyChainSecurity", sourceComponent.getName());
                                                GenericAttribute sourceComponentTamperProtectionAttribute = getAttributeByName(sourceComponentAttributeList, "TamperProtection", sourceComponent.getName());
                                                scInsideTrustedBoundary = Boolean.parseBoolean(sourceComponentInsideTrustedBoundaryAttribute.getValue().toString());
                                                scComponentKind = sourceComponentComponentKindAttribute.getValue().toString().toLowerCase();
                                                scPedigree = sourceComponentPedigreeAttribute.getValue().toString().toLowerCase();
                                                scStrongCryptoAlgorithms = Integer.parseInt(sourceComponentStrongCryptoAlgorithmsAttribute.getValue().toString());
                                                scSupplyChainSecurity = Integer.parseInt(sourceComponentSupplyChainSecurityAttribute.getValue().toString());
                                                scTamperProtection = Integer.parseInt(sourceComponentTamperProtectionAttribute.getValue().toString());
                                            } else {
                                                scInsideTrustedBoundary = true;
                                                scComponentKind = "";
                                                scPedigree = "";
                                                scStrongCryptoAlgorithms = -1;
                                                scSupplyChainSecurity = -1;
                                                scTamperProtection = -1;
                                            }
                                            List<GenericAttribute> connectionAttributeList = connection.getAttribute();
                                            GenericAttribute connectionTypeAttribute = getAttributeByName(connectionAttributeList, "ConnectionType", connection.getName());
                                            GenericAttribute deviceAuthenticationAttribute = getAttributeByName(connectionAttributeList, "DeviceAuthentication", connection.getName());
                                            GenericAttribute sessionAuthenticityAttribute = getAttributeByName(connectionAttributeList, "SessionAuthenticity", connection.getName());
                                            String connectionType = connectionTypeAttribute.getValue().toString().toLowerCase();
                                            int deviceAuthentication = Integer.parseInt(deviceAuthenticationAttribute.getValue().toString());
                                            int sessionAuthenticity = Integer.parseInt(sessionAuthenticityAttribute.getValue().toString());
                                            if ((!scInsideTrustedBoundary || connectionType.equalsIgnoreCase("untrusted")) && !scComponentKind.equalsIgnoreCase("hardware") && ((scPedigree.equalsIgnoreCase("cots") || (scPedigree.equalsIgnoreCase("sourced") && scSupplyChainSecurity == 0 && scTamperProtection == 0)) || ((deviceAuthentication == 0 && sessionAuthenticity == 0) || scStrongCryptoAlgorithms == 0))) {
                                                hasEligibleIncomingChannels = true;
                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                            if (hasEligibleIncomingChannels) {
                                break;
                            }
                        }
                        if (hasEligibleIncomingChannels) {
                            vdm_components.add(componentType);
                            components.add(componentType.getId());
                        }
                    }
                }
            }
        }
        this.attack_cmp_link_map.put("RI", components);
    } catch (CRVException e) {
        System.out.println("CRV Error " + e.getCode() + e.getMessage());
    }
}
Also used : BlockImpl(verdict.vdm.vdm_model.BlockImpl) ComponentType(verdict.vdm.vdm_model.ComponentType) PortMode(verdict.vdm.vdm_model.PortMode) CompInstancePort(verdict.vdm.vdm_model.CompInstancePort) Port(verdict.vdm.vdm_model.Port) GenericAttribute(verdict.vdm.vdm_data.GenericAttribute) Connection(verdict.vdm.vdm_model.Connection) ComponentImpl(verdict.vdm.vdm_model.ComponentImpl) ComponentInstance(verdict.vdm.vdm_model.ComponentInstance) HashSet(java.util.HashSet)

Aggregations

Port (verdict.vdm.vdm_model.Port)36 EventDataPort (org.osate.aadl2.EventDataPort)20 EventPort (org.osate.aadl2.EventPort)20 DataPort (org.osate.aadl2.DataPort)19 CompInstancePort (verdict.vdm.vdm_model.CompInstancePort)16 ArrayList (java.util.ArrayList)12 CyberMission (com.ge.research.osate.verdict.dsl.verdict.CyberMission)11 CyberRel (com.ge.research.osate.verdict.dsl.verdict.CyberRel)11 CyberReq (com.ge.research.osate.verdict.dsl.verdict.CyberReq)11 Event (com.ge.research.osate.verdict.dsl.verdict.Event)11 SafetyRel (com.ge.research.osate.verdict.dsl.verdict.SafetyRel)11 SafetyReq (com.ge.research.osate.verdict.dsl.verdict.SafetyReq)11 Statement (com.ge.research.osate.verdict.dsl.verdict.Statement)11 Verdict (com.ge.research.osate.verdict.dsl.verdict.Verdict)11 AnnexSubclause (org.osate.aadl2.AnnexSubclause)11 LPort (com.ge.research.osate.verdict.dsl.verdict.LPort)9 SLPort (com.ge.research.osate.verdict.dsl.verdict.SLPort)9 ComponentImpl (verdict.vdm.vdm_model.ComponentImpl)9 ComponentType (verdict.vdm.vdm_model.ComponentType)9 BusAccess (org.osate.aadl2.BusAccess)8