String sigAlgName;
if (signee_alias == null || signing_alias == null ||
keyPass == null || keyStore == null) {
throw new AppDescriptorException("signACert got a null argument",
4);
}
Object[] objs = recoverPrivateKey(signing_alias, storePass,
keyPass, keyStore);
PrivateKey privKey = (PrivateKey)objs[0];
if (keyPass == null)
keyPass = (char[])objs[1];
// Determine the signature algorithm
// If no signature algorithm was specified at the command line,
// we choose one that is compatible with the selected private key
String keyAlgName = privKey.getAlgorithm();
if (keyAlgName.equalsIgnoreCase("DSA")
|| keyAlgName.equalsIgnoreCase("DSS")) {
sigAlgName = "SHA1WithDSA";
} else if (keyAlgName.equalsIgnoreCase("RSA")) {
sigAlgName = "SHA1WithRSA";
} else {
throw new
AppDescriptorException("Cannot derive signature algorithm", 5);
}
// Get the old certificate
Certificate oldCert = keyStore.getCertificate(signee_alias);
if (oldCert == null) {
throw new
AppDescriptorException(signee_alias + " has no public key", 4);
}
if (!(oldCert instanceof X509Certificate)) {
throw new AppDescriptorException(signee_alias +
" has no X.509 certificate", 6);
}
// Get the "signing" certificate
Certificate signingCert = keyStore.getCertificate(signing_alias);
if (signingCert == null) {
throw new
AppDescriptorException(signee_alias + " has no public key", 7);
}
if (!(signingCert instanceof X509Certificate)) {
throw new AppDescriptorException(signee_alias +
" has no X.509 certificate", 8);
}
// convert to X509CertImpl, so that we can modify selected fields
// (no public APIs available yet)