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) 2009, 2012, Oracle and/or its affiliates. All rights reserved. 2N/A /* Allocate initial space for the slot list. */ 2N/A /* Then get the slot list itself. */ 2N/A * If the number of slots grew, try again. This 2N/A * is to be consistent with pktool in ONNV. 2N/A * Returns pointer to either null-terminator or next unescaped colon. The 2N/A * string to be extracted starts at the beginning and goes until one character 2N/A * before this pointer. If NULL is returned, the string itself is NULL. 2N/A str =
end +
1;
/* could point to null-terminator */ 2N/A * Compresses away any characters escaped with backslash from given string. 2N/A * The string is altered in-place. Example, "ab\:\\e" becomes "ab:\e". 2N/A * Given a colon-separated token specifier, this functions splits it into 2N/A * its label, manufacturer ID (if any), and serial number (if any). Literal 2N/A * Fields can left blank and trailing colons can be omitted, however leading 2N/A * colons are required as placeholders. For example, these are equivalent: 2N/A * (a) "lbl", "lbl:", "lbl::" (b) "lbl:man", "lbl:man:" 2N/A * but these are not: 2N/A * (c) "man", ":man" (d) "ser", "::ser" 2N/A * Furthermore, the token label is required always. 2N/A * The buffer containing the token specifier is altered by replacing the 2N/A * colons to null-terminators, and pointers returned are pointers into this 2N/A * string. No new memory is allocated. 2N/A /* Token label (required) */ 2N/A *
mark++ =
'\0';
/* mark points to next field, if any */ 2N/A if (*
mark ==
'\0' || *(
mark+
1) ==
'\0')
/* no more fields */ 2N/A /* Manufacturer identifier (optional) */ 2N/A *
mark++ =
'\0';
/* mark points to next field, if any */ 2N/A if (*
mark ==
'\0' || *(
mark+
1) ==
'\0')
/* no more fields */ 2N/A /* Serial number (optional) */ 2N/A *
mark++ =
'\0';
/* null-terminate, just in case */ 2N/A * Find slots that match a token identifier. Token labels take the 2N/A * token_name:manufacturer:serial_number 2N/A * manufacturer and serial number are optional. If used, the fields 2N/A * are delimited by the colon ':' character. 2N/A * Parse token specifier into token_name, manuf_id, serial_no. 2N/A * Token_name is required; manuf_id and serial_no are optional. 2N/A /* Get a list of all slots with tokens present. */ 2N/A /* If there are no such slots, the desired token won't be found. */ 2N/A /* Search the slot list for the token. */ 2N/A /* See if the token label matches. */ 2N/A * If manufacturer id was given, see if it actually matches. 2N/A * If no manufacturer id was given, assume match is true. 2N/A * If serial number was given, see if it actually matches. 2N/A * If no serial number was given, assume match is true. 2N/A break;
/* found it! */ 2N/A /* found the desired token from the slotlist */ 2N/A * If we didn't find the token from the slotlist, check if this token 2N/A * is the one currently hidden by the metaslot. If that's case, 2N/A * we can just use the metaslot, the slot 0. 2N/A * Name: kmf_select_token 2N/A * This function enables the user of PKCS#11 plugin to select a 2N/A * particular PKCS#11 token. Valid token label are required in order to 2N/A * successfully complete this function. 2N/A * All subsequent KMF APIs, which specify PKCS#11 keystore as 2N/A * the backend, will be performed at the selected token. 2N/A * label(input) - pointer to the token label 2N/A * A KMF_RETURN value indicating success or specifying a particular 2N/A * The value KMF_OK indicates success. All other values represent 2N/A * an error condition. 2N/A /* Only one token can be active per thread */ 2N/A /* Find the token with matching label */ 2N/A /* Open a session then log the user into the token */ 2N/A * It is best to try and lookup tokens by label. 2N/A /* We can't determine which slot to initialize */ 2N/A /* Initialize and set the new label (if given) */