git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270495 13f79535-47bb-0310-9956-ffa450edef68master
@@ -0,0 +1,77 @@ | |||||
/* | |||||
* Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
* | |||||
* This software is published under the terms of the Apache Software License | |||||
* version 1.1, a copy of which has been included with this distribution in | |||||
* the LICENSE.txt file. | |||||
*/ | |||||
package org.apache.tools.ant.taskdefs; | |||||
import java.util.ArrayList; | |||||
import java.util.Iterator; | |||||
public class DistinguishedName | |||||
{ | |||||
private ArrayList m_params = new ArrayList(); | |||||
private String m_name; | |||||
private String m_path; | |||||
public Iterator getParams() | |||||
{ | |||||
return m_params.iterator(); | |||||
} | |||||
public Object createParam() | |||||
{ | |||||
final DnameParam param = new DnameParam(); | |||||
m_params.add( param ); | |||||
return param; | |||||
} | |||||
public String encode( final String string ) | |||||
{ | |||||
int end = string.indexOf( ',' ); | |||||
if( -1 == end ) | |||||
{ | |||||
return string; | |||||
} | |||||
final StringBuffer sb = new StringBuffer(); | |||||
int start = 0; | |||||
while( -1 != end ) | |||||
{ | |||||
sb.append( string.substring( start, end ) ); | |||||
sb.append( "\\," ); | |||||
start = end + 1; | |||||
end = string.indexOf( ',', start ); | |||||
} | |||||
sb.append( string.substring( start ) ); | |||||
return sb.toString(); | |||||
} | |||||
public String toString() | |||||
{ | |||||
final int size = m_params.size(); | |||||
final StringBuffer sb = new StringBuffer(); | |||||
boolean firstPass = true; | |||||
for( int i = 0; i < size; i++ ) | |||||
{ | |||||
if( !firstPass ) | |||||
{ | |||||
sb.append( " ," ); | |||||
} | |||||
firstPass = false; | |||||
final DnameParam param = (DnameParam)m_params.get( i ); | |||||
sb.append( encode( param.getName() ) ); | |||||
sb.append( '=' ); | |||||
sb.append( encode( param.getValue() ) ); | |||||
} | |||||
return sb.toString(); | |||||
} | |||||
} |
@@ -0,0 +1,34 @@ | |||||
/* | |||||
* Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
* | |||||
* This software is published under the terms of the Apache Software License | |||||
* version 1.1, a copy of which has been included with this distribution in | |||||
* the LICENSE.txt file. | |||||
*/ | |||||
package org.apache.tools.ant.taskdefs; | |||||
public final class DnameParam | |||||
{ | |||||
private String m_name; | |||||
private String m_value; | |||||
public void setName( final String name ) | |||||
{ | |||||
m_name = name; | |||||
} | |||||
public void setValue( final String value ) | |||||
{ | |||||
m_value = value; | |||||
} | |||||
public String getName() | |||||
{ | |||||
return m_name; | |||||
} | |||||
public String getValue() | |||||
{ | |||||
return m_value; | |||||
} | |||||
} |
@@ -24,48 +24,48 @@ public class GenerateKey | |||||
/** | /** | ||||
* The alias of signer. | * The alias of signer. | ||||
*/ | */ | ||||
protected String alias; | |||||
protected String dname; | |||||
protected DistinguishedName expandedDname; | |||||
protected String keyalg; | |||||
protected String keypass; | |||||
protected int keysize; | |||||
private String m_alias; | |||||
private String m_dname; | |||||
private DistinguishedName m_expandedDname; | |||||
private String m_keyalg; | |||||
private String m_keypass; | |||||
private int m_keysize; | |||||
/** | /** | ||||
* The name of keystore file. | * The name of keystore file. | ||||
*/ | */ | ||||
protected String keystore; | |||||
private String m_keystore; | |||||
protected String sigalg; | |||||
protected String storepass; | |||||
protected String storetype; | |||||
protected int validity; | |||||
protected boolean verbose; | |||||
private String m_sigalg; | |||||
private String m_storepass; | |||||
private String m_storetype; | |||||
private int m_validity; | |||||
private boolean m_verbose; | |||||
public void setAlias( final String alias ) | public void setAlias( final String alias ) | ||||
{ | { | ||||
this.alias = alias; | |||||
m_alias = alias; | |||||
} | } | ||||
public void setDname( final String dname ) | public void setDname( final String dname ) | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( null != expandedDname ) | |||||
if( null != m_expandedDname ) | |||||
{ | { | ||||
throw new TaskException( "It is not possible to specify dname both " + | throw new TaskException( "It is not possible to specify dname both " + | ||||
"as attribute and element." ); | "as attribute and element." ); | ||||
} | } | ||||
this.dname = dname; | |||||
m_dname = dname; | |||||
} | } | ||||
public void setKeyalg( final String keyalg ) | public void setKeyalg( final String keyalg ) | ||||
{ | { | ||||
this.keyalg = keyalg; | |||||
m_keyalg = keyalg; | |||||
} | } | ||||
public void setKeypass( final String keypass ) | public void setKeypass( final String keypass ) | ||||
{ | { | ||||
this.keypass = keypass; | |||||
m_keypass = keypass; | |||||
} | } | ||||
public void setKeysize( final String keysize ) | public void setKeysize( final String keysize ) | ||||
@@ -73,7 +73,7 @@ public class GenerateKey | |||||
{ | { | ||||
try | try | ||||
{ | { | ||||
this.keysize = Integer.parseInt( keysize ); | |||||
m_keysize = Integer.parseInt( keysize ); | |||||
} | } | ||||
catch( final NumberFormatException nfe ) | catch( final NumberFormatException nfe ) | ||||
{ | { | ||||
@@ -83,22 +83,22 @@ public class GenerateKey | |||||
public void setKeystore( final String keystore ) | public void setKeystore( final String keystore ) | ||||
{ | { | ||||
this.keystore = keystore; | |||||
m_keystore = keystore; | |||||
} | } | ||||
public void setSigalg( final String sigalg ) | public void setSigalg( final String sigalg ) | ||||
{ | { | ||||
this.sigalg = sigalg; | |||||
m_sigalg = sigalg; | |||||
} | } | ||||
public void setStorepass( final String storepass ) | public void setStorepass( final String storepass ) | ||||
{ | { | ||||
this.storepass = storepass; | |||||
m_storepass = storepass; | |||||
} | } | ||||
public void setStoretype( final String storetype ) | public void setStoretype( final String storetype ) | ||||
{ | { | ||||
this.storetype = storetype; | |||||
m_storetype = storetype; | |||||
} | } | ||||
public void setValidity( final String validity ) | public void setValidity( final String validity ) | ||||
@@ -106,7 +106,7 @@ public class GenerateKey | |||||
{ | { | ||||
try | try | ||||
{ | { | ||||
this.validity = Integer.parseInt( validity ); | |||||
m_validity = Integer.parseInt( validity ); | |||||
} | } | ||||
catch( final NumberFormatException nfe ) | catch( final NumberFormatException nfe ) | ||||
{ | { | ||||
@@ -116,215 +116,131 @@ public class GenerateKey | |||||
public void setVerbose( final boolean verbose ) | public void setVerbose( final boolean verbose ) | ||||
{ | { | ||||
this.verbose = verbose; | |||||
m_verbose = verbose; | |||||
} | } | ||||
public DistinguishedName createDname() | public DistinguishedName createDname() | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( null != expandedDname ) | |||||
if( null != m_expandedDname ) | |||||
{ | { | ||||
throw new TaskException( "DName sub-element can only be specified once." ); | throw new TaskException( "DName sub-element can only be specified once." ); | ||||
} | } | ||||
if( null != dname ) | |||||
if( null != m_dname ) | |||||
{ | { | ||||
throw new TaskException( "It is not possible to specify dname both " + | throw new TaskException( "It is not possible to specify dname both " + | ||||
"as attribute and element." ); | "as attribute and element." ); | ||||
} | } | ||||
expandedDname = new DistinguishedName(); | |||||
return expandedDname; | |||||
m_expandedDname = new DistinguishedName(); | |||||
return m_expandedDname; | |||||
} | } | ||||
public void execute() | public void execute() | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( null == alias ) | |||||
{ | |||||
throw new TaskException( "alias attribute must be set" ); | |||||
} | |||||
validate(); | |||||
if( null == storepass ) | |||||
{ | |||||
throw new TaskException( "storepass attribute must be set" ); | |||||
} | |||||
final String message = "Generating Key for " + m_alias; | |||||
getLogger().info( message ); | |||||
if( null == dname && null == expandedDname ) | |||||
{ | |||||
throw new TaskException( "dname must be set" ); | |||||
} | |||||
getLogger().info( "Generating Key for " + alias ); | |||||
final ExecTask cmd = (ExecTask)getProject().createTask( "exec" ); | final ExecTask cmd = (ExecTask)getProject().createTask( "exec" ); | ||||
cmd.setExecutable( "keytool" ); | cmd.setExecutable( "keytool" ); | ||||
cmd.createArg().setValue( "-genkey " ); | cmd.createArg().setValue( "-genkey " ); | ||||
if( verbose ) | |||||
if( m_verbose ) | |||||
{ | { | ||||
cmd.createArg().setValue( "-v " ); | cmd.createArg().setValue( "-v " ); | ||||
} | } | ||||
cmd.createArg().setValue( "-alias" ); | cmd.createArg().setValue( "-alias" ); | ||||
cmd.createArg().setValue( alias ); | |||||
cmd.createArg().setValue( m_alias ); | |||||
if( null != dname ) | |||||
if( null != m_dname ) | |||||
{ | { | ||||
cmd.createArg().setValue( "-dname" ); | cmd.createArg().setValue( "-dname" ); | ||||
cmd.createArg().setValue( dname ); | |||||
cmd.createArg().setValue( m_dname ); | |||||
} | } | ||||
if( null != expandedDname ) | |||||
if( null != m_expandedDname ) | |||||
{ | { | ||||
cmd.createArg().setValue( "-dname" ); | cmd.createArg().setValue( "-dname" ); | ||||
cmd.createArg().setValue( expandedDname.toString() ); | |||||
cmd.createArg().setValue( m_expandedDname.toString() ); | |||||
} | } | ||||
if( null != keystore ) | |||||
if( null != m_keystore ) | |||||
{ | { | ||||
cmd.createArg().setValue( "-keystore" ); | cmd.createArg().setValue( "-keystore" ); | ||||
cmd.createArg().setValue( keystore ); | |||||
cmd.createArg().setValue( m_keystore ); | |||||
} | } | ||||
if( null != storepass ) | |||||
if( null != m_storepass ) | |||||
{ | { | ||||
cmd.createArg().setValue( "-storepass" ); | cmd.createArg().setValue( "-storepass" ); | ||||
cmd.createArg().setValue( storepass ); | |||||
cmd.createArg().setValue( m_storepass ); | |||||
} | } | ||||
if( null != storetype ) | |||||
if( null != m_storetype ) | |||||
{ | { | ||||
cmd.createArg().setValue( "-storetype" ); | cmd.createArg().setValue( "-storetype" ); | ||||
cmd.createArg().setValue( storetype ); | |||||
cmd.createArg().setValue( m_storetype ); | |||||
} | } | ||||
cmd.createArg().setValue( "-keypass" ); | cmd.createArg().setValue( "-keypass" ); | ||||
if( null != keypass ) | |||||
if( null != m_keypass ) | |||||
{ | { | ||||
cmd.createArg().setValue( keypass ); | |||||
cmd.createArg().setValue( m_keypass ); | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
cmd.createArg().setValue( storepass ); | |||||
cmd.createArg().setValue( m_storepass ); | |||||
} | } | ||||
if( null != sigalg ) | |||||
if( null != m_sigalg ) | |||||
{ | { | ||||
cmd.createArg().setValue( "-sigalg" ); | cmd.createArg().setValue( "-sigalg" ); | ||||
cmd.createArg().setValue( sigalg ); | |||||
cmd.createArg().setValue( m_sigalg ); | |||||
} | } | ||||
if( null != keyalg ) | |||||
if( null != m_keyalg ) | |||||
{ | { | ||||
cmd.createArg().setValue( "-keyalg" ); | cmd.createArg().setValue( "-keyalg" ); | ||||
cmd.createArg().setValue( keyalg ); | |||||
cmd.createArg().setValue( m_keyalg ); | |||||
} | } | ||||
if( 0 < keysize ) | |||||
if( 0 < m_keysize ) | |||||
{ | { | ||||
cmd.createArg().setValue( "-keysize" ); | cmd.createArg().setValue( "-keysize" ); | ||||
cmd.createArg().setValue( "" + keysize ); | |||||
cmd.createArg().setValue( "" + m_keysize ); | |||||
} | } | ||||
if( 0 < validity ) | |||||
if( 0 < m_validity ) | |||||
{ | { | ||||
cmd.createArg().setValue( "-validity" ); | cmd.createArg().setValue( "-validity" ); | ||||
cmd.createArg().setValue( "" + validity ); | |||||
cmd.createArg().setValue( "" + m_validity ); | |||||
} | } | ||||
cmd.execute(); | cmd.execute(); | ||||
} | } | ||||
public static class DistinguishedName | |||||
{ | |||||
private ArrayList params = new ArrayList(); | |||||
private String name; | |||||
private String path; | |||||
public Iterator getParams() | |||||
{ | |||||
return params.iterator(); | |||||
} | |||||
public Object createParam() | |||||
{ | |||||
DnameParam param = new DnameParam(); | |||||
params.add( param ); | |||||
return param; | |||||
} | |||||
public String encode( final String string ) | |||||
{ | |||||
int end = string.indexOf( ',' ); | |||||
if( -1 == end ) | |||||
return string; | |||||
final StringBuffer sb = new StringBuffer(); | |||||
int start = 0; | |||||
while( -1 != end ) | |||||
{ | |||||
sb.append( string.substring( start, end ) ); | |||||
sb.append( "\\," ); | |||||
start = end + 1; | |||||
end = string.indexOf( ',', start ); | |||||
} | |||||
sb.append( string.substring( start ) ); | |||||
return sb.toString(); | |||||
} | |||||
public String toString() | |||||
{ | |||||
final int size = params.size(); | |||||
final StringBuffer sb = new StringBuffer(); | |||||
boolean firstPass = true; | |||||
for( int i = 0; i < size; i++ ) | |||||
{ | |||||
if( !firstPass ) | |||||
{ | |||||
sb.append( " ," ); | |||||
} | |||||
firstPass = false; | |||||
final DnameParam param = (DnameParam)params.get( i ); | |||||
sb.append( encode( param.getName() ) ); | |||||
sb.append( '=' ); | |||||
sb.append( encode( param.getValue() ) ); | |||||
} | |||||
return sb.toString(); | |||||
} | |||||
} | |||||
public static class DnameParam | |||||
private void validate() throws TaskException | |||||
{ | { | ||||
private String name; | |||||
private String value; | |||||
public void setName( String name ) | |||||
{ | |||||
this.name = name; | |||||
} | |||||
public void setValue( String value ) | |||||
if( null == m_alias ) | |||||
{ | { | ||||
this.value = value; | |||||
final String message = "alias attribute must be set"; | |||||
throw new TaskException( message ); | |||||
} | } | ||||
public String getName() | |||||
if( null == m_storepass ) | |||||
{ | { | ||||
return name; | |||||
final String message = "storepass attribute must be set"; | |||||
throw new TaskException( message ); | |||||
} | } | ||||
public String getValue() | |||||
if( null == m_dname && null == m_expandedDname ) | |||||
{ | { | ||||
return value; | |||||
final String message = "dname must be set"; | |||||
throw new TaskException( message ); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -0,0 +1,77 @@ | |||||
/* | |||||
* Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
* | |||||
* This software is published under the terms of the Apache Software License | |||||
* version 1.1, a copy of which has been included with this distribution in | |||||
* the LICENSE.txt file. | |||||
*/ | |||||
package org.apache.tools.ant.taskdefs; | |||||
import java.util.ArrayList; | |||||
import java.util.Iterator; | |||||
public class DistinguishedName | |||||
{ | |||||
private ArrayList m_params = new ArrayList(); | |||||
private String m_name; | |||||
private String m_path; | |||||
public Iterator getParams() | |||||
{ | |||||
return m_params.iterator(); | |||||
} | |||||
public Object createParam() | |||||
{ | |||||
final DnameParam param = new DnameParam(); | |||||
m_params.add( param ); | |||||
return param; | |||||
} | |||||
public String encode( final String string ) | |||||
{ | |||||
int end = string.indexOf( ',' ); | |||||
if( -1 == end ) | |||||
{ | |||||
return string; | |||||
} | |||||
final StringBuffer sb = new StringBuffer(); | |||||
int start = 0; | |||||
while( -1 != end ) | |||||
{ | |||||
sb.append( string.substring( start, end ) ); | |||||
sb.append( "\\," ); | |||||
start = end + 1; | |||||
end = string.indexOf( ',', start ); | |||||
} | |||||
sb.append( string.substring( start ) ); | |||||
return sb.toString(); | |||||
} | |||||
public String toString() | |||||
{ | |||||
final int size = m_params.size(); | |||||
final StringBuffer sb = new StringBuffer(); | |||||
boolean firstPass = true; | |||||
for( int i = 0; i < size; i++ ) | |||||
{ | |||||
if( !firstPass ) | |||||
{ | |||||
sb.append( " ," ); | |||||
} | |||||
firstPass = false; | |||||
final DnameParam param = (DnameParam)m_params.get( i ); | |||||
sb.append( encode( param.getName() ) ); | |||||
sb.append( '=' ); | |||||
sb.append( encode( param.getValue() ) ); | |||||
} | |||||
return sb.toString(); | |||||
} | |||||
} |
@@ -0,0 +1,34 @@ | |||||
/* | |||||
* Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
* | |||||
* This software is published under the terms of the Apache Software License | |||||
* version 1.1, a copy of which has been included with this distribution in | |||||
* the LICENSE.txt file. | |||||
*/ | |||||
package org.apache.tools.ant.taskdefs; | |||||
public final class DnameParam | |||||
{ | |||||
private String m_name; | |||||
private String m_value; | |||||
public void setName( final String name ) | |||||
{ | |||||
m_name = name; | |||||
} | |||||
public void setValue( final String value ) | |||||
{ | |||||
m_value = value; | |||||
} | |||||
public String getName() | |||||
{ | |||||
return m_name; | |||||
} | |||||
public String getValue() | |||||
{ | |||||
return m_value; | |||||
} | |||||
} |
@@ -24,48 +24,48 @@ public class GenerateKey | |||||
/** | /** | ||||
* The alias of signer. | * The alias of signer. | ||||
*/ | */ | ||||
protected String alias; | |||||
protected String dname; | |||||
protected DistinguishedName expandedDname; | |||||
protected String keyalg; | |||||
protected String keypass; | |||||
protected int keysize; | |||||
private String m_alias; | |||||
private String m_dname; | |||||
private DistinguishedName m_expandedDname; | |||||
private String m_keyalg; | |||||
private String m_keypass; | |||||
private int m_keysize; | |||||
/** | /** | ||||
* The name of keystore file. | * The name of keystore file. | ||||
*/ | */ | ||||
protected String keystore; | |||||
private String m_keystore; | |||||
protected String sigalg; | |||||
protected String storepass; | |||||
protected String storetype; | |||||
protected int validity; | |||||
protected boolean verbose; | |||||
private String m_sigalg; | |||||
private String m_storepass; | |||||
private String m_storetype; | |||||
private int m_validity; | |||||
private boolean m_verbose; | |||||
public void setAlias( final String alias ) | public void setAlias( final String alias ) | ||||
{ | { | ||||
this.alias = alias; | |||||
m_alias = alias; | |||||
} | } | ||||
public void setDname( final String dname ) | public void setDname( final String dname ) | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( null != expandedDname ) | |||||
if( null != m_expandedDname ) | |||||
{ | { | ||||
throw new TaskException( "It is not possible to specify dname both " + | throw new TaskException( "It is not possible to specify dname both " + | ||||
"as attribute and element." ); | "as attribute and element." ); | ||||
} | } | ||||
this.dname = dname; | |||||
m_dname = dname; | |||||
} | } | ||||
public void setKeyalg( final String keyalg ) | public void setKeyalg( final String keyalg ) | ||||
{ | { | ||||
this.keyalg = keyalg; | |||||
m_keyalg = keyalg; | |||||
} | } | ||||
public void setKeypass( final String keypass ) | public void setKeypass( final String keypass ) | ||||
{ | { | ||||
this.keypass = keypass; | |||||
m_keypass = keypass; | |||||
} | } | ||||
public void setKeysize( final String keysize ) | public void setKeysize( final String keysize ) | ||||
@@ -73,7 +73,7 @@ public class GenerateKey | |||||
{ | { | ||||
try | try | ||||
{ | { | ||||
this.keysize = Integer.parseInt( keysize ); | |||||
m_keysize = Integer.parseInt( keysize ); | |||||
} | } | ||||
catch( final NumberFormatException nfe ) | catch( final NumberFormatException nfe ) | ||||
{ | { | ||||
@@ -83,22 +83,22 @@ public class GenerateKey | |||||
public void setKeystore( final String keystore ) | public void setKeystore( final String keystore ) | ||||
{ | { | ||||
this.keystore = keystore; | |||||
m_keystore = keystore; | |||||
} | } | ||||
public void setSigalg( final String sigalg ) | public void setSigalg( final String sigalg ) | ||||
{ | { | ||||
this.sigalg = sigalg; | |||||
m_sigalg = sigalg; | |||||
} | } | ||||
public void setStorepass( final String storepass ) | public void setStorepass( final String storepass ) | ||||
{ | { | ||||
this.storepass = storepass; | |||||
m_storepass = storepass; | |||||
} | } | ||||
public void setStoretype( final String storetype ) | public void setStoretype( final String storetype ) | ||||
{ | { | ||||
this.storetype = storetype; | |||||
m_storetype = storetype; | |||||
} | } | ||||
public void setValidity( final String validity ) | public void setValidity( final String validity ) | ||||
@@ -106,7 +106,7 @@ public class GenerateKey | |||||
{ | { | ||||
try | try | ||||
{ | { | ||||
this.validity = Integer.parseInt( validity ); | |||||
m_validity = Integer.parseInt( validity ); | |||||
} | } | ||||
catch( final NumberFormatException nfe ) | catch( final NumberFormatException nfe ) | ||||
{ | { | ||||
@@ -116,215 +116,131 @@ public class GenerateKey | |||||
public void setVerbose( final boolean verbose ) | public void setVerbose( final boolean verbose ) | ||||
{ | { | ||||
this.verbose = verbose; | |||||
m_verbose = verbose; | |||||
} | } | ||||
public DistinguishedName createDname() | public DistinguishedName createDname() | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( null != expandedDname ) | |||||
if( null != m_expandedDname ) | |||||
{ | { | ||||
throw new TaskException( "DName sub-element can only be specified once." ); | throw new TaskException( "DName sub-element can only be specified once." ); | ||||
} | } | ||||
if( null != dname ) | |||||
if( null != m_dname ) | |||||
{ | { | ||||
throw new TaskException( "It is not possible to specify dname both " + | throw new TaskException( "It is not possible to specify dname both " + | ||||
"as attribute and element." ); | "as attribute and element." ); | ||||
} | } | ||||
expandedDname = new DistinguishedName(); | |||||
return expandedDname; | |||||
m_expandedDname = new DistinguishedName(); | |||||
return m_expandedDname; | |||||
} | } | ||||
public void execute() | public void execute() | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( null == alias ) | |||||
{ | |||||
throw new TaskException( "alias attribute must be set" ); | |||||
} | |||||
validate(); | |||||
if( null == storepass ) | |||||
{ | |||||
throw new TaskException( "storepass attribute must be set" ); | |||||
} | |||||
final String message = "Generating Key for " + m_alias; | |||||
getLogger().info( message ); | |||||
if( null == dname && null == expandedDname ) | |||||
{ | |||||
throw new TaskException( "dname must be set" ); | |||||
} | |||||
getLogger().info( "Generating Key for " + alias ); | |||||
final ExecTask cmd = (ExecTask)getProject().createTask( "exec" ); | final ExecTask cmd = (ExecTask)getProject().createTask( "exec" ); | ||||
cmd.setExecutable( "keytool" ); | cmd.setExecutable( "keytool" ); | ||||
cmd.createArg().setValue( "-genkey " ); | cmd.createArg().setValue( "-genkey " ); | ||||
if( verbose ) | |||||
if( m_verbose ) | |||||
{ | { | ||||
cmd.createArg().setValue( "-v " ); | cmd.createArg().setValue( "-v " ); | ||||
} | } | ||||
cmd.createArg().setValue( "-alias" ); | cmd.createArg().setValue( "-alias" ); | ||||
cmd.createArg().setValue( alias ); | |||||
cmd.createArg().setValue( m_alias ); | |||||
if( null != dname ) | |||||
if( null != m_dname ) | |||||
{ | { | ||||
cmd.createArg().setValue( "-dname" ); | cmd.createArg().setValue( "-dname" ); | ||||
cmd.createArg().setValue( dname ); | |||||
cmd.createArg().setValue( m_dname ); | |||||
} | } | ||||
if( null != expandedDname ) | |||||
if( null != m_expandedDname ) | |||||
{ | { | ||||
cmd.createArg().setValue( "-dname" ); | cmd.createArg().setValue( "-dname" ); | ||||
cmd.createArg().setValue( expandedDname.toString() ); | |||||
cmd.createArg().setValue( m_expandedDname.toString() ); | |||||
} | } | ||||
if( null != keystore ) | |||||
if( null != m_keystore ) | |||||
{ | { | ||||
cmd.createArg().setValue( "-keystore" ); | cmd.createArg().setValue( "-keystore" ); | ||||
cmd.createArg().setValue( keystore ); | |||||
cmd.createArg().setValue( m_keystore ); | |||||
} | } | ||||
if( null != storepass ) | |||||
if( null != m_storepass ) | |||||
{ | { | ||||
cmd.createArg().setValue( "-storepass" ); | cmd.createArg().setValue( "-storepass" ); | ||||
cmd.createArg().setValue( storepass ); | |||||
cmd.createArg().setValue( m_storepass ); | |||||
} | } | ||||
if( null != storetype ) | |||||
if( null != m_storetype ) | |||||
{ | { | ||||
cmd.createArg().setValue( "-storetype" ); | cmd.createArg().setValue( "-storetype" ); | ||||
cmd.createArg().setValue( storetype ); | |||||
cmd.createArg().setValue( m_storetype ); | |||||
} | } | ||||
cmd.createArg().setValue( "-keypass" ); | cmd.createArg().setValue( "-keypass" ); | ||||
if( null != keypass ) | |||||
if( null != m_keypass ) | |||||
{ | { | ||||
cmd.createArg().setValue( keypass ); | |||||
cmd.createArg().setValue( m_keypass ); | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
cmd.createArg().setValue( storepass ); | |||||
cmd.createArg().setValue( m_storepass ); | |||||
} | } | ||||
if( null != sigalg ) | |||||
if( null != m_sigalg ) | |||||
{ | { | ||||
cmd.createArg().setValue( "-sigalg" ); | cmd.createArg().setValue( "-sigalg" ); | ||||
cmd.createArg().setValue( sigalg ); | |||||
cmd.createArg().setValue( m_sigalg ); | |||||
} | } | ||||
if( null != keyalg ) | |||||
if( null != m_keyalg ) | |||||
{ | { | ||||
cmd.createArg().setValue( "-keyalg" ); | cmd.createArg().setValue( "-keyalg" ); | ||||
cmd.createArg().setValue( keyalg ); | |||||
cmd.createArg().setValue( m_keyalg ); | |||||
} | } | ||||
if( 0 < keysize ) | |||||
if( 0 < m_keysize ) | |||||
{ | { | ||||
cmd.createArg().setValue( "-keysize" ); | cmd.createArg().setValue( "-keysize" ); | ||||
cmd.createArg().setValue( "" + keysize ); | |||||
cmd.createArg().setValue( "" + m_keysize ); | |||||
} | } | ||||
if( 0 < validity ) | |||||
if( 0 < m_validity ) | |||||
{ | { | ||||
cmd.createArg().setValue( "-validity" ); | cmd.createArg().setValue( "-validity" ); | ||||
cmd.createArg().setValue( "" + validity ); | |||||
cmd.createArg().setValue( "" + m_validity ); | |||||
} | } | ||||
cmd.execute(); | cmd.execute(); | ||||
} | } | ||||
public static class DistinguishedName | |||||
{ | |||||
private ArrayList params = new ArrayList(); | |||||
private String name; | |||||
private String path; | |||||
public Iterator getParams() | |||||
{ | |||||
return params.iterator(); | |||||
} | |||||
public Object createParam() | |||||
{ | |||||
DnameParam param = new DnameParam(); | |||||
params.add( param ); | |||||
return param; | |||||
} | |||||
public String encode( final String string ) | |||||
{ | |||||
int end = string.indexOf( ',' ); | |||||
if( -1 == end ) | |||||
return string; | |||||
final StringBuffer sb = new StringBuffer(); | |||||
int start = 0; | |||||
while( -1 != end ) | |||||
{ | |||||
sb.append( string.substring( start, end ) ); | |||||
sb.append( "\\," ); | |||||
start = end + 1; | |||||
end = string.indexOf( ',', start ); | |||||
} | |||||
sb.append( string.substring( start ) ); | |||||
return sb.toString(); | |||||
} | |||||
public String toString() | |||||
{ | |||||
final int size = params.size(); | |||||
final StringBuffer sb = new StringBuffer(); | |||||
boolean firstPass = true; | |||||
for( int i = 0; i < size; i++ ) | |||||
{ | |||||
if( !firstPass ) | |||||
{ | |||||
sb.append( " ," ); | |||||
} | |||||
firstPass = false; | |||||
final DnameParam param = (DnameParam)params.get( i ); | |||||
sb.append( encode( param.getName() ) ); | |||||
sb.append( '=' ); | |||||
sb.append( encode( param.getValue() ) ); | |||||
} | |||||
return sb.toString(); | |||||
} | |||||
} | |||||
public static class DnameParam | |||||
private void validate() throws TaskException | |||||
{ | { | ||||
private String name; | |||||
private String value; | |||||
public void setName( String name ) | |||||
{ | |||||
this.name = name; | |||||
} | |||||
public void setValue( String value ) | |||||
if( null == m_alias ) | |||||
{ | { | ||||
this.value = value; | |||||
final String message = "alias attribute must be set"; | |||||
throw new TaskException( message ); | |||||
} | } | ||||
public String getName() | |||||
if( null == m_storepass ) | |||||
{ | { | ||||
return name; | |||||
final String message = "storepass attribute must be set"; | |||||
throw new TaskException( message ); | |||||
} | } | ||||
public String getValue() | |||||
if( null == m_dname && null == m_expandedDname ) | |||||
{ | { | ||||
return value; | |||||
final String message = "dname must be set"; | |||||
throw new TaskException( message ); | |||||
} | } | ||||
} | } | ||||
} | } | ||||