Search in sources :

Example 1 with FactoryConfigurationError

use of javax.xml.stream.FactoryConfigurationError in project OpenAttestation by OpenAttestation.

the class TAHelper method verifyQuoteAndGetPcr.

// BUG #497 need to rewrite this to return List<Pcr> ... the Pcr.equals()  does same as (actually more than) IManifest.verify() because Pcr ensures the index is the same and IManifest does not!  and also it is less redundant, because this method returns Map< pcr index as string, manifest object containing pcr index and value >  
private HashMap<String, PcrManifest> verifyQuoteAndGetPcr(String sessionId, String eventLog) {
    //Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
    HashMap<String, PcrManifest> pcrMp = new HashMap<String, PcrManifest>();
    String setUpFile;
    log.info("verifyQuoteAndGetPcr for session {}", sessionId);
    //log.info( "Command: {}",command);
    //List<String> result = CommandUtil.runCommand(command,true,"VerifyQuote");
    String certFileName = aikverifyhome + File.separator + getCertFileName(sessionId);
    //2. verification
    try {
        setUpFile = ResourceFinder.getFile("attestation-service.properties").getAbsolutePath();
        String fileLocation = setUpFile.substring(0, setUpFile.indexOf("attestation-service.properties"));
        String PrivacyCaCertFileName = "PrivacyCA.cer";
        //X509Certificate machineCertificate = pemToX509Certificate(certFileName);
        //X509Certificate machineCertificate = certFromFile(certFileName);
        certFromFile(certFileName);
        //X509Certificate pcaCert = certFromFile(fileLocation + PrivacyCaCertFileName);
        certFromFile(fileLocation + PrivacyCaCertFileName);
        log.info("passed the verification");
    } catch (Exception e) {
        log.error("Machine certificate was not signed by the privacy CA." + e.toString());
        throw new RuntimeException(e);
    }
    String nonceFileName = aikverifyhome + File.separator + getNonceFileName(sessionId);
    String quoteFileName = aikverifyhome + File.separator + getQuoteFileName(sessionId);
    String rsaPubkeyFileName = aikverifyhome + File.separator + getRSAPubkeyFileName(sessionId);
    List<String> result = aikqverify(nonceFileName, rsaPubkeyFileName, quoteFileName);
    for (String pcrString : result) {
        String[] parts = pcrString.trim().split(" ");
        if (parts.length == 2) {
            String pcrNumber = parts[0].trim().replaceAll(pcrNumberUntaint, "").replaceAll("\n", "");
            String pcrValue = parts[1].trim().replaceAll(pcrValueUntaint, "").replaceAll("\n", "");
            boolean validPcrNumber = pcrNumberPattern.matcher(pcrNumber).matches();
            boolean validPcrValue = pcrValuePattern.matcher(pcrValue).matches();
            if (validPcrNumber && validPcrValue) {
                log.info("Result PCR " + pcrNumber + ": " + pcrValue);
                pcrMp.put(pcrNumber, new PcrManifest(Integer.parseInt(pcrNumber), pcrValue));
            }
        } else {
            log.warn("Result PCR invalid");
        }
    }
    //</modules>
    if (eventLog != null) {
        log.debug("About to start processing eventLog");
        try {
            XMLInputFactory xif = XMLInputFactory.newInstance();
            StringReader sr = new StringReader(eventLog);
            XMLStreamReader reader = xif.createXMLStreamReader(sr);
            int extendedToPCR = -1;
            String digestValue = "";
            String componentName = "";
            while (reader.hasNext()) {
                if (reader.getEventType() == XMLStreamConstants.START_ELEMENT && reader.getLocalName().equalsIgnoreCase("module")) {
                    reader.next();
                    // Get the PCR Number to which the module is extended to
                    if (reader.getLocalName().equalsIgnoreCase("pcrNumber")) {
                        extendedToPCR = Integer.parseInt(reader.getElementText());
                    }
                    reader.next();
                    // Get the Module name 
                    if (reader.getLocalName().equalsIgnoreCase("name")) {
                        componentName = reader.getElementText();
                    }
                    reader.next();
                    // Get the Module hash value 
                    if (reader.getLocalName().equalsIgnoreCase("value")) {
                        digestValue = reader.getElementText();
                    }
                    boolean useHostSpecificDigest = false;
                    if (ArrayUtils.contains(openSourceHostSpecificModules, componentName)) {
                        useHostSpecificDigest = true;
                    }
                    // Attach the PcrEvent logs to the corresponding pcr indexes.
                    // Note: Since we will not be processing the even logs for 17 & 18, we will ignore them for now.
                    Measurement m = convertHostTpmEventLogEntryToMeasurement(extendedToPCR, componentName, digestValue, useHostSpecificDigest);
                    if (pcrMp.containsKey(String.valueOf(extendedToPCR))) {
                        if (pcrMp.get(String.valueOf(extendedToPCR)).containsPcrEventLog(extendedToPCR)) {
                            pcrMp.get(String.valueOf(extendedToPCR)).getPcrEventLog(extendedToPCR).getEventLog().add(m);
                        } else {
                            PcrIndex pcrIndex = new PcrIndex(extendedToPCR);
                            ArrayList<Measurement> list = new ArrayList<Measurement>();
                            list.add(m);
                            PcrEventLog eventlog = new PcrEventLog(pcrIndex, list);
                            pcrMp.get(String.valueOf(extendedToPCR)).setPcrEventLog(eventlog);
                        //pcrMf.setPcrEventLog(new PcrEventLog(new PcrIndex(extendedToPCR), list));
                        }
                    }
                }
                reader.next();
            }
        } catch (FactoryConfigurationError | XMLStreamException | NumberFormatException ex) {
            //log.error(ex.getMessage(), ex); 
            throw new IllegalStateException("Invalid measurement log", ex);
        }
    }
    return pcrMp;
}
Also used : Measurement(com.intel.mtwilson.util.model.Measurement) XMLStreamReader(javax.xml.stream.XMLStreamReader) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PcrEventLog(com.intel.mtwilson.util.model.PcrEventLog) ASException(com.intel.mountwilson.as.common.ASException) KeyStoreException(java.security.KeyStoreException) XMLStreamException(javax.xml.stream.XMLStreamException) SignatureException(java.security.SignatureException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) CertificateException(java.security.cert.CertificateException) UnknownHostException(java.net.UnknownHostException) PcrIndex(com.intel.mtwilson.util.model.PcrIndex) XMLStreamException(javax.xml.stream.XMLStreamException) PcrManifest(com.intel.mountwilson.manifest.data.PcrManifest) FactoryConfigurationError(javax.xml.stream.FactoryConfigurationError) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 2 with FactoryConfigurationError

use of javax.xml.stream.FactoryConfigurationError in project bazel by bazelbuild.

the class AndroidManifestProcessor method writeManifestPackage.

/**
   * Overwrite the package attribute of {@code <manifest>} in an AndroidManifest.xml file.
   *
   * @param manifest The input manifest.
   * @param customPackage The package to write to the manifest.
   * @param output The output manifest to generate.
   * @return The output manifest if generated or the input manifest if no overwriting is required.
   */
/* TODO(apell): switch from custom xml parsing to Gradle merger with NO_PLACEHOLDER_REPLACEMENT
   * set when android common is updated to version 2.5.0.
   */
public Path writeManifestPackage(Path manifest, String customPackage, Path output) {
    if (Strings.isNullOrEmpty(customPackage)) {
        return manifest;
    }
    try {
        Files.createDirectories(output.getParent());
        XMLEventReader reader = XMLInputFactory.newInstance().createXMLEventReader(Files.newInputStream(manifest), UTF_8.name());
        XMLEventWriter writer = XMLOutputFactory.newInstance().createXMLEventWriter(Files.newOutputStream(output), UTF_8.name());
        XMLEventFactory eventFactory = XMLEventFactory.newInstance();
        while (reader.hasNext()) {
            XMLEvent event = reader.nextEvent();
            if (event.isStartElement() && event.asStartElement().getName().toString().equalsIgnoreCase("manifest")) {
                StartElement element = event.asStartElement();
                @SuppressWarnings("unchecked") Iterator<Attribute> attributes = element.getAttributes();
                ImmutableList.Builder<Attribute> newAttributes = ImmutableList.builder();
                while (attributes.hasNext()) {
                    Attribute attr = attributes.next();
                    if (attr.getName().toString().equalsIgnoreCase("package")) {
                        newAttributes.add(eventFactory.createAttribute("package", customPackage));
                    } else {
                        newAttributes.add(attr);
                    }
                }
                writer.add(eventFactory.createStartElement(element.getName(), newAttributes.build().iterator(), element.getNamespaces()));
            } else {
                writer.add(event);
            }
        }
        writer.flush();
    } catch (XMLStreamException | FactoryConfigurationError | IOException e) {
        throw new RuntimeException(e);
    }
    return output;
}
Also used : Attribute(javax.xml.stream.events.Attribute) XMLEventFactory(javax.xml.stream.XMLEventFactory) ImmutableList(com.google.common.collect.ImmutableList) IOException(java.io.IOException) StartElement(javax.xml.stream.events.StartElement) XMLStreamException(javax.xml.stream.XMLStreamException) XMLEventWriter(javax.xml.stream.XMLEventWriter) XMLEvent(javax.xml.stream.events.XMLEvent) XMLEventReader(javax.xml.stream.XMLEventReader) FactoryConfigurationError(javax.xml.stream.FactoryConfigurationError)

Example 3 with FactoryConfigurationError

use of javax.xml.stream.FactoryConfigurationError in project nifi by apache.

the class HtmlDocumentationWriter method write.

@Override
public void write(final ConfigurableComponent configurableComponent, final OutputStream streamToWriteTo, final boolean includesAdditionalDocumentation) throws IOException {
    try {
        XMLStreamWriter xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(streamToWriteTo, "UTF-8");
        xmlStreamWriter.writeDTD("<!DOCTYPE html>");
        xmlStreamWriter.writeStartElement("html");
        xmlStreamWriter.writeAttribute("lang", "en");
        writeHead(configurableComponent, xmlStreamWriter);
        writeBody(configurableComponent, xmlStreamWriter, includesAdditionalDocumentation);
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.close();
    } catch (XMLStreamException | FactoryConfigurationError e) {
        throw new IOException("Unable to create XMLOutputStream", e);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) IOException(java.io.IOException) FactoryConfigurationError(javax.xml.stream.FactoryConfigurationError)

Example 4 with FactoryConfigurationError

use of javax.xml.stream.FactoryConfigurationError in project webservices-axiom by apache.

the class StAXImplementation method newFactory.

private <T> T newFactory(Class<T> type) {
    String className = props == null ? null : props.getProperty(type.getName());
    if (className == null) {
        // by unit tests, but this must not interfere with the dialect tests.
        try {
            BufferedReader in = new BufferedReader(new InputStreamReader(classLoader.getResourceAsStream("META-INF/services/" + type.getName()), "UTF-8"));
            try {
                className = in.readLine();
            } finally {
                in.close();
            }
        } catch (IOException ex) {
            throw new FactoryConfigurationError(ex);
        }
    }
    T factory;
    try {
        factory = classLoader.loadClass(className).asSubclass(type).newInstance();
    } catch (Exception ex) {
        throw new FactoryConfigurationError(ex);
    }
    // is not reliable (because it may be null). Hence the check on ParentLastURLClassLoader.
    if (classLoader instanceof ParentLastURLClassLoader && factory.getClass().getClassLoader() != classLoader) {
        throw new FactoryConfigurationError("Wrong factory: got " + factory.getClass().getName() + " loaded from " + factory.getClass().getClassLoader());
    }
    return factory;
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) FactoryConfigurationError(javax.xml.stream.FactoryConfigurationError) IOException(java.io.IOException)

Example 5 with FactoryConfigurationError

use of javax.xml.stream.FactoryConfigurationError in project sirix by sirixdb.

the class XMLRecordReader method initialize.

@Override
public void initialize(final InputSplit paramGenericSplit, final TaskAttemptContext paramContext) throws IOException {
    final FileSplit split = (FileSplit) paramGenericSplit;
    mConf = paramContext.getConfiguration();
    mEventFactory = XMLEventFactory.newInstance();
    mPageEvents = new ArrayList<>();
    mStart = split.getStart();
    mEnd = mStart + split.getLength();
    mValue = new Text();
    mKey = new DateWritable();
    mWriter = new StringWriter();
    try {
        mEventWriter = XMLOutputFactory.newInstance().createXMLEventWriter(mWriter);
    } catch (final XMLStreamException | FactoryConfigurationError e) {
        LOGWRAPPER.error(e.getMessage(), e);
    }
    final Path file = split.getPath();
    // Open the file and seek to the start of the split.
    final FileSystem fileSys = file.getFileSystem(mConf);
    final FSDataInputStream fileIn = fileSys.open(split.getPath());
    fileIn.seek(mStart);
    final CompressionCodecFactory comprCodecs = new CompressionCodecFactory(mConf);
    final CompressionCodec codec = comprCodecs.getCodec(file);
    InputStream input = fileIn;
    if (codec != null) {
        input = codec.createInputStream(fileIn);
        mEnd = Long.MAX_VALUE;
    }
    input = new BufferedInputStream(input);
    final XMLInputFactory xmlif = XMLInputFactory.newInstance();
    try {
        mReader = xmlif.createXMLEventReader(input);
    } catch (final XMLStreamException e) {
        LOGWRAPPER.error(e.getMessage(), e);
    }
    // Create start/end record filters.
    final String recordIdentifier = mConf.get("record_element_name");
    final String recordNsPrefix = mConf.get("namespace_prefix") == null ? "" : mConf.get("namespace_prefix");
    final String recordNsURI = mConf.get("namespace_URI") == null ? "" : mConf.get("namespace_URI");
    if (recordIdentifier == null) {
        throw new IllegalStateException("Record identifier must be specified (record_elem_name)!");
    }
    if (recordNsPrefix == "" && recordNsURI == "") {
        mRecordElem = mEventFactory.createStartElement(new QName(recordIdentifier), null, null);
    } else {
        mRecordElem = mEventFactory.createStartElement(new QName(recordNsURI, recordIdentifier, recordNsPrefix), null, null);
    }
    mBeginFilter = new EventFilter() {

        @Override
        public boolean accept(final XMLEvent paramEvent) {
            return paramEvent.isStartElement() && paramEvent.asStartElement().getName().getLocalPart().equals(mRecordElem.getName().getLocalPart()) && paramEvent.asStartElement().getName().getPrefix().equals(mRecordElem.getName().getPrefix());
        }
    };
    mEndFilter = new EventFilter() {

        @Override
        public boolean accept(final XMLEvent paramEvent) {
            return paramEvent.isEndElement() && paramEvent.asEndElement().getName().getLocalPart().equals(mRecordElem.getName().getLocalPart()) && paramEvent.asEndElement().getName().getPrefix().equals(mRecordElem.getName().getPrefix());
        }
    };
    mDate = new QName(recordNsURI, mConf.get("timestamp"), recordNsPrefix);
    mPage = new QName(recordNsURI, mConf.get("page"), recordNsPrefix);
    try {
        while (mReader.hasNext() && !(mReader.peek().isStartElement() && mReader.peek().asStartElement().getName().equals(mPage))) {
            mReader.next();
        }
    } catch (final XMLStreamException e) {
        LOGWRAPPER.error(e.getMessage(), e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) BufferedInputStream(java.io.BufferedInputStream) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) InputStream(java.io.InputStream) QName(javax.xml.namespace.QName) Text(org.apache.hadoop.io.Text) FileSplit(org.apache.hadoop.mapreduce.lib.input.FileSplit) EventFilter(javax.xml.stream.EventFilter) StringWriter(java.io.StringWriter) XMLStreamException(javax.xml.stream.XMLStreamException) CompressionCodecFactory(org.apache.hadoop.io.compress.CompressionCodecFactory) BufferedInputStream(java.io.BufferedInputStream) FileSystem(org.apache.hadoop.fs.FileSystem) XMLEvent(javax.xml.stream.events.XMLEvent) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) CompressionCodec(org.apache.hadoop.io.compress.CompressionCodec) FactoryConfigurationError(javax.xml.stream.FactoryConfigurationError) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Aggregations

FactoryConfigurationError (javax.xml.stream.FactoryConfigurationError)25 IOException (java.io.IOException)14 XMLStreamException (javax.xml.stream.XMLStreamException)11 StringWriter (java.io.StringWriter)6 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)6 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)5 ConfigurationException (org.opensaml.xml.ConfigurationException)5 SAXException (org.xml.sax.SAXException)5 StringReader (java.io.StringReader)3 Writer (java.io.Writer)3 XMLInputFactory (javax.xml.stream.XMLInputFactory)3 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)3 XMLEvent (javax.xml.stream.events.XMLEvent)3 MarshallingException (org.opensaml.xml.io.MarshallingException)3 InputStream (java.io.InputStream)2 InvalidKeyException (java.security.InvalidKeyException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 SignatureException (java.security.SignatureException)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 XMLEventReader (javax.xml.stream.XMLEventReader)2