2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License (the "License"). 2N/A * You may not use this file except in compliance with the License. 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. 2N/A/* PKCS#11 URI prefix and attributes. */ 2N/A * Gets a hexadecimal string of the xx:xx:xx-like format and fills the output 2N/A * buffer with bytes representing each of the hexadecimal numbers. Returns 0 on 2N/A * error (missing ':', not a hexadecimal character (eg. 'z'), output buffer 2N/A * overflow, etc.), or the number of hexadecimal numbers processed. 2N/A * number of bytes returned via the output parameter 2N/A /* Counter of the processed bytes. */ 2N/A /* Counter for the used output bytes. */ 2N/A /* We require at least one hexadecimal character. */ 2N/A /* And we accept the 2nd one if it is there. */ 2N/A /* Output buffer overflow? */ 2N/A /* Still some bytes to process? */ 2N/A /* ':' is the only acceptable delimiter. */ 2N/Astatic char hex_table[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2N/A 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2N/A 0, 0, 0, 0, 0, 0,
1,
2,
3,
4,
5,
6,
7,
8,
9, 0, 0, 0, 0, 0, 0, 0,
10,
11,
2N/A 12,
13,
14,
15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2N/A 0, 0, 0, 0, 0, 0,
10,
11,
12,
13,
14,
15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2N/A 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
2N/A * Performs inline percent-decoding of string str. 2N/A * String must be zero-terminated! Implies, that str must not be NULL either. 2N/A * Returns: length of the resulting string 2N/A while (*p !=
'\0') {
2N/A /* cannot overflow - zero-termination constraint on str */ 2N/A /* not copying common unescaped prefix */ 2N/A * Process the PKCS#11 URI. The function expects an allocated URI structure. The 2N/A * caller is later expected to call pkcs11_free_uri() when the parsed URI is no 2N/A * Note that the caller needs to call pkcs11_free_uri() on the 'uri' structure 2N/A * only if PK11_URI_OK is returned but it is always safe to do that since 2N/A * pkcs11_free_uri() checks for NULLs and the structure is zeroized here before 2N/A * invalid PKCS#11 URI (one that has the "pkcs11:" prefix but is 2N/A * otherwise incorrectly specified) 2N/A * malloc(3C) failed when allocating one of the internal buffers. 2N/A * This error can be returned only after the correct "pkcs11:" 2N/A * prefix was found but it does not give any information about the 2N/A * syntax correctness of the URI body. 2N/A * PK11_URI_VALUE_OVERFLOW 2N/A * some attributes in the URI are of the fixed length according to 2N/A * the spec. If any of those attributes overflows we report an 2N/A * PK11_NOT_PKCS11_URI 2N/A * the URI supplied is not the PKCS#11 URI at all (does not have 2N/A * the "pkcs11:" prefix) 2N/A /* Initialize the structure. */ 2N/A /* Be really safe. */ 2N/A /* Check that we have the correct PKCS#11 URI prefix. */ 2N/A /* Dup the string and skip over the prefix then. */ 2N/A * Using strtok_r() would silently skip over multiple semicolons. We 2N/A * must check such situation before moving on. We must also avoid ';' as 2N/A * the first and the last character of the URI. 2N/A /* Now parse the URI. */ 2N/A /* "tok" is not empty so there will be something in "name". */ 2N/A /* Check whether there is '=' at all. */ 2N/A * Fill out the URI structure. We do not accept duplicate 2N/A /* Check for duplicity. */ 2N/A /* Check for duplicity. */ 2N/A /* Check for duplicity. */ 2N/A /* Check for duplicity. */ 2N/A /* Check for duplicity. */ 2N/A * We can have maximum of PK11_MAX_ID_LEN 2-byte 2N/A * numbers separated by ':'s, like 2N/A /* Check for duplicity. */ 2N/A * Check for duplicity. objecttype can not be empty, it 2N/A * would not make sense. 2N/A /* Check for duplicity. */ 2N/A /* Empty pinfile makes no sense. */ 2N/A /* Unknown attribute name. */ 2N/A * Free the PKCS#11 URI structure attributes but do not free the structure 2N/A * itself. The caller needs to call this function only if pkcs11_parse_uri() 2N/A * returned PK11_URI_OK. However, it is always safe to do that for other return 2N/A * codes as well since the structure is zeroized at the beginning of 2N/A * pkcs11_parse_uri() and we check for NULLs here.