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.cms;
 import java.util.Date;
 import java.util.List;
 public class ProvisioningCmsObjectBuilder {
     private static final ASN1ObjectIdentifier CONTENT_TYPE = new ASN1ObjectIdentifier("1.2.840.113549.");
     private X509Certificate cmsCertificate;
     private X509CRL crl;
     private String payloadContent;
         this. = cmsCertificate;
         return this;
     public ProvisioningCmsObjectBuilder withCrl(X509CRL crl) {
         this. = crl;
         return this;
    public ProvisioningCmsObjectBuilder withSignatureProvider(String signatureProvider) {
        this. = signatureProvider;
        return this;
        this. = PayloadParser.serialize(payload);
        return this;
    public ProvisioningCmsObject build(PrivateKey privateKey) {
        Validate.notEmpty("Payload content is required");
        Validate.notNull("cms certificate is required");
        Validate.notNull("crl is required");
        ValidationResult validationResult = parser.getValidationResult();
        if (validationResult.hasFailures()) {
            List<StringfailureMessages = new ArrayList<String>();
            List<ValidationCheckfailures = validationResult.getFailures(new ValidationLocation("generated.cms"));
            for (ValidationCheck check : failures) {
            Validate.isTrue(false"Validation of generated CMS object failed with following errors: " + StringUtils.join(failureMessages","));
        return parser.getProvisioningCmsObject();
    private byte[] generateCms(PrivateKey privateKey) {
        try {
            return doGenerate(privateKey);
        } catch (CMSException e) {
            throw new ProvisioningCmsObjectBuilderException(e);
        } catch (IOException e) {
            throw new ProvisioningCmsObjectBuilderException(e);
        } catch (OperatorCreationException e) {
            throw new ProvisioningCmsObjectBuilderException(e);
        } catch (CRLException e) {
            throw new ProvisioningCmsObjectBuilderException(e);
        } catch (CertificateEncodingException e) {
            throw new ProvisioningCmsObjectBuilderException(e);
        CMSSignedDataGenerator generator = new CMSSignedDataGenerator();
        CMSSignedData data = generator.generate(new CMSProcessableByteArray(.getBytes(Charset.forName("UTF-8"))), true);
        return data.getEncoded();
    private void addSignerInfo(CMSSignedDataGenerator generatorPrivateKey privateKeythrows OperatorCreationException {
        List<X509Extensioncertificates = new ArrayList<X509Extension>();
        generator.addCertificates(new JcaCertStore(certificates));
        generator.addCRLs(new JcaCRLStore(Collections.singleton()));
        Hashtable<ASN1ObjectIdentifierAttributeattributes = new Hashtable<ASN1ObjectIdentifierAttribute>(); // NOPMD
        // -
        // ReplaceHashtableWithMap
        Attribute signingTimeAttribute = new Attribute(.new DERSet(new Time(new Date(DateTimeUtils.currentTimeMillis()))));
        return new AttributeTable(attributes);
New to GrepCode? Check out our FAQ X