📄 pgpkeyback.c
字号:
PGPSize adklistsize,
PGPByte adkclass,
PGPUInt32 * raklist,
PGPSize raklistsize,
PGPByte rakclass,
char const * passphrase,
PGPSize passphraseLength,
PGPBoolean passphraseIsKey,
PGPUInt32 cacheTimeOut,
PGPBoolean cacheGlobal,
PGPUInt32 ** newobjs,
PGPSize * newobjslength,
PGPUInt32 * newkeyid )
{
PGPKeyDB * db;
PGPKeySetRef adkset;
PGPKeySetRef rakset;
PGPSecKey * seckey;
PGPKeySpec * keyspec;
PGPEnv * pgpEnv;
PGPKeyDBObjRef key;
PGPBoolean v3;
PGPByte pkalg;
PGPError err;
if (pgpRPCEnabled())
{
return pgpCreateKeypair_backRPC( context, keydbID,
seckeyBuf, seckeySize, keyspecBuf, keyspecSize,
name, name_len,
adklist, adklistsize, adkclass,
raklist, raklistsize, rakclass,
passphrase, passphraseLength,
passphraseIsKey, cacheTimeOut, cacheGlobal,
newobjs, newobjslength, newkeyid);
}
db = (PGPKeyDB *)keydbID;
pgpAssert( pgpKeyDBIsValid( db ) );
keyspec = pgpKeySpecFromBuf( context, keyspecBuf, keyspecSize, &err );
PGPFreeData( keyspecBuf );
if( IsPGPError( err ) )
{
PGPFreeData( seckeyBuf );
PGPFreeData( adklist );
PGPFreeData( raklist );
return err;
}
v3 = pgpKeySpecVersion( keyspec ) < PGPVERSION_4;
pkalg = pgpKeySpecPkAlg( keyspec );
seckey = pgpSecKeyFromBuf( context, pkalg, seckeyBuf, seckeySize,
v3, NULL, &err );
PGPFreeData( seckeyBuf );
if( IsPGPError( err ) )
{
pgpKeySpecDestroy( keyspec );
PGPFreeData( adklist );
PGPFreeData( raklist );
return err;
}
err = pgpKeySetUnflattenFree( db, adklist, adklistsize, &adkset );
if( IsPGPError( err ) )
{
pgpSecKeyDestroy( seckey );
pgpKeySpecDestroy( keyspec );
PGPFreeKeySet( adkset );
PGPFreeData( raklist );
return err;
}
err = pgpKeySetUnflattenFree( db, raklist, raklistsize, &rakset );
if( IsPGPError( err ) )
{
pgpSecKeyDestroy( seckey );
pgpKeySpecDestroy( keyspec );
PGPFreeKeySet( adkset );
return err;
}
/* Add to cache if requested */
if( IsntNull( passphrase ) )
(void)pgpSecKeyCachePassphrase( seckey, (PGPByte const *)passphrase,
passphraseLength, passphraseIsKey,
cacheTimeOut, cacheGlobal );
pgpEnv = pgpContextGetEnvironment( context );
key = pgpCreateKeypair (pgpEnv, db, seckey, keyspec,
name, name_len,
adkset, adkclass, rakset, rakclass,
(PGPByte *) passphrase, passphraseLength,
passphraseIsKey, &err);
pgpSecKeyDestroy( seckey );
pgpKeySpecDestroy( keyspec );
PGPFreeKeySet( adkset );
PGPFreeKeySet( rakset );
if( IsPGPError( err ) )
return err;
*newkeyid = (PGPUInt32)key;
(void)pgpSetPendingNotify( NULL, NULL, NULL, key );
return pgpCreateKeyArray( context, key, 1, NULL, newobjs, newobjslength );
}
PGPError
pgpCreateSubkeypair_back (
PGPContextRef context,
PGPUInt32 masterkeyID,
PGPByte * seckeyBuf,
PGPSize seckeySize,
PGPByte * keyspecBuf,
PGPSize keyspecSize,
char const * passphrase,
PGPSize passphraseLength,
PGPBoolean passphraseIsKey,
PGPUInt32 cacheTimeOut,
PGPBoolean cacheGlobal,
PGPUInt32 ** newobjs,
PGPSize * newobjslength,
PGPUInt32 * newkeyid )
{
PGPKeyDB * db;
PGPKeyDBObjRef masterkey;
PGPSecKey * seckey;
PGPKeySpec * keyspec;
PGPKeyDBObjRef subkey;
PGPEnv * pgpEnv;
PGPBoolean v3;
PGPByte pkalg;
PGPError err;
if (pgpRPCEnabled())
{
return pgpCreateSubkeypair_backRPC( context, masterkeyID,
seckeyBuf, seckeySize,
keyspecBuf, keyspecSize,
passphrase, passphraseLength,
passphraseIsKey, cacheTimeOut, cacheGlobal,
newobjs, newobjslength, newkeyid );
}
masterkey = (PGPKeyDBObj *) masterkeyID;
pgpAssert( IsNull(masterkey) || pgpKeyDBObjIsValid( masterkey ) );
db = PGPPeekKeyDBObjKeyDB( masterkey );
pgpAssert( pgpKeyDBIsValid( db ) );
keyspec = pgpKeySpecFromBuf( context, keyspecBuf, keyspecSize, &err );
PGPFreeData( keyspecBuf );
if( IsPGPError( err ) )
{
PGPFreeData( seckeyBuf );
return err;
}
v3 = pgpKeySpecVersion( keyspec ) < PGPVERSION_4;
pkalg = pgpKeySpecPkAlg( keyspec );
seckey = pgpSecKeyFromBuf( context, pkalg, seckeyBuf, seckeySize,
v3, NULL, &err );
PGPFreeData( seckeyBuf );
if( IsPGPError( err ) )
{
pgpKeySpecDestroy( keyspec );
return err;
}
/* Add to cache if requested */
if( IsntNull( passphrase ) )
(void)pgpSecKeyCachePassphrase( seckey, (PGPByte const *)passphrase,
passphraseLength, passphraseIsKey,
cacheTimeOut, cacheGlobal );
pgpEnv = pgpContextGetEnvironment( context );
subkey = pgpCreateSubkeypair (masterkey, pgpEnv, seckey,
keyspec, (PGPByte const *)passphrase,
passphraseLength, passphraseIsKey, &err );
pgpSecKeyDestroy( seckey );
pgpKeySpecDestroy( keyspec );
if( IsPGPError( err ) )
return err;
*newkeyid = (PGPUInt32)subkey;
(void)pgpSetPendingNotify( NULL, NULL, NULL, masterkey );
return pgpCreateKeyArray( context, subkey, 1, NULL,
newobjs, newobjslength );
}
PGPError
pgpCountTokens_back (
PGPContextRef context,
PGPUInt32 *numTokens
)
{
if (pgpRPCEnabled())
return pgpCountTokens_backRPC( context, numTokens );
return pgpCountTokens_internal( context, numTokens );
}
PGPError
pgpGetTokenInfo_back (
PGPContextRef context,
PGPUInt32 tokNumber,
PGPTokenInfo *tokenInfo )
{
if (pgpRPCEnabled())
return pgpGetTokenInfo_backRPC( context, tokNumber, tokenInfo );
return pgpGetTokenInfo_internal( context, tokNumber, tokenInfo );
}
PGPError
pgpDeleteKeyOnToken_back (
PGPContextRef context,
PGPUInt32 keydbID,
const PGPKeyID *keyID,
PGPUInt32 tokNumber,
PGPByte const *pin, PGPSize pinLen )
{
if (pgpRPCEnabled())
return pgpDeleteKeyOnToken_backRPC( context, keydbID, keyID, tokNumber, pin, pinLen );
return pgpDeleteKeyOnToken_internal( context, keydbID, keyID, tokNumber, pin, pinLen );
}
PGPError
pgpWipeToken_back (
PGPContextRef context,
PGPUInt32 tokNumber,
PGPByte const * passphrase,
PGPSize passphraseLength
)
{
if (pgpRPCEnabled())
return pgpWipeToken_backRPC( context, tokNumber, passphrase,
passphraseLength );
return pgpWipeToken_internal( context, tokNumber, passphrase,
passphraseLength );
}
PGPError
pgpFormatToken_back (
PGPContextRef context,
PGPUInt32 tokNumber,
PGPByte const * adminPin, PGPSize adminPinLen,
PGPByte const * newUserPin, PGPSize newUserPinLen )
{
if (pgpRPCEnabled())
return pgpFormatToken_backRPC( context, tokNumber,
adminPin, adminPinLen, newUserPin, newUserPinLen );
return pgpFormatToken_internal( context, tokNumber,
adminPin, adminPinLen, newUserPin, newUserPinLen );
}
PGPError
pgpTokenPassphraseIsValid_back (
PGPContextRef context,
PGPUInt32 tokNumber,
PGPByte const * passphrase,
PGPSize passphraseLength
)
{
if (pgpRPCEnabled())
return pgpTokenPassphraseIsValid_backRPC( context, tokNumber,
passphrase, passphraseLength );
return pgpTokenPassphraseIsValid_internal( context, tokNumber, passphrase,
passphraseLength );
}
PGPError
pgpCopyKeyToToken_back (
PGPContextRef context,
PGPUInt32 objid,
PGPUInt32 tokNumber,
PGPBoolean isMaster,
char const * passphrase,
PGPSize passphraseLength,
PGPBoolean hashedPhrase,
char const * PIN,
PGPSize PINlength,
PGPUInt32 cacheTimeOut,
PGPBoolean cacheGlobal)
{
PGPKeyDBObj * key = (PGPKeyDBObj *) objid;
PGPError err;
if (pgpRPCEnabled())
return pgpCopyKeyToToken_backRPC( context, objid, tokNumber,
isMaster,
passphrase, passphraseLength, hashedPhrase, PIN, PINlength,
cacheTimeOut, cacheGlobal);
pgpAssert( pgpKeyIsValid( key ) );
err = pgpCopyKeyToToken_internal( key, tokNumber, isMaster, passphrase,
passphraseLength, hashedPhrase, PIN, PINlength,
cacheTimeOut, cacheGlobal );
return err;
}
PGPError
pgpTokenImportX509_back (
PGPContextRef context,
const PGPByte *keyID,
const PGPByte *userID, PGPSize userIDlen,
const PGPByte *x509, PGPSize x509len,
const PGPByte *password, PGPSize passwordLength )
{
if( pgpRPCEnabled() )
return pgpTokenImportX509_backRPC(
context, keyID, userID, userIDlen,
x509, x509len, password, passwordLength );
return pgpTokenImportX509_internal(
context, keyID, userID, userIDlen,
x509, x509len, password, passwordLength );
}
PGPError
pgpTokenPutKeyContainer_back (
PGPContextRef context,
const PGPByte *keyID,
const PGPByte *password, PGPSize passwordLen,
const PGPByte *cont, PGPSize contSize )
{
if( pgpRPCEnabled() )
return pgpTokenPutKeyContainer_backRPC(
context, keyID, password, passwordLen, cont, contSize );
return pgpTokenPutKeyContainer_internal(
context, keyID, password, passwordLen, cont, contSize );
}
PGPError
pgpTokenGetKeyContainer_back (
PGPContextRef context,
const PGPByte *keyID,
const PGPByte *password, PGPSize passwordSize,
PGPByte **contOut, PGPSize *contOutSize )
{
if( pgpRPCEnabled() )
return pgpTokenGetKeyContainer_backRPC(
context, keyID, password, passwordSize,
contOut, contOutSize );
return pgpTokenGetKeyContainer_internal(
context, keyID, password, passwordSize,
contOut, contOutSize );
}
static PGPError pgpSetPKCS11DrvFile_internal(const PGPByte *module )
{
if( module && *module ) {
if( sP11Module[0] != '\0' ) {
#ifdef PGP_WIN32
/* On Windows filenames are case insensitive */
if( stricmp( sP11Module, module ) != 0 )
#else
if( strcmp( (char *) sP11Module, (char *) module ) != 0 )
#endif
{
pgpUnloadTCL();
strcpy((char *) sP11Module, (char *) module);
}
}
else
strcpy((char *) sP11Module, (char *) module);
}
else {
pgpUnloadTCL();
sP11Module[0] = '\0';
}
return kPGPError_NoErr;
}
PGPError
pgpSetPKCS11DrvFile_back(const PGPByte *module )
{
if (pgpRPCEnabled())
return pgpSetPKCS11DrvFile_backRPC( module );
return pgpSetPKCS11DrvFile_internal( module );
}
PGPError
pgpAddUserID_back (
PGPContextRef context,
PGPUInt32 objid,
PGPBoolean isAttribute,
PGPAttributeType attributeType,
char const * userIDData,
PGPSize userIDLength,
char const * passphrase,
PGPSize passphraseLength,
PGPBoolean hashedPhrase,
PGPUInt32 cacheTimeOut,
PGPBoolean cacheGlobal,
PGPUInt32 ** newobjs,
PGPSize * newobjslength)
{
PGPKeyDBObj * key = (PGPKeyDBObj *) objid;
PGPError err;
if (pgpRPCEnabled())
return pgpAddUserID_backRPC( context, objid, isAttribute,
attributeType, userIDData, userIDLength, passphrase,
passphraseLength, hashedPhrase, cacheTimeOut, cacheGlobal,
newobjs, newobjslength);
pgpAssert( pgpKeyDBObjIsValid( key ) );
err = pgpAddUserID_internal( key, isAttribute, attributeType, userIDData,
userIDLength, passphrase, passphraseLength,
hashedPhrase, cacheTimeOut, cacheGlobal );
if( IsPGPError( err ) )
return err;
(void)pgpSetPendingNotify( NULL, NULL, NULL, key );
return pgpCreateKeyArray( context, key, 1, NULL, newobjs, newobjslength );
}
PGPError
pgpCertifyUserID_back(
PGPContextRef context,
PGPUInt32 useridid,
PGPUInt32 certifying_keyid,
char const * passphrase,
PGPSize passphraseLength,
PGPBoolean hashedPhrase,
PGPUInt32 cacheTimeOut,
PGPBoolean cacheGlobal,
PGPBoolean exportable,
PGPTime creationDate,
PGPUInt32 expiration,
PGPByte trustDepth,
PGPByte trustValue,
char const * sRegExp,
PGPSize sRegExpLength,
PGPUInt32 ** newobjs,
PGPSize * newobjslength
)
{
PGPKeyDBObj * userid = (PGPKeyDBObj *) useridid;
PGPKeyDBObj * certifying_key = (PGPKeyDBObj *) certifying_keyid;
PGPError err;
if (pgpRPCEnabled())
return pgpCertifyUserID_backRPC( context, useridid, certifying_keyid,
passphrase, passphraseLength, hashedPhrase, cacheTimeOut,
cacheGlobal, exportable, creationDate, expiration,
trustDepth, trustValue, sRegExp, sRegExpLength, newobjs,
newobjslength);
pgpAssert( pgpKeyDBObjIsValid( userid ) );
pgpAssert( pgpKeyDBObjIsValid( certifying_key ) );
err = pgpCertifyUserID_internal( userid, certifying_key, passphrase,
passphraseLength, hashedPhrase,
cacheTimeOut, cacheGlobal, exportable,
creationDate, expiration,
trustDepth, trustValue, sRegExp );
if( IsPGPError( err ) )
return err;
(void)pgpSetPendingNotify( NULL, NULL, NULL, PGPPeekKeyDBObjKey(userid) );
return pgpCreateKeyArray( context, userid, 1, NULL,
newobjs, newobjslength );
}
PGPError
pgpCertifyPrimaryUserID_back (PGPContextRef context, PGPUInt32 useridid,
const char *passphrase, PGPSize passphraseLength, PGPBoolean hashedPhrase,
PGPUInt32 cacheTimeOut, PGPBoolean cacheGlobal, PGPUInt32 **newobjs,
PGPSize *newobjslength)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -