Example #1
0
LPSTR __cdecl _pgp_encrypt_keydb(LPCSTR szPlainMsg, PVOID pgpKeyID)
{
	#if defined(_WIN64)
		return 0;
	#else
		PGPKeyID *RemoteKeyID = (PGPKeyID *) pgpKeyID;
		LPSTR szEncMsg = 0;
		PGPSize dwEncMsgLen;

		ClearPGPError();
		if (!pgpKeyDB)
			return 0;

		PGPKeyDBObjRef PublicKey;
		PGPFindKeyByKeyID(pgpKeyDB, RemoteKeyID, &PublicKey);

		PGPError err = PGPEncode(pgpContext,
			PGPOInputBuffer(pgpContext, szPlainMsg, lstrlen(szPlainMsg)),
			PGPOArmorOutput(pgpContext, TRUE),
			PGPOAllocatedOutputBuffer(pgpContext, (LPVOID *)&szEncMsg, 16384, &dwEncMsgLen),
			PGPOEncryptToKeyDBObj(pgpContext, PublicKey),
			PGPOVersionString(pgpContext, szVersionStr),
			PGPOLastOption(pgpContext));

		if (CheckPGPError(err))
			return 0;

		LPSTR szMsg = (LPSTR) LocalAlloc(LPTR,dwEncMsgLen+1);
		_pgp_memcpy(szMsg, szEncMsg, dwEncMsgLen);
		szMsg[dwEncMsgLen] = 0;
		PGPFreeData((LPVOID)szEncMsg);

		return szMsg;
	#endif
}
Example #2
0
LPSTR __cdecl _pgp_encrypt_key(LPCSTR szPlainMsg, LPCSTR pgpKey)
{
	#if defined(_WIN64)
		return 0;
	#else
		LPSTR szEncMsg = 0;
		PGPSize dwEncMsgLen;

		PGPUInt32 dwKeys;
		PGPKeyDBRef PublicKeyDB;
		if (CheckPGPError(_pgp_import_key(&PublicKeyDB,pgpKey)))
			return 0;

		PGPKeyIterRef KeyIterRef;
		PGPNewKeyIterFromKeyDB(PublicKeyDB, &KeyIterRef);

		PGPKeyDBObjRef PublicKey;
		PGPKeyIterNextKeyDBObj(KeyIterRef, kPGPKeyDBObjType_Key, &PublicKey);

		PGPCountKeysInKeyDB(PublicKeyDB, &dwKeys);

		if(dwKeys==0) {
			PGPFreeKeyIter(KeyIterRef);
			PGPFreeKeyDB(PublicKeyDB);
			return 0;
		}

		PGPError err = PGPEncode(pgpContext,
			PGPOInputBuffer(pgpContext, szPlainMsg, lstrlen(szPlainMsg)),
			PGPOArmorOutput(pgpContext, TRUE),
			PGPOAllocatedOutputBuffer(pgpContext, (LPVOID *)&szEncMsg, 16384, &dwEncMsgLen),
			PGPOEncryptToKeyDBObj(pgpContext, PublicKey),
			PGPOVersionString(pgpContext, szVersionStr),
			PGPOLastOption(pgpContext));

		PGPFreeKeyIter(KeyIterRef);
		PGPFreeKeyDB(PublicKeyDB);

		if (CheckPGPError(err))
			return 0;

		LPSTR szMsg = (LPSTR) LocalAlloc(LPTR,dwEncMsgLen+1);
		_pgp_memcpy(szMsg, szEncMsg, dwEncMsgLen);
		szMsg[dwEncMsgLen] = 0;
		PGPFreeData((LPVOID)szEncMsg);

		return szMsg;
	#endif
}
Example #3
0
LPSTR __cdecl _pgp_encrypt_keydb(LPCSTR szPlainMsg, PVOID pgpKeyID)
{
   	PGPKeyID *RemoteKeyID = (PGPKeyID *) pgpKeyID;
    LPSTR szEncMsg = 0;
    DWORD dwEncMsgLen;

	ClearPGPError();
	if(!pgpKeyDB)
		return 0;

#if (PGP_WIN32 < 0x700)
    PGPFilterRef IDFilter;
    PGPNewKeyIDFilter(pgpContext, RemoteKeyID, &IDFilter);

    PGPKeySetRef PublicKey;
    PGPFilterKeySet(pgpKeyDB, IDFilter, &PublicKey);
#else
    PGPKeyDBObjRef PublicKey;
    PGPFindKeyByKeyID(pgpKeyDB, RemoteKeyID, &PublicKey);
#endif

    PGPError err = PGPEncode(pgpContext,
      PGPOInputBuffer(pgpContext, szPlainMsg, lstrlen(szPlainMsg)),
      PGPOArmorOutput(pgpContext, TRUE),
      PGPOAllocatedOutputBuffer(pgpContext, (LPVOID *)&szEncMsg, 16384, (PGPUInt32 *)&dwEncMsgLen),
#if (PGP_WIN32 < 0x700)
      PGPOEncryptToKeySet(pgpContext, PublicKey),
#else
      PGPOEncryptToKeyDBObj(pgpContext, PublicKey),
#endif
      PGPOVersionString(pgpContext, szVersionStr),
      PGPOLastOption(pgpContext));

#if (PGP_WIN32 < 0x700)
	PGPFreeKeySet(PublicKey);
	PGPFreeFilter(IDFilter);
#endif

    if (CheckPGPError(err))
       return 0;

    LPSTR szMsg = (LPSTR) LocalAlloc(LPTR,dwEncMsgLen+1);
    _pgp_memcpy(szMsg, szEncMsg, dwEncMsgLen);
    szMsg[dwEncMsgLen] = 0;
    PGPFreeData((LPVOID)szEncMsg);

    return szMsg;
}
	void
CCRSVerisignServer::PackageAndSendCRSMessage(
	PGPExportFormat	inExportFormat,
	PGPOutputFormat	inOutputFormat,
	PGPKeyRef		inKey,
	PGPKeyRef		inSigningKey,
	PGPByte *		inPassphrase,
	PGPSize			inPassphraseLength,
	PGPBoolean		inIsPassphrase,
	void **			outBuffer,
	PGPSize *		outBufferSize)
{
	PGPError		pgpErr;
	StPGPKeySetRef	singleKeySet;
	StPGPDataRef	buffer;
	PGPSize			bufSize;
	StPGPDataRef	crsMessage;
	PGPSize			crsMessageSize;
	
	InitOperation();
	if (! PGPKeyRefIsValid(inKey)) {
		ThrowPGPError_(kPGPError_OptionNotFound);
	}
	if (! PGPKeyRefIsValid(inSigningKey)) {
		ThrowPGPError_(kPGPError_OptionNotFound);
	}
	if (NULL==(int)(inPassphrase)) {
		ThrowPGPError_(kPGPError_OptionNotFound);
	}
	
	pgpErr = PGPNewSingletonKeySet(inKey, &singleKeySet);
	ThrowIfPGPError_(pgpErr);
	pgpErr = PGPExportKeySet(	singleKeySet,
								PGPOExportFormat(	mContext,
													inExportFormat),
								PGPOAllocatedOutputBuffer(	mContext,
															(void **) &buffer,
															MAX_PGPSize,
															&bufSize),
								PGPOLastOption(mContext));
	ThrowIfPGPError_(pgpErr);
	singleKeySet.Free();
	pgpErr = PGPEncode(	mContext,
						PGPOSignWithKey(	mContext,
											inSigningKey,
											(inIsPassphrase) ?
												PGPOPassphraseBuffer(mContext,
													inPassphrase, inPassphraseLength) :
												PGPOPasskeyBuffer(mContext,
													inPassphrase, inPassphraseLength),
											PGPOLastOption(mContext)),
						PGPOInputBuffer(mContext, static_cast<PGPByte *>(buffer), bufSize),
						PGPOAllocatedOutputBuffer(	mContext,
													(void **) &crsMessage,
													MAX_PGPSize,
													&crsMessageSize),
						PGPOOutputFormat(	mContext,
											inOutputFormat),
						PGPOLastOption(mContext));
	ThrowIfPGPError_(pgpErr);
	buffer.Free();
	*outBufferSize = PostCRSMessage(kPGPKeyServerState_Querying,
									(mPath == 0) ? kDefaultPath : mPath,
									reinterpret_cast<PGPByte **>(outBuffer),
									crsMessageSize,
									static_cast<const PGPByte *>(crsMessage));
}