Ejemplo n.º 1
0
/// Check that SignedInfo contains exactly one Reference to every document,
/// plus one Reference to the SignedProperties
/// @throws SignatureException on a problem in signature
void digidoc::SignatureBES::checkReferences() const throw(SignatureException)
{
    dsig::SignedInfoType& signedInfo = signature->signedInfo();
    dsig::SignedInfoType::ReferenceSequence& refSeq = signedInfo.reference();

    if ( refSeq.size() != (bdoc.documentCount() + 1) )
    {
        // we require exactly one ref to every document, plus one ref to the SignedProperties
        THROW_SIGNATUREEXCEPTION("Number of references in SignedInfo is invalid: found %d, expected %d"
                                 , refSeq.size(), bdoc.documentCount() + 1);

    }

    // check reference to SignedProperties
    bool gotSignatureRef = false; // remember to ensure, it exists only once
    for ( dsig::SignedInfoType::ReferenceSequence::const_iterator itRef = refSeq.begin()
            ; itRef != refSeq.end()
            ; itRef++
        )
    {
        const dsig::ReferenceType& refType = (*itRef);

        if ( isReferenceToSigProps(refType) )
        {
            // the one and only reference to SignedProperties
            if ( gotSignatureRef )
            {
                THROW_SIGNATUREEXCEPTION("SignedInfo element refers to more than one SignedProperties");
            }
            gotSignatureRef = true; // remember this, we don't expect any more of those

            checkReferenceToSigProps(refType);
        } // else: skip, checked elsewhere
    }

    if ( !gotSignatureRef )
    {
        THROW_SIGNATUREEXCEPTION("SignedInfo does not contain reference to SignedProperties");
    }

    // check refs to documents
    checkReferencesToDocs(refSeq);

}
Ejemplo n.º 2
0
void bdoc::Signature::checkReferences()
{
    dsig::SignedInfoType& signedInfo = _sign->signedInfo();
    dsig::SignedInfoType::ReferenceSequence&
    refSeq = signedInfo.reference();

    if (refSeq.size() != (_bdoc->documentCount() + 1)) {
        // we require exactly one ref to every document,
        // plus one ref to the SignedProperties
        THROW_STACK_EXCEPTION(
            "Number of references in SignedInfo is invalid: "
            "found %d, expected %d",
            refSeq.size(), _bdoc->documentCount() + 1);
    }

    bool gotSignatureRef = false;
    for (dsig::SignedInfoType::ReferenceSequence::const_iterator
            itRef = refSeq.begin(); itRef != refSeq.end(); itRef++) {

        const dsig::ReferenceType& refType = (*itRef);

        if (isReferenceToSigProps(refType)) {
            // the one and only reference to SignedProperties
            if (gotSignatureRef) {
                THROW_STACK_EXCEPTION(
                    "SignedInfo element refers to more "
                    "than one SignedProperties");
            }
            gotSignatureRef = true;
            checkReferenceToSigProps(refType);
        }
    }

    if (!gotSignatureRef) {
        THROW_STACK_EXCEPTION(
            "SignedInfo does not contain reference to "
            "SignedProperties");
    }

    checkReferencesToDocs(refSeq);
}