📄 pgpdialogs.cpp
字号:
if( IsntPGPError( err ) )
{
err = pgpOptionsDialogPlatform( context, &options );
}
}
}
return( err );
}
PGPError
PGPOptionsDialog(
PGPContextRef context,
PGPOptionListRef firstOption,
...)
{
PGPError err;
va_list args;
pgpAssert( pgpContextIsValid( context ) );
if( pgpContextIsValid( context ) )
{
PGPOptionListRef optionList;
va_start( args, firstOption );
optionList = pgpBuildOptionListArgs(context, FALSE, firstOption, args);
va_end( args );
err = pgpOptionsDialog( context, optionList );
PGPFreeOptionList( optionList );
}
else
{
va_start( args, firstOption );
pgpFreeVarArgOptionList( firstOption, args );
va_end( args );
err = kPGPError_BadParams;
}
return( err );
}
static const PGPOptionType sKeyOptionSet[] =
{
kCommonAllowedPassphraseOptions,
kPGPOptionType_VerifyPassphrase,
kPGPOptionType_CachePassphrase
};
static PGPError
pgpKeyPassphraseDialog(
PGPContextRef context,
PGPKeyDBObjRef theKey,
PGPOptionListRef optionList)
{
PGPError err;
pgpAssert( pgpContextIsValid( context ) );
pgpAssert( pgpOptionListIsValid( optionList ) );
err = pgpGetOptionListError( optionList );
if( IsntPGPError( err ) )
{
err = pgpCheckOptionsInSet( optionList, sKeyOptionSet,
elemsof( sKeyOptionSet ) );
if( IsntPGPError( err ) )
{
CPGPKeyPassphraseDialogOptions options;
err = options.GatherOptions( context, optionList );
if( IsntPGPError( err ) )
{
options.mDefaultKey = theKey; /* Overloading mDefaultKey */
err = pgpKeyPassphraseDialogPlatform( context, &options );
}
}
}
return( err );
}
PGPError
PGPKeyPassphraseDialog(
PGPContextRef context,
PGPKeyDBObjRef theKey,
PGPOptionListRef firstOption,
...)
{
PGPError err;
va_list args;
pgpAssert( pgpContextIsValid( context ) );
pgpAssert( PGPKeyDBObjRefIsValid( theKey ) );
if( pgpContextIsValid( context ) &&
PGPKeyDBObjRefIsValid( theKey ) )
{
PGPOptionListRef optionList;
va_start( args, firstOption );
optionList = pgpBuildOptionListArgs(context, FALSE, firstOption, args);
va_end( args );
err = pgpKeyPassphraseDialog( context, theKey, optionList );
PGPFreeOptionList( optionList );
}
else
{
va_start( args, firstOption );
pgpFreeVarArgOptionList( firstOption, args );
va_end( args );
err = kPGPError_BadParams;
}
return( err );
}
static PGPError
FindValidSecretKey(
PGPKeySetRef keySet,
PGPBoolean signing,
PGPKeyDBObjRef defaultPrivateKey,
PGPKeyDBObjRef preferredKey,
PGPKeyDBObjRef *secretKeyPtr)
{
PGPError err;
PGPKeyListRef keyList;
PGPKeyDBObjProperty keyProperty;
PGPKeyDBObjRef splitKeyRef = kInvalidPGPKeyDBObjRef;
PGPKeyDBObjRef secretKeyRef = kInvalidPGPKeyDBObjRef;
PGPKeyDBObjRef defaultKey = kInvalidPGPKeyDBObjRef;
PGPBoolean foundDefaultKey = FALSE;
PGPBoolean foundPreferredKey = FALSE;
PGPBoolean preferredIsSplitKey = FALSE;
PGPBoolean defaultIsSplitKey = FALSE;
*secretKeyPtr = kInvalidPGPKeyDBObjRef;
/* Note that defaultKey may be a split key */
if( ! PGPKeyDBObjRefIsValid( preferredKey ) )
preferredKey = defaultPrivateKey;
if( signing )
{
keyProperty = kPGPKeyProperty_CanSign;
}
else
{
keyProperty = kPGPKeyProperty_CanDecrypt;
}
err = PGPOrderKeySet( keySet, kPGPKeyOrdering_Any, FALSE, &keyList );
if( IsntPGPError( err ) )
{
PGPKeyIterRef keyIterator;
err = PGPNewKeyIter( keyList, &keyIterator );
if( IsntPGPError( err ) )
{
PGPKeyDBObjRef theKey;
err = PGPKeyIterNextKeyDBObj( keyIterator, kPGPKeyDBObjType_Key, &theKey );
while( IsntPGPError( err ) )
{
PGPBoolean canOperate;
err = PGPGetKeyDBObjBooleanProperty( theKey, keyProperty, &canOperate );
if( IsntPGPError( err ) )
{
if( canOperate )
{
PGPBoolean isSplitKey = FALSE;
(void) PGPGetKeyDBObjBooleanProperty( theKey,
kPGPKeyProperty_IsSecretShared, &isSplitKey );
if( theKey == defaultKey )
{
foundDefaultKey = TRUE;
if( isSplitKey )
defaultIsSplitKey = TRUE;
}
if( theKey == preferredKey )
{
foundPreferredKey = TRUE;
if( isSplitKey )
preferredIsSplitKey = TRUE;
}
if( isSplitKey )
{
if( ! PGPKeyDBObjRefIsValid( splitKeyRef ) )
splitKeyRef = theKey;
}
else
{
if( ! PGPKeyDBObjRefIsValid( secretKeyRef ) )
secretKeyRef = theKey;
/*
** If we've found the preferred key and we have
** at least one non-split key, we can stop
*/
if( foundPreferredKey )
break;
}
}
err = PGPKeyIterNextKeyDBObj( keyIterator, kPGPKeyDBObjType_Key, &theKey );
}
}
if( err == kPGPError_EndOfIteration )
err = kPGPError_NoErr;
PGPFreeKeyIter( keyIterator );
}
PGPFreeKeyList( keyList );
}
if( IsntPGPError( err ) )
{
if( PGPKeyDBObjRefIsValid( secretKeyRef ) )
{
/*
** Do not allow a split key as the best secret key
** if we're decrypting and at least one other secret
** key is available.
*/
if( ! signing )
{
if( preferredIsSplitKey )
foundPreferredKey = FALSE;
if( defaultIsSplitKey )
foundDefaultKey = FALSE;
}
if( foundPreferredKey )
{
*secretKeyPtr = preferredKey;
}
else if( foundDefaultKey )
{
*secretKeyPtr = defaultKey;
}
else
{
*secretKeyPtr = secretKeyRef;
}
}
else if( PGPKeyDBObjRefIsValid( splitKeyRef ) )
{
if( foundPreferredKey )
{
*secretKeyPtr = preferredKey;
}
else if( foundDefaultKey )
{
*secretKeyPtr = defaultKey;
}
else
{
*secretKeyPtr = splitKeyRef;
}
if( signing )
{
err = kPGPError_KeyUnusableForSignature;
}
else
{
err = kPGPError_KeyUnusableForDecryption;
}
}
else
{
err = kPGPError_SecretKeyNotFound;
}
}
return( err );
}
static const PGPOptionType sSigningOptionSet[] =
{
kCommonAllowedPassphraseOptions,
kPGPOptionType_VerifyPassphrase,
kPGPOptionType_FindMatchingKey
};
static PGPError
pgpSigningPassphraseDialog(
PGPContextRef context,
PGPKeyDBRef allKeys,
PGPOptionListRef optionList,
PGPKeyDBObjRef *signingKey)
{
PGPError err;
pgpAssert( pgpContextIsValid( context ) );
pgpAssert( pgpOptionListIsValid( optionList ) );
err = pgpGetOptionListError( optionList );
if( IsntPGPError( err ) )
{
err = pgpCheckOptionsInSet( optionList, sSigningOptionSet,
elemsof( sSigningOptionSet ) );
if( IsntPGPError( err ) )
{
CPGPSigningPassphraseDialogOptions options;
err = options.GatherOptions( context, optionList );
if( IsntPGPError( err ) )
{
PGPKeySetRef allKeysSet;
err = PGPNewKeySet( allKeys, &allKeysSet );
if( IsntPGPError( err ) )
{
err = FindValidSecretKey( allKeysSet, TRUE,
options.mDefaultKey,
options.mDefaultKey,
&options.mDefaultKey );
if( IsntPGPError( err ) )
{
options.mKeySet = allKeysSet;
options.mPassphraseKeyPtr = signingKey;
err = pgpSigningPassphraseDialogPlatform( context,
&options );
}
else if( err == kPGPError_KeyUnusableForSignature )
{
/* Special case. We return a split key, if found */
*signingKey = options.mDefaultKey;
}
PGPFreeKeySet( allKeysSet );
}
}
}
}
return( err );
}
PGPError
PGPSigningPassphraseDialog(
PGPContextRef context,
PGPKeyDBRef allKeys,
PGPKeyDBObjRef *signingKey,
PGPOptionListRef firstOption,
...)
{
PGPError err;
va_list args;
pgpAssert( pgpContextIsValid( context ) );
pgpAssert( PGPKeyDBRefIsValid( allKeys ) );
if( IsntNull( signingKey ) )
*signingKey = kInvalidPGPKeyDBObjRef;
if( pgpContextIsValid( context ) &&
PGPKeyDBRefIsValid( allKeys ) &&
IsntNull( signingKey ) )
{
PGPOptionListRef optionList;
va_start( args, firstOption );
optionList = pgpBuildOptionListArgs(context, FALSE, firstOption, args);
va_end( args );
err = pgpSigningPassphraseDialog( context, allKeys,
optionList, signingKey );
PGPFreeOptionList( optionList );
}
else
{
va_start( args, firstOption );
pgpFreeVarArgOptionList( firstOption, args );
va_end( args );
err = kPGPError_BadParams;
}
return( err );
}
static const PGPOptionType sDecryptionOptionSet[] =
{
kCommonAllowedPassphraseOptions,
kPGPOptionType_VerifyPassphrase,
kPGPOptionType_FindMatchingKey,
kPGPOptionType_KeyServerUpdateParams
};
static PGPError
pgpDecryptionPassphraseDialog(
PGPContextRef context,
PGPKeySetRef recipientKeys,
const PGPKeyID keyIDList[],
PGPUInt32 keyIDCount,
PGPOptionListRef optionList,
PGPKeyDBObjRef *decryptionKey)
{
PGPError err;
pgpAssert( pgpContextIsValid( context ) );
pgpAssert( pgpOptionListIsValid( optionList ) );
err = pgpGetOptionListError( optionList );
if( IsntPGPError( err ) )
{
err = pgpCheckOptionsInSet( optionList, sDecryptionOptionSet,
elemsof( sDecryptionOptionSet ) );
if( IsntPGPError( err ) )
{
CPGPDecryptionPassphraseDialogOptions options;
err = options.GatherOptions( context, optionList );
if( IsntPGPError( err ) )
{
err = FindValidSecretKey( recipientKeys, FALSE,
options.mDefaultKey, options.mDefaultKey,
&options.mDefaultKey );
/* Proceed with dialog even when no keys are found */
if( err == kPGPError_SecretKeyNotFound )
err = kPGPError_NoErr;
if( IsntPGPError( err ) )
{
options.mKeySet = recipientKeys;
options.mPassphraseKeyPtr = decryptionKey;
options.mKeyIDList = keyIDList;
options.mKeyIDCount = keyIDCount;
err = options.GatherMissingKeys();
if( IsntPGPError( err ) )
{
err = pgpDecryptionPassphraseDialogPlatform( context,
&options );
}
if( IsPGPError( err ) &&
IsntNull( options.mNewKeys ) &&
PGPKeyDBRefIsValid( *options.mNewKeys ) )
{
PGPFreeKeyDB( *options.mNewKeys );
*options.mNewKeys = kInvalidPGPKeyDBRef;
}
}
else if( err == kPGPError_KeyUnusableForDecryption )
{
/* Special case. We return a split key, if found */
*decryptionKey = options.mDefaultKey;
}
}
}
}
return( err );
}
PGPError
PGPDecryptionPassphraseDialog(
PGPContextRef context,
PGPKeySetRef recipientKeys,
PGPUInt32 keyIDCount,
const PGPKeyID keyIDList[],
PGPKeyDBObjRef *decryptionKey,
PGPOptionListRef firstOption,
...)
{
PGPError err = kPGPError_NoErr;
va_list args;
pgpAssert( pgpContextIsValid( context ) );
pgpAssert( PGPKeySetRefIsValid( recipientKeys ) );
if( IsntNull( decryptionKey ) )
*decryptionKey = kInvalidPGPKeyDBObjRef;
if( pgpContextIsValid( context ) &&
PGPKeySetRefIsValid( recipientKeys ) &&
IsntNull( decryptionKey ) )
{
PGPOptionListRef optionList;
va_start( args, firstOption );
optionList = pgpBuildOptionListArgs(context, FALSE, firstOption, args);
va_end( args );
err = pgpDecryptionPassphraseDialog( context, recipientKeys, keyIDList,
keyIDCount, optionList, decryptionKey );
PGPFreeOptionList( optionList );
}
else
{
va_start( args, firstOption );
pgpFreeVarArgOptionList( firstOption, args );
va_end( args );
err = kPGPError_BadParams;
}
return( err );
}
static const PGPOptionType sConfirmationPassphraseOptionSet[] =
{
kCommonAllowedPassphraseOptions,
kPGPOptionType_ShowPassphraseQuality
};
static PGPError
pgpConfirmationPassphraseDialog(
PGPContextRef context,
PGPOptionListRef optionList,
PGPUInt32 minPassphraseLength)
{
PGPError err;
pgpAssert( pgpContextIsValid( context ) );
pgpAssert( pgpOptionListIsValid( optionList ) );
err = pgpGetOptionListError( optionList );
if( IsntPGPError( err ) )
{
err = pgpCheckOptionsInSet( optionList,
sConfirmationPassphraseOptionSet,
elemsof( sConfirmationPassphraseOptionSet ) );
if( IsntPGPError( err ) )
{
CPGPConfirmationPassphraseDialogOptions options;
err = options.GatherOptions( context, optionList );
if( IsntPGPError( err ) )
{
if( options.mMinPassphraseLength < minPassphraseLength )
{
options.mMinPassphraseLength = minPassphraseLength;
}
err = pgpConfirmationPassphraseDialogPlatform( context,
&options );
}
}
}
return( err );
}
PGPError
PGPConfirmationPassphraseDialog(
PGPContextRef context,
PGPOptionListRef firstOption,
...)
{
PGPError err = kPGPError_NoErr;
va_list args;
pgpAssert( pgpContextIsValid( context ) );
if( pgpContextIsValid( context ) )
{
PGPOptionListRef optionList;
va_start( args, firstOption );
optionList = pgpBuildOptionListArgs(context, FALSE, firstOption, args);
va_end( args );
err = pgpConfirmationPassphraseDialog( context, optionList, 0 );
PGPFreeOptionList( optionList );
}
else
{
va_start( args, firstOption );
pgpFreeVarArgOptionList( firstOption, args );
va_end( args );
err = kPGPError_BadParams;
}
return( err );
}
PGPError
PGPConventionalEncryptionPassphraseDialog(
PGPContextRef context,
PGPOptionListRef firstOption,
...)
{
PGPError err = kPGPError_NoErr;
va_list args;
pgpAssert( pgpContextIsValid( context ) );
if( pgpContextIsValid( context ) )
{
PGPOptionListRef optionList;
va_start( args, firstOption );
optionList = pgpBuildOptionListArgs(context, FALSE, firstOption, args);
va_end( args );
err = pgpConfirmationPassphraseDialog( context, optionList, 0 );
PGPFreeOptionList( optionList );
}
else
{
va_start( args, firstOption );
pgpFreeVarArgOptionList( firstOption, args );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -