port the libstrongswan memory allocation methods to pluto
This commit is contained in:
@@ -95,7 +95,7 @@ pkcs10_add_subjectAltName(generalName_t **subjectAltNames, generalNames_t kind
|
||||
break;
|
||||
}
|
||||
|
||||
gn = alloc_thing(generalName_t, "subjectAltName");
|
||||
gn = malloc_thing(generalName_t);
|
||||
gn->kind = kind;
|
||||
gn->name = asn1_simple_object(asn1_type, name);
|
||||
gn->next = *subjectAltNames;
|
||||
@@ -193,7 +193,7 @@ pkcs10_t*
|
||||
pkcs10_build(RSA_private_key_t *key, chunk_t subject, chunk_t challengePassword
|
||||
, generalName_t *subjectAltNames, int signature_alg)
|
||||
{
|
||||
pkcs10_t *pkcs10 = alloc_thing(pkcs10_t, "pkcs10_t");
|
||||
pkcs10_t *pkcs10 = malloc_thing(pkcs10_t);
|
||||
|
||||
pkcs10->subject = subject;
|
||||
pkcs10->private_key = key;
|
||||
@@ -215,6 +215,6 @@ pkcs10_free(pkcs10_t *pkcs10)
|
||||
if (pkcs10 != NULL)
|
||||
{
|
||||
freeanychunk(pkcs10->request);
|
||||
pfree(pkcs10);
|
||||
free(pkcs10);
|
||||
}
|
||||
}
|
||||
|
||||
+12
-12
@@ -276,7 +276,7 @@ scep_generate_pkcs10_fingerprint(chunk_t pkcs10, chunk_t *fingerprint)
|
||||
/* the fingerprint is the MD5 hash in hexadecimal format */
|
||||
compute_digest(pkcs10, OID_MD5, &digest);
|
||||
fingerprint->len = 2*digest.len;
|
||||
fingerprint->ptr = alloc_bytes(fingerprint->len + 1, "fingerprint");
|
||||
fingerprint->ptr = malloc(fingerprint->len + 1);
|
||||
datatot(digest.ptr, digest.len, 16, fingerprint->ptr, fingerprint->len + 1);
|
||||
}
|
||||
|
||||
@@ -296,14 +296,14 @@ scep_generate_transaction_id(const RSA_public_key_t *rsak
|
||||
u_char *pos;
|
||||
|
||||
compute_digest(public_key, OID_MD5, &digest);
|
||||
pfree(public_key.ptr);
|
||||
free(public_key.ptr);
|
||||
|
||||
/* is the most significant bit of the digest set? */
|
||||
msb_set = (*digest.ptr & 0x80) == 0x80;
|
||||
|
||||
/* allocate space for the serialNumber */
|
||||
serialNumber->len = msb_set + digest.len;
|
||||
serialNumber->ptr = alloc_bytes(serialNumber->len, "serialNumber");
|
||||
serialNumber->ptr = malloc(serialNumber->len);
|
||||
|
||||
/* the serial number as the two's complement of the digest */
|
||||
pos = serialNumber->ptr;
|
||||
@@ -315,7 +315,7 @@ scep_generate_transaction_id(const RSA_public_key_t *rsak
|
||||
|
||||
/* the transaction id is the serial number in hex format */
|
||||
transID->len = 2*digest.len;
|
||||
transID->ptr = alloc_bytes(transID->len + 1, "transID");
|
||||
transID->ptr = malloc(transID->len + 1);
|
||||
datatot(digest.ptr, digest.len, 16, transID->ptr, transID->len + 1);
|
||||
}
|
||||
|
||||
@@ -415,7 +415,7 @@ escape_http_request(chunk_t req)
|
||||
|
||||
/* compute and allocate the size of the base64-encoded request */
|
||||
int len = 1 + 4*((req.len + 2)/3);
|
||||
char *encoded_req = alloc_bytes(len, "encoded request");
|
||||
char *encoded_req = malloc(len);
|
||||
|
||||
/* do the base64 conversion */
|
||||
len = datatot(req.ptr, req.len, 64, encoded_req, len);
|
||||
@@ -431,7 +431,7 @@ escape_http_request(chunk_t req)
|
||||
plus++;
|
||||
}
|
||||
|
||||
escaped_req = alloc_bytes(len + 3*(lines + plus), "escaped request");
|
||||
escaped_req = malloc(len + 3*(lines + plus));
|
||||
|
||||
/* escape special characters in the request */
|
||||
p1 = encoded_req;
|
||||
@@ -457,7 +457,7 @@ escape_http_request(chunk_t req)
|
||||
n++;
|
||||
}
|
||||
*p2 = '\0';
|
||||
pfreeany(encoded_req);
|
||||
free(encoded_req);
|
||||
return escaped_req;
|
||||
}
|
||||
#endif
|
||||
@@ -498,10 +498,10 @@ scep_http_request(const char *url, chunk_t pkcs7, scep_op_t op
|
||||
/* form complete url */
|
||||
int len = strlen(url) + 20 + strlen(operation) + strlen(escaped_req) + 1;
|
||||
|
||||
complete_url = alloc_bytes(len, "complete url");
|
||||
complete_url = malloc(len);
|
||||
snprintf(complete_url, len, "%s?operation=%s&message=%s"
|
||||
, url, operation, escaped_req);
|
||||
pfreeany(escaped_req);
|
||||
free(escaped_req);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPGET, TRUE);
|
||||
headers = curl_slist_append(headers, "Pragma:");
|
||||
@@ -515,7 +515,7 @@ scep_http_request(const char *url, chunk_t pkcs7, scep_op_t op
|
||||
/* form complete url */
|
||||
int len = strlen(url) + 11 + strlen(operation) + 1;
|
||||
|
||||
complete_url = alloc_bytes(len, "complete url");
|
||||
complete_url = malloc(len);
|
||||
snprintf(complete_url, len, "%s?operation=%s", url, operation);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPGET, FALSE);
|
||||
@@ -533,7 +533,7 @@ scep_http_request(const char *url, chunk_t pkcs7, scep_op_t op
|
||||
/* form complete url */
|
||||
int len = strlen(url) + 32 + strlen(operation) + 1;
|
||||
|
||||
complete_url = alloc_bytes(len, "complete url");
|
||||
complete_url = malloc(len);
|
||||
snprintf(complete_url, len, "%s?operation=%s&message=CAIdentifier"
|
||||
, url, operation);
|
||||
|
||||
@@ -567,7 +567,7 @@ scep_http_request(const char *url, chunk_t pkcs7, scep_op_t op
|
||||
}
|
||||
curl_slist_free_all(headers);
|
||||
curl_easy_cleanup(curl);
|
||||
pfreeany(complete_url);
|
||||
free(complete_url);
|
||||
|
||||
return (res == CURLE_OK);
|
||||
#else /* !LIBCURL */
|
||||
|
||||
@@ -146,7 +146,7 @@ exit_scepclient(err_t message, ...)
|
||||
if (private_key != NULL)
|
||||
{
|
||||
free_RSA_private_content(private_key);
|
||||
pfree(private_key);
|
||||
free(private_key);
|
||||
}
|
||||
freeanychunk(pkcs1);
|
||||
freeanychunk(pkcs7);
|
||||
@@ -703,7 +703,7 @@ int main(int argc, char **argv)
|
||||
/*
|
||||
* input of PKCS#1 file
|
||||
*/
|
||||
private_key = alloc_thing(RSA_private_key_t, "RSA_private_key_t");
|
||||
private_key = malloc_thing(RSA_private_key_t);
|
||||
|
||||
if (filetype_in & PKCS1) /* load an RSA key pair from file */
|
||||
{
|
||||
@@ -767,7 +767,7 @@ int main(int argc, char **argv)
|
||||
if (ugh != NULL)
|
||||
exit_scepclient(ugh);
|
||||
|
||||
clonetochunk(subject, dn.ptr, dn.len, "subject dn");
|
||||
clonetochunk(subject, dn.ptr, dn.len);
|
||||
|
||||
DBG(DBG_CONTROL,
|
||||
DBG_log("building pkcs10 object:")
|
||||
@@ -820,7 +820,7 @@ int main(int argc, char **argv)
|
||||
plog(" transaction ID: %.*s", (int)transID.len, transID.ptr);
|
||||
|
||||
/* generate a self-signed X.509 certificate */
|
||||
x509_signer = alloc_thing(x509cert_t, "signer cert");
|
||||
x509_signer = malloc_thing(x509cert_t);
|
||||
*x509_signer = empty_x509cert;
|
||||
x509_signer->serialNumber = serialNumber;
|
||||
x509_signer->sigAlg = OID_SHA1_WITH_RSA;
|
||||
|
||||
Reference in New Issue
Block a user