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.crypto.cms.manifest;
 
 
 import java.net.URI;
 import java.util.Map;
 import java.util.Set;

A manifest of files published by a CA certificate.

Use the ManifestCmsBuilder or ManifestCmsParser to construct this object.

 
 public class ManifestCms extends RpkiSignedObject {
 
     private static final long serialVersionUID = 1L;
 
     public static final int DEFAULT_VERSION = 0;
 
     public static final String CONTENT_TYPE_OID = "1.2.840.113549.1.9.16.1.26";
 
     public static final String FILE_HASH_ALGORITHM = .;
 
     private Map<Stringbyte[]> files;
 
 
     ManifestCms(RpkiSignedObjectInfo cmsObjectDataManifestCmsGeneralInfo manifestCmsGeneralInfoMap<Stringbyte[]> files) {
         super(cmsObjectData);
         this. = manifestCmsGeneralInfo;
         this. = files;
     }
 
     public int getVersion() {
         return .getVersion();
     }
 
     public BigInteger getNumber() {
         return .getNumber();
     }
 
     public String getFileHashAlgorithm() {
         return .getFileHashAlgorithm();
     }
 
     public DateTime getThisUpdateTime() {
         return .getThisUpdateTime();
     }
    public DateTime getNextUpdateTime() {
        return .getNextUpdateTime();
    }
    public int size() {
        return .size();
    }
    public boolean containsFile(String fileName) {
        return .containsKey(fileName);
    }
    public Map<Stringbyte[]> getFiles() {
        return ;
    }
    public Set<StringgetFileNames() {
        return .keySet();
    }
    @Override
    public URI getCrlUri() {
    }
    @Override
    public URI getParentCertificateUri() {
        return getCertificate().getParentCertificateUri();
    }
    @Override
    public void validate(String locationCertificateRepositoryObjectValidationContext contextCrlLocator crlLocatorValidationOptions optionsValidationResult result) {
        ValidationLocation savedCurrentLocation = result.getCurrentLocation();
        result.setLocation(new ValidationLocation(getCrlUri()));
        X509Crl crl = crlLocator.getCrl(getCrlUri(), contextresult);
        result.setLocation(savedCurrentLocation);
        if (crl == null) {
            return;
        }
        result.setLocation(new ValidationLocation(location));
        checkManifestAndEeCertificateValidityTimes(optionsresult);
        ManifestCmsEeCertificateValidator validator = new ManifestCmsEeCertificateValidator(optionsresultcontext.getCertificate(), crlcontext.getResources());
        validator.validate(locationgetCertificate());
    }
        ValidityPeriod certificateValidity = getCertificate().getValidityPeriod();
        DateTime now = new DateTime();
        DateTime nextUpdateTime = getNextUpdateTime();
        if (now.isAfter(nextUpdateTime)) {
            if (nextUpdateTime.plusDays(options.getMaxStaleDays()).isAfter(now)) {
                 result.warnIfTrue(true.);
            } else {
                result.rejectIfTrue(true.);
            }
        }
    }

    
    @Deprecated
    public byte[] getHash(String fileName) {
        return .get(fileName);
    }
    public boolean verifyFileContents(String fileNamebyte[] contents) {
        return getFileContentSpecification(fileName).isSatisfiedBy(contents);
    }
        Validate.isTrue(containsFile(fileName));
        return new FileContentSpecification(getHash(fileName));
    }
    public static byte[] hashContents(byte[] contents) {
        DigestOutputStream digestOut = null;
        try {
            Digest digest = new SHA256Digest();
            digestOut = new DigestOutputStream(digest);
            digestOut.write(contents);
            digestOut.flush();
            byte[] digestValue = new byte[digest.getDigestSize()];
            digest.doFinal(digestValue, 0);
            return digestValue;
        } catch (IOException e) {
            throw new ManifestCmsException(e);
        } finally {
            if (digestOut != null) {
                IOUtils.closeQuietly(digestOut);
            }
        }
    }
    public static class FileContentSpecification implements Specification<byte[]> {
        private byte[] hash;
        public FileContentSpecification(byte[] hash) {
            this. = Arrays.copyOf(hashhash.length);
        }
        public byte[] getHash() {
            return Arrays.copyOf(.);
        }
        @Override
        public boolean isSatisfiedBy(byte[] contents) {
            return Arrays.equals(hashContents(contents));
        }
        @Override
        public int hashCode() {
            final int prime = 31;
            int result = 1;
            result = prime * result + Arrays.hashCode();
            return result;
        }
        @Override
        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final FileContentSpecification other = (FileContentSpecificationobj;
            return Arrays.equals(other.hash);
        }
        @Override
        public String toString() {
            return new ToStringBuilder(this.).append("hash").toString();
        }
    }
New to GrepCode? Check out our FAQ X