} else {
signKey = keys[0];
}
if (signKey == null) {
throw new GeneralSecurityException("No signature key selected.");
}
}
if(signKey == null && (cryptoType == PGP_SIGN || cryptoType == PGP_BOTH)){
Key[] keys = cryptoManager.getPrivateKeysForAddress(from.getAddress(), EncryptionManager.PGP, true);
if (keys == null || keys.length == 0) {
// show dialog
signKey = CryptoKeySelector.selectPrivateKey(Pooka.getProperty("Pooka.crypto.privateKey.forSign", "Select key to sign this message."), EncryptionManager.PGP, true);
} else {
signKey = keys[0];
}
if (signKey == null) {
throw new GeneralSecurityException("No signature key selected.");
}
}
List encKeys = new LinkedList();
//TODO: get the encKey from the available public keys
if (cryptoType == SMIME_ENCRYPT || cryptoType == SMIME_BOTH || cryptoType == PGP_ENCRYPT || cryptoType == PGP_BOTH) {
String type = (cryptoType == SMIME_ENCRYPT || cryptoType == SMIME_BOTH) ? EncryptionManager.SMIME : EncryptionManager.PGP;
// Get the public key of the senders
Address[] froms = mm.getFrom();
for (int i = 0; i < froms.length; i++) {
from = (InternetAddress) froms[i];
Key[] keys = cryptoManager.getPublicKeys(from.getAddress(), type, false);
if (keys != null && keys.length > 0) {
encKeys.add(keys[0]);
}
}
// Get the public key of the receivers
Address[] receivers = mm.getAllRecipients();
for (int i = 0; i < receivers.length; i++) {
InternetAddress rec = (InternetAddress) receivers[i];
Key[] keys = cryptoManager.getPublicKeys(rec.getAddress(), type, false);
if (keys != null && keys.length > 0) {
encKeys.add(keys[0]);
} else {
Key key = CryptoKeySelector.selectPublicKey(Pooka.getProperty("Pooka.crypto.publicKey.forEncrypt", "Select key to encrypt this message."), EncryptionManager.PGP, false);
if (key != null)
encKeys.add(key);
else
throw new GeneralSecurityException("found no certificate for " + rec.getAddress());
}
}
/*Key encKey = CryptoKeySelector.selectPublicKey(
Pooka.getProperty("Pooka.crypto.publicKey.forEncrypt",
"Select key to encrypt this message."),