Coder Social home page Coder Social logo

java-stix's People

Contributors

gtback avatar leemeng-tecforte avatar manonthegithub avatar nemonik avatar rroberge avatar ruke47 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

java-stix's Issues

org.mitre.stix.stix_1.STIXPackage.fromXMLString parsing XML to String issue

I am using stix 1.2.0.2 with the dependency
compile 'org.mitre:stix:1.2.0.2' from
https://github.com/STIXProject/java-stix but I see the following error
when I try to convert a XML file to String calling the API . I am
using java version "1.7.0_76" Java(TM) SE Runtime Environment (build
1.7.0_76-b13) to compile. The artifact is deployed in Oracle Weblogic Server 12.1.3 but works from command line invoking main class from the jar

org.mitre.stix.stix_1.STIXPackage.fromXMLString(STIXPackage.java:1087)

java.lang.ClassCastException:
com.sun.org.apache.xerces.internal.dom.DocumentImpl cannot be cast to
org.w3c.dom.Element
at org.eclipse.persistence.internal.oxm.XMLCompositeObjectMappingNodeValue.endSelfNodeValue(XMLCompositeObjectMappingNodeValue.java:431)
at org.eclipse.persistence.oxm.record.UnmarshalRecord.endDocument(UnmarshalRecord.java:597)
at org.eclipse.persistence.oxm.record.UnmarshalRecord.endDocument(UnmarshalRecord.java:587)
at org.eclipse.persistence.oxm.record.UnmarshalRecord.endElement(UnmarshalRecord.java:1038)
at org.eclipse.persistence.internal.oxm.record.XMLReader$ValidatingContentHandler.endElement(XMLReader.java:438)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:609)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1782)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2973)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:117)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:648)
at weblogic.xml.jaxp.WebLogicXMLReader.parse(WebLogicXMLReader.java:133)
at weblogic.xml.jaxp.RegistryXMLReader.parse(RegistryXMLReader.java:173)
at org.eclipse.persistence.internal.oxm.record.XMLReader.parse(XMLReader.java:222)
at org.eclipse.persistence.internal.oxm.record.SAXUnmarshaller.unmarshal(SAXUnmarshaller.java:883)
at org.eclipse.persistence.internal.oxm.record.SAXUnmarshaller.unmarshal(SAXUnmarshaller.java:372)
at org.eclipse.persistence.internal.oxm.record.SAXUnmarshaller.unmarshal(SAXUnmarshaller.java:613)
at org.eclipse.persistence.internal.oxm.record.SAXUnmarshaller.unmarshal(SAXUnmarshaller.java:649)
at org.eclipse.persistence.oxm.XMLUnmarshaller.unmarshal(XMLUnmarshaller.java:588)
at org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:285)
at org.mitre.stix.stix_1.STIXPackage.fromXMLString(STIXPackage.java:1087)

Thanks,
Sunil

Problems runing the sample code example with ver 1.2.0.2

Hi

I downloaded the jar release of stix-1.2.0.2 (I also compiled it by myself but I thought that maybe I did something wrong) and tried to run the sample code, XMLParser.java

I compile it using eclipce and get some errors

XMLParser:

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The type org.jvnet.jaxb2_commons.lang.ToString cannot be resolved. It is indirectly referenced from required .class files
The type org.jvnet.jaxb2_commons.lang.HashCode cannot be resolved. It is indirectly referenced from required .class files
The type org.jvnet.jaxb2_commons.lang.Equals cannot be resolved. It is indirectly referenced from required .class files

at org.mitre.stix.examples.XMLParser.main(XMLParser.java:53)

It looks like the org.jvnet.jaxb2_commons library that you depends on doesn't included inside your jar.

Hope you could help me

Bug: converting stix messages with DocumentUtilities.toDocument is very slow( > 1 second)

The method in DocumentUtilities has following implementation:

public static Document toDocument(JAXBElement<?> jaxbElement,
			boolean prettyPrint) {

		Document document = null;
		
		try {
			DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
					.newInstance();
			documentBuilderFactory.setNamespaceAware(true);
			documentBuilderFactory.setIgnoringElementContentWhitespace(true);
			documentBuilderFactory.isIgnoringComments();
			documentBuilderFactory.setCoalescing(true);

			document = documentBuilderFactory.newDocumentBuilder()
					.newDocument();
//!!! this is costly operation, should be performed once per application!!!
			JAXBContext jaxbContext = JAXBContext.newInstance(jaxbElement
					.getDeclaredType().getPackage().getName());

			Marshaller marshaller = jaxbContext.createMarshaller();

			marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
					prettyPrint);

			marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");

			try {
				marshaller.marshal(jaxbElement, document);
			} catch (JAXBException e) {
				// otherwise handle non-XMLRootElements
				QName qualifiedName = new QName(
						STIXSchema.getNamespaceURI(jaxbElement), jaxbElement
								.getClass().getSimpleName());

				@SuppressWarnings({ "rawtypes", "unchecked" })
				JAXBElement root = new JAXBElement(qualifiedName,
						jaxbElement.getClass(), jaxbElement);

				marshaller.marshal(root, document);
			}

			removeUnusedNamespaces(document);

		} catch (ParserConfigurationException e) {
			throw new RuntimeException(e);
		} catch (JAXBException e) {
			throw new RuntimeException(e);
		}
		
		return document;
	}

The problem is that new JAXBContext is initialized with JAXBContext.newInstance every time you want to convert your stix package to document, but it is costly and takes more than a second. JAXBContext should be instantiated once and cached.

Can't rename to Archive_File_Object.xsd : Permission denied

I'm running the gradle in GIT Bash command window and get the error as mentioned above.

Below are the command window log:
$ ./gradlew -x signArchives
:buildSrc:compileJava UP-TO-DATE
:buildSrc:compileGroovy UP-TO-DATE
:buildSrc:processResources UP-TO-DATE
:buildSrc:classes UP-TO-DATE
:buildSrc:jar UP-TO-DATE
:buildSrc:assemble UP-TO-DATE
:buildSrc:compileTestJava UP-TO-DATE
:buildSrc:compileTestGroovy UP-TO-DATE
:buildSrc:processTestResources UP-TO-DATE
:buildSrc:testClasses UP-TO-DATE
:buildSrc:test UP-TO-DATE
:buildSrc:check UP-TO-DATE
:buildSrc:build UP-TO-DATE
:clean UP-TO-DATE
:retrieveSchemas
Schemas are present. Retrieval is not needed.
Patching C:\workspace\git\java-stix\src\main\resources\schemas\v1.2.0\cybox
objects\Archive_File_Object.xsd
[ant:patch] patch: **** can't rename /tmp/po010680' toC:\workspace\git\java-stix\src\main\resources\schemas\v1.2.0\cybox\objects\Archive_File_Object.xsd' : Permission denied
[ant:patch] 'patch' failed with exit code 2
:createPrefixNamespaceBindings FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':createPrefixNamespaceBindings'.

    1

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug
    option to get more log output.

BUILD FAILED

Total time: 7.465 secs

Maven repository jars compiled with Java 8

Our project's customer has specified Java 7 in their deployment enviroment, but when I run the STIX jar against a version 7 JRE I get a:

java.lang.UnsupportedClassVersionError: org/mitre/cybox/common_2/ObjectPropertiesType : Unsupported major.minor version 52.0

And wikipedia (http://en.wikipedia.org/wiki/Java_class_file) says than version 52.0 is for J2SE 8. This project's README says that the project builds under version 7, so would it be possible to provide the maven repository jars compiled under that version of the JDK?

After parsing a STIX UTF-8 document Observable's file name is null

  • Library version 1.1.1.2
  • The STIX xml document to reproduce this issue is:
<stix:STIX_Package id="mandiant:package-190593d6-1861-4cfe-b212-c016fce1e241" version="1.0.1"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:stix="http://stix.mitre.org/stix-1"
    xmlns:stixVocabs="http://stix.mitre.org/default_vocabularies-1"
    xmlns:stixCommon="http://stix.mitre.org/common-1"
    xmlns:cybox="http://cybox.mitre.org/cybox-2"
    xmlns:cyboxCommon="http://cybox.mitre.org/common-2"
    xmlns:cyboxVocabs="http://cybox.mitre.org/default_vocabularies-2"
    xmlns:indicator="http://stix.mitre.org/Indicator-2"
    xmlns:ttp="http://stix.mitre.org/TTP-1"
    xmlns:marking="http://data-marking.mitre.org/Marking-1"
    xmlns:simpleMarking="http://data-marking.mitre.org/extensions/MarkingStructure#Simple-1"
    xmlns:mandiant="http://www.mandiant.com"
    xmlns:FileObj="http://cybox.mitre.org/objects#FileObject-2"

    xsi:schemaLocation="
    http://stix.mitre.org/stix-1 http://stix.mitre.org/XMLSchema/core/1.0.1/stix_core.xsd
    http://stix.mitre.org/default_vocabularies-1 http://stix.mitre.org/XMLSchema/default_vocabularies/1.0.1/stix_default_vocabularies.xsd
    http://stix.mitre.org/common-1 http://stix.mitre.org/XMLSchema/common/1.0.1/stix_common.xsd
    http://cybox.mitre.org/cybox-2 http://cybox.mitre.org/XMLSchema/core/2.0.1/cybox_core.xsd
    http://cybox.mitre.org/common-2 http://cybox.mitre.org/XMLSchema/common/2.0.1/cybox_common.xsd
    http://cybox.mitre.org/default_vocabularies-2 http://cybox.mitre.org/XMLSchema/default_vocabularies/2.0.1/cybox_default_vocabularies.xsd
    http://stix.mitre.org/Indicator-2 http://stix.mitre.org/XMLSchema/indicator/2.0.1/indicator.xsd
    http://stix.mitre.org/TTP-1 http://stix.mitre.org/XMLSchema/ttp/1.0.1/ttp.xsd
    http://data-marking.mitre.org/Marking-1 http://stix.mitre.org/XMLSchema/data_marking/1.0.1/data_marking.xsd
    http://data-marking.mitre.org/extensions/MarkingStructure#Simple-1 http://stix.mitre.org/XMLSchema/extensions/marking/simple_marking/1.0.1/simple_marking.xsd
    http://cybox.mitre.org/objects#FileObject-2 http://cybox.mitre.org/XMLSchema/objects/File/2.0.1/File_Object.xsd
    ">
    <stix:STIX_Header>
        <stix:Title>STIX Exploratory UTF κόσμε</stix:Title>
        <stix:Package_Intent xsi:type="stixVocabs:PackageIntentVocab-1.0">Package Intent UTF κόσμε</stix:Package_Intent>
        <stix:Description>STIX Exploratory Description UTF κόσμε</stix:Description>
        <stix:Handling>
            <marking:Marking xmlns="http://data-marking.mitre.org">
                <marking:Controlled_Structure>//node()</marking:Controlled_Structure>
                <marking:Marking_Structure xsi:type="simpleMarking:SimpleMarkingStructureType">
                    <simpleMarking:Statement>Statement UTF κόσμε</simpleMarking:Statement>
                </marking:Marking_Structure>
            </marking:Marking>
        </stix:Handling>
        <stix:Information_Source>
            <stixCommon:Identity>
                <stixCommon:Name>Mandiant</stixCommon:Name>
            </stixCommon:Identity>
            <stixCommon:Contributors>
                <stixCommon:Contributor>
                    <stixCommon:Name>MITRE (STIX Conversion) UTF κόσμε</stixCommon:Name>
                </stixCommon:Contributor>
            </stixCommon:Contributors>
        </stix:Information_Source>
    </stix:STIX_Header>

    <stix:Observables cybox_minor_version="0" cybox_major_version="1" cybox_update_version="1">

        <!-- UTF encoding test -->
        <cybox:Observable id="mandiant:observable-f21f0e4b-815a-4520-86e4-8a048e14ff3e">
                <cybox:Object>
                    <cybox:Properties xsi:type="FileObj:FileObjectType">
                        <FileObj:Hashes>
                            <cyboxCommon:Hash>
                                <cyboxCommon:Type>MD5</cyboxCommon:Type>
                                <cyboxCommon:Simple_Hash_Value>481a2f2c588910c21a668c19b63c1138</cyboxCommon:Simple_Hash_Value>
                                <FileObj:File_Name>κόσμε.exe</FileObj:File_Name>
                            </cyboxCommon:Hash>
                        </FileObj:Hashes>
                    </cybox:Properties>
                </cybox:Object>
        </cybox:Observable>
    </stix:Observables>
</stix:STIX_Package>
  • Then use the following API to create the corresponding STIXPackage object:
final String stixContent = IOUtils.toString(inputStream, "UTF-8");
final STIXPackage stixPackage = STIXPackage.fromXMLString(stixContent);
  • Finally what I get is:
    • stixContent has all the expected UTF-8 strings (titles, file name).
    • stixPackage has only UTF-8 strings for the STIX header xml, but not for the Observabes xml section, particularly filename which equals to null

Add support for validation against external schemas

Not sure if this belongs here or in java-stix-validator, so sorry if I posted in the wrong place.

If I define a custom ControlledVocabularyType extension as described here and then attempt to validate an instance document which leverages that controlled vocabulary, I get the following error in java-stix-validator:

SAXParseException:
    Public ID: null
    System ID: null
    Line     : 3
    Column   : 70
    Message  : cvc-elt.4.2: Cannot resolve 'customVocabs:CustomVocab-1.0' to a type definition for element 'stix:Package_Intent'.

It would be nice to provide a function which makes it easy to pass in a directory of schemas to validate a STIX document against and support the validation of third-party extensions.

STIX 2.0 Support

Hi,
Are you planning to publish a version with STIX 2.0 support soon?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.