2010-05-20 12 views
6

मैं चींटी signjar task के साथ जार फ़ाइलों पर हस्ताक्षर करता हूं और अब मैं तैनाती से पहले परीक्षण करना चाहता हूं।मैं चींटी का उपयोग कर एक हस्ताक्षरित जार फ़ाइल कैसे देख सकता हूं?

मैं

jarsigner -verify sbundle.jar 

से सलाह ले सकते, लेकिन मैं अगर यह चींटी के साथ भी ऐसा ही करने के लिए संभव है पता नहीं है?

उत्तर

5

एक विकल्प एक मेवेन स्क्रिप्ट पर आपके निर्माण का आधार होगा।
Maven jarsigner:verify plugin

प्रस्तावित करते हैं कि एक वैध संभावना नहीं है करता है, तो आप अभी भी Exec Ant task उपयोग कर सकते हैं सीधे jarsigner आदेश कॉल करने के लिए। यदि रिटर्न कोड सही ढंग से सेट किया गया है, तो आप विशेषता failonerror जोड़ सकते हैं (यदि आदेश 0 से अधिक रिटर्न कोड के साथ बाहर निकलता है तो बिल्ड प्रक्रिया को रोकें)

+0

@martin: तब आप ऐसा (टाइपो और लिंक) – VonC

3

चींटी स्थितियां "जारी" की पेशकश करती हैं।

"परीक्षण करें कि एक जर्फ़ाइल हस्ताक्षरित है या नहीं। अगर हस्ताक्षर का नाम पारित किया गया है, तो फ़ाइल उस विशेष हस्ताक्षर की उपस्थिति के लिए जांच की जाती है, अन्यथा किसी भी हस्ताक्षर के अस्तित्व के लिए फ़ाइल की जांच की जाती है। यह कठोर हस्ताक्षर नहीं करता है सत्यापन; यह केवल हस्ताक्षर की उपस्थिति को देखता है। यह स्थिति अपाचे एंट 1.7 में जोड़ा गया था। "

Ant conditions

4

निम्नलिखित चींटी कोड से JAR फ़ाइल हस्ताक्षर की पुष्टि करने के लिए इस्तेमाल किया जा सकता है। स्क्रिप्ट विफल हो जाएगी जैसे ही यह एक जेएआर-फाइल का सामना करता है जहां हस्ताक्षर वैध नहीं है या जहां यह गुम है।

ध्यान दें कि एंटी-कॉन्ट्रिब कार्य के लिए आवश्यक है।

<!-- Macro to verify whether or not a JAR file is signed --> 
<macrodef name="verify-signatures"> 
    <attribute name="filesetref" /> 
    <sequential> 
     <for param="file"> 
      <path> 
       <fileset refid="@{filesetref}" /> 
      </path> 
      <sequential> 
       <echo message="Verifying signature on file: @{file}" /> 
       <exec executable="jarsigner" failonerror="true"> 
        <arg value="-verify" /> 
        <arg value="@{file}" /> 
       </exec> 
       <fail message="@{file} must be signed"> 
        <condition> 
         <not> 
          <issigned file="@{file}" /> 
         </not> 
        </condition> 
       </fail> 
      </sequential> 
     </for> 
    </sequential> 
</macrodef> 

<!-- Define the list of files to check --> 
<fileset dir="p2repo" id="jarfiles"> 
    <include name="**/*.jar" /> 
</fileset> 

<!-- Verify signatures --> 
<verify-signatures filesetref="jarfiles" /> 
1

@ टॉर्किल्डर के उत्तर के आधार पर।

मैक्रो पास नेस्टेड पथ या फाइलसेट को ant-contrib for task पर बनाना संभव है।

<target name="verify-artifacts" description="Just an example of usage"> 
    <verify-artifacts> 
     <fileset dir="${project.ear.dir}" includes="*.*ar"/> 
    </verify-artifacts> 
</target> 

<macrodef name="verify-artifacts"> 
    <element name="artifact-path" implicit="true"/> 
    <sequential> 
     <for param="file"> 
      <artifact-path/> 
      <sequential> 
       <verify-artifact file="@{file}"/> 
      </sequential> 
     </for> 
    </sequential> 
</macrodef> 

<macrodef name="verify-artifact"> 
    <attribute name="file"/> 
    <attribute name="alias" default="${artifact.sign.keystore.alias}"/> 
    <attribute name="keystore" default="${artifact.sign.keystore.path}"/> 
    <attribute name="password" default="${artifact.sign.keystore.password}"/> 
    <sequential> 
     <if> 
      <istrue value="${artifact.sign.enabled}"/> 
      <then> 
       <echo message="Trying to verify @{file} with alias @{alias} from @{keystore}"/> 
       <required-macro-param value="@{alias}" prop="artifact.sign.keystore.alias"/> 
       <required-macro-param value="@{keystore}" prop="artifact.sign.keystore.path"/> 
       <required-macro-param value="@{password}" prop="artifact.sign.keystore.password"/> 
       <fail message="Keystore path '@{keystore}' not found"> 
        <condition> 
         <not><available file="@{keystore}" type="file"/></not> 
        </condition> 
       </fail> 
       <fail message="Artifact '@{file}' not found"> 
        <condition> 
         <not><available file="@{file}" type="file"/></not> 
        </condition> 
       </fail> 
       <!-- jarsigner -verify -keystore @{keystore} -storepass @{password} @{file} @{alias} --> 
       <exec executable="jarsigner" failonerror="true"> 
        <arg value="-verify"/> 
        <arg value="-keystore"/> 
        <arg value="@{keystore}"/> 
        <arg value="-storepass"/> 
        <arg value="@{password}"/> 
        <arg value="@{file}"/> 
        <arg value="@{alias}"/> 
       </exec> 
      </then> 
     </if> 
    </sequential> 
</macrodef> 

<macrodef name="required-macro-param"> 
    <attribute name="prop"/> 
    <attribute name="value"/> 
    <sequential> 
     <!--<echo message="@{value}"/>--> 
     <fail message="You must set property '@{prop}'"> 
      <condition> 
       <and> 
        <or> 
         <equals arg1="@{value}" arg2=""/> 
         <matches string="@{value}" pattern="^\$\{.*?\}$"/> 
        </or> 
        <!--<not><isset property="@{prop}"/></not>--> 
       </and> 
      </condition> 
     </fail> 
    </sequential> 
</macrodef> 

<macrodef name="sign-artifact"> 
    <attribute name="file"/> 
    <attribute name="alias" default="${artifact.sign.keystore.alias}"/> 
    <attribute name="keystore" default="${artifact.sign.keystore.path}"/> 
    <attribute name="password" default="${artifact.sign.keystore.password}"/> 
    <sequential> 
     <if> 
      <istrue value="${artifact.sign.enabled}"/> 
      <then> 
       <echo message="Trying to sign @{file} with alias @{alias} from @{keystore}"/> 
       <required-macro-param value="@{alias}" prop="artifact.sign.keystore.alias"/> 
       <required-macro-param value="@{keystore}" prop="artifact.sign.keystore.path"/> 
       <required-macro-param value="@{password}" prop="artifact.sign.keystore.password"/> 
       <fail message="Keystore path '@{keystore}' not found"> 
        <condition> 
         <not><available file="@{keystore}" type="file"/></not> 
        </condition> 
       </fail> 
       <fail message="Artifact '@{file}' not found"> 
        <condition> 
         <not><available file="@{file}" type="file"/></not> 
        </condition> 
       </fail> 
       <signjar jar="@{file}" alias="@{alias}" keystore="@{keystore}" storepass="@{password}"/> 
       <fail message="Signature check failed"> 
        <condition> 
         <not><issigned file="@{file}" name="@{alias}"/></not> 
        </condition> 
       </fail> 
      </then> 
     </if> 
    </sequential> 
</macrodef> 

<macrodef name="sign-artifacts"> 
    <element name="artifact-path" implicit="true"/> 
    <sequential> 
     <for param="file"> 
      <artifact-path/> 
      <sequential> 
       <sign-artifact file="@{file}"/> 
      </sequential> 
     </for> 
    </sequential> 
</macrodef> 

<property name="artifact.sign.enabled" value="true"/> 
<property name="artifact.sign.keystore.alias" value="alias"/> 
<property name="artifact.sign.keystore.path" value="keystore.jks"/> 
<property name="artifact.sign.keystore.password" value="pwd"/> 
+0

मैं इस सवाल का जवाब पसंद करते हैं के लिए धन्यवाद, क्योंकि यह वास्तव में जाँच करता है कि जार निर्दिष्ट कीस्ट्रोक के साथ प्रवेश किया है। मेरे पास ऐसे मुद्दे थे जहां पहली लिपि पारित हुई थी क्योंकि यह केवल चेक किया गया था और बाद में विभिन्न हस्ताक्षरकर्ताओं के साथ जार के साथ समस्याएं थीं। – javydreamercsw

1

आप ऐसा करने के लिए चींटी में VerifyJar कार्य का उपयोग कर सकते हैं। एंट हेल्प https://ant.apache.org/manual/Tasks/verifyjar.html

एकाधिक JAR फ़ाइलों को एक बार में सत्यापित करने के लिए नमूना कोड यहां दिया गया है।

verifyjar keystore="mykeystore" keypass="abc" 
      storepass="abc" alias="myalias"> 
    <path> 
     <fileset dir="${build.dir}/signedjar" includes="**/*.jar" /> 
    </path> 
</verifyjar> 
संबंधित मुद्दे

 संबंधित मुद्दे