mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-07 01:35:00 -05:00
generate single key
This commit is contained in:
parent
fa0bd5edb4
commit
617f117e23
@ -116,6 +116,8 @@ public class PgpKeyOperation {
|
|||||||
* @throws PgpGeneralException
|
* @throws PgpGeneralException
|
||||||
* @throws InvalidAlgorithmParameterException
|
* @throws InvalidAlgorithmParameterException
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// TODO: key flags?
|
||||||
public PGPSecretKey createKey(int algorithmChoice, int keySize, String passPhrase,
|
public PGPSecretKey createKey(int algorithmChoice, int keySize, String passPhrase,
|
||||||
boolean isMasterKey) throws NoSuchAlgorithmException, PGPException, NoSuchProviderException,
|
boolean isMasterKey) throws NoSuchAlgorithmException, PGPException, NoSuchProviderException,
|
||||||
PgpGeneralException, InvalidAlgorithmParameterException {
|
PgpGeneralException, InvalidAlgorithmParameterException {
|
||||||
|
@ -290,18 +290,19 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
|
|||||||
|
|
||||||
// fill values for this action
|
// fill values for this action
|
||||||
Bundle data = new Bundle();
|
Bundle data = new Bundle();
|
||||||
|
Boolean isMasterKey;
|
||||||
|
|
||||||
String passPhrase;
|
String passPhrase;
|
||||||
if (mEditors.getChildCount() > 0) {
|
if (mEditors.getChildCount() > 0) {
|
||||||
PGPSecretKey masterKey = ((KeyEditor) mEditors.getChildAt(0)).getValue();
|
PGPSecretKey masterKey = ((KeyEditor) mEditors.getChildAt(0)).getValue();
|
||||||
passPhrase = PassphraseCacheService
|
passPhrase = PassphraseCacheService
|
||||||
.getCachedPassphrase(mActivity, masterKey.getKeyID());
|
.getCachedPassphrase(mActivity, masterKey.getKeyID());
|
||||||
|
isMasterKey = true;
|
||||||
data.putByteArray(KeychainIntentService.GENERATE_KEY_MASTER_KEY,
|
|
||||||
PgpConversionHelper.PGPSecretKeyToBytes(masterKey));
|
|
||||||
} else {
|
} else {
|
||||||
passPhrase = "";
|
passPhrase = "";
|
||||||
|
isMasterKey = false;
|
||||||
}
|
}
|
||||||
|
data.putBoolean(KeychainIntentService.GENERATE_KEY_MASTER_KEY, isMasterKey);
|
||||||
data.putString(KeychainIntentService.GENERATE_KEY_SYMMETRIC_PASSPHRASE, passPhrase);
|
data.putString(KeychainIntentService.GENERATE_KEY_SYMMETRIC_PASSPHRASE, passPhrase);
|
||||||
data.putInt(KeychainIntentService.GENERATE_KEY_ALGORITHM, mNewKeyAlgorithmChoice.getId());
|
data.putInt(KeychainIntentService.GENERATE_KEY_ALGORITHM, mNewKeyAlgorithmChoice.getId());
|
||||||
data.putInt(KeychainIntentService.GENERATE_KEY_KEY_SIZE, mNewKeySize);
|
data.putInt(KeychainIntentService.GENERATE_KEY_KEY_SIZE, mNewKeySize);
|
||||||
@ -322,30 +323,15 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
|
|||||||
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
|
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
|
||||||
// get new key from data bundle returned from service
|
// get new key from data bundle returned from service
|
||||||
Bundle data = message.getData();
|
Bundle data = message.getData();
|
||||||
PGPSecretKeyRing newKeyRing = (PGPSecretKeyRing) PgpConversionHelper
|
PGPSecretKey newKey = (PGPSecretKey) PgpConversionHelper
|
||||||
.BytesToPGPKeyRing(data
|
.BytesToPGPKey(data
|
||||||
.getByteArray(KeychainIntentService.RESULT_NEW_KEY));
|
.getByteArray(KeychainIntentService.RESULT_NEW_KEY));
|
||||||
|
|
||||||
boolean isMasterKey = (mEditors.getChildCount() == 0);
|
|
||||||
|
|
||||||
// take only the key from this ring
|
|
||||||
PGPSecretKey newKey = null;
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Iterator<PGPSecretKey> it = newKeyRing.getSecretKeys();
|
|
||||||
|
|
||||||
if (isMasterKey) {
|
|
||||||
newKey = it.next();
|
|
||||||
} else {
|
|
||||||
// first one is the master key
|
|
||||||
it.next();
|
|
||||||
newKey = it.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
// add view with new key
|
// add view with new key
|
||||||
KeyEditor view = (KeyEditor) mInflater.inflate(R.layout.edit_key_key_item,
|
KeyEditor view = (KeyEditor) mInflater.inflate(R.layout.edit_key_key_item,
|
||||||
mEditors, false);
|
mEditors, false);
|
||||||
view.setEditorListener(SectionView.this);
|
view.setEditorListener(SectionView.this);
|
||||||
view.setValue(newKey, isMasterKey, -1);
|
view.setValue(newKey, newKey.isMasterKey(), -1);
|
||||||
mEditors.addView(view);
|
mEditors.addView(view);
|
||||||
SectionView.this.updateEditorsVisible();
|
SectionView.this.updateEditorsVisible();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user