Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
The BSD License Copyright (c) 2010-2012 RIPE NCC All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the RIPE NCC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 package net.ripe.rpki.commons.provisioning.interop;
 
 import static org.junit.Assert.*;
 
 import java.io.File;
 import java.util.List;
 import org.junit.Test;
 
 
 public class ProcessIscUpdownPdusTest {
 
     private static final String PATH_TO_TEST_PDUS = "src/test/resources/isc-interop-updown";
 
     @Test
         byte[] encoded = FileUtils.readFileToByteArray(new File( + "/pdu.200.der"));
         ProvisioningCmsObjectParser parser = new ProvisioningCmsObjectParser();
         parser.parseCms("cms"encoded);
         ValidationResult validationResult = parser.getValidationResult();
         for (ValidationCheck check : validationResult.getFailures(new ValidationLocation("cms"))) {
             ..println("Failure: " + check);
         }
         ProvisioningCmsObject provisioningCmsObject = parser.getProvisioningCmsObject();
 
         CertificateIssuanceRequestPayload payload = (CertificateIssuanceRequestPayloadprovisioningCmsObject.getPayload();
 
         PKCS10CertificationRequest certificateRequest = payload.getRequestElement().getCertificateRequest();
 
         RpkiCaCertificateRequestParser rpkiCaCertificateRequestParser = new RpkiCaCertificateRequestParser(certificateRequest);
         assertNotNull(rpkiCaCertificateRequestParser.getCaRepositoryUri());
         assertNotNull(rpkiCaCertificateRequestParser.getManifestUri());
         assertNotNull(rpkiCaCertificateRequestParser.getPublicKey());
     }
 
     @Test
     public void shouldReadIscChildIdentityXml() throws IOException {
         assertNotNull(childCert);
     }
 
     @Test
     public void shouldReadIscIssuerXml() throws IOException {
         String parentXml = FileUtils.readFileToString(new File( + "/issuer-alice-child-bob-parent.xml"), "UTF-8");
         ParentIdentitySerializer serializer = new ParentIdentitySerializer();
         ParentIdentity parentId = serializer.deserialize(parentXml);
         assertNotNull(parentId);
     }
        String childIdXml = FileUtils.readFileToString(new File( + "/carol-child-id.xml"), "UTF-8");
        ChildIdentitySerializer serializer = new ChildIdentitySerializer();
        ChildIdentity childId = serializer.deserialize(childIdXml);
        ProvisioningIdentityCertificate childCert = childId.getIdentityCertificate();
        return childCert;
    }
    @Test
    public void shouldValidateRequest() throws IOException {
        // Note this object expired 30 June 2012. Maybe get a new one sometime?
        byte[] encoded = FileUtils.readFileToByteArray(new File( + "/pdu.200.der"));
        parser.parseCms("cms"encoded);
        ProvisioningCmsObject provisioningCmsObject = parser.getProvisioningCmsObject();
        ProvisioningCmsObjectValidator validator = new ProvisioningCmsObjectValidator(new ValidationOptions(), provisioningCmsObjectchildCert);
        ValidationResult result = new ValidationResult();
        validator.validate(result);
//        for (ValidationLocation location : result.getValidatedLocations()) {
//            for (ValidationCheck check : result.getFailures(location)) {
//                System.err.println(location + " : " + check);
//            }
//        }
        List<ValidationCheckfailures = result.getFailuresForAllLocations();
        assertEquals(3, failures.size());
        failures.contains(new ValidationCheck(.."2012-06-30T04:08:03.000Z"));
        failures.contains(new ValidationCheck(.."2012-06-30T04:07:24.000Z"));
        failures.contains(new ValidationCheck(.."2012-06-30T04:07:24.000Z"));
    }
    @Test
    public void shouldParseAllIscUpDownMessages() throws IOException {
        String[] Files = new String[] {"pdu.170.der""pdu.171.der""pdu.172.der""pdu.173.der""pdu.180.der""pdu.183.der""pdu.184.der",
                "pdu.189.der""pdu.196.der""pdu.199.der""pdu.200.der""pdu.205.der"};
        for (String fileName : Files) {
            byte[] encoded = FileUtils.readFileToByteArray(new File( + "/" + fileName));
            ProvisioningCmsObjectParser parser = new ProvisioningCmsObjectParser();
            parser.parseCms("cms"encoded);
//            System.err.println("\nDumping: " + fileName + "\n");
//            HexDump.dump(encoded, 0, System.err, 0);
//            System.err.println("\n");
            assertTrue("Error parsing file: " + fileName + " and giving up!", !parser.getValidationResult().hasFailures());
        }
    }
    @Test
    public void shouldParseRpkidParentResponseXml() throws IOException {
        String xml = FileUtils.readFileToString(new File( + "/rpkid-parent-response.xml"), "UTF-8");
        ParentIdentitySerializer serializer = new ParentIdentitySerializer();
        ParentIdentity parentId = serializer.deserialize(xml);
        assertNotNull(parentId);
    }
    @Test
        // dtag-outbound-1.der
        String[] Files = new String[] {"dtag-outbound-1.der""dtag-outbound-9.der" };
        for (String fileName : Files) {
            String base64Encoded = FileUtils.readFileToString(new File( + "/" + fileName));
            byte[] encoded = Base64.decodeBase64(base64Encoded);
            ProvisioningCmsObjectParser parser = new ProvisioningCmsObjectParser();
            parser.parseCms("cms"encoded);
            ValidationResult validationResult = parser.getValidationResult();
//            System.err.println("\nDumping: " + fileName + "\n");
//            HexDump.dump(encoded, 0, System.err, 0);
//            System.err.println("\n");
//
//            ASN1Primitive decodedObject = Asn1Util.decode(encoded);
//            System.err.println(ASN1Dump.dumpAsString(decodedObject));
//
//            for (ValidationLocation location : validationResult.getValidatedLocations()) {
//                for (ValidationCheck check : validationResult.getAllValidationChecksForLocation(location)) {
//                    System.err.println(check);
//                }
//            }
            assertTrue("Error parsing file: " + fileName + " and giving up!", !validationResult.hasFailures());
        }
    }
    @SuppressWarnings("unused")
    private void dumpAsn1StructureToStdErr(byte[] encoded) {
        ..println(ASN1Dump.dumpAsString(Asn1Util.decode(encoded)));
    }
New to GrepCode? Check out our FAQ X