Add OCSP parsing files as part of the X509 module

OCSP by itself is a protocol between an OCSP responder and a client.
The protocol messages are encoded in X.509 format, so I have created
the place-holder files x509_ocsp.c and x509_ocsp.h that will contain
the X.509 parser and verification for OCSP messages.
This commit is contained in:
Andres Amaya Garcia
2017-08-24 16:01:02 +01:00
committed by Andres Amaya Garcia
parent 4cfdb54e2c
commit 22b1db8a4c
4 changed files with 131 additions and 1 deletions

View File

@@ -0,0 +1,52 @@
/**
* \file x509_ocsp.h
*
* \brief OCSP generic defines and structures
*
* Copyright (C) 2017, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
* 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.
*
* This file is part of mbed TLS (https://tls.mbed.org)
*/
#ifndef MBEDTLS_X509_OCSP_H
#define MBEDTLS_X509_OCSP_H
#if !defined(MBEDTLS_CONFIG_FILE)
#include "config.h"
#else
#include MBEDTLS_CONFIG_FILE
#endif
#include "x509.h"
#include "x509_crt.h"
#include "md.h"
#include "pk.h"
#include <stdint.h>
typedef struct mbedtls_x509_ocsp_response {
} mbedtls_x509_ocsp_response;
int mbedtls_x509_ocsp_response_info( char *buf, size_t size,
const char *prefix,
const mbedtls_x509_ocsp_response *resp );
int mbedtls_x509_ocsp_parse_response_file( mbedtls_x509_ocsp_response *resp,
const char *path );
int mbedtls_x509_ocsp_parse_response( mbedtls_x509_ocsp_response *resp,
unsigned char *buf, size_t buflen );
#endif /* !MBEDTLS_X509_OCSP_H */

View File

@@ -66,6 +66,7 @@ set(src_x509
x509_crl.c
x509_crt.c
x509_csr.c
x509_ocsp.c
x509write_crt.c
x509write_csr.c
)

View File

@@ -66,7 +66,8 @@ OBJS_CRYPTO= aes.o aesni.o arc4.o \
OBJS_X509= certs.o pkcs11.o x509.o \
x509_create.o x509_crl.o x509_crt.o \
x509_csr.o x509write_crt.o x509write_csr.o
x509_csr.o x509write_crt.o x509write_csr.o \
x509_ocsp.o
OBJS_TLS= debug.o net_sockets.o \
ssl_cache.o ssl_ciphersuites.o \

76
library/x509_ocsp.c Normal file
View File

@@ -0,0 +1,76 @@
/*
* OCSP response parsing and verification
*
* Copyright (C) 2017, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
* 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.
*
* This file is part of mbed TLS (https://tls.mbed.org)
*/
#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
#include MBEDTLS_CONFIG_FILE
#endif
#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <stdlib.h>
#define mbedtls_free free
#define mbedtls_calloc calloc
#define mbedtls_snprintf snprintf
#endif
#include "mbedtls/x509.h"
#include "mbedtls/x509_crt.h"
#include "mbedtls/x509_ocsp.h"
#include "mbedtls/asn1.h"
#include "mbedtls/md.h"
#include "mbedtls/pk.h"
#include "mbedtls/oid.h"
#include <stdint.h>
#include <string.h>
int mbedtls_x509_ocsp_parse_response( mbedtls_x509_ocsp_response *resp,
unsigned char *buf, size_t buflen )
{
return( 0 );
}
int mbedtls_x509_ocsp_response_info( char *buf, size_t size,
const char *prefix,
const mbedtls_x509_ocsp_response *resp )
{
return( 0 );
}
int mbedtls_x509_ocsp_parse_response_file( mbedtls_x509_ocsp_response *resp,
const char *path )
{
int ret;
size_t n;
unsigned char *buf;
if( ( ret = mbedtls_pk_load_file( path, &buf, &n ) ) != 0 )
return( ret );
ret = mbedtls_x509_ocsp_parse_response( resp, buf, n );
mbedtls_zeroize( buf, n );
mbedtls_free( buf );
return( ret );
}