/* * Created on 27.11.2003 * * (c) Stabsstelle IKT-Strategie des Bundes */ package at.gv.egovernment.moa.spss.slinterface.beans; import iaik.asn1.ObjectID; import iaik.asn1.structures.Name; import iaik.utils.RFC2253NameParser; import iaik.utils.RFC2253NameParserException; import org.w3c.dom.Document; import org.w3c.dom.Element; import at.gv.egovernment.moa.spss.slinterface.Constants; import at.gv.egovernment.moa.spss.slinterface.DOMUtils; /** * @author Gregor Karlinger (mailto:gregor.karlinger@cio.gv.at) */ public class SignerInfoBean { private static final String SIGNERINFO_ELEM_ = "SignerInfo"; private static final String X509DATA_ELEM_ = "X509Data"; private static final String X509SUBJNAME_ELEM_ = "X509SubjectName"; private static final String X509ISSUERSERIAL_ELEM_ = "X509IssuerSerial"; private static final String SERIAL_ELEM_ = "X509SerialNumber"; private static final String ISSUER_ELEM_ = "X509IssuerName"; private static final String QUALCERT_ELEM_ = "QualifiedCertificate"; private Element signerInfoElem_; private String subjectNameItemSel_; private String issuerNameItemSel_; /* ---------------------------------------------------------------------------------------------------- */ public SignerInfoBean(Document slResponseDoc) { Element verifyXMLResponseElem = slResponseDoc.getDocumentElement(); signerInfoElem_ = DOMUtils.getChildElem( verifyXMLResponseElem, Constants.NSURI_SL_11_, SIGNERINFO_ELEM_); subjectNameItemSel_ = "2.5.4.3"; issuerNameItemSel_ = "2.5.4.3"; } /* ---------------------------------------------------------------------------------------------------- */ public void setSubjectNameItemSel(String selector) { subjectNameItemSel_ = selector; } /* ---------------------------------------------------------------------------------------------------- */ public String getSubjectNameItem() { Element x509DataElem = DOMUtils.getChildElem(signerInfoElem_, Constants.NSURI_DSIG_, X509DATA_ELEM_); String subjectNameStr = DOMUtils.getChildText(x509DataElem, Constants.NSURI_DSIG_, X509SUBJNAME_ELEM_); if (subjectNameStr == null) return null; return getRDN(subjectNameStr, subjectNameItemSel_); } /* ---------------------------------------------------------------------------------------------------- */ public String getSerial() { Element x509DataElem = DOMUtils.getChildElem(signerInfoElem_, Constants.NSURI_DSIG_, X509DATA_ELEM_); Element iSElem = DOMUtils.getChildElem(x509DataElem, Constants.NSURI_DSIG_, X509ISSUERSERIAL_ELEM_); return DOMUtils.getChildText(iSElem, Constants.NSURI_DSIG_, SERIAL_ELEM_); } /* ---------------------------------------------------------------------------------------------------- */ public void setIssuerNameItemSel(String selector) { issuerNameItemSel_ = selector; } /* ---------------------------------------------------------------------------------------------------- */ public String getIssuerNameItem() { Element x509DataElem = DOMUtils.getChildElem(signerInfoElem_, Constants.NSURI_DSIG_, X509DATA_ELEM_); Element iSElem = DOMUtils.getChildElem(x509DataElem, Constants.NSURI_DSIG_, X509ISSUERSERIAL_ELEM_); String issuerNameStr = DOMUtils.getChildText(iSElem, Constants.NSURI_DSIG_, ISSUER_ELEM_); if (issuerNameStr == null) return null; return getRDN(issuerNameStr, issuerNameItemSel_); } /* ---------------------------------------------------------------------------------------------------- */ public boolean getIsQualified() { Element x509DataElem = DOMUtils.getChildElem(signerInfoElem_, Constants.NSURI_DSIG_, X509DATA_ELEM_); Element qCElem = DOMUtils.getChildElem(x509DataElem, Constants.NSURI_SL_11_, QUALCERT_ELEM_); return (qCElem != null); } /* ---------------------------------------------------------------------------------------------------- */ private String getRDN(String nameStr, String oidStr) { try { RFC2253NameParser nameParser = new RFC2253NameParser(nameStr); Name name = nameParser.parse(); ObjectID oid = ObjectID.getObjectID(oidStr); if (oid == null) return null; String[] rdns = name.getRDNs(oid); if (rdns == null) return null; StringBuffer rdnsStr = new StringBuffer(); for (int i = 0; i < rdns.length; i++) { if (i > 0) rdnsStr.append(", "); rdnsStr.append(rdns[i]); } return rdnsStr.toString(); } catch (RFC2253NameParserException e) { return null; } } }