Beispiel #1
0
/* Given a raw key, cook up a Binary key */
void CryptKit::FEEKeyInfoProvider::CssmKeyToBinary(
    CssmKey				*paramKey,		// optional, ignored
    CSSM_KEYATTR_FLAGS	&attrFlags,		// IN/OUT
    BinaryKey 			**binKey)
{
    *binKey = NULL;
    feePubKey feeKey = NULL;

    /* first cook up a feePubKey, then drop that into a BinaryKey */
    feeKey = rawCssmKeyToFee(mKey);
    FEEBinaryKey *feeBinKey = new FEEBinaryKey(feeKey);
    *binKey = feeBinKey;
}
Beispiel #2
0
/*
 * Obtain key size in bits.
 * Currently only raw public keys are dealt with (they're the ones
 * which come from certs, the only current use for this function).
 * Note that if we need to handle ref keys, we'll need a session ref...
 */
void CryptKit::FEEKeyInfoProvider::QueryKeySizeInBits(
    CSSM_KEY_SIZE &keySize)
{
    feePubKey feeKey = NULL;

    if(mKey.blobType() != CSSM_KEYBLOB_RAW) {
        CssmError::throwMe(CSSMERR_CSP_INVALID_KEY_FORMAT);
    }
    feeKey = rawCssmKeyToFee(mKey);
    keySize.LogicalKeySizeInBits = feePubKeyBitsize(feeKey);
    keySize.EffectiveKeySizeInBits = keySize.LogicalKeySizeInBits;
    feePubKeyFree(feeKey);
}
/* 
 * Convert a CssmKey to a feePubKey. May result in the creation of a new
 * feePubKey (when cssmKey is a raw key); allocdKey is true in that case
 * in which case the caller generally has to free the allocd key).
 */
feePubKey CryptKit::cssmKeyToFee(
	const CssmKey	&cssmKey,
	AppleCSPSession	&session,
	bool			&allocdKey)	// RETURNED
{
	feePubKey feeKey = NULL;
	allocdKey = false;
	
	const CSSM_KEYHEADER *hdr = &cssmKey.KeyHeader;
	switch(hdr->AlgorithmId) {
		case CSSM_ALGID_FEE:
		case CSSM_ALGID_ECDSA:
			break;
		default:
			// someone else's key (should never happen)
			CssmError::throwMe(CSSMERR_CSP_INVALID_ALGORITHM);
	}
	switch(hdr->BlobType) {
		case CSSM_KEYBLOB_RAW:
			feeKey = rawCssmKeyToFee(cssmKey);
			allocdKey = true;
			break;
		case CSSM_KEYBLOB_REFERENCE:
		{
			BinaryKey &binKey = session.lookupRefKey(cssmKey);
			FEEBinaryKey *feeBinKey = dynamic_cast<FEEBinaryKey *>(&binKey);
			/* this cast failing means that this is some other
			 * kind of binary key */
			if(feeBinKey == NULL) {
				feeMiscDebug("CryptKit::cssmKeyToFee: wrong BinaryKey subclass\n");
				CssmError::throwMe(CSSMERR_CSP_INVALID_KEY);
			}
			assert(feeBinKey->feeKey() != NULL);
			feeKey = feeBinKey->feeKey();
			break;
		}
		default:
			CssmError::throwMe(CSSMERR_CSP_KEY_BLOB_TYPE_INCORRECT);
	}
	return feeKey;
}