Check-in [66507306f5]
Overview
Comment:Fixed issues with padding
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 66507306f5956ac2f95f1957d5c737097248a57b
User & Date: rkeene on 2010-05-17 19:43:12
Other Links: manifest | tags
Context
2010-05-17
19:53
Updated to treat a request of read of 0 bytes as a no-op. check-in: 45212cc4ca user: rkeene tags: trunk
19:43
Fixed issues with padding check-in: 66507306f5 user: rkeene tags: trunk
19:37
Updated to support determining key size from X.509 object (untested)

Updated to set HW TOKEN flag

Updated to pad sign/decrypt message to key size (untested) check-in: a2ac84031e user: rkeene tags: trunk

Changes

Modified cackey.c from [e6d26b97df] to [64d4505a46].

1835
1836
1837
1838
1839
1840
1841

1842
1843
1844
1845
1846
1847
1848
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849







+







 *     ...
 *
 */
static ssize_t cackey_signdecrypt(struct cackey_slot *slot, struct cackey_identity *identity, unsigned char *buf, size_t buflen, unsigned char *outbuf, size_t outbuflen) {
	unsigned char *tmpbuf, *tmpbuf_s;
	unsigned char bytes_to_send, p1;
	cackey_ret send_ret;
	uint16_t respcode;
	size_t tmpbuflen, padlen;
	int free_tmpbuf = 0;
	int le;

	CACKEY_DEBUG_PRINTF("Called.");

	if (buflen > 255) {
1906
1907
1908
1909
1910
1911
1912
1913
1914





1915
1916
1917
1918
1919
1920
1921
1907
1908
1909
1910
1911
1912
1913


1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925







-
-
+
+
+
+
+







			free_tmpbuf = 1;

			padlen = tmpbuflen - buflen - 3;

			tmpbuf[0] = 0x00;
			tmpbuf[1] = 0x01;
			memset(&tmpbuf[2], 0xFF, padlen);
			tmpbuf[padlen]= 0x00;
			memcpy(&tmpbuf[padlen + 1], buf, buflen);
			tmpbuf[padlen + 2]= 0x00;
			memcpy(&tmpbuf[padlen + 3], buf, buflen);

			CACKEY_DEBUG_PRINTBUF("Unpadded:", buf, buflen);
			CACKEY_DEBUG_PRINTBUF("Padded:", tmpbuf, tmpbuflen);
		} else {
			tmpbuf = buf;
			tmpbuflen = buflen;
			free_tmpbuf = 0;
			padlen = 0;
		}
	} else {
1943
1944
1945
1946
1947
1948
1949
1950

1951
1952




1953
1954
1955
1956
1957
1958
1959
1947
1948
1949
1950
1951
1952
1953

1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967







-
+


+
+
+
+







			bytes_to_send = 245;
			p1 = 0x80;
		} else {
			bytes_to_send = tmpbuflen;
			p1 = 0x00;
		}

		send_ret = cackey_send_apdu(slot, GSCIS_CLASS_GLOBAL_PLATFORM, GSCIS_INSTR_SIGNDECRYPT, p1, 0x00, bytes_to_send, tmpbuf, le, NULL, outbuf, &outbuflen);
		send_ret = cackey_send_apdu(slot, GSCIS_CLASS_GLOBAL_PLATFORM, GSCIS_INSTR_SIGNDECRYPT, p1, 0x00, bytes_to_send, tmpbuf, le, &respcode, outbuf, &outbuflen);
		if (send_ret != CACKEY_PCSC_S_OK) {
			CACKEY_DEBUG_PRINTF("ADPU Sending Failed -- returning in error.");

			if (respcode == 0x6982) {
				CACKEY_DEBUG_PRINTF("Security status not satisified.");
			}

			if (free_tmpbuf) {
				if (tmpbuf_s) {
					free(tmpbuf_s);
				}
			}