72.3. 署名付きデータ
crypto-cms:sign
エンドポイントは、通常 1 つのルートで定義され、別のルートでは complimentary crypto-cms:verify
で定義されますが、このエンドポイントはもう一方のルートの後に表示されます。
以下の例は、Signed Data メッセージを作成する方法と、Signed Data メッセージを検証する方法を示しています。
Java DSL の基本例
import org.apache.camel.util.jsse.KeyStoreParameters; import org.apache.camel.component.crypto.cms.sig.DefaultSignerInfo; ... KeyStoreParameters keystore = new KeyStoreParameters(); keystore.setType("JCEKS"); keystore.setResource("keystore/keystore.jceks); keystore.setPassword("some_password"); // this password will also be used for accessing the private key if not specified in the signerInfo1 bean //Signer Information, by default the following signed attributes are included: contentType, signingTime, messageDigest, and cmsAlgorithmProtect; by default no unsigned attribute is included. // If you want to add your own signed attributes or unsigned attributes, see methods DefaultSignerInfo.setSignedAttributeGenerator and DefaultSignerInfo.setUnsignedAttributeGenerator. DefaultSignerInfo signerInfo1 = new DefaultSignerInfo(); signerInfo1.setIncludeCertificates(true); // if set to true then the certificate chain of the private key will be added to the Signed Data object signerInfo1.setSignatureAlgorithm("SHA256withRSA"); // signature algorithm; attention, the signature algorithm must fit to the signer private key. signerInfo1.setPrivateKeyAlias("rsa"); // alias of the private key used for the signing signerInfo1.setPassword("private_key_pw".toCharArray()); // optional parameter, if not set then the password of the KeyStoreParameters will be used for accessing the private key signerInfo1.setKeyStoreParameters(keystore); simpleReg.put("keyStoreParameters", keystore); //register keystore in the registry simpleReg.put("signer1", signerInfo1); //register signer info in the registry from("direct:start") .to("crypto-cms:sign://testsign?signer=#signer1&includeContent=true&toBase64=true") .to("crypto-cms:verify://testverify?keyStoreParameters=#keyStoreParameters&fromBase64=true"") .to("mock:result");
import org.apache.camel.util.jsse.KeyStoreParameters;
import org.apache.camel.component.crypto.cms.sig.DefaultSignerInfo;
...
KeyStoreParameters keystore = new KeyStoreParameters();
keystore.setType("JCEKS");
keystore.setResource("keystore/keystore.jceks);
keystore.setPassword("some_password"); // this password will also be used for accessing the private key if not specified in the signerInfo1 bean
//Signer Information, by default the following signed attributes are included: contentType, signingTime, messageDigest, and cmsAlgorithmProtect; by default no unsigned attribute is included.
// If you want to add your own signed attributes or unsigned attributes, see methods DefaultSignerInfo.setSignedAttributeGenerator and DefaultSignerInfo.setUnsignedAttributeGenerator.
DefaultSignerInfo signerInfo1 = new DefaultSignerInfo();
signerInfo1.setIncludeCertificates(true); // if set to true then the certificate chain of the private key will be added to the Signed Data object
signerInfo1.setSignatureAlgorithm("SHA256withRSA"); // signature algorithm; attention, the signature algorithm must fit to the signer private key.
signerInfo1.setPrivateKeyAlias("rsa"); // alias of the private key used for the signing
signerInfo1.setPassword("private_key_pw".toCharArray()); // optional parameter, if not set then the password of the KeyStoreParameters will be used for accessing the private key
signerInfo1.setKeyStoreParameters(keystore);
simpleReg.put("keyStoreParameters", keystore); //register keystore in the registry
simpleReg.put("signer1", signerInfo1); //register signer info in the registry
from("direct:start")
.to("crypto-cms:sign://testsign?signer=#signer1&includeContent=true&toBase64=true")
.to("crypto-cms:verify://testverify?keyStoreParameters=#keyStoreParameters&fromBase64=true"")
.to("mock:result");
Spring XML の基本例
<keyStoreParameters xmlns="http://camel.apache.org/schema/spring" id="keyStoreParameters1" resource="./keystore/keystore.jceks" password="some_password" type="JCEKS" /> <bean id="signer1" class="org.apache.camel.component.crypto.cms.sig.DefaultSignerInfo"> <property name="keyStoreParameters" ref="keyStoreParameters1" /> <property name="privateKeyAlias" value="rsa" /> <property name="signatureAlgorithm" value="SHA256withRSA" /> <property name="includeCertificates" value="true" /> <!-- optional parameter 'password', if not set then the password of the KeyStoreParameters will be used for accessing the private key --> <property name="password" value="private_key_pw" /> </bean> ... <route> <from uri="direct:start" /> <to uri="crypto-cms:sign://testsign?signer=#signer1&includeContent=true&toBase64=true" /> <to uri="crypto-cms:verify://testverify?keyStoreParameters=#keyStoreParameters1&fromBase64=true" /> <to uri="mock:result" /> </route>
<keyStoreParameters xmlns="http://camel.apache.org/schema/spring"
id="keyStoreParameters1" resource="./keystore/keystore.jceks"
password="some_password" type="JCEKS" />
<bean id="signer1"
class="org.apache.camel.component.crypto.cms.sig.DefaultSignerInfo">
<property name="keyStoreParameters" ref="keyStoreParameters1" />
<property name="privateKeyAlias" value="rsa" />
<property name="signatureAlgorithm" value="SHA256withRSA" />
<property name="includeCertificates" value="true" />
<!-- optional parameter 'password', if not set then the password of the KeyStoreParameters will be used for accessing the private key -->
<property name="password" value="private_key_pw" />
</bean>
...
<route>
<from uri="direct:start" />
<to uri="crypto-cms:sign://testsign?signer=#signer1&includeContent=true&toBase64=true" />
<to uri="crypto-cms:verify://testverify?keyStoreParameters=#keyStoreParameters1&fromBase64=true" />
<to uri="mock:result" />
</route>
Java DSL の 2 つの署名者の例
import org.apache.camel.util.jsse.KeyStoreParameters; import org.apache.camel.component.crypto.cms.sig.DefaultSignerInfo; ... KeyStoreParameters keystore = new KeyStoreParameters(); keystore.setType("JCEKS"); keystore.setResource("keystore/keystore.jceks); keystore.setPassword("some_password"); // this password will also be used for accessing the private key if not specified in the signerInfo1 bean //Signer Information, by default the following signed attributes are included: contentType, signingTime, messageDigest, and cmsAlgorithmProtect; by default no unsigned attribute is included. // If you want to add your own signed attributes or unsigned attributes, see methods DefaultSignerInfo.setSignedAttributeGenerator and DefaultSignerInfo.setUnsignedAttributeGenerator. DefaultSignerInfo signerInfo1 = new DefaultSignerInfo(); signerInfo1.setIncludeCertificates(true); // if set to true then the certificate chain of the private key will be added to the Signed Data object signerInfo1.setSignatureAlgorithm("SHA256withRSA"); // signature algorithm; attention, the signature algorithm must fit to the signer private key. signerInfo1.setPrivateKeyAlias("rsa"); // alias of the private key used for the signing signerInfo1.setPassword("private_key_pw".toCharArray()); // optional parameter, if not set then the password of the KeyStoreParameters will be used for accessing the private key signerInfo1.setKeyStoreParameters(keystore); DefaultSignerInfo signerInfo2 = new DefaultSignerInfo(); signerInfo2.setIncludeCertificates(true); signerInfo2.setSignatureAlgorithm("SHA256withDSA"); signerInfo2.setPrivateKeyAlias("dsa"); signerInfo2.setKeyStoreParameters(keystore); simpleReg.put("keyStoreParameters", keystore); //register keystore in the registry simpleReg.put("signer1", signerInfo1); //register signer info in the registry simpleReg.put("signer2", signerInfo2); //register signer info in the registry from("direct:start") .to("crypto-cms:sign://testsign?signer=#signer1&signer=#signer2&includeContent=true") .to("crypto-cms:verify://testverify?keyStoreParameters=#keyStoreParameters") .to("mock:result");
import org.apache.camel.util.jsse.KeyStoreParameters;
import org.apache.camel.component.crypto.cms.sig.DefaultSignerInfo;
...
KeyStoreParameters keystore = new KeyStoreParameters();
keystore.setType("JCEKS");
keystore.setResource("keystore/keystore.jceks);
keystore.setPassword("some_password"); // this password will also be used for accessing the private key if not specified in the signerInfo1 bean
//Signer Information, by default the following signed attributes are included: contentType, signingTime, messageDigest, and cmsAlgorithmProtect; by default no unsigned attribute is included.
// If you want to add your own signed attributes or unsigned attributes, see methods DefaultSignerInfo.setSignedAttributeGenerator and DefaultSignerInfo.setUnsignedAttributeGenerator.
DefaultSignerInfo signerInfo1 = new DefaultSignerInfo();
signerInfo1.setIncludeCertificates(true); // if set to true then the certificate chain of the private key will be added to the Signed Data object
signerInfo1.setSignatureAlgorithm("SHA256withRSA"); // signature algorithm; attention, the signature algorithm must fit to the signer private key.
signerInfo1.setPrivateKeyAlias("rsa"); // alias of the private key used for the signing
signerInfo1.setPassword("private_key_pw".toCharArray()); // optional parameter, if not set then the password of the KeyStoreParameters will be used for accessing the private key
signerInfo1.setKeyStoreParameters(keystore);
DefaultSignerInfo signerInfo2 = new DefaultSignerInfo();
signerInfo2.setIncludeCertificates(true);
signerInfo2.setSignatureAlgorithm("SHA256withDSA");
signerInfo2.setPrivateKeyAlias("dsa");
signerInfo2.setKeyStoreParameters(keystore);
simpleReg.put("keyStoreParameters", keystore); //register keystore in the registry
simpleReg.put("signer1", signerInfo1); //register signer info in the registry
simpleReg.put("signer2", signerInfo2); //register signer info in the registry
from("direct:start")
.to("crypto-cms:sign://testsign?signer=#signer1&signer=#signer2&includeContent=true")
.to("crypto-cms:verify://testverify?keyStoreParameters=#keyStoreParameters")
.to("mock:result");
Spring XML の 2 つの署名者の例
<keyStoreParameters xmlns="http://camel.apache.org/schema/spring" id="keyStoreParameters1" resource="./keystore/keystore.jceks" password="some_password" type="JCEKS" /> <bean id="signer1" class="org.apache.camel.component.crypto.cms.sig.DefaultSignerInfo"> <property name="keyStoreParameters" ref="keyStoreParameters1" /> <property name="privateKeyAlias" value="rsa" /> <property name="signatureAlgorithm" value="SHA256withRSA" /> <property name="includeCertificates" value="true" /> <!-- optional parameter 'password', if not set then the password of the KeyStoreParameters will be used for accessing the private key --> <property name="password" value="private_key_pw" /> </bean> <bean id="signer2" class="org.apache.camel.component.crypto.cms.sig.DefaultSignerInfo"> <property name="keyStoreParameters" ref="keyStoreParameters1" /> <property name="privateKeyAlias" value="dsa" /> <property name="signatureAlgorithm" value="SHA256withDSA" /> <!-- optional parameter 'password', if not set then the password of the KeyStoreParameters will be used for accessing the private key --> <property name="password" value="private_key_pw2" /> </bean> ... <route> <from uri="direct:start" /> <to uri="crypto-cms:sign://testsign?signer=#signer1&signer=#signer2&includeContent=true" /> <to uri="crypto-cms:verify://testverify?keyStoreParameters=#keyStoreParameters1" /> <to uri="mock:result" /> </route>
<keyStoreParameters xmlns="http://camel.apache.org/schema/spring"
id="keyStoreParameters1" resource="./keystore/keystore.jceks"
password="some_password" type="JCEKS" />
<bean id="signer1"
class="org.apache.camel.component.crypto.cms.sig.DefaultSignerInfo">
<property name="keyStoreParameters" ref="keyStoreParameters1" />
<property name="privateKeyAlias" value="rsa" />
<property name="signatureAlgorithm" value="SHA256withRSA" />
<property name="includeCertificates" value="true" />
<!-- optional parameter 'password', if not set then the password of the KeyStoreParameters will be used for accessing the private key -->
<property name="password" value="private_key_pw" />
</bean>
<bean id="signer2"
class="org.apache.camel.component.crypto.cms.sig.DefaultSignerInfo">
<property name="keyStoreParameters" ref="keyStoreParameters1" />
<property name="privateKeyAlias" value="dsa" />
<property name="signatureAlgorithm" value="SHA256withDSA" />
<!-- optional parameter 'password', if not set then the password of the KeyStoreParameters will be used for accessing the private key -->
<property name="password" value="private_key_pw2" />
</bean>
...
<route>
<from uri="direct:start" />
<to uri="crypto-cms:sign://testsign?signer=#signer1&signer=#signer2&includeContent=true" />
<to uri="crypto-cms:verify://testverify?keyStoreParameters=#keyStoreParameters1" />
<to uri="mock:result" />
</route>
Java DSL での接続解除署名の例
import org.apache.camel.util.jsse.KeyStoreParameters; import org.apache.camel.component.crypto.cms.sig.DefaultSignerInfo; ... KeyStoreParameters keystore = new KeyStoreParameters(); keystore.setType("JCEKS"); keystore.setResource("keystore/keystore.jceks); keystore.setPassword("some_password"); // this password will also be used for accessing the private key if not specified in the signerInfo1 bean //Signer Information, by default the following signed attributes are included: contentType, signingTime, messageDigest, and cmsAlgorithmProtect; by default no unsigned attribute is included. // If you want to add your own signed attributes or unsigned attributes, see methods DefaultSignerInfo.setSignedAttributeGenerator and DefaultSignerInfo.setUnsignedAttributeGenerator. DefaultSignerInfo signerInfo1 = new DefaultSignerInfo(); signerInfo1.setIncludeCertificates(true); // if set to true then the certificate chain of the private key will be added to the Signed Data object signerInfo1.setSignatureAlgorithm("SHA256withRSA"); // signature algorithm; attention, the signature algorithm must fit to the signer private key. signerInfo1.setPrivateKeyAlias("rsa"); // alias of the private key used for the signing signerInfo1.setPassword("private_key_pw".toCharArray()); // optional parameter, if not set then the password of the KeyStoreParameters will be used for accessing the private key signerInfo1.setKeyStoreParameters(keystore); simpleReg.put("keyStoreParameters", keystore); //register keystore in the registry simpleReg.put("signer1", signerInfo1); //register signer info in the registry from("direct:start") //with the option includeContent=false the SignedData object without the signed text will be written into the header "CamelCryptoCmsSignedData" .to("crypto-cms:sign://testsign?signer=#signer1&includeContent=false&toBase64=true") //the verifier reads the Signed Data object form the header CamelCryptoCmsSignedData and assumes that the signed content is in the message body .to("crypto-cms:verify://testverify?keyStoreParameters=#keyStoreParameters&signedDataHeaderBase64=true") .to("mock:result");
import org.apache.camel.util.jsse.KeyStoreParameters;
import org.apache.camel.component.crypto.cms.sig.DefaultSignerInfo;
...
KeyStoreParameters keystore = new KeyStoreParameters();
keystore.setType("JCEKS");
keystore.setResource("keystore/keystore.jceks);
keystore.setPassword("some_password"); // this password will also be used for accessing the private key if not specified in the signerInfo1 bean
//Signer Information, by default the following signed attributes are included: contentType, signingTime, messageDigest, and cmsAlgorithmProtect; by default no unsigned attribute is included.
// If you want to add your own signed attributes or unsigned attributes, see methods DefaultSignerInfo.setSignedAttributeGenerator and DefaultSignerInfo.setUnsignedAttributeGenerator.
DefaultSignerInfo signerInfo1 = new DefaultSignerInfo();
signerInfo1.setIncludeCertificates(true); // if set to true then the certificate chain of the private key will be added to the Signed Data object
signerInfo1.setSignatureAlgorithm("SHA256withRSA"); // signature algorithm; attention, the signature algorithm must fit to the signer private key.
signerInfo1.setPrivateKeyAlias("rsa"); // alias of the private key used for the signing
signerInfo1.setPassword("private_key_pw".toCharArray()); // optional parameter, if not set then the password of the KeyStoreParameters will be used for accessing the private key
signerInfo1.setKeyStoreParameters(keystore);
simpleReg.put("keyStoreParameters", keystore); //register keystore in the registry
simpleReg.put("signer1", signerInfo1); //register signer info in the registry
from("direct:start")
//with the option includeContent=false the SignedData object without the signed text will be written into the header "CamelCryptoCmsSignedData"
.to("crypto-cms:sign://testsign?signer=#signer1&includeContent=false&toBase64=true")
//the verifier reads the Signed Data object form the header CamelCryptoCmsSignedData and assumes that the signed content is in the message body
.to("crypto-cms:verify://testverify?keyStoreParameters=#keyStoreParameters&signedDataHeaderBase64=true")
.to("mock:result");
Spring XML でデタッチされた署名の例
<keyStoreParameters xmlns="http://camel.apache.org/schema/spring" id="keyStoreParameters1" resource="./keystore/keystore.jceks" password="some_password" type="JCEKS" /> <bean id="signer1" class="org.apache.camel.component.crypto.cms.sig.DefaultSignerInfo"> <property name="keyStoreParameters" ref="keyStoreParameters1" /> <property name="privateKeyAlias" value="rsa" /> <property name="signatureAlgorithm" value="SHA256withRSA" /> <property name="includeCertificates" value="true" /> <!-- optional parameter 'password', if not set then the password of the KeyStoreParameters will be used for accessing the private key --> <property name="password" value="private_key_pw" /> </bean> ... <route> <from uri="direct:start" /> <!-- with the option includeContent=false the SignedData object without the signed text will be written into the header "CamelCryptoCmsSignedData" --> <to uri="crypto-cms:sign://testsign?signer=#signer1&includeContent=false&toBase64=true" /> <!-- the verifier reads the Signed Data object form the header CamelCryptoCmsSignedData and assumes that the signed content is in the message body --> <to uri="crypto-cms:verify://testverify?keyStoreParameters=#keyStoreParameters1&signedDataHeaderBase64=true" /> <to uri="mock:result" /> </route>
<keyStoreParameters xmlns="http://camel.apache.org/schema/spring"
id="keyStoreParameters1" resource="./keystore/keystore.jceks"
password="some_password" type="JCEKS" />
<bean id="signer1"
class="org.apache.camel.component.crypto.cms.sig.DefaultSignerInfo">
<property name="keyStoreParameters" ref="keyStoreParameters1" />
<property name="privateKeyAlias" value="rsa" />
<property name="signatureAlgorithm" value="SHA256withRSA" />
<property name="includeCertificates" value="true" />
<!-- optional parameter 'password', if not set then the password of the KeyStoreParameters will be used for accessing the private key -->
<property name="password" value="private_key_pw" />
</bean>
...
<route>
<from uri="direct:start" />
<!-- with the option includeContent=false the SignedData object without the signed text will be written into the header "CamelCryptoCmsSignedData" -->
<to uri="crypto-cms:sign://testsign?signer=#signer1&includeContent=false&toBase64=true" />
<!-- the verifier reads the Signed Data object form the header CamelCryptoCmsSignedData and assumes that the signed content is in the message body -->
<to uri="crypto-cms:verify://testverify?keyStoreParameters=#keyStoreParameters1&signedDataHeaderBase64=true" />
<to uri="mock:result" />
</route>