2011-07-13 02:18:24 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-07-13 02:18:24 +04:00
|
|
|
* Certificate Handling
|
|
|
|
*
|
2012-02-03 03:20:02 +04:00
|
|
|
* Copyright 2011 Jiten Pathy
|
2011-07-13 02:18:24 +04:00
|
|
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-01-25 19:45:21 +04:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2012-11-22 04:22:41 +04:00
|
|
|
#include <winpr/crt.h>
|
|
|
|
|
2012-01-25 19:45:21 +04:00
|
|
|
#include <openssl/pem.h>
|
|
|
|
#include <openssl/rsa.h>
|
|
|
|
|
2011-07-13 02:18:24 +04:00
|
|
|
#include "certificate.h"
|
|
|
|
|
2011-07-13 05:43:52 +04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* X.509 Certificate Structure
|
|
|
|
*
|
|
|
|
* Certificate ::= SEQUENCE
|
|
|
|
* {
|
|
|
|
* tbsCertificate TBSCertificate,
|
|
|
|
* signatureAlgorithm AlgorithmIdentifier,
|
|
|
|
* signatureValue BIT_STRING
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* TBSCertificate ::= SEQUENCE
|
|
|
|
* {
|
|
|
|
* version [0] EXPLICIT Version DEFAULT v1,
|
|
|
|
* serialNumber CertificateSerialNumber,
|
|
|
|
* signature AlgorithmIdentifier,
|
|
|
|
* issuer Name,
|
|
|
|
* validity Validity,
|
|
|
|
* subject Name,
|
|
|
|
* subjectPublicKeyInfo SubjectPublicKeyInfo,
|
|
|
|
* issuerUniqueID [1] IMPLICIT UniqueIdentifier OPTIONAL,
|
|
|
|
* subjectUniqueId [2] IMPLICIT UniqueIdentifier OPTIONAL,
|
|
|
|
* extensions [3] EXPLICIT Extensions OPTIONAL
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* Version ::= INTEGER { v1(0), v2(1), v3(2) }
|
|
|
|
*
|
|
|
|
* CertificateSerialNumber ::= INTEGER
|
|
|
|
*
|
|
|
|
* AlgorithmIdentifier ::= SEQUENCE
|
|
|
|
* {
|
|
|
|
* algorithm OBJECT_IDENTIFIER,
|
|
|
|
* parameters ANY DEFINED BY algorithm OPTIONAL
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* Name ::= CHOICE { RDNSequence }
|
|
|
|
*
|
|
|
|
* RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
|
|
|
|
*
|
|
|
|
* RelativeDistinguishedName ::= SET OF AttributeTypeAndValue
|
|
|
|
*
|
|
|
|
* AttributeTypeAndValue ::= SEQUENCE
|
|
|
|
* {
|
|
|
|
* type AttributeType,
|
|
|
|
* value AttributeValue
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* AttributeType ::= OBJECT_IDENTIFIER
|
|
|
|
*
|
|
|
|
* AttributeValue ::= ANY DEFINED BY AttributeType
|
|
|
|
*
|
|
|
|
* Validity ::= SEQUENCE
|
|
|
|
* {
|
|
|
|
* notBefore Time,
|
|
|
|
* notAfter Time
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* Time ::= CHOICE
|
|
|
|
* {
|
|
|
|
* utcTime UTCTime,
|
|
|
|
* generalTime GeneralizedTime
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* UniqueIdentifier ::= BIT_STRING
|
|
|
|
*
|
|
|
|
* SubjectPublicKeyInfo ::= SEQUENCE
|
|
|
|
* {
|
|
|
|
* algorithm AlgorithmIdentifier,
|
|
|
|
* subjectPublicKey BIT_STRING
|
|
|
|
* }
|
|
|
|
*
|
2011-07-13 07:50:51 +04:00
|
|
|
* RSAPublicKey ::= SEQUENCE
|
|
|
|
* {
|
|
|
|
* modulus INTEGER
|
|
|
|
* publicExponent INTEGER
|
|
|
|
* }
|
|
|
|
*
|
2011-07-13 05:43:52 +04:00
|
|
|
* Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension
|
|
|
|
*
|
|
|
|
* Extension ::= SEQUENCE
|
|
|
|
* {
|
|
|
|
* extnID OBJECT_IDENTIFIER
|
|
|
|
* critical BOOLEAN DEFAULT FALSE,
|
|
|
|
* extnValue OCTET_STRING
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-01-18 17:36:49 +04:00
|
|
|
static const char *certificate_read_errors[] = {
|
|
|
|
"Certificate tag",
|
|
|
|
"TBSCertificate",
|
|
|
|
"Explicit Contextual Tag [0]",
|
|
|
|
"version",
|
|
|
|
"CertificateSerialNumber",
|
|
|
|
"AlgorithmIdentifier",
|
|
|
|
"Issuer Name",
|
|
|
|
"Validity",
|
|
|
|
"Subject Name",
|
|
|
|
"SubjectPublicKeyInfo Tag",
|
|
|
|
"subjectPublicKeyInfo::AlgorithmIdentifier",
|
|
|
|
"subjectPublicKeyInfo::subjectPublicKey",
|
|
|
|
"RSAPublicKey Tag",
|
|
|
|
"modulusLength",
|
|
|
|
"zero padding",
|
|
|
|
"modulusLength",
|
|
|
|
"modulus",
|
|
|
|
"publicExponent length",
|
|
|
|
"publicExponent"
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-07-13 05:43:52 +04:00
|
|
|
/**
|
|
|
|
* Read X.509 Certificate
|
|
|
|
* @param certificate certificate module
|
|
|
|
* @param cert X.509 certificate
|
|
|
|
*/
|
|
|
|
|
2013-01-12 17:49:01 +04:00
|
|
|
BOOL certificate_read_x509_certificate(rdpCertBlob* cert, rdpCertInfo* info)
|
2011-07-13 05:43:52 +04:00
|
|
|
{
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* s;
|
2011-07-13 05:43:52 +04:00
|
|
|
int length;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE padding;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 version;
|
2011-07-13 07:50:51 +04:00
|
|
|
int modulus_length;
|
|
|
|
int exponent_length;
|
2013-01-18 17:36:49 +04:00
|
|
|
int error = 0;
|
2011-07-13 05:43:52 +04:00
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
s = Stream_New(cert->data, cert->length);
|
2013-01-16 21:10:54 +04:00
|
|
|
info->Modulus = 0;
|
2011-07-13 05:43:52 +04:00
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
if (!ber_read_sequence_tag(s, &length)) /* Certificate (SEQUENCE) */
|
2013-01-12 17:49:01 +04:00
|
|
|
goto error1;
|
2013-01-18 17:36:49 +04:00
|
|
|
error++;
|
2011-07-13 05:43:52 +04:00
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
if (!ber_read_sequence_tag(s, &length)) /* TBSCertificate (SEQUENCE) */
|
2013-01-12 17:49:01 +04:00
|
|
|
goto error1;
|
2013-01-18 17:36:49 +04:00
|
|
|
error++;
|
2011-07-13 05:43:52 +04:00
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
if (!ber_read_contextual_tag(s, 0, &length, TRUE)) /* Explicit Contextual Tag [0] */
|
2013-01-12 17:49:01 +04:00
|
|
|
goto error1;
|
2013-01-18 17:36:49 +04:00
|
|
|
error++;
|
2013-05-09 01:48:30 +04:00
|
|
|
if (!ber_read_integer(s, &version)) /* version (INTEGER) */
|
2013-01-12 17:49:01 +04:00
|
|
|
goto error1;
|
2013-01-18 17:36:49 +04:00
|
|
|
error++;
|
2011-07-13 05:43:52 +04:00
|
|
|
version++;
|
|
|
|
|
|
|
|
/* serialNumber */
|
2013-05-09 01:48:30 +04:00
|
|
|
if (!ber_read_integer(s, NULL)) /* CertificateSerialNumber (INTEGER) */
|
2013-01-12 17:49:01 +04:00
|
|
|
goto error1;
|
2013-01-18 17:36:49 +04:00
|
|
|
error++;
|
2011-07-13 05:43:52 +04:00
|
|
|
|
|
|
|
/* signature */
|
2013-05-09 01:48:30 +04:00
|
|
|
if (!ber_read_sequence_tag(s, &length) || !Stream_SafeSeek(s, length)) /* AlgorithmIdentifier (SEQUENCE) */
|
2013-01-12 17:49:01 +04:00
|
|
|
goto error1;
|
2013-01-18 17:36:49 +04:00
|
|
|
error++;
|
2011-07-13 05:43:52 +04:00
|
|
|
|
|
|
|
/* issuer */
|
2013-05-09 01:48:30 +04:00
|
|
|
if (!ber_read_sequence_tag(s, &length) || !Stream_SafeSeek(s, length)) /* Name (SEQUENCE) */
|
2013-01-12 17:49:01 +04:00
|
|
|
goto error1;
|
2013-01-18 17:36:49 +04:00
|
|
|
error++;
|
2011-07-13 05:43:52 +04:00
|
|
|
|
|
|
|
/* validity */
|
2013-05-09 01:48:30 +04:00
|
|
|
if (!ber_read_sequence_tag(s, &length) || !Stream_SafeSeek(s, length)) /* Validity (SEQUENCE) */
|
2013-01-12 17:49:01 +04:00
|
|
|
goto error1;
|
2013-01-18 17:36:49 +04:00
|
|
|
error++;
|
2011-07-13 05:43:52 +04:00
|
|
|
|
|
|
|
/* subject */
|
2013-05-09 01:48:30 +04:00
|
|
|
if (!ber_read_sequence_tag(s, &length) || !Stream_SafeSeek(s, length)) /* Name (SEQUENCE) */
|
2013-01-12 17:49:01 +04:00
|
|
|
goto error1;
|
2013-01-18 17:36:49 +04:00
|
|
|
error++;
|
2011-07-13 05:43:52 +04:00
|
|
|
|
|
|
|
/* subjectPublicKeyInfo */
|
2013-05-09 01:48:30 +04:00
|
|
|
if (!ber_read_sequence_tag(s, &length)) /* SubjectPublicKeyInfo (SEQUENCE) */
|
2013-01-12 17:49:01 +04:00
|
|
|
goto error1;
|
2013-01-18 17:36:49 +04:00
|
|
|
error++;
|
2011-07-13 05:43:52 +04:00
|
|
|
|
|
|
|
/* subjectPublicKeyInfo::AlgorithmIdentifier */
|
2013-05-09 01:48:30 +04:00
|
|
|
if (!ber_read_sequence_tag(s, &length) || !Stream_SafeSeek(s, length)) /* AlgorithmIdentifier (SEQUENCE) */
|
2013-01-12 17:49:01 +04:00
|
|
|
goto error1;
|
2013-01-18 17:36:49 +04:00
|
|
|
error++;
|
2011-07-13 05:43:52 +04:00
|
|
|
|
|
|
|
/* subjectPublicKeyInfo::subjectPublicKey */
|
2013-05-09 01:48:30 +04:00
|
|
|
if (!ber_read_bit_string(s, &length, &padding)) /* BIT_STRING */
|
2013-01-12 17:49:01 +04:00
|
|
|
goto error1;
|
2013-01-18 17:36:49 +04:00
|
|
|
error++;
|
2011-07-13 07:50:51 +04:00
|
|
|
|
|
|
|
/* RSAPublicKey (SEQUENCE) */
|
2013-05-09 01:48:30 +04:00
|
|
|
if (!ber_read_sequence_tag(s, &length)) /* SEQUENCE */
|
2013-01-12 17:49:01 +04:00
|
|
|
goto error1;
|
2013-01-18 17:36:49 +04:00
|
|
|
error++;
|
2011-07-13 07:50:51 +04:00
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
if (!ber_read_integer_length(s, &modulus_length)) /* modulus (INTEGER) */
|
2013-01-12 17:49:01 +04:00
|
|
|
goto error1;
|
2013-01-18 17:36:49 +04:00
|
|
|
error++;
|
2011-07-13 23:10:43 +04:00
|
|
|
|
|
|
|
/* skip zero padding, if any */
|
|
|
|
do
|
|
|
|
{
|
2013-05-09 01:48:30 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 1)
|
2013-01-12 17:49:01 +04:00
|
|
|
goto error1;
|
2013-05-09 01:48:30 +04:00
|
|
|
|
2013-05-09 00:27:21 +04:00
|
|
|
Stream_Peek_UINT8(s, padding);
|
2011-07-13 23:10:43 +04:00
|
|
|
|
|
|
|
if (padding == 0)
|
|
|
|
{
|
2013-05-09 01:48:30 +04:00
|
|
|
if (!Stream_SafeSeek(s, 1))
|
2013-01-12 17:49:01 +04:00
|
|
|
goto error1;
|
2013-05-09 01:48:30 +04:00
|
|
|
|
2011-07-13 23:10:43 +04:00
|
|
|
modulus_length--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (padding == 0);
|
2013-05-09 01:48:30 +04:00
|
|
|
|
2013-01-18 17:36:49 +04:00
|
|
|
error++;
|
2011-07-13 23:10:43 +04:00
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < modulus_length)
|
2013-01-12 17:49:01 +04:00
|
|
|
goto error1;
|
2013-05-09 01:48:30 +04:00
|
|
|
|
2012-09-24 12:40:32 +04:00
|
|
|
info->ModulusLength = modulus_length;
|
|
|
|
info->Modulus = (BYTE*) malloc(info->ModulusLength);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read(s, info->Modulus, info->ModulusLength);
|
2013-01-18 17:36:49 +04:00
|
|
|
error++;
|
2011-07-13 07:50:51 +04:00
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
if (!ber_read_integer_length(s, &exponent_length)) /* publicExponent (INTEGER) */
|
2013-01-12 17:49:01 +04:00
|
|
|
goto error2;
|
2013-05-09 01:48:30 +04:00
|
|
|
|
2013-01-18 17:36:49 +04:00
|
|
|
error++;
|
2013-05-09 01:48:30 +04:00
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < exponent_length || exponent_length > 4)
|
2013-01-12 17:49:01 +04:00
|
|
|
goto error2;
|
2013-05-09 01:48:30 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read(s, &info->exponent[4 - exponent_length], exponent_length);
|
2012-09-24 12:40:32 +04:00
|
|
|
crypto_reverse(info->Modulus, info->ModulusLength);
|
2011-09-19 19:56:12 +04:00
|
|
|
crypto_reverse(info->exponent, 4);
|
2012-02-02 06:11:46 +04:00
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
Stream_Free(s, FALSE);
|
2013-01-12 17:49:01 +04:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
error2:
|
|
|
|
free(info->Modulus);
|
2013-01-14 02:37:50 +04:00
|
|
|
info->Modulus = 0;
|
2013-01-12 17:49:01 +04:00
|
|
|
error1:
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "error reading when reading certificate: part=%s error=%d\n", certificate_read_errors[error], error);
|
2013-05-09 01:48:30 +04:00
|
|
|
Stream_Free(s, FALSE);
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
2011-07-13 05:43:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiate new X.509 Certificate Chain.
|
|
|
|
* @param count certificate chain count
|
|
|
|
* @return new X.509 certificate chain
|
|
|
|
*/
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
rdpX509CertChain* certificate_new_x509_certificate_chain(UINT32 count)
|
2011-07-13 02:18:24 +04:00
|
|
|
{
|
2011-08-16 23:00:25 +04:00
|
|
|
rdpX509CertChain* x509_cert_chain;
|
2011-07-13 02:18:24 +04:00
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
x509_cert_chain = (rdpX509CertChain*) malloc(sizeof(rdpX509CertChain));
|
2011-07-13 02:18:24 +04:00
|
|
|
|
|
|
|
x509_cert_chain->count = count;
|
2012-11-22 04:22:41 +04:00
|
|
|
x509_cert_chain->array = (rdpCertBlob*) malloc(sizeof(rdpCertBlob) * count);
|
|
|
|
ZeroMemory(x509_cert_chain->array, sizeof(rdpCertBlob) * count);
|
2011-07-13 02:18:24 +04:00
|
|
|
|
|
|
|
return x509_cert_chain;
|
|
|
|
}
|
|
|
|
|
2011-07-13 05:43:52 +04:00
|
|
|
/**
|
|
|
|
* Free X.509 Certificate Chain.
|
|
|
|
* @param x509_cert_chain X.509 certificate chain to be freed
|
|
|
|
*/
|
|
|
|
|
2011-08-16 23:00:25 +04:00
|
|
|
void certificate_free_x509_certificate_chain(rdpX509CertChain* x509_cert_chain)
|
2011-07-13 02:18:24 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2012-02-02 06:11:46 +04:00
|
|
|
if (x509_cert_chain != NULL)
|
2011-07-13 02:18:24 +04:00
|
|
|
{
|
2012-02-02 06:11:46 +04:00
|
|
|
for (i = 0; i < (int) x509_cert_chain->count; i++)
|
|
|
|
{
|
|
|
|
if (x509_cert_chain->array[i].data != NULL)
|
2012-10-09 07:21:26 +04:00
|
|
|
free(x509_cert_chain->array[i].data);
|
2012-02-02 06:11:46 +04:00
|
|
|
}
|
2011-07-13 02:18:24 +04:00
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(x509_cert_chain->array);
|
|
|
|
free(x509_cert_chain);
|
2012-02-02 06:11:46 +04:00
|
|
|
}
|
2011-07-13 02:18:24 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static BOOL certificate_process_server_public_key(rdpCertificate* certificate, wStream* s, UINT32 length)
|
2011-09-05 22:02:52 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE magic[4];
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 keylen;
|
|
|
|
UINT32 bitlen;
|
|
|
|
UINT32 datalen;
|
|
|
|
UINT32 modlen;
|
2011-09-05 22:02:52 +04:00
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 20)
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read(s, magic, 4);
|
2012-09-24 12:40:32 +04:00
|
|
|
|
2011-09-05 22:02:52 +04:00
|
|
|
if (memcmp(magic, "RSA1", 4) != 0)
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "gcc_process_server_public_key: magic error\n");
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-09-05 22:02:52 +04:00
|
|
|
}
|
2011-09-15 06:09:33 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, keylen);
|
|
|
|
Stream_Read_UINT32(s, bitlen);
|
|
|
|
Stream_Read_UINT32(s, datalen);
|
|
|
|
Stream_Read(s, certificate->cert_info.exponent, 4);
|
2011-09-05 22:02:52 +04:00
|
|
|
modlen = keylen - 8;
|
2012-09-24 12:40:32 +04:00
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < modlen + 8) // count padding
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
2012-09-24 12:40:32 +04:00
|
|
|
certificate->cert_info.ModulusLength = modlen;
|
|
|
|
certificate->cert_info.Modulus = malloc(certificate->cert_info.ModulusLength);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read(s, certificate->cert_info.Modulus, certificate->cert_info.ModulusLength);
|
2012-01-25 19:55:03 +04:00
|
|
|
/* 8 bytes of zero padding */
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek(s, 8);
|
2011-09-15 06:09:33 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-09-05 22:02:52 +04:00
|
|
|
}
|
|
|
|
|
2013-01-14 02:37:50 +04:00
|
|
|
static BOOL certificate_process_server_public_signature(rdpCertificate* certificate,
|
2013-03-21 23:19:33 +04:00
|
|
|
const BYTE* sigdata, int sigdatalen, wStream* s, UINT32 siglen)
|
2011-09-05 22:02:52 +04:00
|
|
|
{
|
2012-01-19 07:42:19 +04:00
|
|
|
int i, sum;
|
2012-09-24 12:40:32 +04:00
|
|
|
CryptoMd5 md5ctx;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE sig[TSSK_KEY_LENGTH];
|
|
|
|
BYTE encsig[TSSK_KEY_LENGTH + 8];
|
|
|
|
BYTE md5hash[CRYPTO_MD5_DIGEST_LENGTH];
|
2012-01-19 07:42:19 +04:00
|
|
|
|
|
|
|
md5ctx = crypto_md5_init();
|
|
|
|
crypto_md5_update(md5ctx, sigdata, sigdatalen);
|
|
|
|
crypto_md5_final(md5ctx, md5hash);
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read(s, encsig, siglen);
|
2012-02-03 02:36:07 +04:00
|
|
|
|
2012-01-19 07:42:19 +04:00
|
|
|
/* Last 8 bytes shall be all zero. */
|
2012-02-03 02:36:07 +04:00
|
|
|
|
2012-01-19 07:42:19 +04:00
|
|
|
for (sum = 0, i = sizeof(encsig) - 8; i < sizeof(encsig); i++)
|
|
|
|
sum += encsig[i];
|
2012-02-03 02:36:07 +04:00
|
|
|
|
|
|
|
if (sum != 0)
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "certificate_process_server_public_signature: invalid signature\n");
|
2012-10-09 10:31:28 +04:00
|
|
|
//return FALSE;
|
2012-01-19 07:42:19 +04:00
|
|
|
}
|
2012-02-03 02:36:07 +04:00
|
|
|
|
2012-01-19 07:42:19 +04:00
|
|
|
siglen -= 8;
|
|
|
|
|
|
|
|
crypto_rsa_public_decrypt(encsig, siglen, TSSK_KEY_LENGTH, tssk_modulus, tssk_exponent, sig);
|
|
|
|
|
|
|
|
/* Verify signature. */
|
2012-02-03 02:36:07 +04:00
|
|
|
if (memcmp(md5hash, sig, sizeof(md5hash)) != 0)
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "certificate_process_server_public_signature: invalid signature\n");
|
2012-10-09 10:31:28 +04:00
|
|
|
//return FALSE;
|
2012-01-19 07:42:19 +04:00
|
|
|
}
|
2012-02-03 02:36:07 +04:00
|
|
|
|
2012-01-19 07:42:19 +04:00
|
|
|
/*
|
|
|
|
* Verify rest of decrypted data:
|
|
|
|
* The 17th byte is 0x00.
|
|
|
|
* The 18th through 62nd bytes are each 0xFF.
|
|
|
|
* The 63rd byte is 0x01.
|
|
|
|
*/
|
2012-02-03 02:36:07 +04:00
|
|
|
|
2012-01-19 07:42:19 +04:00
|
|
|
for (sum = 0, i = 17; i < 62; i++)
|
|
|
|
sum += sig[i];
|
2012-02-03 02:36:07 +04:00
|
|
|
|
|
|
|
if (sig[16] != 0x00 || sum != 0xFF * (62 - 17) || sig[62] != 0x01)
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "certificate_process_server_public_signature: invalid signature\n");
|
2012-10-09 10:31:28 +04:00
|
|
|
//return FALSE;
|
2012-01-19 07:42:19 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-09-05 22:02:52 +04:00
|
|
|
}
|
|
|
|
|
2011-07-13 05:43:52 +04:00
|
|
|
/**
|
|
|
|
* Read a Server Proprietary Certificate.\n
|
|
|
|
* @param certificate certificate module
|
|
|
|
* @param s stream
|
|
|
|
*/
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL certificate_read_server_proprietary_certificate(rdpCertificate* certificate, wStream* s)
|
2011-07-13 02:18:24 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 dwSigAlgId;
|
|
|
|
UINT32 dwKeyAlgId;
|
|
|
|
UINT32 wPublicKeyBlobType;
|
|
|
|
UINT32 wPublicKeyBlobLen;
|
|
|
|
UINT32 wSignatureBlobType;
|
|
|
|
UINT32 wSignatureBlobLen;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* sigdata;
|
2012-01-19 07:42:19 +04:00
|
|
|
int sigdatalen;
|
2011-09-05 22:02:52 +04:00
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 12)
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
|
|
|
|
2012-01-19 07:42:19 +04:00
|
|
|
/* -4, because we need to include dwVersion */
|
2013-04-30 06:35:15 +04:00
|
|
|
sigdata = Stream_Pointer(s) - 4;
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, dwSigAlgId);
|
|
|
|
Stream_Read_UINT32(s, dwKeyAlgId);
|
2012-09-24 12:40:32 +04:00
|
|
|
|
2012-01-17 20:55:31 +04:00
|
|
|
if (!(dwSigAlgId == SIGNATURE_ALG_RSA && dwKeyAlgId == KEY_EXCHANGE_ALG_RSA))
|
2011-09-05 22:02:52 +04:00
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "certificate_read_server_proprietary_certificate: parse error 1\n");
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-09-05 22:02:52 +04:00
|
|
|
}
|
2012-09-24 12:40:32 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, wPublicKeyBlobType);
|
2012-09-24 12:40:32 +04:00
|
|
|
|
2011-09-05 22:02:52 +04:00
|
|
|
if (wPublicKeyBlobType != BB_RSA_KEY_BLOB)
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "certificate_read_server_proprietary_certificate: parse error 2\n");
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-09-05 22:02:52 +04:00
|
|
|
}
|
2012-09-24 12:40:32 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, wPublicKeyBlobLen);
|
2013-05-09 01:48:30 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < wPublicKeyBlobLen)
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
2012-09-24 12:40:32 +04:00
|
|
|
|
2011-09-05 22:02:52 +04:00
|
|
|
if (!certificate_process_server_public_key(certificate, s, wPublicKeyBlobLen))
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "certificate_read_server_proprietary_certificate: parse error 3\n");
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-09-05 22:02:52 +04:00
|
|
|
}
|
2012-09-24 12:40:32 +04:00
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
sigdatalen = Stream_Pointer(s) - sigdata;
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, wSignatureBlobType);
|
2012-09-24 12:40:32 +04:00
|
|
|
|
2011-09-05 22:02:52 +04:00
|
|
|
if (wSignatureBlobType != BB_RSA_SIGNATURE_BLOB)
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "certificate_read_server_proprietary_certificate: parse error 4\n");
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-09-05 22:02:52 +04:00
|
|
|
}
|
2012-09-24 12:40:32 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, wSignatureBlobLen);
|
2013-05-09 01:48:30 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < wSignatureBlobLen)
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
2012-09-24 12:40:32 +04:00
|
|
|
|
2012-02-04 11:21:39 +04:00
|
|
|
if (wSignatureBlobLen != 72)
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "certificate_process_server_public_signature: invalid signature length (got %d, expected %d)\n", wSignatureBlobLen, 64);
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-01-19 07:42:19 +04:00
|
|
|
}
|
2012-09-24 12:40:32 +04:00
|
|
|
|
2012-01-19 07:42:19 +04:00
|
|
|
if (!certificate_process_server_public_signature(certificate, sigdata, sigdatalen, s, wSignatureBlobLen))
|
2011-09-05 22:02:52 +04:00
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "certificate_read_server_proprietary_certificate: parse error 5\n");
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-09-05 22:02:52 +04:00
|
|
|
}
|
2011-09-15 06:09:33 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-07-13 02:18:24 +04:00
|
|
|
}
|
|
|
|
|
2011-07-13 05:43:52 +04:00
|
|
|
/**
|
|
|
|
* Read an X.509 Certificate Chain.\n
|
|
|
|
* @param certificate certificate module
|
|
|
|
* @param s stream
|
|
|
|
*/
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL certificate_read_server_x509_certificate_chain(rdpCertificate* certificate, wStream* s)
|
2011-07-13 02:18:24 +04:00
|
|
|
{
|
|
|
|
int i;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 certLength;
|
|
|
|
UINT32 numCertBlobs;
|
2013-01-14 02:37:50 +04:00
|
|
|
BOOL ret;
|
2011-07-13 02:18:24 +04:00
|
|
|
|
2011-07-15 09:11:09 +04:00
|
|
|
DEBUG_CERTIFICATE("Server X.509 Certificate Chain");
|
2011-07-13 02:18:24 +04:00
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, numCertBlobs); /* numCertBlobs */
|
2011-07-13 02:18:24 +04:00
|
|
|
|
|
|
|
certificate->x509_cert_chain = certificate_new_x509_certificate_chain(numCertBlobs);
|
|
|
|
|
2011-08-17 05:08:14 +04:00
|
|
|
for (i = 0; i < (int) numCertBlobs; i++)
|
2011-07-13 02:18:24 +04:00
|
|
|
{
|
2013-05-09 01:48:30 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
2013-05-09 01:48:30 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, certLength);
|
2013-05-09 01:48:30 +04:00
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < certLength)
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
2011-07-13 02:18:24 +04:00
|
|
|
|
2011-07-15 09:11:09 +04:00
|
|
|
DEBUG_CERTIFICATE("\nX.509 Certificate #%d, length:%d", i + 1, certLength);
|
2011-07-13 02:18:24 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
certificate->x509_cert_chain->array[i].data = (BYTE*) malloc(certLength);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read(s, certificate->x509_cert_chain->array[i].data, certLength);
|
2011-07-13 07:50:51 +04:00
|
|
|
certificate->x509_cert_chain->array[i].length = certLength;
|
|
|
|
|
2011-07-13 02:18:24 +04:00
|
|
|
if (numCertBlobs - i == 2)
|
2011-07-13 07:50:51 +04:00
|
|
|
{
|
2011-08-16 23:00:25 +04:00
|
|
|
rdpCertInfo cert_info;
|
2011-07-15 09:11:09 +04:00
|
|
|
DEBUG_CERTIFICATE("License Server Certificate");
|
2013-01-14 02:37:50 +04:00
|
|
|
ret = certificate_read_x509_certificate(&certificate->x509_cert_chain->array[i], &cert_info);
|
2012-10-09 22:52:07 +04:00
|
|
|
DEBUG_LICENSE("modulus length:%d", (int) cert_info.ModulusLength);
|
2013-01-19 18:28:07 +04:00
|
|
|
if (cert_info.Modulus)
|
2013-01-16 21:10:54 +04:00
|
|
|
free(cert_info.Modulus);
|
2013-01-19 18:28:07 +04:00
|
|
|
if (!ret) {
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "failed to read License Server, content follows:\n");
|
2013-01-19 18:28:07 +04:00
|
|
|
winpr_HexDump(certificate->x509_cert_chain->array[i].data, certificate->x509_cert_chain->array[i].length);
|
2013-01-14 02:37:50 +04:00
|
|
|
return FALSE;
|
2013-01-19 18:28:07 +04:00
|
|
|
}
|
2011-07-13 07:50:51 +04:00
|
|
|
}
|
2011-07-13 02:18:24 +04:00
|
|
|
else if (numCertBlobs - i == 1)
|
2011-07-13 07:50:51 +04:00
|
|
|
{
|
2011-07-15 09:11:09 +04:00
|
|
|
DEBUG_CERTIFICATE("Terminal Server Certificate");
|
2013-01-14 02:37:50 +04:00
|
|
|
if (!certificate_read_x509_certificate(&certificate->x509_cert_chain->array[i], &certificate->cert_info))
|
|
|
|
return FALSE;
|
2012-10-09 22:52:07 +04:00
|
|
|
DEBUG_CERTIFICATE("modulus length:%d", (int) certificate->cert_info.ModulusLength);
|
2011-07-13 07:50:51 +04:00
|
|
|
}
|
2011-07-13 02:18:24 +04:00
|
|
|
}
|
2011-09-15 06:09:33 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-07-13 02:18:24 +04:00
|
|
|
}
|
|
|
|
|
2011-07-13 05:43:52 +04:00
|
|
|
/**
|
|
|
|
* Read a Server Certificate.\n
|
|
|
|
* @param certificate certificate module
|
|
|
|
* @param server_cert server certificate
|
|
|
|
* @param length certificate length
|
|
|
|
*/
|
|
|
|
|
2013-01-25 22:47:56 +04:00
|
|
|
int certificate_read_server_certificate(rdpCertificate* certificate, BYTE* server_cert, int length)
|
2011-07-13 02:18:24 +04:00
|
|
|
{
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* s;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 dwVersion;
|
2013-01-25 22:47:56 +04:00
|
|
|
int status = 1;
|
2011-07-13 02:18:24 +04:00
|
|
|
|
|
|
|
if (length < 1)
|
|
|
|
{
|
2012-02-29 00:31:09 +04:00
|
|
|
DEBUG_CERTIFICATE("null server certificate\n");
|
2013-01-25 22:47:56 +04:00
|
|
|
return 0;
|
2011-07-13 02:18:24 +04:00
|
|
|
}
|
|
|
|
|
2013-01-12 17:49:01 +04:00
|
|
|
if (length < 4)
|
2013-01-25 22:47:56 +04:00
|
|
|
return -1;
|
2013-01-12 17:49:01 +04:00
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
s = Stream_New(server_cert, length);
|
2012-02-29 00:31:09 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, dwVersion); /* dwVersion (4 bytes) */
|
2011-07-13 02:18:24 +04:00
|
|
|
|
|
|
|
switch (dwVersion & CERT_CHAIN_VERSION_MASK)
|
|
|
|
{
|
|
|
|
case CERT_CHAIN_VERSION_1:
|
2013-01-25 22:47:56 +04:00
|
|
|
status = certificate_read_server_proprietary_certificate(certificate, s);
|
2011-07-13 02:18:24 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CERT_CHAIN_VERSION_2:
|
2013-01-25 22:47:56 +04:00
|
|
|
status = certificate_read_server_x509_certificate_chain(certificate, s);
|
2011-07-13 02:18:24 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "invalid certificate chain version:%d\n", dwVersion & CERT_CHAIN_VERSION_MASK);
|
2013-01-25 22:47:56 +04:00
|
|
|
status = -1;
|
2011-07-13 02:18:24 +04:00
|
|
|
break;
|
|
|
|
}
|
2011-09-05 22:02:52 +04:00
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
Stream_Free(s, FALSE);
|
2013-01-25 22:47:56 +04:00
|
|
|
|
|
|
|
return status;
|
2011-07-13 02:18:24 +04:00
|
|
|
}
|
|
|
|
|
2012-11-08 08:29:24 +04:00
|
|
|
rdpRsaKey* key_new(const char* keyfile)
|
2012-01-25 19:45:21 +04:00
|
|
|
{
|
2012-09-24 12:40:32 +04:00
|
|
|
FILE* fp;
|
|
|
|
RSA* rsa;
|
2012-11-08 08:29:24 +04:00
|
|
|
rdpRsaKey* key;
|
2012-01-25 19:45:21 +04:00
|
|
|
|
2012-11-22 04:22:41 +04:00
|
|
|
key = (rdpRsaKey*) malloc(sizeof(rdpRsaKey));
|
|
|
|
ZeroMemory(key, sizeof(rdpRsaKey));
|
2012-02-03 02:36:07 +04:00
|
|
|
|
2012-01-25 19:45:21 +04:00
|
|
|
if (key == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
fp = fopen(keyfile, "r");
|
2012-02-03 02:36:07 +04:00
|
|
|
|
|
|
|
if (fp == NULL)
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "unable to load RSA key from %s: %s.", keyfile, strerror(errno));
|
2012-10-09 07:21:26 +04:00
|
|
|
free(key) ;
|
2012-01-25 19:45:21 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-02-03 02:36:07 +04:00
|
|
|
|
2012-01-25 19:45:21 +04:00
|
|
|
rsa = PEM_read_RSAPrivateKey(fp, NULL, NULL, NULL);
|
2012-02-03 02:36:07 +04:00
|
|
|
|
|
|
|
if (rsa == NULL)
|
|
|
|
{
|
2012-01-25 19:45:21 +04:00
|
|
|
ERR_print_errors_fp(stdout);
|
|
|
|
fclose(fp);
|
2012-10-09 07:21:26 +04:00
|
|
|
free(key) ;
|
2012-01-25 19:45:21 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-02-03 02:36:07 +04:00
|
|
|
|
2012-01-25 19:45:21 +04:00
|
|
|
fclose(fp);
|
|
|
|
|
2012-02-03 02:36:07 +04:00
|
|
|
switch (RSA_check_key(rsa))
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
RSA_free(rsa);
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "invalid RSA key in %s", keyfile);
|
2012-10-09 07:21:26 +04:00
|
|
|
free(key) ;
|
2012-02-03 02:36:07 +04:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
/* Valid key. */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2013-03-29 02:06:34 +04:00
|
|
|
ERR_print_errors_fp(stderr);
|
2012-02-03 02:36:07 +04:00
|
|
|
RSA_free(rsa);
|
2012-10-09 07:21:26 +04:00
|
|
|
free(key) ;
|
2012-02-03 02:36:07 +04:00
|
|
|
return NULL;
|
2012-01-25 19:45:21 +04:00
|
|
|
}
|
|
|
|
|
2012-02-03 02:36:07 +04:00
|
|
|
if (BN_num_bytes(rsa->e) > 4)
|
|
|
|
{
|
2012-01-25 19:45:21 +04:00
|
|
|
RSA_free(rsa);
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "RSA public exponent too large in %s", keyfile);
|
2012-10-09 07:21:26 +04:00
|
|
|
free(key) ;
|
2012-01-25 19:45:21 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-09-24 12:40:32 +04:00
|
|
|
key->ModulusLength = BN_num_bytes(rsa->n);
|
|
|
|
key->Modulus = (BYTE*) malloc(key->ModulusLength);
|
|
|
|
BN_bn2bin(rsa->n, key->Modulus);
|
|
|
|
crypto_reverse(key->Modulus, key->ModulusLength);
|
|
|
|
|
|
|
|
key->PrivateExponentLength = BN_num_bytes(rsa->d);
|
|
|
|
key->PrivateExponent = (BYTE*) malloc(key->PrivateExponentLength);
|
|
|
|
BN_bn2bin(rsa->d, key->PrivateExponent);
|
|
|
|
crypto_reverse(key->PrivateExponent, key->PrivateExponentLength);
|
|
|
|
|
2012-01-25 19:45:21 +04:00
|
|
|
memset(key->exponent, 0, sizeof(key->exponent));
|
|
|
|
BN_bn2bin(rsa->e, key->exponent + sizeof(key->exponent) - BN_num_bytes(rsa->e));
|
|
|
|
crypto_reverse(key->exponent, sizeof(key->exponent));
|
|
|
|
|
|
|
|
RSA_free(rsa);
|
|
|
|
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
2012-11-08 08:29:24 +04:00
|
|
|
void key_free(rdpRsaKey* key)
|
2012-01-25 19:45:21 +04:00
|
|
|
{
|
|
|
|
if (key != NULL)
|
|
|
|
{
|
2012-09-24 12:40:32 +04:00
|
|
|
free(key->Modulus);
|
|
|
|
free(key->PrivateExponent);
|
2012-10-09 07:21:26 +04:00
|
|
|
free(key);
|
2012-01-25 19:45:21 +04:00
|
|
|
}
|
|
|
|
}
|
2012-02-03 02:36:07 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiate new certificate module.\n
|
|
|
|
* @param rdp RDP module
|
|
|
|
* @return new certificate module
|
|
|
|
*/
|
|
|
|
|
2012-02-03 03:20:02 +04:00
|
|
|
rdpCertificate* certificate_new()
|
2012-02-03 02:36:07 +04:00
|
|
|
{
|
|
|
|
rdpCertificate* certificate;
|
|
|
|
|
2012-11-22 04:22:41 +04:00
|
|
|
certificate = (rdpCertificate*) malloc(sizeof(rdpCertificate));
|
|
|
|
ZeroMemory(certificate, sizeof(rdpCertificate));
|
2012-02-03 02:36:07 +04:00
|
|
|
|
|
|
|
if (certificate != NULL)
|
|
|
|
{
|
|
|
|
certificate->x509_cert_chain = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return certificate;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free certificate module.
|
|
|
|
* @param certificate certificate module to be freed
|
|
|
|
*/
|
|
|
|
|
|
|
|
void certificate_free(rdpCertificate* certificate)
|
|
|
|
{
|
|
|
|
if (certificate != NULL)
|
|
|
|
{
|
|
|
|
certificate_free_x509_certificate_chain(certificate->x509_cert_chain);
|
|
|
|
|
2012-09-24 12:40:32 +04:00
|
|
|
if (certificate->cert_info.Modulus != NULL)
|
|
|
|
free(certificate->cert_info.Modulus);
|
2012-02-03 02:36:07 +04:00
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(certificate);
|
2012-02-03 02:36:07 +04:00
|
|
|
}
|
|
|
|
}
|