如何添加UnsignedProperties?

时间:2017-10-30 16:15:48

标签: java xml sign xades4j

我尝试使用XADES-BES和智能卡签署XML文档。 我根据自己的需要对SignerBES.java类进行了一些更改,签名创建效果很好!

我的问题:我如何添加UnsignedProperties来获得这样的东西:

                <SignerRole>
          <ClaimedRoles>
            <ClaimedRole>EST</ClaimedRole>
          </ClaimedRoles>
        </SignerRole>
      </SignedSignatureProperties>
      <SignedDataObjectProperties>
        <DataObjectFormat ObjectReference="#sigId">
          <Description>des</Description>
          <MimeType>text/xml</MimeType>
          <Encoding>base64</Encoding>
        </DataObjectFormat>
        <CommitmentTypeIndication>
          <CommitmentTypeId>
            <Identifier/>
          </CommitmentTypeId>
          <AllSignedDataObjects/>
          <CommitmentTypeQualifiers>
            <CommitmentTypeQualifier>commitment</CommitmentTypeQualifier>
          </CommitmentTypeQualifiers>
        </CommitmentTypeIndication>
      </SignedDataObjectProperties>
    </SignedProperties>
    <UnsignedProperties>
      <UnsignedSignatureProperties>
        <SignatureTimeStamp>
          <EncapsulatedTimeStamp>noTimStampToken</EncapsulatedTimeStamp>
        </SignatureTimeStamp>
        <CounterSignature/>
        <CompleteCertificateRefs/>
        <CompleteRevocationRefs/>
        <SigAndRefsTimeStamp/>
        <RefsOnlyTimeStamp/>
        <CertificatesValues/>
        <RevocationValues/>
        <ArchiveTimeStamp/>
      </UnsignedSignatureProperties>
    </UnsignedProperties>
  </QualifyingProperties>
</ds:Object>

这是一个代码片段SignerBES.java:

    Collection<SignedSignatureProperty> fsssp = new ArrayList<SignedSignatureProperty>(2);
Collection<UnsignedSignatureProperty> fsusp = new ArrayList<UnsignedSignatureProperty>(2);


getFormatSpecificSignatureProperties(fsssp, fsusp, signingCertificateChain);
// Gather all the signature and data objects properties.
QualifyingProperties qualifProps = qualifPropsProcessor.getQualifyingProperties(
        signedDataObjects, fsssp, fsusp);

// LOG
System.out.println("fsusp"+fsusp.size());

我尝试在SignerBES.java和DefaultSignaturePropertiesProvider.java中添加它,但我不知道如何添加它:

    public class DefaultSignaturePropertiesProvider implements SignaturePropertiesProvider  
{   
@Override
public void provideProperties(SignaturePropertiesCollector signaturePropsCol)
{
signaturePropsCol.setSigningTime(new SigningTimeProperty());
signaturePropsCol.setSignerRole(new SignerRoleProperty("EST"));

// UnsignedProperty
// OtherUnsignedSignatureProperty otherUnsignedProp=null;    
// signaturePropsCol.addOtherSignatureProperty(otherUnsignedProp);
}}

1 个答案:

答案 0 :(得分:0)

我不认为我完全理解你正在尝试的东西,因为你似乎在搞乱lib源代码。无论如何,请查看this page on the project docs

当您使用其中一个签名配置文件时,xades4j会自动添加许多未签名的限定属性(例如,如果您使用XAdesCSigningProfile,则会添加CompleteCertificateRefs / CompleteRevocationRefs)。

其他属性是高级表单的一部分,只能在验证现有签名时添加。有关其他信息,请参阅this wiki page和[此javadocs页面](http://luisgoncalves.github.io/xades4j/javadocs/1.4.0/reference/xades4j/verification/XadesVerifier.html#verify(org.w3c.dom.Element,xades4j.verification.SignatureSpecificVerificationOptions,xades4j.production.XadesSignatureFormatExtender,xades4j.verification.XAdESForm)。

最后,某些属性(例如CounterSignature)不会绑定到任何特定表单,并且可以使用在签名配置文件上注册的自定义SignaturePropertiesProvider添加到任何签名中使用