📄 p7read.c
字号:
if (status != VT_ERROR_UNKNOWN_BER)
break;
status = 0;
break;
}
/* Build an ID object from the encoding.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VtCreateIdentityObject (
(VtLibCtx)libCtx, (VtIdentityImpl *)0, (Pointer)0, &idObj);
if (status != 0)
break;
/* Use the encoded ID to set the ID object.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VtDecodeIdentity (
encoding, encodingLen, decoders, decoderCount, &schemaType, idObj);
if (status != 0)
{
/* If the reason the function failed is just that it didn't know
* what the encoding was, that's not an error.
*/
if (status != VT_ERROR_UNKNOWN_SCHEMA)
break;
status = 0;
break;
}
/* We have an identity object, add it to the identity list.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VtAddIdObjectToIdentityList (recipients, idObj, &index);
} while (0);
VtDestroyIdentityObject (&idObj);
if (encoding != (unsigned char *)0)
Z2Free (encoding);
VOLT_LOG_ERROR_INFO_COMPARE (
status, libCtx, 0, status, 0, 0,
(char *)0, "AddIdFromIssuerSerial", fnctLine, (char *)0)
return (status);
}
int VoltGetEncodedIdFromRecipInfoAlloc (
VoltLibCtx *libCtx,
Asn1RecipientInfo *recipInfo,
unsigned char **encodedId,
unsigned int *encodedIdLen
)
{
int status;
unsigned int index, encodingLen, theTag, lengthLen, valueLen, b64DataLen;
UInt32 lenLo, lenHi;
unsigned char *encoding, *b64Data;
unsigned char *buffer = (unsigned char *)0;
VtAlgorithmObject base64 = (VtAlgorithmObject)0;
VtBase64Info base64Info;
unsigned char expectedTags[7] = { 0x30, 0x30, 0x31, 0x30, 0x06, 0x0c, 0x02 };
unsigned char expectedOid[VoltIdAtNameOidBytesLen] =
{ VoltIdAtNameOidBytes };
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
/* The IssuerAndSerialNumber should look like this.
*
* 30 len SEQ: IssuerAndSerialNumber
* 30 len SEQ OF RDN
* 31 len SET OF Attribute
* 30 len SEQ: Attribute
* 06 03 OID
* 55 04 29
* 0c len value (ANY, UTF8String)
* <Base64 of encoded ID>
* 02 01 INTEGER: serialNumber
* 01
*
* If it doesn't look like that (either it doesn't have that
* structure or the OID is not the same or the serialNumber is not 1),
* just return 0.
* Actually, the value can be UTF8String or PrintableString. This
* function will accept either.
*/
encoding = recipInfo->issuerSerial->base.data;
encodingLen = (unsigned int)(recipInfo->issuerSerial->base.length);
/* Check each of the tags.
*/
status = VT_ERROR_UNKNOWN_BER;
for (index = 0; index < 7; ++index)
{
/* Any encoding? If not, this wasn't the Base64 encoding of the
* encoded identity.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
if (encodingLen == 0)
break;
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
if (VoltDecodeTagAndLen (
libCtx, encoding, encodingLen, &theTag, &lengthLen, &lenLo, &lenHi,
sizeof (unsigned int)) != 0)
break;
valueLen = (unsigned int)lenLo;
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
/* For the first 4 tags, just move on to the next tag.
*/
if (index < 4)
{
/* Expected tag?
*/
VOLT_SET_FNCT_LINE (fnctLine)
if (encoding[0] != expectedTags[index])
break;
encoding += (1 + lengthLen);
encodingLen -= (1 + lengthLen);
continue;
}
/* This tag is supposed to be the OID.
*/
if (index == 4)
{
/* Expected tag?
*/
VOLT_SET_FNCT_LINE (fnctLine)
if (encoding[0] != expectedTags[index])
break;
VOLT_SET_FNCT_LINE (fnctLine)
if (encodingLen <= (1 + lengthLen + valueLen))
break;
VOLT_SET_FNCT_LINE (fnctLine)
if (valueLen != VoltIdAtNameOidBytesLen)
break;
VOLT_SET_FNCT_LINE (fnctLine)
if (Z2Memcmp (
encoding + 1 + lengthLen, expectedOid, VoltIdAtNameOidBytesLen) != 0)
break;
encoding += (1 + lengthLen + valueLen);
encodingLen -= (1 + lengthLen + valueLen);
continue;
}
/* This should be the Base64 encoded identity.
*/
if (index == 5)
{
/* Expected tag?
*/
VOLT_SET_FNCT_LINE (fnctLine)
if ( (encoding[0] != 0x0c) && (encoding[0] != 0x13) )
break;
VOLT_SET_FNCT_LINE (fnctLine)
if (encodingLen <= (1 + lengthLen + valueLen))
break;
b64Data = encoding + 1 + lengthLen;
b64DataLen = valueLen;
encoding += (1 + lengthLen + valueLen);
encodingLen -= (1 + lengthLen + valueLen);
continue;
}
/* This should be the serial number and it should be 1.
*/
VOLT_SET_FNCT_LINE (fnctLine)
if (encodingLen < (1 + lengthLen + valueLen))
break;
/* Expected tag?
*/
VOLT_SET_FNCT_LINE (fnctLine)
if (encoding[0] != expectedTags[index])
break;
VOLT_SET_FNCT_LINE (fnctLine)
if (valueLen != 1)
break;
VOLT_SET_FNCT_LINE (fnctLine)
encoding += (1 + lengthLen);
if (encoding[0] != 1)
break;
status = 0;
}
do
{
/* If the for loop exited with an error, quit.
*/
if (status != 0)
break;
/* Build the object that will Base64 decode the identity.
*/
base64Info.base64BlockSize = 76;
base64Info.newLineCharacter = VT_BASE64_NO_NEW_LINE;
base64Info.errorCheck = VT_BASE64_NO_ERROR_CHECK;
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtCreateAlgorithmObject (
(VtLibCtx)libCtx, VtAlgorithmImplBase64, (Pointer)&base64Info,
&base64);
if (status != 0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VtDecodeInit (base64);
if (status != 0)
break;
/* How big does the buffer need to be?
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VtDecodeFinal (
base64, (VtRandomObject)0, b64Data, b64DataLen,
(unsigned char *)0, 0, &valueLen);
if (status == 0)
status = VT_ERROR_UNKNOWN_BER;
if (status != VT_ERROR_BUFFER_TOO_SMALL)
break;
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
buffer = (unsigned char *)Z2Malloc (valueLen, 0);
if (buffer == (unsigned char *)0)
break;
/* Decode into the buffer.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtDecodeFinal (
base64, (VtRandomObject)0, b64Data, b64DataLen,
buffer, valueLen, &valueLen);
if (status != 0)
break;
*encodedId = buffer;
*encodedIdLen = valueLen;
} while (0);
VtDestroyAlgorithmObject (&base64);
/* If success, we're done.
*/
if (status == 0)
return (0);
/* If error, free the buffer.
*/
if (buffer != (unsigned char *)0)
Z2Free (buffer);
VOLT_LOG_ERROR_INFO (
libCtx, 0, status, 0, errorType,
(char *)0, "VoltGetEncodedIdFromRecipInfoAlloc", fnctLine, (char *)0)
return (status);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -