// --- BEGIN COPYRIGHT BLOCK --- // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; version 2 of the License. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with this program; if not, write to the Free Software Foundation, Inc., // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // // (C) 2007 Red Hat, Inc. // All rights reserved. // --- END COPYRIGHT BLOCK --- package com.netscape.cmstools; import java.io.ByteArrayInputStream; import java.io.FileInputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import netscape.security.util.CertPrettyPrint; import netscape.security.x509.X509CertImpl; import org.mozilla.jss.asn1.ASN1Util; import org.mozilla.jss.asn1.INTEGER; import org.mozilla.jss.asn1.OBJECT_IDENTIFIER; import org.mozilla.jss.asn1.OCTET_STRING; import org.mozilla.jss.asn1.SEQUENCE; import org.mozilla.jss.asn1.SET; import org.mozilla.jss.pkix.cert.Certificate; import org.mozilla.jss.pkix.cmc.CMCStatusInfo; import org.mozilla.jss.pkix.cmc.OtherInfo; import org.mozilla.jss.pkix.cmc.PendInfo; import org.mozilla.jss.pkix.cmc.ResponseBody; import org.mozilla.jss.pkix.cmc.TaggedAttribute; import org.mozilla.jss.pkix.cms.EncapsulatedContentInfo; /** * Tool for parsing a CMC response * *

* @version $Revision$, $Date$ * */ public class CMCResponse { public CMCResponse() { } public static void printOutput(String path, String filename) { byte[] bb = new byte[10000]; FileInputStream fis = null; try { fis = new FileInputStream(filename); while (fis.available() > 0) fis.read(bb, 0, 10000); } catch (Exception e) { System.out.println("Error reading the response. Exception: "+e.toString()); System.exit(1); } try { ByteArrayInputStream bis = new ByteArrayInputStream(bb); org.mozilla.jss.pkix.cms.ContentInfo cii = (org.mozilla.jss.pkix.cms.ContentInfo) org.mozilla.jss.pkix.cms.ContentInfo.getTemplate().decode(bis); org.mozilla.jss.pkix.cms.SignedData cmcFullResp = (org.mozilla.jss.pkix.cms.SignedData)cii.getInterpretedContent(); String content = ""; if (cmcFullResp.hasCertificates()) { SET certs = cmcFullResp.getCertificates(); int numCerts = certs.size(); for (int i = 0; i < numCerts; i++) { Certificate cert = (Certificate) certs.elementAt(i); X509CertImpl certImpl = new X509CertImpl(ASN1Util.encode(cert)); CertPrettyPrint print = new CertPrettyPrint(certImpl); content += print.toString(Locale.getDefault()); } } System.out.println("Certificates: "); System.out.println(content); System.out.println(""); EncapsulatedContentInfo ci = cmcFullResp.getContentInfo(); OBJECT_IDENTIFIER id = ci.getContentType(); OBJECT_IDENTIFIER dataid = new OBJECT_IDENTIFIER("1.2.840.113549.1.7.1"); if (!id.equals(OBJECT_IDENTIFIER.id_cct_PKIResponse) && !id.equals(dataid)) { System.out.println("Invalid CMC Response Format"); } if (!ci.hasContent()) return; OCTET_STRING content1 = ci.getContent(); ByteArrayInputStream bbis = new ByteArrayInputStream(content1.toByteArray()); ResponseBody responseBody = (ResponseBody) (new ResponseBody.Template()).decode(bbis); SEQUENCE controlSequence = responseBody.getControlSequence(); int numControls = controlSequence.size(); System.out.println("Number of controls is "+numControls); INTEGER bodyPartId = null; String error = ""; for (int i=0; i -i "); } public static void main(String args[]) { String filename = null, path = null; if (args.length != 4) { printUsage(); System.exit(1); } for (int i=0; i